some changes in the model classes and its xml-descriptions
[mir.git] / source / mir / core / model / Image.java
1 /*
2  * Image.java
3  * 
4  * Copyright (C) 2001, 2002, 2003 The Mir-coders group
5  *
6  * This file is part of Mir.
7  *
8  * Mir is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Mir is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Mir; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  * In addition, as a special exception, The Mir-coders gives permission to link
23  * the code of this program with  any library licensed under the Apache Software License,
24  * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
25  * (or with modified versions of the above that use the same license as the above),
26  * and distribute linked combinations including the two.  You must obey the
27  * GNU General Public License in all respects for all of the code used other than
28  * the above mentioned libraries.  If you modify this file, you may extend this
29  * exception to your version of the file, but you are not obligated to do so.
30  * If you do not wish to do so, delete this exception statement from your version.
31  */
32 package mir.core.model;
33
34 import java.io.Serializable;
35 import java.sql.Connection;
36 import java.sql.SQLException;
37
38 import net.sf.hibernate.CallbackException;
39 import net.sf.hibernate.HibernateException;
40 import net.sf.hibernate.Lifecycle;
41 import net.sf.hibernate.Session;
42
43 import org.apache.commons.lang.builder.ToStringBuilder;
44 import org.postgresql.PGConnection;
45 import org.postgresql.largeobject.LargeObject;
46 import org.postgresql.largeobject.LargeObjectManager;
47
48 /**
49  * 
50  * Image
51  * @author idefix
52  * @version $Id: Image.java,v 1.3 2003/08/17 19:13:19 idfx Exp $
53  */
54 public class Image extends UploadedMedia 
55         implements Serializable, Lifecycle {
56
57     /** nullable persistent field */
58     private int imageData;
59
60     /** nullable persistent field */
61     private int iconData;
62
63     /** nullable persistent field */
64     private String year;
65
66     /** nullable persistent field */
67     private short imgWidth;
68
69     /** nullable persistent field */
70     private short imgHeight;
71
72     /** persistent field */
73     private short imgFormat;
74
75     /** persistent field */
76     private short imgLayout;
77
78     /** persistent field */
79     private short imgType;
80
81     /** persistent field */
82     private short imgColor;
83
84     /** nullable persistent field */
85     private short iconWidth;
86
87     /** nullable persistent field */
88     private short iconHeight;
89
90     /** default constructor */
91     public Image() {
92     }
93
94     public int getImageData() {
95         return this.imageData;
96     }
97
98     public void setImageData(int imageData) {
99         this.imageData = imageData;
100     }
101
102     public int getIconData() {
103         return this.iconData;
104     }
105
106     public void setIconData(int iconData) {
107         this.iconData = iconData;
108     }
109
110     public java.lang.String getYear() {
111         return this.year;
112     }
113
114     public void setYear(java.lang.String year) {
115         this.year = year;
116     }
117
118     public short getImgWidth() {
119         return this.imgWidth;
120     }
121
122     public void setImgWidth(short imgWidth) {
123         this.imgWidth = imgWidth;
124     }
125
126     public short getImgHeight() {
127         return this.imgHeight;
128     }
129
130     public void setImgHeight(short imgHeight) {
131         this.imgHeight = imgHeight;
132     }
133
134     public short getImgFormat() {
135         return this.imgFormat;
136     }
137
138     public void setImgFormat(short imgFormat) {
139         this.imgFormat = imgFormat;
140     }
141
142     public short getImgLayout() {
143         return this.imgLayout;
144     }
145
146     public void setImgLayout(short imgLayout) {
147         this.imgLayout = imgLayout;
148     }
149
150     public short getImgType() {
151         return this.imgType;
152     }
153
154     public void setImgType(short imgType) {
155         this.imgType = imgType;
156     }
157
158     public short getImgColor() {
159         return this.imgColor;
160     }
161
162     public void setImgColor(short imgColor) {
163         this.imgColor = imgColor;
164     }
165
166     public short getIconWidth() {
167         return this.iconWidth;
168     }
169
170     public void setIconWidth(short iconWidth) {
171         this.iconWidth = iconWidth;
172     }
173
174     public short getIconHeight() {
175         return this.iconHeight;
176     }
177
178     public void setIconHeight(short iconHeight) {
179         this.iconHeight = iconHeight;
180     }
181
182     public String toString() {
183         return new ToStringBuilder(this)
184             .append("id", getId())
185             .toString();
186     }
187
188                 /* (non-Javadoc)
189                  * @see net.sf.hibernate.Lifecycle#onSave(net.sf.hibernate.Session)
190                  */
191                 public boolean onSave(Session arg0) throws CallbackException {
192                         // TODO Auto-generated method stub
193                         return false;
194                 }
195
196                 /* (non-Javadoc)
197                  * @see net.sf.hibernate.Lifecycle#onUpdate(net.sf.hibernate.Session)
198                  */
199                 public boolean onUpdate(Session arg0) throws CallbackException {
200                         // TODO Auto-generated method stub
201                         return false;
202                 }
203
204                 /* (non-Javadoc)
205                  * @see net.sf.hibernate.Lifecycle#onDelete(net.sf.hibernate.Session)
206                  */
207                 public boolean onDelete(Session arg0) throws CallbackException {
208                         // TODO Auto-generated method stub
209                         return false;
210                 }
211
212                 /* (non-Javadoc)
213                  * @see net.sf.hibernate.Lifecycle#onLoad(net.sf.hibernate.Session, java.io.Serializable)
214                  */
215                 public void onLoad(Session session, Serializable arg1) {
216                         // TODO Auto-generated method stub
217                         System.out.println("hello: ");
218                         try {
219                                 Connection connection = session.connection();
220                                 if(connection instanceof PGConnection){
221                                         PGConnection pgcon = (PGConnection)connection;
222                                         LargeObjectManager largeObjectManager = pgcon.getLargeObjectAPI();
223                                         LargeObject image = largeObjectManager.open(getImageData());
224                                         System.out.println("juppii" + image.size()  + " " + this.getMediaType().getId());
225                                 }
226                         } catch (HibernateException e) {
227                                 // TODO Auto-generated catch block
228                                 e.printStackTrace();
229                         } catch (SQLException e) {
230                                 // TODO Auto-generated catch block
231                                 e.printStackTrace();
232                         }
233                 }
234
235 }