jlint debugging...
[mir.git] / source / mircoders / entity / EntityImages.java
1 package mircoders.entity;
2
3 import java.lang.*;
4 import java.io.*;
5 import java.util.*;
6 import java.sql.*;
7
8 import mir.entity.*;
9 import mir.misc.*;
10 import mir.storage.*;
11
12 /**
13  * Diese Klasse enthält die Daten eines MetaObjekts
14  *
15  * @author RK
16  * @version 11.11.2000
17  */
18
19
20 public class EntityImages extends Entity
21 {
22         public EntityImages()
23         {
24                 super();
25         }
26
27         public EntityImages(StorageObject theStorage) {
28                 this();
29                 setStorage(theStorage);
30         }
31
32         //
33         // methods
34
35
36
37         public byte[] getImage() throws StorageObjectException
38         {
39                 theLog.printDebugInfo("--getimage started");
40                 Connection con=null;Statement stmt=null;
41                 byte[] img_data=null;
42
43                 try {
44                         con = theStorageObject.getPooledCon();
45                         con.setAutoCommit(false);
46                         stmt = con.createStatement();
47                         ResultSet rs = theStorageObject.executeSql(stmt,"select image_data from images where id="+getId());
48                         if(rs!=null) {
49                                 if (rs.next()) {
50                                          img_data = rs.getBytes(1);
51                                 }
52                                 rs.close();
53                         }
54                 }
55                 catch (Exception e) {throwStorageObjectException(e, "-- getImage gescheitert: ");}
56                 finally {
57                         try {con.setAutoCommit(true); } catch (Exception e) {;}
58                         theStorageObject.freeConnection(con,stmt); }
59
60                 return img_data;
61         }
62
63         public void setImage(byte[] uploadData, String imageType)
64             throws StorageObjectException {
65         int type = 0;
66
67         //hack -mh
68         if (imageType.equals("1"))
69             type = 1;
70          //end hack
71
72                 if (uploadData!=null) {
73                         Connection con=null;PreparedStatement pstmt=null;
74                         try {
75
76                                 theLog.printDebugInfo("settimage :: making internal representation of image");
77                                 WebdbImage webdbImage= new WebdbImage(uploadData,type);
78                                 theLog.printDebugInfo("settimage :: made internal representation of image");
79                                 byte[] imageData = webdbImage.getImage();
80                                 theLog.printDebugInfo("settimage :: getImage");
81                                 byte[] iconData = webdbImage.getIcon();
82                                 theLog.printDebugInfo("settimage :: getIcon");
83
84                                 if (iconData!=null && imageData!=null) {
85                                         con = theStorageObject.getPooledCon();
86                                         con.setAutoCommit(false);
87                                         theLog.printDebugInfo("settimage :: trying to insert image");
88
89                                         // setting values
90                                         String sql = "update images set img_height='"+webdbImage.getImageHeight() +
91                                                 "',img_width='"   + webdbImage.getImageWidth() +
92                                                 "',icon_height='" + webdbImage.getIconHeight() +
93                                                 "',icon_width='"  + webdbImage.getIconWidth()  +  "', image_data=?, icon_data=? where id="+getId();
94                                         theLog.printDebugInfo("settimage :: updating sizes: "+ sql);
95                                         pstmt = con.prepareStatement(sql);
96                                         pstmt.setBytes(1, imageData);
97                                         pstmt.setBytes(2, iconData);
98                                         pstmt.executeUpdate();
99                                         sql="update content set is_produced='0' where to_media="+getId();
100                                         pstmt = con.prepareStatement(sql);
101                                         pstmt.executeUpdate();
102                                 }
103                         }
104                         catch (Exception e) {throwStorageObjectException(e, "settimage :: setImage gescheitert: ");}
105                         finally {
106                                 try { if (con!=null) con.setAutoCommit(true); } catch (Exception e) {;}
107                                 theStorageObject.freeConnection(con,pstmt); }
108                 }
109         }
110
111         public void update() throws StorageObjectException {
112                 super.update();
113                 try {
114                         theStorageObject.executeUpdate("update content set is_produced='0' where to_media="+getId());
115                 } catch (SQLException e) {
116                         throwStorageObjectException(e, "EntityImages :: update :: failed!! ");
117                 }
118         }
119
120         public void setValues(HashMap theStringValues)
121         {
122                 if (theStringValues != null) {
123                         if (!theStringValues.containsKey("is_published"))
124                          theStringValues.put("is_published","0");
125                 }
126                 super.setValues(theStringValues);
127         }
128
129         public byte[] getIcon() throws StorageObjectException
130         {
131                 Connection con=null;Statement stmt=null;
132                 byte[] img_data=null;
133
134                 try {
135                         con = theStorageObject.getPooledCon();
136                         con.setAutoCommit(false);
137                         stmt = con.createStatement();
138                         ResultSet rs = theStorageObject.executeSql(stmt,"select icon_data from images where id="+getId());
139                         if(rs!=null) {
140                                 if (rs.next()) {
141                                          img_data = rs.getBytes(1);
142                                 }
143                                 rs.close();
144                         }
145                 }
146                 catch (Exception e) {throwStorageObjectException(e, "-- getIcon gescheitert: ");}
147                 finally {
148                         try {con.setAutoCommit(true); } catch (Exception e) {;}
149                         theStorageObject.freeConnection(con,stmt); }
150
151                 return img_data;
152         }
153
154 }