KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > legacy > Foo


1 //$Id: Foo.java,v 1.1 2004/09/26 05:18:25 oneovthafew Exp $
2
package org.hibernate.test.legacy;
3
4 import java.io.Serializable JavaDoc;
5 import java.sql.Timestamp JavaDoc;
6 import java.util.Calendar JavaDoc;
7 import java.util.Date JavaDoc;
8 import java.util.Locale JavaDoc;
9
10 import org.hibernate.CallbackException;
11 import org.hibernate.Session;
12 import org.hibernate.classic.Lifecycle;
13
14 public class Foo implements Lifecycle, FooProxy, Serializable JavaDoc {
15
16     private static int count=0;
17
18     public static class Struct implements java.io.Serializable JavaDoc {
19         String JavaDoc name;
20         int count;
21         public boolean equals(Object JavaDoc other) {
22             Struct s = (Struct) other;
23             return ( s.name==name || s.name.equals(name) ) && s.count==count;
24         }
25         public int hashCode() {
26             return count;
27         }
28     }
29
30     /*public boolean equals(Object other) {
31         FooProxy otherFoo = (FooProxy) other;
32         return this.key.equals( otherFoo.getKey() ) && this._string.equals( otherFoo.getString() );
33     }
34
35     public int hashCode() {
36         return key.hashCode() - _string.hashCode();
37     }*/

38
39     String JavaDoc key;
40     FooProxy _foo;
41     String JavaDoc _string;
42     Date JavaDoc _date;
43     Date JavaDoc _timestamp;
44     Integer JavaDoc _integer;
45     Long JavaDoc _long;
46     Short JavaDoc _short;
47     Float JavaDoc _float;
48     Double JavaDoc _double;
49     Boolean JavaDoc _boolean;
50     Byte JavaDoc _byte;
51     Integer JavaDoc _null;
52     int _int;
53     boolean _bool;
54     float _zero;
55     byte[] _bytes;
56     boolean yesno;
57     java.io.Serializable JavaDoc blob;
58     java.io.Serializable JavaDoc nullBlob;
59     byte[] binary;
60     String JavaDoc[] custom;
61     FooComponent component;
62     char _char;
63     Fee dependent;
64     Locale JavaDoc theLocale;
65     private int version;
66     private Timestamp JavaDoc versionTimestamp;
67     private Calendar JavaDoc versionCalendar;
68     private float formula;
69     private String JavaDoc joinedProp;
70
71     private int x;
72
73     public int getX() {
74         return x;
75     }
76     public void setX(int x) {
77         this.x = x;
78     }
79
80     public Foo() {
81     }
82
83     public Foo(int x) {
84         this.x=x;
85     }
86
87     public boolean onSave(Session db) throws CallbackException {
88         _string = "a string";
89         _date = new Date JavaDoc(123);
90         _timestamp = new Date JavaDoc( System.currentTimeMillis() );
91         _integer = new Integer JavaDoc( -666 );
92         _long = new Long JavaDoc( 696969696969696969l - count++ );
93         _short = new Short JavaDoc("42");
94         _float = new Float JavaDoc( 6666.66f );
95         //_double = new Double( 1.33e-69 ); // this double is too big for the sap db jdbc driver
96
_double = new Double JavaDoc( 1.12e-36 );
97         _boolean = new Boolean JavaDoc(true);
98         _byte = new Byte JavaDoc( (byte) 127 );
99         _int = 2;
100         _char = '@';
101         _bytes = _string.getBytes();
102         Struct s = new Struct();
103         s.name="name";
104         s.count = 69;
105         blob = s;
106         binary = ( _string + "yada yada yada" ).getBytes();
107         custom = new String JavaDoc[] { "foo", "bar" };
108         component = new FooComponent("foo", 12, new Date JavaDoc[] { _date, _timestamp, null, new Date JavaDoc() }, new FooComponent("bar", 666, new Date JavaDoc[] { new Date JavaDoc(123456l), null }, null ) );
109         component.setGlarch( new Glarch() );
110         dependent = new Fee();
111         dependent.setFi( "belongs to foo # " + getKey() );
112         theLocale = Locale.getDefault();
113         return NO_VETO;
114     }
115
116     public boolean onDelete(Session db) throws CallbackException {
117         return NO_VETO;
118     }
119     public boolean onUpdate(Session db) throws CallbackException {
120         return NO_VETO;
121     }
122
123     public void onLoad(Session db, Serializable JavaDoc id) {
124     }
125
126     public String JavaDoc getKey() {
127         return key;
128     }
129     public void setKey(String JavaDoc key) {
130         this.key = key;
131     }
132
133     public FooProxy getFoo() {
134         return _foo;
135     }
136     public void setFoo(FooProxy foo) {
137         _foo = foo;
138     }
139
140     public String JavaDoc getString() {
141         return _string;
142     }
143     public void setString(String JavaDoc string) {
144         _string = string;
145         //if (_foo!=null) _foo.setString(string);
146
}
147
148     public java.util.Date JavaDoc getDate() {
149         return _date;
150     }
151     public void setDate(java.util.Date JavaDoc date) {
152         _date = date;
153     }
154
155     public java.util.Date JavaDoc getTimestamp() {
156         return _timestamp;
157     }
158     public void setTimestamp(java.util.Date JavaDoc timestamp) {
159         _timestamp = timestamp;
160     }
161
162     public Integer JavaDoc getInteger() {
163         return _integer;
164     }
165     public void setInteger(Integer JavaDoc iinteger) {
166         _integer = iinteger;
167     }
168     public Long JavaDoc getLong() {
169         return _long;
170     }
171     public void setLong(Long JavaDoc llong) {
172         _long = llong;
173     }
174
175
176     public Short JavaDoc getShort() {
177         return _short;
178     }
179     public void setShort(Short JavaDoc sshort) {
180         _short = sshort;
181     }
182     public Float JavaDoc getFloat() {
183         return _float;
184     }
185     public void setFloat(Float JavaDoc ffloat) {
186         _float = ffloat;
187     }
188     public Double JavaDoc getDouble() {
189         return _double;
190     }
191     public void setDouble(Double JavaDoc ddouble) {
192         _double = ddouble;
193     }
194     public Boolean JavaDoc getBoolean() {
195         return _boolean;
196     }
197     public void setBoolean(Boolean JavaDoc bboolean) {
198         _boolean = bboolean;
199     }
200     public byte[] getBytes() {
201         return _bytes;
202     }
203     public void setBytes(byte[] bytes) {
204         _bytes = bytes;
205     }
206     public float getZero() {
207         return _zero;
208     }
209     public void setZero(float zero) {
210         _zero = zero;
211     }
212     public boolean getBool() {
213         return _bool;
214     }
215     public void setBool(boolean bool) {
216         _bool = bool;
217     }
218
219     public int getInt() {
220         return _int;
221     }
222     public void setInt(int iint) {
223         _int = iint;
224     }
225
226     public Integer JavaDoc getNull() {
227         return _null;
228     }
229     public void setNull(Integer JavaDoc nnull) {
230         _null = nnull;
231     }
232
233     public Byte JavaDoc getByte() {
234         return _byte;
235     }
236
237     public void setByte(Byte JavaDoc bbyte) {
238         _byte = bbyte;
239     }
240
241     public String JavaDoc toString() {
242         return this.getClass().getName() + ": " + key;
243     }
244
245     public void disconnect() {
246         if ( _foo!=null) _foo.disconnect();
247         _foo=null;
248     }
249
250     public boolean equalsFoo(Foo other) {
251         if ( _bytes!=other._bytes ) {
252             if ( _bytes==null || other._bytes==null ) return false;
253             if ( _bytes.length!=other._bytes.length ) return false;
254             for ( int i=0; i< _bytes.length; i++) {
255                 if ( _bytes[i] != other._bytes[i] ) return false;
256             }
257         }
258
259         return ( this._bool == other._bool )
260         && ( ( this._boolean == other._boolean ) || ( this._boolean.equals(other._boolean) ) )
261         && ( ( this._byte == other._byte ) || ( this._byte.equals(other._byte) ) )
262         //&& ( ( this._date == other._date ) || ( this._date.getDate() == other._date.getDate() && this._date.getMonth() == other._date.getMonth() && this._date.getYear() == other._date.getYear() ) )
263
&& ( ( this._double == other._double ) || ( this._double.equals(other._double) ) )
264         && ( ( this._float == other._float ) || ( this._float.equals(other._float) ) )
265         && ( this._int == other._int )
266         && ( ( this._integer == other._integer ) || ( this._integer.equals(other._integer) ) )
267         && ( ( this._long == other._long ) || ( this._long.equals(other._long) ) )
268         && ( this._null == other._null )
269         && ( ( this._short == other._short ) || ( this._short.equals(other._short) ) )
270         && ( ( this._string == other._string) || ( this._string.equals(other._string) ) )
271         //&& ( ( this._timestamp==other._timestamp) || ( this._timestamp.getDate() == other._timestamp.getDate() && this._timestamp.getYear() == other._timestamp.getYear() && this._timestamp.getMonth() == other._timestamp.getMonth() ) )
272
&& ( this._zero == other._zero )
273         && ( ( this._foo == other._foo ) || ( this._foo.getKey().equals( other._foo.getKey() ) ) )
274         && ( ( this.blob == other.blob ) || ( this.blob.equals(other.blob) ) )
275         && ( this.yesno == other.yesno )
276         && ( ( this.binary == other.binary ) || java.util.Arrays.equals(this.binary, other.binary) )
277         && ( this.key.equals(other.key) )
278         && ( this.theLocale.equals(other.theLocale) )
279         && ( ( this.custom == other.custom ) || ( this.custom[0].equals(other.custom[0]) && this.custom[1].equals(other.custom[1]) ) );
280
281     }
282
283     public boolean getYesno() {
284         return yesno;
285     }
286
287     public void setYesno(boolean yesno) {
288         this.yesno = yesno;
289     }
290
291     public java.io.Serializable JavaDoc getBlob() {
292         return blob;
293     }
294
295     public void setBlob(java.io.Serializable JavaDoc blob) {
296         this.blob = blob;
297     }
298
299     public java.io.Serializable JavaDoc getNullBlob() {
300         return nullBlob;
301     }
302
303     public void setNullBlob(java.io.Serializable JavaDoc nullBlob) {
304         this.nullBlob = nullBlob;
305     }
306
307     public byte[] getBinary() {
308         return binary;
309     }
310     public void setBinary(byte[] binary) {
311         this.binary = binary;
312     }
313
314     public String JavaDoc[] getCustom() {
315         return custom;
316     }
317
318     public void setCustom(String JavaDoc[] custom) {
319         this.custom = custom;
320     }
321
322     public FooComponent getComponent() {
323         return component;
324     }
325     public void setComponent(FooComponent component) {
326         this.component = component;
327     }
328
329     public FooComponent getNullComponent() {
330         return null;
331     }
332     public void setNullComponent(FooComponent fc) throws Exception JavaDoc {
333         if (fc!=null) throw new Exception JavaDoc("Null component");
334     }
335
336     public Character JavaDoc getChar() {
337         return new Character JavaDoc(_char);
338     }
339
340     public void setChar(Character JavaDoc _char) {
341         this._char = _char.charValue();
342     }
343
344     public Fee getDependent() {
345         return dependent;
346     }
347
348     public void setDependent(Fee dependent) {
349         this.dependent = dependent;
350     }
351
352     /**
353      * Returns the locale.
354      * @return Locale
355      */

356     public Locale JavaDoc getLocale() {
357         return theLocale;
358     }
359
360     /**
361      * Sets the locale.
362      * @param locale The locale to set
363      */

364     public void setLocale(Locale JavaDoc locale) {
365         this.theLocale = locale;
366     }
367
368     /**
369      * Returns the version.
370      * @return int
371      */

372     public int getVersion() {
373         return version;
374     }
375
376     /**
377      * Sets the version.
378      * @param version The version to set
379      */

380     public void setVersion(int version) {
381         this.version = version;
382     }
383
384     /**
385      * Returns the versionTimestamp.
386      * @return Timestamp
387      */

388     public Timestamp JavaDoc getVersionTimestamp() {
389         return versionTimestamp;
390     }
391
392     /**
393      * Sets the versionTimestamp.
394      * @param versionTimestamp The versionTimestamp to set
395      */

396     public void setVersionTimestamp(Timestamp JavaDoc versionTimestamp) {
397         this.versionTimestamp = versionTimestamp;
398     }
399
400     public void finalize() { }
401
402     public Calendar JavaDoc getVersionCalendar() {
403         return versionCalendar;
404     }
405
406     public void setVersionCalendar(Calendar JavaDoc calendar) {
407         versionCalendar = calendar;
408     }
409
410     public float getFormula() {
411         return formula;
412     }
413
414     public void setFormula(float f) {
415         formula = f;
416     }
417
418     /**
419      * @return Returns the joinedProp.
420      */

421     public String JavaDoc getJoinedProp() {
422         return joinedProp;
423     }
424
425     /**
426      * @param joinedProp The joinedProp to set.
427      */

428     public void setJoinedProp(String JavaDoc joinedProp) {
429         this.joinedProp = joinedProp;
430     }
431
432 }
433
434
435
436
437
438
Popular Tags