next steps in new persitence
[mir.git] / source / mir / core / model / Image.java
index 65c132e..a4777f3 100755 (executable)
@@ -1,11 +1,22 @@
 package mir.core.model;
 
 import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import net.sf.hibernate.CallbackException;
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.Lifecycle;
+import net.sf.hibernate.Session;
 
 import org.apache.commons.lang.builder.ToStringBuilder;
+import org.postgresql.PGConnection;
+import org.postgresql.largeobject.LargeObject;
+import org.postgresql.largeobject.LargeObjectManager;
 
 /** @author Hibernate CodeGenerator */
-public class Image extends UploadedMedia implements Serializable {
+public class Image extends UploadedMedia 
+       implements Serializable, Lifecycle {
 
     /** nullable persistent field */
     private int imageData;
@@ -138,4 +149,51 @@ public class Image extends UploadedMedia implements Serializable {
             .toString();
     }
 
+               /* (non-Javadoc)
+                * @see net.sf.hibernate.Lifecycle#onSave(net.sf.hibernate.Session)
+                */
+               public boolean onSave(Session arg0) throws CallbackException {
+                       // TODO Auto-generated method stub
+                       return false;
+               }
+
+               /* (non-Javadoc)
+                * @see net.sf.hibernate.Lifecycle#onUpdate(net.sf.hibernate.Session)
+                */
+               public boolean onUpdate(Session arg0) throws CallbackException {
+                       // TODO Auto-generated method stub
+                       return false;
+               }
+
+               /* (non-Javadoc)
+                * @see net.sf.hibernate.Lifecycle#onDelete(net.sf.hibernate.Session)
+                */
+               public boolean onDelete(Session arg0) throws CallbackException {
+                       // TODO Auto-generated method stub
+                       return false;
+               }
+
+               /* (non-Javadoc)
+                * @see net.sf.hibernate.Lifecycle#onLoad(net.sf.hibernate.Session, java.io.Serializable)
+                */
+               public void onLoad(Session session, Serializable arg1) {
+                       // TODO Auto-generated method stub
+                       System.out.println("hello: ");
+                       try {
+                               Connection connection = session.connection();
+                               if(connection instanceof PGConnection){
+                                       PGConnection pgcon = (PGConnection)connection;
+                                       LargeObjectManager largeObjectManager = pgcon.getLargeObjectAPI();
+                                       LargeObject image = largeObjectManager.open(getImageData());
+                                       System.out.println("juppii" + image.size()  + " " + this.getMediaType().getId());
+                               }
+                       } catch (HibernateException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       } catch (SQLException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       }
+               }
+
 }