1 package mircoders.entity;
10 import webdb.storage.*;
13 * Diese Klasse enthält die Daten eines MetaObjekts
20 public class EntityImage extends AbstractEntity implements Entity
22 private static int instances;
30 public EntityImage(StorageObject theStorage) {
32 setStorage(theStorage);
40 public byte[] getImage()
42 theLog.printDebugInfo("--getimage started");
43 Connection con=null;Statement stmt=null;
47 con = theStorageObject.getPooledCon();
48 con.setAutoCommit(false);
49 stmt = con.createStatement();
50 ResultSet rs = theStorageObject.executeSql(stmt,"select image_data from images where id="+getId());
53 img_data = rs.getBytes(1);
58 catch (Exception e) {theLog.printDebugInfo("-- getImage gescheitert: "+e.toString());}
60 try {con.setAutoCommit(true); } catch (Exception e) {;}
61 theStorageObject.freeConnection(con,stmt); }
66 public void setImage(byte[] uploadData, int imageType)
68 if (uploadData!=null) {
69 Connection con=null;PreparedStatement pstmt=null;
72 theLog.printDebugInfo("settimage :: making internal representation of image");
73 WebdbImage webdbImage= new WebdbImage(uploadData,imageType);
74 theLog.printDebugInfo("settimage :: made internal representation of image");
75 byte[] imageData = webdbImage.getImage();
76 theLog.printDebugInfo("settimage :: getImage");
77 byte[] iconData = webdbImage.getIcon();
78 theLog.printDebugInfo("settimage :: getIcon");
80 if (iconData!=null && imageData!=null) {
81 con = theStorageObject.getPooledCon();
82 con.setAutoCommit(false);
83 theLog.printDebugInfo("settimage :: trying to insert image");
86 String sql = "update images set img_height='"+webdbImage.getImageHeight() +
87 "',img_width='" + webdbImage.getImageWidth() +
88 "',icon_height='" + webdbImage.getIconHeight() +
89 "',icon_width='" + webdbImage.getIconWidth() + "', image_data=?, icon_data=? where id="+getId();
90 theLog.printDebugInfo("settimage :: updating sizes: "+ sql);
91 pstmt = con.prepareStatement(sql);
92 pstmt.setBytes(1, imageData);
93 pstmt.setBytes(2, iconData);
94 pstmt.executeUpdate();
95 sql="update content set is_produced='0' where to_media="+getId();
96 pstmt = con.prepareStatement(sql);
97 pstmt.executeUpdate();
100 catch (Exception e) {theLog.printDebugInfo("settimage :: setImage gescheitert: "+e.toString());}
102 try {con.setAutoCommit(true); } catch (Exception e) {;}
103 theStorageObject.freeConnection(con,pstmt); }
107 public void update() throws StorageObjectException {
110 theStorageObject.executeUpdate("update content set is_produced='0' where to_media="+getId());
111 } catch (SQLException e) {
112 theLog.printError("EntityImage :: update :: failed!! "+ e.toString());
116 public void setValues(HashMap theStringValues)
118 if (theStringValues != null) {
119 if (!theStringValues.containsKey("is_published"))
120 theStringValues.put("is_published","0");
122 super.setValues(theStringValues);
125 public byte[] getIcon()
127 Connection con=null;Statement stmt=null;
128 byte[] img_data=null;
131 con = theStorageObject.getPooledCon();
132 con.setAutoCommit(false);
133 stmt = con.createStatement();
134 ResultSet rs = theStorageObject.executeSql(stmt,"select icon_data from images where id="+getId());
137 img_data = rs.getBytes(1);
142 catch (Exception e) {theLog.printDebugInfo("-- getIcon gescheitert: "+e.toString());}
144 try {con.setAutoCommit(true); } catch (Exception e) {;}
145 theStorageObject.freeConnection(con,stmt); }
150 public void finalize() {