Source Code Cross Referenced for JdoCallbacksTck.java in  » Database-ORM » Speedo_1.4.5 » org » objectweb » speedo » runtime » tck » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » Speedo_1.4.5 » org.objectweb.speedo.runtime.tck 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.runtime.tck;
018:
019:        import java.util.Calendar;
020:        import java.util.Date;
021:
022:        import javax.jdo.JDODataStoreException;
023:        import javax.jdo.JDOUserException;
024:        import javax.jdo.PersistenceManager;
025:        import javax.jdo.PersistenceManagerFactory;
026:        import javax.jdo.Transaction;
027:
028:        import org.objectweb.speedo.SpeedoTestHelper;
029:        import org.objectweb.speedo.pobjects.tck.InstanceCallbackClass;
030:        import org.objectweb.util.monolog.api.BasicLevel;
031:
032:        public class JdoCallbacksTck extends SpeedoTestHelper {
033:
034:            public JdoCallbacksTck(String s) {
035:                super (s);
036:            }
037:
038:            void checkInstances(String label, int intValue,
039:                    String capturedNextObjName, int numberOfChildren,
040:                    int sumOfChildrenIntValue) {
041:                if (InstanceCallbackClass.processedIndex[intValue] != true) {
042:                    logger.log(BasicLevel.ERROR, label
043:                            + "Callback never made on object with intValue = "
044:                            + intValue);
045:                    //incrementErrorCount();
046:                    return;
047:                }
048:                if (capturedNextObjName != null
049:                        & InstanceCallbackClass.capturedNextObjName[intValue] == null) {
050:                    logger.log(BasicLevel.ERROR, label
051:                            + "nextObj attribute for object with intValue = "
052:                            + intValue + " should not have been null.");
053:                    //incrementErrorCount();
054:                } else if (capturedNextObjName == null
055:                        & InstanceCallbackClass.capturedNextObjName[intValue] != null) {
056:                    logger.log(BasicLevel.ERROR, label
057:                            + "nextObj attribute for object with intValue = "
058:                            + intValue + " should  have been null.");
059:                    //incrementErrorCount();
060:                } else if (capturedNextObjName != null
061:                        && !InstanceCallbackClass.capturedNextObjName[intValue]
062:                                .equals(capturedNextObjName)) {
063:                    logger
064:                            .log(
065:                                    BasicLevel.ERROR,
066:                                    label
067:                                            + "nextObj.name attribute for object with intValue = "
068:                                            + intValue
069:                                            + " should  have been \""
070:                                            + capturedNextObjName
071:                                            + "\".  It was \""
072:                                            + InstanceCallbackClass.capturedNextObjName[intValue]
073:                                            + "\" instead.");
074:                    //incrementErrorCount();
075:                }
076:
077:                if (InstanceCallbackClass.numberOfChildren[intValue] != numberOfChildren) {
078:                    logger
079:                            .log(
080:                                    BasicLevel.ERROR,
081:                                    label
082:                                            + "Number of instances in attribute children for object with intValue = "
083:                                            + intValue
084:                                            + " should  have been "
085:                                            + numberOfChildren
086:                                            + ".  It was "
087:                                            + InstanceCallbackClass.numberOfChildren[intValue]
088:                                            + " instead.");
089:                    //incrementErrorCount();
090:                }
091:
092:                if (InstanceCallbackClass.sumOfChildrenIntValue[intValue] != sumOfChildrenIntValue) {
093:                    logger
094:                            .log(
095:                                    BasicLevel.ERROR,
096:                                    label
097:                                            + "Sum of intValue of instances in attribute children for object with intValue = "
098:                                            + intValue
099:                                            + " should have been "
100:                                            + sumOfChildrenIntValue
101:                                            + ".  It was "
102:                                            + InstanceCallbackClass.sumOfChildrenIntValue[intValue]
103:                                            + " instead.");
104:                    //incrementErrorCount();
105:                }
106:            }
107:
108:            void checkPMAccess(String label, int intValue,
109:                    boolean transactionActive) {
110:                if (InstanceCallbackClass.processedIndex[intValue] != true) {
111:                    logger.log(BasicLevel.ERROR, label
112:                            + "Callback never made on object with intValue = "
113:                            + intValue);
114:                    //incrementErrorCount();
115:                    return;
116:                }
117:                // Only  verify isActive() returned true for the object if transactionActive is true
118:                if (transactionActive
119:                        & InstanceCallbackClass.transactionActive[intValue] != true) {
120:                    logger
121:                            .log(
122:                                    BasicLevel.ERROR,
123:                                    label
124:                                            + "PersistenceManager.currentTransaction.isAcive() returned false");
125:                    //incrementErrorCount();
126:                }
127:            }
128:
129:            //  The attributes are:  label, name, date, intValue, doubleValue, childToDelete, charValue
130:            void checkFieldValues(String label, int intValue, String name,
131:                    Date timeStamp, double doubleValue, short childToDelete,
132:                    char charValue) {
133:                if (InstanceCallbackClass.processedIndex[intValue] != true) {
134:                    logger.log(BasicLevel.ERROR, label
135:                            + "Callback never made on object with intValue = "
136:                            + intValue);
137:                    //incrementErrorCount();
138:                    return;
139:                }
140:
141:                if (!InstanceCallbackClass.capturedName[intValue].equals(name)) {
142:                    logger.log(BasicLevel.ERROR, label
143:                            + "name attribute for object with intValue = "
144:                            + intValue + " should be \"" + name
145:                            + "\".  It was \""
146:                            + InstanceCallbackClass.capturedName[intValue]
147:                            + "\" instead.");
148:                    //incrementErrorCount();
149:                }
150:
151:                if (!InstanceCallbackClass.capturedTimeStamp[intValue]
152:                        .equals(timeStamp)) {
153:                    logger.log(BasicLevel.ERROR, label
154:                            + "timeStamp attribute for object with intValue = "
155:                            + intValue + " should be " + timeStamp
156:                            + ".  It was "
157:                            + InstanceCallbackClass.capturedTimeStamp[intValue]
158:                            + " instead.");
159:                    //incrementErrorCount();
160:                }
161:
162:                if (InstanceCallbackClass.capturedDoubleValue[intValue] != doubleValue) {
163:                    logger
164:                            .log(
165:                                    BasicLevel.ERROR,
166:                                    label
167:                                            + "doubleValue attribute for object with intValue = "
168:                                            + intValue
169:                                            + " should be "
170:                                            + doubleValue
171:                                            + ".  It was "
172:                                            + InstanceCallbackClass.capturedDoubleValue[intValue]
173:                                            + " instead.");
174:                    //incrementErrorCount();
175:                }
176:
177:                if (InstanceCallbackClass.capturedCharValue[intValue] != charValue) {
178:                    logger.log(BasicLevel.ERROR, label
179:                            + "charValue attribute for object with intValue = "
180:                            + intValue + " should be " + charValue
181:                            + ".  It was "
182:                            + InstanceCallbackClass.capturedCharValue[intValue]
183:                            + " instead.");
184:                    //incrementErrorCount();
185:                }
186:
187:                if (InstanceCallbackClass.capturedChildToDelete[intValue] != childToDelete) {
188:                    logger
189:                            .log(
190:                                    BasicLevel.ERROR,
191:                                    label
192:                                            + "childToDelete attribute for object with intValue = "
193:                                            + intValue
194:                                            + " should be "
195:                                            + childToDelete
196:                                            + ".  It was "
197:                                            + InstanceCallbackClass.capturedChildToDelete[intValue]
198:                                            + " instead.");
199:                    //incrementErrorCount();
200:                }
201:            }
202:
203:            /** Touch fields to guarantee that they are loaded into the instance
204:             */
205:            double touchFields(InstanceCallbackClass o) {
206:                // make a checksum from the fields and return it; this cannot be optimized out...
207:                double rc = o.doubleValue;
208:                rc += o.intValue;
209:                rc += o.charValue;
210:                rc += o.childToDelete;
211:                rc += o.name.length();
212:                rc += o.timeStamp.getTime();
213:                return rc;
214:            }
215:
216:            protected String getLoggerName() {
217:                return LOG_NAME + ".rt.tck.JdoCallbacksTck";
218:            }
219:
220:            public void testCallingJdoPreclear() {
221:                logger.log(BasicLevel.INFO, "testCallingJdoPreclear");
222:
223:                PersistenceManagerFactory fact = getPMF();
224:                PersistenceManager pm = fact.getPersistenceManager();
225:                Transaction t = pm.currentTransaction();
226:                t.setRetainValues(false); // instances transition to hollow after commit
227:
228:                InstanceCallbackClass.initializeStaticsForTest();
229:                t.begin();
230:                InstanceCallbackClass.removeAllInstances(pm); // always start fresh with no instances
231:                t.commit();
232:
233:                t.begin();
234:                Calendar cal = Calendar.getInstance();
235:                cal.set(1999, 1, 15, 12, 0);
236:                Date createTime = cal.getTime();
237:                cal.set(2002, 1, 15, 12, 0);
238:                Date laterDate = cal.getTime();
239:                InstanceCallbackClass secondaryObj = new InstanceCallbackClass(
240:                        "secondaryObj", createTime, 2, 2.2, (short) -20, '2',
241:                        null);
242:                InstanceCallbackClass primaryObj = new InstanceCallbackClass(
243:                        "primaryObj", laterDate, 1, 1.1, (short) -10, '1',
244:                        secondaryObj);
245:                pm.makePersistent(primaryObj);
246:                pm.makePersistent(secondaryObj);
247:                Object secondaryObjId = pm.getObjectId(secondaryObj);
248:                Object primaryObjId = pm.getObjectId(primaryObj);
249:                t.commit();
250:
251:                InstanceCallbackClass.performPreClearTests = true;
252:                t.begin();
253:                try {
254:                    primaryObj = (InstanceCallbackClass) pm.getObjectById(
255:                            primaryObjId, true);
256:                    touchFields(primaryObj); // load fields of primaryObj (make it persistent-clean)
257:
258:                } catch (JDOUserException e) {
259:                    logger
260:                            .log(
261:                                    BasicLevel.ERROR,
262:                                    "Failed to find primaryObj created in previous transaction.  Got JDOUserException "
263:                                            + e);
264:                    fail("CallingJdoPreclear: Failed to find primaryObj created in previous transaction.");
265:
266:                } catch (JDODataStoreException e) {
267:                    logger
268:                            .log(
269:                                    BasicLevel.ERROR,
270:                                    "Failed to find primaryObj created in previous transaction.  Got JDOUserException "
271:                                            + e);
272:                    fail("CallingJdoPreclear: Failed to find primaryObj created in previous transaction.");
273:                }
274:
275:                secondaryObj = primaryObj.nextObj;
276:                if (secondaryObj == null) {
277:                    logger
278:                            .log(
279:                                    BasicLevel.ERROR,
280:                                    "Failed to find secondaryObj created in previous transaction using reference from primaryObj.");
281:                    fail("CallingJdoPreclear: Failed to find secondaryObj created in previous transaction.");
282:                }
283:                touchFields(secondaryObj);
284:
285:                primaryObj.addChild(secondaryObj); // primaryObj contains one child;  secondaryObj contains none. primaryObj is now dirty
286:
287:                cal.set(2005, 6, 28, 0, 0);
288:                Date stillLaterDate = cal.getTime();
289:                InstanceCallbackClass ternaryObj = new InstanceCallbackClass(
290:                        "ternaryObj", stillLaterDate, 3, 3.3, (short) -30, '3',
291:                        null);
292:                pm.makePersistent(ternaryObj);
293:                ternaryObj.addChild(secondaryObj);
294:                ternaryObj.addChild(primaryObj);
295:                t.commit();
296:
297:                // verify attributes in what was persistent-clean object--secondaryObj
298:                checkFieldValues("jdoPreClear attribute access:  ", 2,
299:                        "secondaryObj", createTime, 2.2, (short) -20, '2');
300:
301:                // verify attributes in what was persistent-dirty object--primaryObj
302:                checkFieldValues("jdoPreClear attribute access:  ", 1,
303:                        "primaryObj", laterDate, 1.1, (short) -10, '1');
304:
305:                // verify attributes in what was persistent-new object--ternaryObj
306:                checkFieldValues("jdoPreClear attribute access:  ", 3,
307:                        "ternaryObj", stillLaterDate, 3.3, (short) -30, '3');
308:                pm.close();
309:                /*
310:                if( getErrorCount() > 0 )
311:                	return Status.failed("Assertion A10.3-1 (CallingJdoPreclear) failed");
312:                else
313:                	return Status.passed("Assertion A10.3-1 (CallingJdoPreclear) passed");
314:                 */
315:            }
316:
317:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.