1 package mircoders.entity;
13 * Diese Klasse enthält die Daten eines MetaObjekts
20 public class EntityImages extends Entity
27 public EntityImages(StorageObject theStorage) {
29 setStorage(theStorage);
37 public byte[] getImage() throws StorageObjectException
39 theLog.printDebugInfo("--getimage started");
40 Connection con=null;Statement stmt=null;
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());
50 img_data = rs.getBytes(1);
55 catch (Exception e) {throwStorageObjectException(e, "-- getImage gescheitert: ");}
57 try {con.setAutoCommit(true); } catch (Exception e) {;}
58 theStorageObject.freeConnection(con,stmt); }
63 public void setImage(byte[] uploadData, String imageType)
64 throws StorageObjectException {
68 if (imageType.equals("1"))
72 if (uploadData!=null) {
73 Connection con=null;PreparedStatement pstmt=null;
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");
84 if (iconData!=null && imageData!=null) {
85 con = theStorageObject.getPooledCon();
86 con.setAutoCommit(false);
87 theLog.printDebugInfo("settimage :: trying to insert image");
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();
104 catch (Exception e) {throwStorageObjectException(e, "settimage :: setImage gescheitert: ");}
106 try { if (con!=null) con.setAutoCommit(true); } catch (Exception e) {;}
107 theStorageObject.freeConnection(con,pstmt); }
111 public void update() throws StorageObjectException {
114 theStorageObject.executeUpdate("update content set is_produced='0' where to_media="+getId());
115 } catch (SQLException e) {
116 throwStorageObjectException(e, "EntityImages :: update :: failed!! ");
120 public void setValues(HashMap theStringValues)
122 if (theStringValues != null) {
123 if (!theStringValues.containsKey("is_published"))
124 theStringValues.put("is_published","0");
126 super.setValues(theStringValues);
129 public byte[] getIcon() throws StorageObjectException
131 Connection con=null;Statement stmt=null;
132 byte[] img_data=null;
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());
141 img_data = rs.getBytes(1);
146 catch (Exception e) {throwStorageObjectException(e, "-- getIcon gescheitert: ");}
148 try {con.setAutoCommit(true); } catch (Exception e) {;}
149 theStorageObject.freeConnection(con,stmt); }