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, getAudio
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 audio data and meta data
29 public class EntityAudio extends EntityUploadedMedia
36 public EntityAudio(StorageObject theStorage) {
38 setStorage(theStorage);
46 public byte[] getAudio() throws StorageObjectException
48 theLog.printDebugInfo("--getaudio 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 audio_data from audio 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 data = lob.read(lob.size());
68 //data = rs.getBytes(1);
72 } catch (Exception e) {
74 theLog.printError("EntityAudio -- getAudio failed"+e.toString());
75 throwStorageObjectException(e, "EntityAudio -- getAudio failed: ");
79 con.setAutoCommit(true);
80 } catch (Exception e) {
83 "EntityAudio -- getAudio reseting transaction mode failed"
86 theStorageObject.freeConnection(con,stmt);
92 public void setAudio(byte[] uploadData)
93 throws StorageObjectException {
95 if (uploadData!=null) {
96 java.sql.Connection con=null;PreparedStatement pstmt=null;
99 if (uploadData!=null) {
100 con = theStorageObject.getPooledCon();
101 con.setAutoCommit(false);
102 theLog.printDebugInfo("setaudio :: trying to insert audio");
105 LargeObjectManager lom;
106 java.sql.Connection jCon;
107 jCon = ((com.codestudio.sql.PoolManConnectionHandle)con)
108 .getNativeConnection();
109 lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI();
110 int oid = lom.create();
111 LargeObject lob = lom.open(oid);
112 lob.write(uploadData);
114 String sql = "update images set"
116 +" where id="+getId();
117 theLog.printDebugInfo("setaudio :: updating: "+ sql);
118 pstmt = con.prepareStatement(sql);
119 //pstmt.setBytes(1, imageData);
120 //pstmt.setBytes(2, iconData);
121 pstmt.executeUpdate();
122 sql="update content set is_produced='0' where to_media="+getId();
123 pstmt = con.prepareStatement(sql);
124 pstmt.executeUpdate();
127 catch (Exception e) {
128 throwStorageObjectException(e,"setaudio ::failed: ");
131 try { if (con!=null) con.setAutoCommit(true); } catch (Exception e) {;}
132 theStorageObject.freeConnection(con,pstmt); }
137 public void update() throws StorageObjectException {
140 theStorageObject.executeUpdate("update content set is_produced='0' where to_media="+getId());
141 } catch (SQLException e) {
142 throwStorageObjectException(e, "EntityAudio :: update :: failed!! ");
146 public void setValues(HashMap theStringValues)
148 if (theStringValues != null) {
149 if (!theStringValues.containsKey("is_published"))
150 theStringValues.put("is_published","0");
152 super.setValues(theStringValues);