Source Code Cross Referenced for TestVersion.java in  » Database-ORM » openjpa » org » apache » openjpa » persistence » annotations » 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 » openjpa » org.apache.openjpa.persistence.annotations 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.    
018:         */
019:        package org.apache.openjpa.persistence.annotations;
020:
021:        import javax.persistence.*;
022:
023:        import org.apache.openjpa.jdbc.conf.*;
024:        import org.apache.openjpa.jdbc.meta.*;
025:        import org.apache.openjpa.jdbc.meta.strats.*;
026:
027:        import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
028:
029:        import org.apache.openjpa.persistence.OpenJPAEntityManager;
030:        import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
031:        import org.apache.openjpa.persistence.OpenJPAPersistence;
032:
033:        /*
034:         Test for opt-lock
035:
036:         @author Steve Kim
037:         */
038:        public class TestVersion extends AnnotationTestCase {
039:            private Object oid;
040:
041:            private Object oid1;
042:
043:            private Object oid2;
044:
045:            public TestVersion(String name) {
046:                super (name, "annotationcactusapp");
047:            }
048:
049:            public void setUp() {
050:                new AnnoTest1();
051:                new AnnoTest2();
052:                new AnnoTest3();
053:
054:                deleteAll(AnnoTest1.class);
055:                deleteAll(AnnoTest2.class);
056:
057:                OpenJPAEntityManager em = currentEntityManager();
058:                startTx(em);
059:                AnnoTest1 test1 = new AnnoTest1();
060:                test1.setPk(new Long(5));
061:                test1.setBasic(50);
062:                test1.setTransient(500);
063:                em.persist(test1);
064:
065:                AnnoTest2 test2 = new AnnoTest2();
066:                test2.setPk1(5);
067:                test2.setPk2("bar");
068:                test2.setBasic("50");
069:                em.persist(test2);
070:
071:                AnnoTest3 test3 = new AnnoTest3();
072:                test3.setPk(new Long(3));
073:                test3.setBasic2(50);
074:                em.persist(test3);
075:                oid = em.getObjectId(test1);
076:                oid1 = em.getObjectId(test2);
077:                oid2 = em.getObjectId(test3);
078:
079:                endTx(em);
080:                endEm(em);
081:            }
082:
083:            /*
084:             * Fix Me aokeke -- Testcases causes deadlock during runtime CR307216 is used to track this issue.
085:             */
086:            public void testVersionNumeric() {
087:                OpenJPAEntityManager em1 = currentEntityManager();
088:                startTx(em1);
089:                EntityManager em2 = getEmf().createEntityManager();
090:
091:                AnnoTest1 pc1 = em1.find(AnnoTest1.class, oid);
092:                AnnoTest1 pc2 = em2.find(AnnoTest1.class, oid);
093:                assertEquals(1, pc1.getVersion());
094:                assertEquals(1, pc2.getVersion());
095:                assertEquals(0, pc1.getTransient());
096:                pc1.setBasic(75);
097:
098:                endTx(em1);
099:                endEm(em1);
100:
101:                em2.getTransaction().begin();
102:                pc2.setBasic(75);
103:                em1 = (OpenJPAEntityManager) currentEntityManager();
104:                pc1 = em1.find(AnnoTest1.class, oid);
105:                assertEquals(2, pc1.getVersion());
106:                endEm(em1);
107:                try {
108:                    em2.getTransaction().commit();
109:                    fail("Optimistic fail");
110:                } catch (RuntimeException re) {
111:                } catch (Exception e) {
112:                } finally {
113:                    em2.close();
114:                }
115:            }
116:
117:            public void testVersionTimestamp() {
118:                OpenJPAEntityManager em1 = currentEntityManager();
119:                startTx(em1);
120:                OpenJPAEntityManager em2 = getEmf().createEntityManager();
121:
122:                AnnoTest2 pc1 = em1.find(AnnoTest2.class, oid1);
123:                AnnoTest2 pc2 = em2.find(AnnoTest2.class, oid1);
124:                assertNotNull(pc1.getVersion());
125:                assertEquals(pc1.getVersion(), pc2.getVersion());
126:                pc1.setBasic("75");
127:
128:                endTx(em1);
129:                endEm(em1);
130:
131:                em2.getTransaction().begin();
132:                pc2.setBasic("75");
133:
134:                em1 = (OpenJPAEntityManager) currentEntityManager();
135:                pc1 = em1.find(AnnoTest2.class, oid1);
136:                assertTrue(pc1.getVersion().compareTo(pc2.getVersion()) > 0);
137:                endEm(em1);
138:                try {
139:                    em2.getTransaction().commit();
140:                    fail("Optimistic fail");
141:                } catch (RuntimeException re) {
142:                } catch (Exception e) {
143:                } finally {
144:                    em2.close();
145:                }
146:            }
147:
148:            public void testVersionSubclass() {
149:                OpenJPAEntityManager em1 = currentEntityManager();
150:                startTx(em1);
151:                OpenJPAEntityManager em2 = getEmf().createEntityManager();
152:
153:                AnnoTest3 pc1 = em1.find(AnnoTest3.class, oid2);
154:                AnnoTest3 pc2 = em2.find(AnnoTest3.class, oid2);
155:                assertEquals(1, pc1.getVersion());
156:                assertEquals(1, pc2.getVersion());
157:                pc1.setBasic2(75);
158:
159:                endTx(em1);
160:                endEm(em1);
161:
162:                em2.getTransaction().begin();
163:                pc2.setBasic2(75);
164:
165:                em1 = (OpenJPAEntityManager) currentEntityManager();
166:                pc1 = em1.find(AnnoTest3.class, oid2);
167:                assertEquals(2, pc1.getVersion());
168:                endEm(em1);
169:                try {
170:                    em2.getTransaction().commit();
171:                    fail("Optimistic fail");
172:                } catch (RuntimeException re) {
173:                } catch (Exception e) {
174:                } finally {
175:                    em2.close();
176:                }
177:            }
178:
179:            public void testVersionNoChange() {
180:                OpenJPAEntityManager em = currentEntityManager();
181:                startTx(em);
182:
183:                AnnoTest1 pc = em.find(AnnoTest1.class, oid);
184:                assertEquals(1, pc.getVersion());
185:                assertEquals(0, pc.getTransient());
186:                pc.setTransient(750);
187:                endTx(em);
188:                endEm(em);
189:
190:                em = (OpenJPAEntityManager) currentEntityManager();
191:                pc = em.find(AnnoTest1.class, oid);
192:                assertEquals(1, pc.getVersion());
193:                assertEquals(0, pc.getTransient());
194:                endEm(em);
195:            }
196:
197:            public void testNoDefaultVersionWithoutFieldOrColumn() {
198:                OpenJPAEntityManager pm = (OpenJPAEntityManager) currentEntityManager();
199:                ClassMapping cls = ((JDBCConfigurationImpl) ((OpenJPAEntityManagerSPI) OpenJPAPersistence
200:                        .cast(pm)).getConfiguration())
201:                        .getMappingRepositoryInstance().getMapping(
202:                                EmbedOwner.class, null, true);
203:                assertEquals(NoneVersionStrategy.getInstance(), cls
204:                        .getVersion().getStrategy());
205:                assertEquals(0, cls.getVersion().getColumns().length);
206:                endEm(pm);
207:            }
208:
209:            public void testVersionWithField() {
210:                OpenJPAEntityManager pm = (OpenJPAEntityManager) currentEntityManager();
211:                ClassMapping cls = ((JDBCConfigurationImpl) ((OpenJPAEntityManagerSPI) OpenJPAPersistence
212:                        .cast(pm)).getConfiguration())
213:                        .getMappingRepositoryInstance().getMapping(
214:                                AnnoTest1.class, null, true);
215:                assertTrue(NoneVersionStrategy.getInstance() != cls
216:                        .getVersion().getStrategy());
217:                assertEquals(1, cls.getVersion().getColumns().length);
218:                endEm(pm);
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.