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


001:        /*
002:         * TestStateManagerImplData.java
003:         *
004:         * Created on October 13, 2006, 5:40 PM
005:         *
006:         * To change this template, choose Tools | Template Manager
007:         * and open the template in the editor.
008:         */
009:        /*
010:         * Licensed to the Apache Software Foundation (ASF) under one
011:         * or more contributor license agreements.  See the NOTICE file
012:         * distributed with this work for additional information
013:         * regarding copyright ownership.  The ASF licenses this file
014:         * to you under the Apache License, Version 2.0 (the
015:         * "License"); you may not use this file except in compliance
016:         * with the License.  You may obtain a copy of the License at
017:         *
018:         * http://www.apache.org/licenses/LICENSE-2.0
019:         *
020:         * Unless required by applicable law or agreed to in writing,
021:         * software distributed under the License is distributed on an
022:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
023:         * KIND, either express or implied.  See the License for the
024:         * specific language governing permissions and limitations
025:         * under the License.    
026:         */
027:        package org.apache.openjpa.persistence.kernel;
028:
029:        import org.apache.openjpa.persistence.kernel.common.apps.ModRuntimeTest1;
030:
031:        import org.apache.openjpa.kernel.OpenJPAStateManager;
032:        import org.apache.openjpa.meta.ClassMetaData;
033:        import org.apache.openjpa.persistence.OpenJPAEntityManager;
034:
035:        public class TestStateManagerImplData extends BaseKernelTest {
036:
037:            ClassMetaData _meta;
038:
039:            Boolean _f1;
040:
041:            Boolean _f3;
042:
043:            /**
044:             * Creates a new instance of TestStateManagerImplData
045:             */
046:            public TestStateManagerImplData() {
047:            }
048:
049:            public TestStateManagerImplData(String test) {
050:                super (test);
051:            }
052:
053:            public void setUpMetaData(ClassMetaData meta) {
054:                _meta = meta;
055:                _f1 = _meta.getField(1).usesImplData();
056:                _f3 = _meta.getField(3).usesImplData();
057:                _meta.getField(1).setUsesImplData(Boolean.TRUE);
058:                _meta.getField(3).setUsesImplData(null);
059:            }
060:
061:            public void tearDownMetaData() {
062:                _meta.getField(1).setUsesImplData(_f1);
063:                _meta.getField(3).setUsesImplData(_f3);
064:            }
065:
066:            public void testImplData() {
067:                ModRuntimeTest1 pc = new ModRuntimeTest1();
068:
069:                OpenJPAEntityManager pm = getPM(false, false);
070:                startTx(pm);
071:                pm.persist(pc);
072:                OpenJPAStateManager sm = getStateManager(pc, pm);
073:                setUpMetaData(sm.getMetaData());
074:                try {
075:                    // test instance level
076:                    Object inst = new Object();
077:                    assertNull(sm.getImplData());
078:                    assertNull(sm.setImplData(inst, true));
079:                    assertEquals(inst, sm.getImplData());
080:                    assertTrue(sm.isImplDataCacheable());
081:                    assertEquals(inst, sm.setImplData(null, false));
082:                    assertNull(sm.getImplData());
083:                    assertFalse(sm.isImplDataCacheable());
084:                    sm.setImplData(inst, false);
085:                    assertFalse(sm.isImplDataCacheable());
086:
087:                    // test field level
088:                    Object f1 = new Object();
089:                    Object f3 = new Object();
090:
091:                    assertNull(sm.getImplData(1));
092:                    assertFalse(sm.isImplDataCacheable(1));
093:                    assertNull(sm.setImplData(1, f1));
094:                    assertEquals(f1, sm.getImplData(1));
095:                    assertTrue(!sm.isImplDataCacheable(1));
096:                    assertEquals(f1, sm.setImplData(1, null));
097:                    assertNull(sm.getImplData(1));
098:                    assertFalse(sm.isImplDataCacheable(1));
099:                    sm.setImplData(1, f1);
100:
101:                    assertNull(sm.setImplData(3, f3));
102:                    assertEquals(f3, sm.getImplData(3));
103:                    assertTrue(sm.isImplDataCacheable(3));
104:                    assertEquals(f1, sm.getImplData(1));
105:
106:                    // this should clear field data
107:                    endTx(pm);
108:
109:                    assertEquals(inst, sm.getImplData());
110:                    assertNull(sm.getImplData(1));
111:                    assertNull(sm.getImplData(3));
112:
113:                    endEm(pm);
114:                } finally {
115:                    tearDownMetaData();
116:                }
117:            }
118:
119:            public void testNotClearedIfRetainValues() {
120:                deleteAll(ModRuntimeTest1.class);
121:                notClearedIfRetainValuesTest(true);
122:                notClearedIfRetainValuesTest(false);
123:            }
124:
125:            private void notClearedIfRetainValuesTest(boolean optimistic) {
126:                ModRuntimeTest1 pc = new ModRuntimeTest1("pc", 1);
127:                int key = 1;
128:                Object value = new Object();
129:
130:                // make instance persistent
131:                OpenJPAEntityManager pm = getPM(optimistic, true);
132:                startTx(pm);
133:                pm.persist(pc);
134:                Object oid = pm.getObjectId(pc);
135:
136:                OpenJPAStateManager sm = getStateManager(pc, pm);
137:                assertNotNull(sm);
138:                setUpMetaData(sm.getMetaData());
139:                try {
140:                    // set impl data
141:                    sm.setImplData(key, value);
142:                    assertEquals(value, sm.getImplData(key));
143:                    endTx(pm);
144:
145:                    // test in nontransactional setting
146:                    assertEquals(value, sm.getImplData(key));
147:
148:                    // test in next transaction
149:                    startTx(pm);
150:                    pc = (ModRuntimeTest1) pm.find(ModRuntimeTest1.class, oid);
151:                    sm = getStateManager(pc, pm);
152:                    assertNotNull(sm);
153:                    if (pm.getOptimistic())
154:                        assertEquals(value, sm.getImplData(key));
155:                    else
156:                        assertNull(sm.getImplData(key));
157:                    endTx(pm);
158:                    endEm(pm);
159:                } finally {
160:                    tearDownMetaData();
161:                }
162:
163:                // test in another pm for good measure
164:                pm = getPM(optimistic, true);
165:                pc = (ModRuntimeTest1) pm.find(ModRuntimeTest1.class, oid);
166:                sm = getStateManager(pc, pm);
167:                assertNotNull(sm);
168:                setUpMetaData(sm.getMetaData());
169:                try {
170:                    sm.setImplData(key, value);
171:                    assertEquals(value, sm.getImplData(key));
172:
173:                    // test in transaction; re-lookup pc to be sure it enters the trans
174:                    startTx(pm);
175:                    pc = (ModRuntimeTest1) pm.find(ModRuntimeTest1.class, oid);
176:                    if (pm.getOptimistic())
177:                        assertEquals(value, sm.getImplData(key));
178:                    else {
179:                        assertNull(sm.getImplData(key));
180:                        sm.setImplData(key, value);
181:                    }
182:                    endTx(pm);
183:
184:                    // test outside of transaction
185:                    assertEquals(value, sm.getImplData(key));
186:                    endEm(pm);
187:                } finally {
188:                    tearDownMetaData();
189:                }
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.