Source Code Cross Referenced for ContractVersionEffectivenessTest.java in  » Database-ORM » db-ojb » org » apache » ojb » broker » 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 » db ojb » org.apache.ojb.broker 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Author: Matthew Baird
003:         * mattbaird@yahoo.com
004:         */package org.apache.ojb.broker;
005:
006:        import org.apache.ojb.broker.query.Criteria;
007:        import org.apache.ojb.broker.query.Query;
008:        import org.apache.ojb.broker.query.QueryFactory;
009:        import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
010:        import org.apache.ojb.junit.PBTestCase;
011:
012:        import java.sql.Timestamp;
013:        import java.util.Iterator;
014:
015:        /**
016:         * This TestClass tests OJB ability to handle Contract Version Effectiveness patterns.
017:         */
018:        public class ContractVersionEffectivenessTest extends PBTestCase {
019:            private int COUNT = 10;
020:
021:            public static void main(String[] args) {
022:                String[] arr = { ContractVersionEffectivenessTest.class
023:                        .getName() };
024:                junit.textui.TestRunner.main(arr);
025:            }
026:
027:            /**
028:             * Insert the method's description here.
029:             * Creation date: (24.12.2000 00:33:40)
030:             */
031:            public ContractVersionEffectivenessTest(String name)
032:
033:            {
034:                super (name);
035:            }
036:
037:            /**
038:             * Insert the method's description here.
039:             * Creation date: (06.12.2000 21:58:53)
040:             */
041:            public void setUp() throws Exception {
042:                super .setUp();
043:            }
044:
045:            /**
046:             * Insert the method's description here.
047:             * Creation date: (06.12.2000 21:59:14)
048:             */
049:            public void tearDown() throws Exception {
050:                super .tearDown();
051:            }
052:
053:            private void createTestData() {
054:                broker.beginTransaction();
055:                for (int i = 0; i < COUNT; i++) {
056:                    Contract contract = new Contract();
057:                    contract.setPk("C" + System.currentTimeMillis());
058:                    contract.setContractValue1("contractvalue1");
059:                    contract.setContractValue2(1);
060:                    contract.setContractValue3("contractvalue3");
061:                    contract.setContractValue4(new Timestamp(System
062:                            .currentTimeMillis()));
063:                    broker.store(contract);
064:
065:                    Version version = new Version();
066:                    version.setPk("V" + System.currentTimeMillis());
067:                    version.setVersionValue1("versionvalue1");
068:                    version.setVersionValue2(1);
069:                    version.setVersionValue3(new Timestamp(System
070:                            .currentTimeMillis()));
071:                    version.setContract(contract);
072:                    broker.store(version);
073:
074:                    Effectiveness eff = new Effectiveness();
075:                    eff.setPk("E" + System.currentTimeMillis());
076:                    eff.setEffValue1("effvalue1");
077:                    eff.setEffValue2(1);
078:                    eff.setEffValue3(new Timestamp(System.currentTimeMillis()));
079:                    eff.setVersion(version);
080:                    broker.store(eff);
081:                }
082:                broker.commitTransaction();
083:            }
084:
085:            public void testCreateContractVersionEffectiveness() {
086:                createTestData();
087:            }
088:
089:            public void testAutoRetrieveFalse() {
090:                ojbChangeReferenceSetting(Contract.class, "relatedToContract",
091:                        false, ObjectReferenceDescriptor.CASCADE_OBJECT,
092:                        ObjectReferenceDescriptor.CASCADE_OBJECT, false);
093:                String name = "testAutoRetrieveFalse_"
094:                        + System.currentTimeMillis();
095:                Contract contract = new Contract();
096:                contract.setPk("C" + System.currentTimeMillis());
097:                contract.setContractValue1(name + "_Contract");
098:                contract.setContractValue2(1);
099:                contract.setContractValue3("contractvalue3");
100:                contract.setContractValue4(new Timestamp(System
101:                        .currentTimeMillis()));
102:
103:                RelatedToContract rc = new RelatedToContract();
104:                rc.setPk("R_" + System.currentTimeMillis());
105:                rc.setRelatedValue1(name + "_RelatedToContract");
106:
107:                contract.setRelatedToContract(rc);
108:                broker.beginTransaction();
109:                // auto-update is true
110:                broker.store(contract);
111:                broker.commitTransaction();
112:
113:                broker.clearCache();
114:                Identity oid = broker.serviceIdentity().buildIdentity(contract);
115:                Contract newC = (Contract) broker.getObjectByIdentity(oid);
116:                assertNotNull(newC);
117:                // auto-retrieve is false
118:                assertNull(newC.getRelatedToContract());
119:                broker.retrieveAllReferences(newC);
120:                // now the field should be populated
121:                assertNotNull(newC.getRelatedToContract());
122:            }
123:
124:            public void testUpdateContractVersionEffectiveness() {
125:                createTestData();
126:
127:                Criteria crit = new Criteria();
128:                Query q;
129:                Iterator iter;
130:                /**
131:                 * update effectiveness first
132:                 */
133:                q = QueryFactory.newQuery(Effectiveness.class, crit);
134:                iter = broker.getIteratorByQuery(q);
135:                Effectiveness eff = null;
136:                broker.beginTransaction();
137:                while (iter.hasNext()) {
138:                    eff = (Effectiveness) iter.next();
139:                    eff.setEffValue1("effValueUpdated");
140:                    broker.store(eff);
141:                }
142:                broker.commitTransaction();
143:                /**
144:                 * then version
145:                 */
146:                Version version = null;
147:                q = QueryFactory.newQuery(Version.class, crit);
148:                iter = broker.getIteratorByQuery(q);
149:                broker.beginTransaction();
150:                while (iter.hasNext()) {
151:                    version = (Version) iter.next();
152:                    version.setVersionValue1("verValueUpdated");
153:                    broker.store(version);
154:                }
155:                broker.commitTransaction();
156:                /**
157:                 * the contract
158:                 */
159:                Contract contract = null;
160:                q = QueryFactory.newQuery(Contract.class, crit);
161:                iter = broker.getIteratorByQuery(q);
162:                broker.beginTransaction();
163:                while (iter.hasNext()) {
164:                    contract = (Contract) iter.next();
165:                    contract.setContractValue1("contractValueUpdated");
166:                    broker.store(contract);
167:                }
168:                broker.commitTransaction();
169:            }
170:
171:            public void testDeleteContractVersionEffectiveness() {
172:                createTestData();
173:
174:                Criteria crit = new Criteria();
175:                Query q;
176:                Iterator iter;
177:                /**
178:                 * delete effectiveness first
179:                 */
180:                q = QueryFactory.newQuery(Effectiveness.class, crit);
181:                iter = broker.getIteratorByQuery(q);
182:                broker.beginTransaction();
183:                while (iter.hasNext()) {
184:                    broker.delete(iter.next());
185:                }
186:                broker.commitTransaction();
187:                /**
188:                 * then version
189:                 */
190:                q = QueryFactory.newQuery(Version.class, crit);
191:                iter = broker.getIteratorByQuery(q);
192:                broker.beginTransaction();
193:                while (iter.hasNext()) {
194:                    broker.delete(iter.next());
195:                }
196:                broker.commitTransaction();
197:                /**
198:                 * the contract
199:                 */
200:                q = QueryFactory.newQuery(Contract.class, crit);
201:                iter = broker.getIteratorByQuery(q);
202:                broker.beginTransaction();
203:                while (iter.hasNext()) {
204:                    broker.delete(iter.next());
205:                }
206:                broker.commitTransaction();
207:            }
208:
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.