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, getOther
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 * This class handles storage of other data and meta data
29 public class EntityOther extends EntityUploadedMedia
36 public EntityOther(StorageObject theStorage) {
38 setStorage(theStorage);
46 public byte[] getOther() throws StorageObjectException
48 theLog.printDebugInfo("--getother 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 other_data from other 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());
68 //img_data = rs.getBytes(1);
72 } catch (Exception e) {
74 theLog.printError("EntityOther -- getOther failed"+e.toString());
75 throwStorageObjectException(e, "EntityOther -- getOther failed: ");
79 con.setAutoCommit(true);
80 } catch (Exception e) {
83 "EntityOther -- getOther reseting transaction mode failed"
86 theStorageObject.freeConnection(con,stmt);
92 public void setOther(byte[] otherData, String otherType)
93 throws StorageObjectException {
95 if (otherData!=null) {
96 java.sql.Connection con=null;PreparedStatement pstmt=null;
99 theLog.printDebugInfo("settother :: making internal representation of other");
100 theLog.printDebugInfo("settother :: made internal representation of other");
101 theLog.printDebugInfo("settother :: getOther");
103 if ( otherData!=null) {
104 con = theStorageObject.getPooledCon();
105 con.setAutoCommit(false);
106 theLog.printDebugInfo("settother :: trying to insert other");
109 pstmt.setBytes(1, otherData);
110 String sql="update content set is_produced='0' where to_media="+getId();
111 pstmt = con.prepareStatement(sql);
112 pstmt.executeUpdate();
115 catch (Exception e) {throwStorageObjectException(e, "settother :: setOther gescheitert: ");}
117 try { if (con!=null) con.setAutoCommit(true); } catch (Exception e) {;}
118 theStorageObject.freeConnection(con,pstmt); }
122 public void update() throws StorageObjectException {
125 theStorageObject.executeUpdate("update content set is_produced='0' where to_media="+getId());
126 } catch (SQLException e) {
127 throwStorageObjectException(e, "EntityOther :: update :: failed!! ");
131 public void setValues(HashMap theStringValues)
133 if (theStringValues != null) {
134 if (!theStringValues.containsKey("is_published"))
135 theStringValues.put("is_published","0");
137 super.setValues(theStringValues);