1 package mircoders.entity;
9 * kind of hack for postgres non-standard LargeObjects that Poolman
10 * doesn't know about. see all the casting, LargeObj stuff in getIcon, getImage
11 * at some point when postgres has normal BLOB support, this should go.
13 import org.postgresql.Connection;
14 import org.postgresql.largeobject.LargeObject;
15 import org.postgresql.largeobject.LargeObjectManager;
22 * Diese Klasse enthält die Daten eines MetaObjekts
29 public class EntityImages extends Entity
36 public EntityImages(StorageObject theStorage) {
38 setStorage(theStorage);
46 public byte[] getImage() throws StorageObjectException
48 theLog.printDebugInfo("--getimage started");
49 java.sql.Connection con=null;Statement stmt=null;
53 con = theStorageObject.getPooledCon();
54 con.setAutoCommit(false);
55 LargeObjectManager lom;
56 java.sql.Connection jCon;
57 stmt = con.createStatement();
58 ResultSet rs = theStorageObject.executeSql(stmt,
59 "select image_data from images where id="+getId());
60 jCon = ((com.codestudio.sql.PoolManConnectionHandle)con)
61 .getNativeConnection();
62 lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI();
65 LargeObject lob = lom.open(rs.getInt(1));
66 img_data = lob.read(lob.size());
67 System.err.println("LOB IMG SIZE: "+lob.size());
69 System.err.println("res set img NOT NULL2");
70 //img_data = rs.getBytes(1);
74 } catch (Exception e) {
76 theLog.printError("EntityImages -- getImage failed"+e.toString());
77 throwStorageObjectException(e, "EntityImages -- getImage failed: ");
81 con.setAutoCommit(true);
82 } catch (Exception e) {
85 "EntityImages -- getImage reseting transaction mode failed"
88 theStorageObject.freeConnection(con,stmt);
94 public void setImage(byte[] uploadData, String imageType)
95 throws StorageObjectException {
99 if (imageType.equals("1"))
103 if (uploadData!=null) {
104 java.sql.Connection con=null;PreparedStatement pstmt=null;
107 theLog.printDebugInfo("settimage :: making internal representation of image");
108 WebdbImage webdbImage= new WebdbImage(uploadData,type);
109 theLog.printDebugInfo("settimage :: made internal representation of image");
110 byte[] imageData = webdbImage.getImage();
111 theLog.printDebugInfo("settimage :: getImage");
112 byte[] iconData = webdbImage.getIcon();
113 theLog.printDebugInfo("settimage :: getIcon");
115 if (iconData!=null && imageData!=null) {
116 con = theStorageObject.getPooledCon();
117 con.setAutoCommit(false);
118 theLog.printDebugInfo("settimage :: trying to insert image");
121 String sql = "update images set img_height='"+webdbImage.getImageHeight() +
122 "',img_width='" + webdbImage.getImageWidth() +
123 "',icon_height='" + webdbImage.getIconHeight() +
124 "',icon_width='" + webdbImage.getIconWidth() + "', image_data=?, icon_data=? where id="+getId();
125 theLog.printDebugInfo("settimage :: updating sizes: "+ sql);
126 pstmt = con.prepareStatement(sql);
127 pstmt.setBytes(1, imageData);
128 pstmt.setBytes(2, iconData);
129 pstmt.executeUpdate();
130 sql="update content set is_produced='0' where to_media="+getId();
131 pstmt = con.prepareStatement(sql);
132 pstmt.executeUpdate();
135 catch (Exception e) {throwStorageObjectException(e, "settimage :: setImage gescheitert: ");}
137 try { if (con!=null) con.setAutoCommit(true); } catch (Exception e) {;}
138 theStorageObject.freeConnection(con,pstmt); }
142 public void update() throws StorageObjectException {
145 theStorageObject.executeUpdate("update content set is_produced='0' where to_media="+getId());
146 } catch (SQLException e) {
147 throwStorageObjectException(e, "EntityImages :: update :: failed!! ");
151 public void setValues(HashMap theStringValues)
153 if (theStringValues != null) {
154 if (!theStringValues.containsKey("is_published"))
155 theStringValues.put("is_published","0");
157 super.setValues(theStringValues);
160 public byte[] getIcon() throws StorageObjectException
162 java.sql.Connection con=null;Statement stmt=null;
163 byte[] img_data=null;
166 con = theStorageObject.getPooledCon();
167 con.setAutoCommit(false);
168 LargeObjectManager lom;
169 java.sql.Connection jCon;
170 stmt = con.createStatement();
171 ResultSet rs = theStorageObject.executeSql(stmt,
172 "select icon_data from images where id="+getId());
173 jCon = ((com.codestudio.sql.PoolManConnectionHandle)con)
174 .getNativeConnection();
175 lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI();
177 System.err.println("res set NOT NULL");
179 LargeObject lob = lom.open(rs.getInt(1));
180 img_data = lob.read(lob.size());
181 System.err.println("LOB SIZE: "+lob.size());
183 System.err.println("res set NOT NULL2");
184 //img_data = rs.getBytes(1);
185 System.err.println("res set NOT NULL3");
189 } catch (Exception e) {
191 theLog.printError("EntityImages -- getIcon failed"+e.toString());
192 throwStorageObjectException(e, "EntityImages -- getIcon failed:");
195 con.setAutoCommit(true);
196 } catch (Exception e) {
199 "EntityImages -- getIcon reseting transaction mode failed"
202 theStorageObject.freeConnection(con,stmt);