1 package mircoders.entity;
13 * Diese Klasse enthält die Daten eines MetaObjekts
20 public class EntityImages extends Entity
22 private static int instances;
30 public EntityImages(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, String imageType)
71 if (imageType.equals("1"))
75 if (uploadData!=null) {
76 Connection con=null;PreparedStatement pstmt=null;
79 theLog.printDebugInfo("settimage :: making internal representation of image");
80 WebdbImage webdbImage= new WebdbImage(uploadData,type);
81 theLog.printDebugInfo("settimage :: made internal representation of image");
82 byte[] imageData = webdbImage.getImage();
83 theLog.printDebugInfo("settimage :: getImage");
84 byte[] iconData = webdbImage.getIcon();
85 theLog.printDebugInfo("settimage :: getIcon");
87 if (iconData!=null && imageData!=null) {
88 con = theStorageObject.getPooledCon();
89 con.setAutoCommit(false);
90 theLog.printDebugInfo("settimage :: trying to insert image");
93 String sql = "update images set img_height='"+webdbImage.getImageHeight() +
94 "',img_width='" + webdbImage.getImageWidth() +
95 "',icon_height='" + webdbImage.getIconHeight() +
96 "',icon_width='" + webdbImage.getIconWidth() + "', image_data=?, icon_data=? where id="+getId();
97 theLog.printDebugInfo("settimage :: updating sizes: "+ sql);
98 pstmt = con.prepareStatement(sql);
99 pstmt.setBytes(1, imageData);
100 pstmt.setBytes(2, iconData);
101 pstmt.executeUpdate();
102 sql="update content set is_produced='0' where to_media="+getId();
103 pstmt = con.prepareStatement(sql);
104 pstmt.executeUpdate();
107 catch (Exception e) {theLog.printDebugInfo("settimage :: setImage gescheitert: "+e.toString());}
109 try {con.setAutoCommit(true); } catch (Exception e) {;}
110 theStorageObject.freeConnection(con,pstmt); }
114 public void update() throws StorageObjectException {
117 theStorageObject.executeUpdate("update content set is_produced='0' where to_media="+getId());
118 } catch (SQLException e) {
119 theLog.printError("EntityImages :: update :: failed!! "+ e.toString());
123 public void setValues(HashMap theStringValues)
125 if (theStringValues != null) {
126 if (!theStringValues.containsKey("is_published"))
127 theStringValues.put("is_published","0");
129 super.setValues(theStringValues);
132 public byte[] getIcon()
134 Connection con=null;Statement stmt=null;
135 byte[] img_data=null;
138 con = theStorageObject.getPooledCon();
139 con.setAutoCommit(false);
140 stmt = con.createStatement();
141 ResultSet rs = theStorageObject.executeSql(stmt,"select icon_data from images where id="+getId());
144 img_data = rs.getBytes(1);
149 catch (Exception e) {theLog.printDebugInfo("-- getIcon gescheitert: "+e.toString());}
151 try {con.setAutoCommit(true); } catch (Exception e) {;}
152 theStorageObject.freeConnection(con,stmt); }
157 public void finalize() {