Source Code Cross Referenced for BaseKernelTest.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:         * BaseKernelTest.java
003:         *
004:         * Created on October 9, 2006, 12:56 PM
005:         *
006:         * To change this template, choose Tools | Template Manager
007:         * and open the template in the editor.
008:         */
009:
010:        /*
011:         * Licensed to the Apache Software Foundation (ASF) under one
012:         * or more contributor license agreements.  See the NOTICE file
013:         * distributed with this work for additional information
014:         * regarding copyright ownership.  The ASF licenses this file
015:         * to you under the Apache License, Version 2.0 (the
016:         * "License"); you may not use this file except in compliance
017:         * with the License.  You may obtain a copy of the License at
018:         *
019:         * http://www.apache.org/licenses/LICENSE-2.0
020:         *
021:         * Unless required by applicable law or agreed to in writing,
022:         * software distributed under the License is distributed on an
023:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
024:         * KIND, either express or implied.  See the License for the
025:         * specific language governing permissions and limitations
026:         * under the License.    
027:         */
028:        package org.apache.openjpa.persistence.kernel;
029:
030:        import java.beans.BeanInfo;
031:        import java.beans.Introspector;
032:        import java.beans.PropertyDescriptor;
033:        import java.lang.reflect.InvocationTargetException;
034:        import java.lang.reflect.Method;
035:        import java.math.BigDecimal;
036:        import java.math.BigInteger;
037:        import java.util.*;
038:        import javax.management.IntrospectionException;
039:        import org.apache.openjpa.kernel.Broker;
040:        import org.apache.openjpa.kernel.OpenJPAStateManager;
041:        import org.apache.openjpa.lib.conf.ConfigurationProvider;
042:        import org.apache.openjpa.lib.conf.Configurations;
043:        import org.apache.openjpa.persistence.OpenJPAPersistence;
044:        import org.apache.openjpa.persistence.JPAFacadeHelper;
045:        import org.apache.openjpa.persistence.kernel.common.apps.*;
046:        import java.lang.annotation.Annotation;
047:        import junit.framework.*;
048:        import javax.persistence.EntityManager;
049:        import javax.persistence.EntityManagerFactory;
050:        import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
051:        import org.apache.openjpa.persistence.OpenJPAEntityManager;
052:
053:        public abstract class BaseKernelTest extends
054:                org.apache.openjpa.persistence.common.utils.AbstractTestCase {
055:            private static Map _sysprops = new HashMap();
056:
057:            /** Creates a new instance of BaseKernelTest */
058:            public BaseKernelTest() {
059:            }
060:
061:            public BaseKernelTest(String name) {
062:                super (name, "kernelcactusapp");
063:            }
064:
065:            protected OpenJPAEntityManager getPM() {
066:                return currentEntityManager();
067:            }
068:
069:            protected OpenJPAEntityManager getPM(boolean optimistic,
070:                    boolean retainValues) {
071:                OpenJPAEntityManager em = currentEntityManager();
072:                em.setNontransactionalRead(true);
073:                em.setRetainState(retainValues);
074:                if (em.getTransaction().isActive()) {
075:                    em.getTransaction().commit();
076:                    em.setOptimistic(optimistic);
077:                }
078:
079:                return em;
080:            }
081:
082:            protected Object persist(Object ob) {
083:                //FIXME  - this is just a workaround 
084:                //  Broker broker = .getBrokerFactory().newBroker();
085:                Broker broker = JPAFacadeHelper
086:                        .toBroker(currentEntityManager());
087:                broker.begin();
088:                broker.persist(ob, null);
089:                Object id = broker.getObjectId(ob);
090:                broker.commit();
091:                broker.close();
092:                return id;
093:            }
094:
095:            protected Properties getProperties() {
096:                return getProperties(null);
097:            }
098:
099:            /**
100:             * Return the runtime properties, optionally overriding or setting
101:             * some via the given array, which should be in the form
102:             * { key, val, key, val, ... }.
103:             */
104:            protected synchronized Properties getProperties(String[] props) {
105:                Properties p = new Properties(System.getProperties());
106:                String str = p.getProperty("openjpa.properties",
107:                        "kodo.properties");
108:                if (str != null && str.length() > 0) {
109:                    // cache system properties to reduce load on file system
110:                    Properties loaded = (Properties) _sysprops.get(str);
111:                    if (loaded == null) {
112:                        loaded = new Properties();
113:                        ConfigurationProvider cp = (ConfigurationProvider) Configurations
114:                                .getProperty(str, null);
115:
116:                        if (cp != null)
117:                            loaded.putAll(cp.getProperties());
118:                        _sysprops.put(str, loaded);
119:                    }
120:                    p.putAll(loaded);
121:                }
122:
123:                for (int i = 0; props != null && i < props.length; i += 2) {
124:                    if (props[i + 1] != null) {
125:                        // remove any duplicate kodo/openjpa property so we don't clash
126:                        if (props[i].startsWith("openjpa."))
127:                            p.remove("openjpa." + props[i].substring(5));
128:                        else if (props[i].startsWith("openjpa."))
129:                            p.remove("openjpa." + props[i].substring(8));
130:
131:                        p.setProperty(props[i], props[i + 1]);
132:                    } else {
133:                        p.remove(props[i]);
134:                    }
135:                }
136:                return p;
137:            }
138:            //
139:            //
140:            //    /**
141:            //     * Assert that the given List contain the exact same
142:            //     * elements. This is different than the normal List contract, which
143:            //     * states that list1.equals(list2) if each element e1.equals(e2).
144:            //     * This method asserts that e1 == n2.
145:            //     */
146:            //    public static void assertIdentical(List c1, List c2) {
147:            //        assertEquals(c1.size(), c2.size());
148:            //        for (Iterator i1 = c1.iterator(), i2 = c2.iterator();
149:            //            i1.hasNext() && i2.hasNext();)
150:            //            assertTrue(i1.next() == i2.next());
151:            //    }
152:            //
153:            //    /**
154:            //     * Assert that the collection parameter is already ordered
155:            //     * according to the specified comparator.
156:            //     */
157:            //    public void assertOrdered(Collection c, Comparator comp) {
158:            //        List l1 = new LinkedList(c);
159:            //        List l2 = new LinkedList(c);
160:            //        assertEquals(l1, l2);
161:            //        Collections.sort(l2, comp);
162:            //        assertEquals(l1, l2);
163:            //        Collections.sort(l1, comp);
164:            //        assertEquals(l1, l2);
165:            //    }
166:            //
167:            //    ////////////////////
168:            //    // Assertion Helpers
169:            //    ////////////////////
170:            //
171:            //    public void assertNotEquals(Object a, Object b) {
172:            //        if (a == null && b != null)
173:            //            return;
174:            //        if (a != null && b == null)
175:            //            return;
176:            //        if (!(a.equals(b)))
177:            //            return;
178:            //        if (!(b.equals(a)))
179:            //            return;
180:            //
181:            //        fail("expected !<" + a + ">.equals(<" + b + ">)");
182:            //    }
183:            //
184:            //    public void assertSize(int size, Object ob) {
185:            //        if (ob == null) {
186:            //            assertEquals(size, 0);
187:            //            return;
188:            //        }
189:            //
190:            //        if (ob instanceof Collection)
191:            //            ob = ((Collection) ob).iterator();
192:            //        if (ob instanceof Iterator) {
193:            //            Iterator i = (Iterator) ob;
194:            //            int count = 0;
195:            //            while (i.hasNext()) {
196:            //                count++;
197:            //                i.next();
198:            //            }
199:            //
200:            //            assertEquals(size, count);
201:            //        } else
202:            //            fail("assertSize: expected Collection, Iterator, "
203:            //                + "Query, or Extent, but got "
204:            //                + ob.getClass().getName());
205:            //    }
206:
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.