KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > pobjects > basic > BasicA


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo.pobjects.basic;
19
20 import java.io.Serializable JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.Calendar JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Date JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Locale JavaDoc;
28
29 import javax.jdo.InstanceCallbacks;
30 import javax.jdo.PersistenceManager;
31 import javax.jdo.PersistenceManagerFactory;
32 import javax.jdo.Query;
33
34 /**
35  *
36  * @author S.Chassande-Barrioz
37  */

38 public class BasicA implements Serializable JavaDoc, InstanceCallbacks {
39
40     public final static int CALLBACK_INIT = 1;
41     static String JavaDoc nonPersistentField1 = "static field not persistent";
42     final static String JavaDoc nonPersistentField2 = "final static field not persistent";
43     public String JavaDoc f1 = null;
44     public int f2 = 0;
45     private int privateField = -1;
46     protected int protectedField = -2;
47     int noModifierField = -3;
48     private Date JavaDoc d;
49     private Date JavaDoc d2;
50     private long l;
51     protected String JavaDoc undeclaredField;
52     private String JavaDoc nonullField = "nonnull";
53     private char[] myArrayOfchar;
54     private int checkJdoLoad = CALLBACK_INIT;
55     private int checkJdoStore = CALLBACK_INIT;
56     private int checkJdoClear = CALLBACK_INIT;
57     private int checkJdoDelete = CALLBACK_INIT;
58     private Locale JavaDoc locale = Locale.getDefault();
59
60     public static List JavaDoc getAllBasicA(PersistenceManagerFactory pmf) {
61         PersistenceManager pm = pmf.getPersistenceManager();
62         Query q = pm.newQuery();
63         q.setClass(BasicA.class);
64         Collection JavaDoc col = (Collection JavaDoc) q.execute();
65         ArrayList JavaDoc al = new ArrayList JavaDoc();
66         for(Iterator JavaDoc it= col.iterator(); it.hasNext();) {
67             al.add(it.next());
68         }
69         q.closeAll();
70         pm.close();
71         return al;
72     }
73
74
75     private BasicA(String JavaDoc f1, int f2) {
76         this.f1 = f1;
77         if (this.f1 != null) {
78             myArrayOfchar = this.f1.toCharArray();
79         } else {
80             myArrayOfchar = null;
81         }
82         this.f2 = f2;
83         d = getTime();
84         l = 1234567890L;
85         undeclaredField = f1 + "_undeclared";
86     }
87
88     protected BasicA(String JavaDoc f1) {
89         this();
90         if (d == null) {
91             throw new NullPointerException JavaDoc("d is null");
92         }
93         this.f1 = f1;
94         if (this.f1 != null) {
95             myArrayOfchar = f1.toCharArray();
96         } else {
97             myArrayOfchar = null;
98         }
99         d = getTime();
100         l = 1234567890L;
101         undeclaredField = f1 + "_undeclared";
102     }
103     public BasicA() {
104         d = getTime();
105         l = 1234567890L;
106         undeclaredField = "undeclared";
107     }
108
109     public Date JavaDoc getTime() {
110         return new Date JavaDoc((Calendar.getInstance().getTime().getTime() / 1000) * 1000);
111     }
112
113     public String JavaDoc readF1() {
114         return f1;
115     }
116
117     public void writeF1(String JavaDoc f1) {
118         this.f1 = f1;
119         if (this.f1 != null) {
120             myArrayOfchar = f1.toCharArray();
121         } else {
122             myArrayOfchar = null;
123         }
124     }
125
126     public int readF2() {
127         return f2;
128     }
129
130     public void writeF2(int f2) {
131         this.f2 = f2;
132     }
133
134     public void incF2() {
135         this.f2 = this.f2 + 1;
136     }
137
138     public String JavaDoc readF1_F2() {
139         return f1 + f2;
140     }
141
142     public void writeF1() {
143         f1 = "azerty";
144         undeclaredField = f1.toString();
145         myArrayOfchar = this.f1.toCharArray();
146     }
147
148     public void writeF2() {
149         f2 = 1;
150     }
151
152     public void writeF1_F2() {
153         f1 = "qsdfgh";
154         f2 = 2;
155     }
156
157     public void delegateWriteF1() {
158         writeF1();
159     }
160
161     public void jdoPostLoad() {
162         checkJdoLoad++;
163         readF1_F2();
164     }
165
166     public void jdoPreStore() {
167         checkJdoStore++;
168     }
169
170     public void jdoPreClear() {
171         checkJdoClear++;
172     }
173
174     public void jdoPreDelete() {
175         checkJdoDelete++;
176     }
177
178     public int getCheckJdoLoad() {
179         return checkJdoLoad;
180     }
181
182     public int getCheckJdoStore() {
183         return checkJdoStore;
184     }
185
186     public int getCheckJdoClear() {
187         return checkJdoClear;
188     }
189
190     public int getCheckJdoDelete() {
191         return checkJdoDelete;
192     }
193
194     public Locale JavaDoc getLocale() {
195         return locale;
196     }
197
198     public void setLocale(Locale JavaDoc l) {
199         this.locale = l;
200     }
201
202     public String JavaDoc getNonullField() {
203         return nonullField;
204     }
205
206     public void setNonullField(String JavaDoc nonullField) {
207         this.nonullField = nonullField;
208     }
209     
210     public String JavaDoc getUndeclaredField() {
211         return undeclaredField;
212     }
213     public void setUndeclaredField(String JavaDoc undeclaredField) {
214         this.undeclaredField = undeclaredField;
215     }
216 }
217
Popular Tags