moved media handler implementations to mircoders/media for added flexibility.
[mir.git] / source / mircoders / entity / EntityAudio.java
index 8e0f37d..a780e7a 100755 (executable)
@@ -47,7 +47,7 @@ public class EntityAudio extends EntityUploadedMedia
        {
                theLog.printDebugInfo("--getaudio started");
                java.sql.Connection con=null;Statement stmt=null;
-               byte[] img_data=null;
+               byte[] data=null;
 
                try {
                        con = theStorageObject.getPooledCon();
@@ -63,9 +63,9 @@ public class EntityAudio extends EntityUploadedMedia
                        if(rs!=null) {
               if (rs.next()) {
                 LargeObject lob = lom.open(rs.getInt(1));
-                img_data = lob.read(lob.size());
+                data = lob.read(lob.size());
                 lob.close();
-                //img_data = rs.getBytes(1);
+                //data = rs.getBytes(1);
               }
             rs.close();
                        }
@@ -86,39 +86,54 @@ public class EntityAudio extends EntityUploadedMedia
           theStorageObject.freeConnection(con,stmt);
         }
 
-               return img_data;
+               return data;
        }
 
-       public void setAudio(byte[] audioData, String audioType)
+       public void setAudio(byte[] uploadData)
            throws StorageObjectException {
 
-               if (audioData!=null) {
+               if (uploadData!=null) {
                        java.sql.Connection con=null;PreparedStatement pstmt=null;
                        try {
 
-                               theLog.printDebugInfo("settaudio :: making internal representation of audio");
-                               theLog.printDebugInfo("settaudio :: made internal representation of audio");
-                               theLog.printDebugInfo("settaudio :: getAudio");
-
-                               if ( audioData!=null) {
+                               if (uploadData!=null) {
                                        con = theStorageObject.getPooledCon();
                                        con.setAutoCommit(false);
-                                       theLog.printDebugInfo("settaudio :: trying to insert audio");
+                                       theLog.printDebugInfo("setaudio :: trying to insert audio");
 
                                        // setting values
-                                       pstmt.setBytes(1, audioData);
-                                       String sql="update content set is_produced='0' where to_media="+getId();
+                    LargeObjectManager lom;
+                    java.sql.Connection jCon;
+                    jCon = ((com.codestudio.sql.PoolManConnectionHandle)con)
+                            .getNativeConnection();
+                    lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI();
+                    int oid = lom.create();
+                    LargeObject lob = lom.open(oid);
+                    lob.write(uploadData);
+                    lob.close();
+                    String sql = "update images set"
+                                 +" audio_data="+oid
+                                 +" where id="+getId();
+                                       theLog.printDebugInfo("setaudio :: updating: "+ sql);
+                                       pstmt = con.prepareStatement(sql);
+                                       //pstmt.setBytes(1, imageData);
+                                       //pstmt.setBytes(2, iconData);
+                                       pstmt.executeUpdate();
+                                       sql="update content set is_produced='0' where to_media="+getId();
                                        pstmt = con.prepareStatement(sql);
                                        pstmt.executeUpdate();
                                }
                        }
-                       catch (Exception e) {throwStorageObjectException(e, "settaudio :: setAudio gescheitert: ");}
+                       catch (Exception e) {
+                throwStorageObjectException(e,"setaudio ::failed: ");
+            }
                        finally {
                                try { if (con!=null) con.setAutoCommit(true); } catch (Exception e) {;}
                                theStorageObject.freeConnection(con,pstmt); }
                }
        }
 
+
        public void update() throws StorageObjectException {
                super.update();
                try {