1 package mircoders.entity;
13 * Diese Klasse enthält die Daten eines MetaObjekts
20 public class EntityImages extends AbstractEntity implements 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"))
74 if (uploadData!=null) {
75 Connection con=null;PreparedStatement pstmt=null;
78 theLog.printDebugInfo("settimage :: making internal representation of image");
79 WebdbImage webdbImage= new WebdbImage(uploadData,type);
80 theLog.printDebugInfo("settimage :: made internal representation of image");
81 byte[] imageData = webdbImage.getImage();
82 theLog.printDebugInfo("settimage :: getImage");
83 byte[] iconData = webdbImage.getIcon();
84 theLog.printDebugInfo("settimage :: getIcon");
86 if (iconData!=null && imageData!=null) {
87 con = theStorageObject.getPooledCon();
88 con.setAutoCommit(false);
89 theLog.printDebugInfo("settimage :: trying to insert image");
92 String sql = "update images set img_height='"+webdbImage.getImageHeight() +
93 "',img_width='" + webdbImage.getImageWidth() +
94 "',icon_height='" + webdbImage.getIconHeight() +
95 "',icon_width='" + webdbImage.getIconWidth() + "', image_data=?, icon_data=? where id="+getId();
96 theLog.printDebugInfo("settimage :: updating sizes: "+ sql);
97 pstmt = con.prepareStatement(sql);
98 pstmt.setBytes(1, imageData);
99 pstmt.setBytes(2, iconData);
100 pstmt.executeUpdate();
101 sql="update content set is_produced='0' where to_media="+getId();
102 pstmt = con.prepareStatement(sql);
103 pstmt.executeUpdate();
106 catch (Exception e) {theLog.printDebugInfo("settimage :: setImage gescheitert: "+e.toString());}
108 try {con.setAutoCommit(true); } catch (Exception e) {;}
109 theStorageObject.freeConnection(con,pstmt); }
113 public void update() throws StorageObjectException {
116 theStorageObject.executeUpdate("update content set is_produced='0' where to_media="+getId());
117 } catch (SQLException e) {
118 theLog.printError("EntityImages :: update :: failed!! "+ e.toString());
122 public void setValues(HashMap theStringValues)
124 if (theStringValues != null) {
125 if (!theStringValues.containsKey("is_published"))
126 theStringValues.put("is_published","0");
128 super.setValues(theStringValues);
131 public byte[] getIcon()
133 Connection con=null;Statement stmt=null;
134 byte[] img_data=null;
137 con = theStorageObject.getPooledCon();
138 con.setAutoCommit(false);
139 stmt = con.createStatement();
140 ResultSet rs = theStorageObject.executeSql(stmt,"select icon_data from images where id="+getId());
143 img_data = rs.getBytes(1);
148 catch (Exception e) {theLog.printDebugInfo("-- getIcon gescheitert: "+e.toString());}
150 try {con.setAutoCommit(true); } catch (Exception e) {;}
151 theStorageObject.freeConnection(con,stmt); }
156 public void finalize() {