a4777f33a2efbe83a77db9afe992a731ab9b9ab1
[mir.git] / source / mir / core / model / Image.java
1 package mir.core.model;
2
3 import java.io.Serializable;
4 import java.sql.Connection;
5 import java.sql.SQLException;
6
7 import net.sf.hibernate.CallbackException;
8 import net.sf.hibernate.HibernateException;
9 import net.sf.hibernate.Lifecycle;
10 import net.sf.hibernate.Session;
11
12 import org.apache.commons.lang.builder.ToStringBuilder;
13 import org.postgresql.PGConnection;
14 import org.postgresql.largeobject.LargeObject;
15 import org.postgresql.largeobject.LargeObjectManager;
16
17 /** @author Hibernate CodeGenerator */
18 public class Image extends UploadedMedia 
19         implements Serializable, Lifecycle {
20
21     /** nullable persistent field */
22     private int imageData;
23
24     /** nullable persistent field */
25     private int iconData;
26
27     /** nullable persistent field */
28     private String year;
29
30     /** nullable persistent field */
31     private short imgWidth;
32
33     /** nullable persistent field */
34     private short imgHeight;
35
36     /** persistent field */
37     private short imgFormat;
38
39     /** persistent field */
40     private short imgLayout;
41
42     /** persistent field */
43     private short imgType;
44
45     /** persistent field */
46     private short imgColor;
47
48     /** nullable persistent field */
49     private short iconWidth;
50
51     /** nullable persistent field */
52     private short iconHeight;
53
54     /** default constructor */
55     public Image() {
56     }
57
58     public int getImageData() {
59         return this.imageData;
60     }
61
62     public void setImageData(int imageData) {
63         this.imageData = imageData;
64     }
65
66     public int getIconData() {
67         return this.iconData;
68     }
69
70     public void setIconData(int iconData) {
71         this.iconData = iconData;
72     }
73
74     public java.lang.String getYear() {
75         return this.year;
76     }
77
78     public void setYear(java.lang.String year) {
79         this.year = year;
80     }
81
82     public short getImgWidth() {
83         return this.imgWidth;
84     }
85
86     public void setImgWidth(short imgWidth) {
87         this.imgWidth = imgWidth;
88     }
89
90     public short getImgHeight() {
91         return this.imgHeight;
92     }
93
94     public void setImgHeight(short imgHeight) {
95         this.imgHeight = imgHeight;
96     }
97
98     public short getImgFormat() {
99         return this.imgFormat;
100     }
101
102     public void setImgFormat(short imgFormat) {
103         this.imgFormat = imgFormat;
104     }
105
106     public short getImgLayout() {
107         return this.imgLayout;
108     }
109
110     public void setImgLayout(short imgLayout) {
111         this.imgLayout = imgLayout;
112     }
113
114     public short getImgType() {
115         return this.imgType;
116     }
117
118     public void setImgType(short imgType) {
119         this.imgType = imgType;
120     }
121
122     public short getImgColor() {
123         return this.imgColor;
124     }
125
126     public void setImgColor(short imgColor) {
127         this.imgColor = imgColor;
128     }
129
130     public short getIconWidth() {
131         return this.iconWidth;
132     }
133
134     public void setIconWidth(short iconWidth) {
135         this.iconWidth = iconWidth;
136     }
137
138     public short getIconHeight() {
139         return this.iconHeight;
140     }
141
142     public void setIconHeight(short iconHeight) {
143         this.iconHeight = iconHeight;
144     }
145
146     public String toString() {
147         return new ToStringBuilder(this)
148             .append("id", getId())
149             .toString();
150     }
151
152                 /* (non-Javadoc)
153                  * @see net.sf.hibernate.Lifecycle#onSave(net.sf.hibernate.Session)
154                  */
155                 public boolean onSave(Session arg0) throws CallbackException {
156                         // TODO Auto-generated method stub
157                         return false;
158                 }
159
160                 /* (non-Javadoc)
161                  * @see net.sf.hibernate.Lifecycle#onUpdate(net.sf.hibernate.Session)
162                  */
163                 public boolean onUpdate(Session arg0) throws CallbackException {
164                         // TODO Auto-generated method stub
165                         return false;
166                 }
167
168                 /* (non-Javadoc)
169                  * @see net.sf.hibernate.Lifecycle#onDelete(net.sf.hibernate.Session)
170                  */
171                 public boolean onDelete(Session arg0) throws CallbackException {
172                         // TODO Auto-generated method stub
173                         return false;
174                 }
175
176                 /* (non-Javadoc)
177                  * @see net.sf.hibernate.Lifecycle#onLoad(net.sf.hibernate.Session, java.io.Serializable)
178                  */
179                 public void onLoad(Session session, Serializable arg1) {
180                         // TODO Auto-generated method stub
181                         System.out.println("hello: ");
182                         try {
183                                 Connection connection = session.connection();
184                                 if(connection instanceof PGConnection){
185                                         PGConnection pgcon = (PGConnection)connection;
186                                         LargeObjectManager largeObjectManager = pgcon.getLargeObjectAPI();
187                                         LargeObject image = largeObjectManager.open(getImageData());
188                                         System.out.println("juppii" + image.size()  + " " + this.getMediaType().getId());
189                                 }
190                         } catch (HibernateException e) {
191                                 // TODO Auto-generated catch block
192                                 e.printStackTrace();
193                         } catch (SQLException e) {
194                                 // TODO Auto-generated catch block
195                                 e.printStackTrace();
196                         }
197                 }
198
199 }