001: /**
002: * Copyright (C) 2001-2004 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.pobjects.basic;
018:
019: import java.io.Serializable;
020: import java.util.ArrayList;
021: import java.util.Calendar;
022: import java.util.Collection;
023: import java.util.Date;
024: import java.util.Iterator;
025: import java.util.List;
026: import java.util.Locale;
027:
028: import javax.jdo.InstanceCallbacks;
029: import javax.jdo.PersistenceManager;
030: import javax.jdo.PersistenceManagerFactory;
031: import javax.jdo.Query;
032:
033: /**
034: *
035: * @author S.Chassande-Barrioz
036: */
037: public class BasicA implements Serializable, InstanceCallbacks {
038:
039: public final static int CALLBACK_INIT = 1;
040: static String nonPersistentField1 = "static field not persistent";
041: final static String nonPersistentField2 = "final static field not persistent";
042: public String f1 = null;
043: public int f2 = 0;
044: private int privateField = -1;
045: protected int protectedField = -2;
046: int noModifierField = -3;
047: private Date d;
048: private Date d2;
049: private long l;
050: protected String undeclaredField;
051: private String nonullField = "nonnull";
052: private char[] myArrayOfchar;
053: private int checkJdoLoad = CALLBACK_INIT;
054: private int checkJdoStore = CALLBACK_INIT;
055: private int checkJdoClear = CALLBACK_INIT;
056: private int checkJdoDelete = CALLBACK_INIT;
057: private Locale locale = Locale.getDefault();
058:
059: public static List getAllBasicA(PersistenceManagerFactory pmf) {
060: PersistenceManager pm = pmf.getPersistenceManager();
061: Query q = pm.newQuery();
062: q.setClass(BasicA.class);
063: Collection col = (Collection) q.execute();
064: ArrayList al = new ArrayList();
065: for (Iterator it = col.iterator(); it.hasNext();) {
066: al.add(it.next());
067: }
068: q.closeAll();
069: pm.close();
070: return al;
071: }
072:
073: public static List getAllBasicAId(PersistenceManagerFactory pmf) {
074: PersistenceManager pm = pmf.getPersistenceManager();
075: Query q = pm.newQuery();
076: q.setClass(BasicA.class);
077: Collection col = (Collection) q.execute();
078: ArrayList al = new ArrayList();
079: for (Iterator it = col.iterator(); it.hasNext();) {
080: al.add(pm.getObjectId(it.next()));
081: }
082: q.closeAll();
083: pm.close();
084: return al;
085: }
086:
087: public BasicA(String f1, int f2) {
088: this .f1 = f1;
089: if (this .f1 != null) {
090: myArrayOfchar = this .f1.toCharArray();
091: } else {
092: myArrayOfchar = null;
093: }
094: this .f2 = f2;
095: d = getTime();
096: l = 1234567890L;
097: undeclaredField = f1 + "_undeclared";
098: }
099:
100: protected BasicA(String f1) {
101: this ();
102: if (d == null) {
103: throw new NullPointerException("d is null");
104: }
105: this .f1 = f1;
106: if (this .f1 != null) {
107: myArrayOfchar = f1.toCharArray();
108: } else {
109: myArrayOfchar = null;
110: }
111: d = getTime();
112: l = 1234567890L;
113: undeclaredField = f1 + "_undeclared";
114: }
115:
116: public BasicA() {
117: d = getTime();
118: l = 1234567890L;
119: undeclaredField = "undeclared";
120: }
121:
122: public Date getTime() {
123: return new Date(
124: (Calendar.getInstance().getTime().getTime() / 1000) * 1000);
125: }
126:
127: public String readF1() {
128: return f1;
129: }
130:
131: public void writeF1(String f1) {
132: this .f1 = f1;
133: if (this .f1 != null) {
134: myArrayOfchar = f1.toCharArray();
135: } else {
136: myArrayOfchar = null;
137: }
138: }
139:
140: public int readF2() {
141: return f2;
142: }
143:
144: public void writeF2(int f2) {
145: this .f2 = f2;
146: }
147:
148: public void incF2() {
149: this .f2 = this .f2 + 1;
150: }
151:
152: public String readF1_F2() {
153: return f1 + f2;
154: }
155:
156: public void writeF1() {
157: f1 = "azerty";
158: undeclaredField = f1.toString();
159: myArrayOfchar = this .f1.toCharArray();
160: }
161:
162: public void writeF2() {
163: f2 = 1;
164: }
165:
166: public void writeF1_F2() {
167: f1 = "qsdfgh";
168: f2 = 2;
169: }
170:
171: public void delegateWriteF1() {
172: writeF1();
173: }
174:
175: public void jdoPostLoad() {
176: checkJdoLoad++;
177: readF1_F2();
178: }
179:
180: public void jdoPreStore() {
181: checkJdoStore++;
182: }
183:
184: public void jdoPreClear() {
185: checkJdoClear++;
186: }
187:
188: public void jdoPreDelete() {
189: checkJdoDelete++;
190: }
191:
192: public int getCheckJdoLoad() {
193: return checkJdoLoad;
194: }
195:
196: public int getCheckJdoStore() {
197: return checkJdoStore;
198: }
199:
200: public int getCheckJdoClear() {
201: return checkJdoClear;
202: }
203:
204: public int getCheckJdoDelete() {
205: return checkJdoDelete;
206: }
207:
208: public Locale getLocale() {
209: return locale;
210: }
211:
212: public void setLocale(Locale l) {
213: this .locale = l;
214: }
215:
216: public String getNonullField() {
217: return nonullField;
218: }
219:
220: public void setNonullField(String nonullField) {
221: this .nonullField = nonullField;
222: }
223:
224: public String getUndeclaredField() {
225: return undeclaredField;
226: }
227:
228: public void setUndeclaredField(String undeclaredField) {
229: this.undeclaredField = undeclaredField;
230: }
231: }
|