openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jrba...@apache.org
Subject svn commit: r800951 - in /openjpa/trunk: openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ openjpa-integration/validation/src/test/resources/org/apache/openjpa/integration/validation/ openjpa-persistence-jdbc/src/m...
Date Tue, 04 Aug 2009 20:32:50 GMT
Author: jrbauer
Date: Tue Aug  4 20:32:49 2009
New Revision: 800951

URL: http://svn.apache.org/viewvc?rev=800951&view=rev
Log:
OPENJPA-1208 Set compatibility options and validation mode based on persistence version.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestSpecCompatibilityOptions.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/nopriv_persistence.xml
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/conf/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/conf/META-INF/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/conf/META-INF/persistence-2_0-config.xml
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/compat/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/compat/persistence_1_0.xml
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/compat/persistence_2_0.xml
  (with props)
Modified:
    openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java
    openjpa/trunk/openjpa-integration/validation/src/test/resources/org/apache/openjpa/integration/validation/persistence.xml
    openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml
    openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestSpecificationConfiguration.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachCascade.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachNoCascade.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachStateCascade.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetach.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/TestAccessMods.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java
    openjpa/trunk/openjpa-project/src/doc/manual/migration_considerations.xml

Modified: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java?rev=800951&r1=800950&r2=800951&view=diff
==============================================================================
--- openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java
(original)
+++ openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java
Tue Aug  4 20:32:49 2009
@@ -21,6 +21,7 @@
 import java.util.Set;
 
 import javax.persistence.Query;
+import javax.persistence.spi.ValidationMode;
 import javax.validation.ConstraintViolation;
 import javax.validation.ConstraintViolationException;
 
@@ -29,6 +30,7 @@
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
 import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.test.PersistenceTestCase;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
@@ -75,16 +77,24 @@
  *
  * @version $Rev$ $Date$
  */
-public class TestConstraints extends SingleEMFTestCase {
+public class TestConstraints extends PersistenceTestCase {
 
+    private static OpenJPAEntityManagerFactorySPI emf = null;
+    
     @Override
     public void setUp() {
-        super.setUp(CLEAR_TABLES,
-            ConstraintNull.class, ConstraintBoolean.class,
-            ConstraintDecimal.class, ConstraintNumber.class,
-            ConstraintDigits.class, ConstraintSize.class,
-            ConstraintDates.class, ConstraintPattern.class,
-            Person.class, Address.class);
+        
+        emf = (OpenJPAEntityManagerFactorySPI) 
+        OpenJPAPersistence.createEntityManagerFactory(
+                "ConstraintPU",
+                "org/apache/openjpa/integration/validation/persistence.xml");
+    }
+    
+    @Override
+    public void tearDown() {
+        if (emf != null) {
+            cleanup(emf);
+        }
     }
 
     /**
@@ -95,6 +105,7 @@
     public void testNullUpdateConstraint() {
         getLog().trace("testNullUpdateConstraint() started");
         
+        long id = 0;
         // Part 1 - Create and persist a valid entity
         // create EM from default EMF
         OpenJPAEntityManager em = emf.createEntityManager();
@@ -110,6 +121,7 @@
             ConstraintNull c = ConstraintNull.createValid();
             em.persist(c);
             em.getTransaction().commit();
+            id = c.getId();
             getLog().trace("testNullUpdateConstraint() Part 1 of 2 passed");
         } catch (Exception e) {
             // unexpected
@@ -129,7 +141,7 @@
         assertNotNull(em);        
         try {
             // update entity to be invalid
-            ConstraintNull c = em.find(ConstraintNull.class, new Integer(1));
+            ConstraintNull c = em.find(ConstraintNull.class, id);
             em.getTransaction().begin();
             c.setNullRequired(new String("not null"));
             em.flush();

Modified: openjpa/trunk/openjpa-integration/validation/src/test/resources/org/apache/openjpa/integration/validation/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/resources/org/apache/openjpa/integration/validation/persistence.xml?rev=800951&r1=800950&r2=800951&view=diff
==============================================================================
--- openjpa/trunk/openjpa-integration/validation/src/test/resources/org/apache/openjpa/integration/validation/persistence.xml
(original)
+++ openjpa/trunk/openjpa-integration/validation/src/test/resources/org/apache/openjpa/integration/validation/persistence.xml
Tue Aug  4 20:32:49 2009
@@ -124,5 +124,23 @@
             <!-- Properties passed in via createEMF -->
         </properties>
     </persistence-unit>
+
+    <persistence-unit name="ConstraintPU">
+        <class>org.apache.openjpa.integration.validation.ConstraintNull</class>
+        <class>org.apache.openjpa.integration.validation.ConstraintBoolean</class>
+        <class>org.apache.openjpa.integration.validation.ConstraintDecimal</class>
+        <class>org.apache.openjpa.integration.validation.ConstraintNumber</class>
+        <class>org.apache.openjpa.integration.validation.ConstraintDigits</class>
+        <class>org.apache.openjpa.integration.validation.ConstraintSize</class>
+        <class>org.apache.openjpa.integration.validation.ConstraintDates</class>
+        <class>org.apache.openjpa.integration.validation.ConstraintPattern</class>
+        <class>org.apache.openjpa.integration.validation.Person</class>
+        <class>org.apache.openjpa.integration.validation.Address</class>    
   
+        <validation-mode>AUTO</validation-mode>
+        <properties>
+            <property name="openjpa.jdbc.SynchronizeMappings" 
+                value="buildSchema"/>
+        </properties>
+    </persistence-unit>
     
 </persistence>

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml?rev=800951&r1=800950&r2=800951&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml Tue Aug  4 20:32:49 2009
@@ -80,9 +80,7 @@
             <exclude name="**/Unenhanced*.class" />
             <exclude name="**/AbstractUnenhanced*.class" />
             <exclude name="**/unenhanced/*.class" />
-			<exclude name="**/persistence/property/PrivAccessModsEntity.class"/>
-			<exclude name="**/persistence/property/EntityContact.class"/>
-			<exclude name="**/persistence/property/EmbeddableAddress.class"/>
+			<exclude name="**/persistence/property/AccessModsEntity.class"/>
         </fileset>
         <openjpac>
             <classpath refid="cp" />
@@ -103,12 +101,10 @@
         </openjpac>
 		<!-- Enhance with private persistent properties compatibility option -->
         <openjpac>
-            <config compatibility="PrivatePersistentProperties=true" />
+            <config propertiesFile="${project.build.testOutputDirectory}/META-INF/nopriv_persistence.xml"
/>
             <classpath refid="cp" />
             <fileset dir="${project.build.testOutputDirectory}">
-				<include name="**/persistence/property/PrivAccessModsEntity.class"/>
-    			<include name="**/persistence/property/EntityContact.class"/>
-    			<include name="**/persistence/property/EmbeddableAddress.class"/>
+				<include name="**/persistence/property/AccessModsEntity.class"/>
             </fileset>
             <config log="DefaultLevel=${openjpa.loglevel}" />
         </openjpac>

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java?rev=800951&r1=800950&r2=800951&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java
Tue Aug  4 20:32:49 2009
@@ -94,7 +94,7 @@
             return false;
         JDBCConfigurationImpl conf = (JDBCConfigurationImpl) c;
         Specification jpa = PersistenceProductDerivation.SPEC_JPA;
-        if (!jpa.equals(conf.getSpecificationInstance()))
+        if (!jpa.getName().equals(conf.getSpecificationInstance().getName()))
             return false;
         
         conf.mappingDefaultsPlugin.setDefault(jpa.getName());

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestSpecificationConfiguration.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestSpecificationConfiguration.java?rev=800951&r1=800950&r2=800951&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestSpecificationConfiguration.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestSpecificationConfiguration.java
Tue Aug  4 20:32:49 2009
@@ -20,6 +20,8 @@
 
 import javax.persistence.PersistenceException;
 
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
@@ -42,13 +44,34 @@
         assertTrue(spec.isSame("jpa"));
     }
     
-    public void testSpecificationVersionIsJPA2() {
+    public void testSpecificationVersionIsJPA1() {
         Specification spec = getSpecifcation();
         int major = spec.getVersion();
-        assertEquals(2, major);
+        assertEquals(1, major);
         assertTrue(spec.isSame("JPA"));
     }
-    
+
+    public void testSpecificationVersionIsJPA2() {
+        
+        OpenJPAEntityManagerFactorySPI emf1 = null;
+        try {
+          emf1 = 
+            (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
+            createEntityManagerFactory("persistence2_0",
+            "org/apache/openjpa/conf/META-INF/" +
+            "persistence-2_0-config.xml");
+
+            Specification spec = emf1.getConfiguration().getSpecificationInstance();
+            int major = spec.getVersion();
+            assertEquals(2, major);
+            assertTrue(spec.isSame("JPA"));
+        } finally {
+            if (emf1 != null) {
+                emf1.close();
+            }
+        }
+    }
+
     public void testLowerVersionCanBeSet() {
         super.setUp("openjpa.Specification", "JPA 1.0");
         Specification spec = getSpecifcation();

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestSpecCompatibilityOptions.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestSpecCompatibilityOptions.java?rev=800951&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestSpecCompatibilityOptions.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestSpecCompatibilityOptions.java
Tue Aug  4 20:32:49 2009
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.compat;
+
+import org.apache.openjpa.conf.Compatibility;
+import org.apache.openjpa.conf.Specification;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.test.PersistenceTestCase;
+
+public class TestSpecCompatibilityOptions 
+    extends PersistenceTestCase {
+    
+    /*
+     * Verifies compatibility options and spec level are appropriate
+     * for a version 2 persistence.xml
+     */
+    public void testJPA1CompatibilityOptions() {
+        OpenJPAEntityManagerFactorySPI emf =
+        (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
+            createEntityManagerFactory("persistence_1_0",
+                "org/apache/openjpa/persistence/compat/" +
+                "persistence_1_0.xml");
+
+        Compatibility compat = emf.getConfiguration().getCompatibilityInstance();
+        assertTrue(compat.getFlushBeforeDetach());
+        assertTrue(compat.getCopyOnDetach());
+        assertTrue(compat.getPrivatePersistentProperties());
+        String vMode = emf.getConfiguration().getValidationMode();
+        assertEquals("NONE", vMode);
+        Specification spec = emf.getConfiguration().getSpecificationInstance();
+        assertEquals("JPA", spec.getName().toUpperCase());
+        assertEquals(spec.getVersion(), 1);
+        
+        emf.close();
+
+    }
+
+    /*
+     * Verifies compatibility options and spec level are appropriate
+     * for a version 2 persistence.xml
+     */
+    public void testJPA2CompatibilityOptions() {
+        OpenJPAEntityManagerFactorySPI emf =
+        (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
+            createEntityManagerFactory("persistence_2_0",
+                "org/apache/openjpa/persistence/compat/" +
+                "persistence_2_0.xml");
+
+        Compatibility compat = emf.getConfiguration().getCompatibilityInstance();
+        assertFalse(compat.getFlushBeforeDetach());
+        assertFalse(compat.getCopyOnDetach());
+        assertFalse(compat.getPrivatePersistentProperties());
+        String vMode = emf.getConfiguration().getValidationMode();
+        assertEquals("AUTO", vMode);
+        Specification spec = emf.getConfiguration().getSpecificationInstance();
+        assertEquals("JPA", spec.getName().toUpperCase());
+        assertEquals(spec.getVersion(), 2);
+        
+        emf.close();
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestSpecCompatibilityOptions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachCascade.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachCascade.java?rev=800951&r1=800950&r2=800951&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachCascade.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachCascade.java
Tue Aug  4 20:32:49 2009
@@ -71,6 +71,9 @@
         assertNotNull(em);
         compat = emf.getConfiguration().getCompatibilityInstance();
         assertNotNull(compat);
+        compat.setFlushBeforeDetach(false);
+        compat.setCopyOnDetach(false);
+        compat.setCascadeWithDetach(true);
     }
 
     private void create(int id) {
@@ -145,6 +148,8 @@
     
     // Make sure cascade is no longer done by default
     public void testNoCascade() {
+        boolean cwd = compat.getCascadeWithDetach();
+        compat.setCascadeWithDetach(false);
         id++;
         em.getTransaction().begin();
         create(id);
@@ -155,6 +160,7 @@
         assertFalse(em.contains(e1));
         assertTrue(em.contains(e14));
         em.getTransaction().commit();
+        compat.setCascadeWithDetach(cwd);
     }
     
     // Change to the previous behavior to always cascade
@@ -179,6 +185,8 @@
     
     // Test explicit cascade of entities
     public void testCascadeOfEntities() {
+        boolean cwd = compat.getCascadeWithDetach();
+        compat.setCascadeWithDetach(false);
         id++;
         em.getTransaction().begin();
         create(id);
@@ -193,6 +201,7 @@
         assertTrue(em.contains(e6));
         assertTrue(em.contains(e7));
         em.getTransaction().commit();
+        compat.setCascadeWithDetach(cwd);
     }
     
     // Test always cascade of entities

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachNoCascade.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachNoCascade.java?rev=800951&r1=800950&r2=800951&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachNoCascade.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachNoCascade.java
Tue Aug  4 20:32:49 2009
@@ -47,6 +47,10 @@
         em = emf.createEntityManager();
         assertNotNull(em);
         compat = emf.getConfiguration().getCompatibilityInstance();
+        compat.setFlushBeforeDetach(true);
+        compat.setCopyOnDetach(false);
+        compat.setCascadeWithDetach(false);
+
     }
     
     private void create(int id) {
@@ -60,9 +64,9 @@
         e1.setE14(e14);
     }
     
-    // Make sure the default values are now changed
-    public void testChangedDefaults() {
-        assertFalse(compat.getFlushBeforeDetach());
+    // Make sure the default values are the same
+    public void testDefaults() {
+        assertTrue(compat.getFlushBeforeDetach());
         assertFalse(compat.getCopyOnDetach());
         assertFalse(compat.getCascadeWithDetach());
     }
@@ -105,6 +109,10 @@
     // are still managed.
     public void testClearOne() {
         id++;
+        boolean cwd = compat.getCascadeWithDetach();
+        boolean cod = compat.getCopyOnDetach();
+        compat.setCascadeWithDetach(false);
+        compat.setCopyOnDetach(false);
         em.getTransaction().begin();
         create(id);
         em.persistAll(allEntities);
@@ -114,6 +122,8 @@
         assertTrue(em.contains(e14));
         assertTrue(em.contains(e7));
         em.getTransaction().commit();
+        compat.setCascadeWithDetach(cwd);
+        compat.setCopyOnDetach(cod);
     }
     
     // Test clear on a new, unmanaged object. Nothing should happen. After
@@ -131,6 +141,12 @@
     
     // Test clear on dirty object. Make sure the change is not flushed.
     public void testClearDirty() {
+
+        boolean cod = compat.getCopyOnDetach();
+        boolean fbd = compat.getFlushBeforeDetach();
+        compat.setCopyOnDetach(false);
+        compat.setFlushBeforeDetach(false);
+        
         id++;
         em.getTransaction().begin();
         create(id);
@@ -150,11 +166,20 @@
         assertNotEquals("new name", e1.getName());
         assertEquals("entity1", e1.getName());
         em.getTransaction().commit();
+        
+        compat.setCopyOnDetach(cod);
+        compat.setFlushBeforeDetach(fbd);
     }
     
     // Remove an Entity before clearing it. Make sure it is still in the
     // DB after the commit.
     public void testClearRemove() {
+
+        boolean cwd = compat.getCascadeWithDetach();
+        boolean cod = compat.getCopyOnDetach();
+        compat.setCascadeWithDetach(false);
+        compat.setCopyOnDetach(false);
+        
         id++;
         em.getTransaction().begin();
         create(id);
@@ -172,11 +197,19 @@
         e1 = em.find(Entity1.class, id);
         assertNotNull(e1); 
         em.getTransaction().commit();
+        
+        compat.setCascadeWithDetach(cwd);
+        compat.setCopyOnDetach(cod);
     }
     
     // Try to clear an entity that has already been cleared. There should be
     // no exception and the entity should still not be there.
     public void testClearOnClearedEntity() {
+        boolean cwd = compat.getCascadeWithDetach();
+        boolean cod = compat.getCopyOnDetach();
+        compat.setCascadeWithDetach(false);
+        compat.setCopyOnDetach(false);
+
         id++;
         em.getTransaction().begin();
         create(id);
@@ -185,10 +218,18 @@
         em.detach(e1);
         assertFalse(em.contains(e1));
         em.getTransaction().commit();
+
+        compat.setCascadeWithDetach(cwd);
+        compat.setCopyOnDetach(cod);
     }
     
     // Test that no copy is done by default
     public void testNoCopy() {
+        boolean cwd = compat.getCascadeWithDetach();
+        boolean cod = compat.getCopyOnDetach();
+        compat.setCascadeWithDetach(false);
+        compat.setCopyOnDetach(false);
+
         id++;
         em.getTransaction().begin();
         create(id);
@@ -206,7 +247,10 @@
         em.getTransaction().commit();
 
         compat.setCascadeWithDetach(false);
-}
+
+        compat.setCascadeWithDetach(cwd);
+        compat.setCopyOnDetach(cod);
+    }
     
     // Change copy option and validate
     public void testCopy() {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachStateCascade.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachStateCascade.java?rev=800951&r1=800950&r2=800951&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachStateCascade.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachStateCascade.java
Tue Aug  4 20:32:49 2009
@@ -62,6 +62,9 @@
         assertNotNull(em);
         compat = emf.getConfiguration().getCompatibilityInstance();
         assertNotNull(compat);
+        compat.setFlushBeforeDetach(true);
+        compat.setCopyOnDetach(false);
+        compat.setCascadeWithDetach(false);
         id++;
         create(id);
         

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetach.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetach.java?rev=800951&r1=800950&r2=800951&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetach.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detachment/TestDetach.java
Tue Aug  4 20:32:49 2009
@@ -22,6 +22,7 @@
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.openjpa.conf.Compatibility;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.MetaDataRepository;
 import org.apache.openjpa.meta.ValueMetaData;
@@ -56,6 +57,12 @@
     public void setUp() {
         super.setUp(DMCustomer.class, DMCustomerInventory.class, DMItem.class,
             CLEAR_TABLES);
+        
+        Compatibility compat = 
+            emf.getConfiguration().getCompatibilityInstance();
+        compat.setCopyOnDetach(false);
+        compat.setFlushBeforeDetach(false);
+        
         em = emf.createEntityManager();
         root = createData();
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/TestAccessMods.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/TestAccessMods.java?rev=800951&r1=800950&r2=800951&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/TestAccessMods.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/TestAccessMods.java
Tue Aug  4 20:32:49 2009
@@ -26,13 +26,14 @@
     extends SingleEMFTestCase {
 
         public void setUp() {
-            setUp(DROP_TABLES, AccessModsEntity.class);
+            setUp("openjpa.Compatibility", "PrivatePersistentProperties=false",
+                DROP_TABLES, AccessModsEntity.class);
         }
         
         /**
-         * Verifies that by default, per JPA spec, non-transient public and 
-         * protected properties should be persistent.  Private should not be
-         * persistent.
+         * Verifies that when the PrivatePersistentProperties compat option 
+         * is false, non-transient public and protected properties should be 
+         * persistent.  Private should not be persistent.
          */
         public void testAccessMods() {
             EntityManager em = emf.createEntityManager();            

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/nopriv_persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/nopriv_persistence.xml?rev=800951&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/nopriv_persistence.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/nopriv_persistence.xml
Tue Aug  4 20:32:49 2009
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+ 
+ http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.   
+-->
+<persistence
+    xmlns="http://java.sun.com/xml/ns/persistence"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
+        http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+    version="2.0" >
+
+   <persistence-unit name="Persistence_2_0_PU">
+        <description>
+            This PU
+        </description>
+        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
+        <properties>
+           <!-- Since this is a 2.0 persistence file, this option is set by default -->
+           <!-- property name="openjpa.Compatibility" value="PrivatePersistentProperties=false"/-->
+        </properties>
+    </persistence-unit>
+</persistence>
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/nopriv_persistence.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/conf/META-INF/persistence-2_0-config.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/conf/META-INF/persistence-2_0-config.xml?rev=800951&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/conf/META-INF/persistence-2_0-config.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/conf/META-INF/persistence-2_0-config.xml
Tue Aug  4 20:32:49 2009
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+ 
+ http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.   
+-->
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    version="2.0">
+    
+    <persistence-unit name="persistence2_0">
+        <description>PU for testing JPA 2.0 spec level</description>
+    </persistence-unit>
+    
+
+</persistence>

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/conf/META-INF/persistence-2_0-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/compat/persistence_1_0.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/compat/persistence_1_0.xml?rev=800951&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/compat/persistence_1_0.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/compat/persistence_1_0.xml
Tue Aug  4 20:32:49 2009
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<persistence
+    xmlns="http://java.sun.com/xml/ns/persistence"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
+        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
+    version="1.0" >
+    <persistence-unit name="persistence_1_0" transaction-type="RESOURCE_LOCAL">
+    </persistence-unit>
+</persistence>
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/compat/persistence_1_0.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/compat/persistence_2_0.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/compat/persistence_2_0.xml?rev=800951&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/compat/persistence_2_0.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/compat/persistence_2_0.xml
Tue Aug  4 20:32:49 2009
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<persistence
+    xmlns="http://java.sun.com/xml/ns/persistence"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
+        http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+    version="2.0" >
+    <persistence-unit name="persistence_2_0" transaction-type="RESOURCE_LOCAL">
+    </persistence-unit>
+</persistence>
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/compat/persistence_2_0.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java?rev=800951&r1=800950&r2=800951&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
Tue Aug  4 20:32:49 2009
@@ -344,7 +344,7 @@
         /*
          * OpenJPA 1.x permitted private properties to be persistent.  This is
          * contrary to the JPA 1.0 specification, which states that persistent
-         * properties must be private or protected. OpenJPA 2.0+ will adhere
+         * properties must be public or protected. OpenJPA 2.0+ will adhere
          * to the specification by default, but provides a compatibility
          * option to provide pre-2.0 behavior.
          */

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java?rev=800951&r1=800950&r2=800951&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
Tue Aug  4 20:32:49 2009
@@ -181,6 +181,8 @@
             compatibility.setFlushBeforeDetach(true);
             compatibility.setCopyOnDetach(true);
             compatibility.setPrivatePersistentProperties(true);
+            // Disable bean validation for spec level < 2 configurations
+            conf.validationMode.set(String.valueOf(ValidationMode.NONE));
         } 
         return true;
     }
@@ -563,7 +565,19 @@
         public void setInto(Configuration conf) {
             if (conf instanceof OpenJPAConfiguration) {
                 OpenJPAConfiguration oconf = (OpenJPAConfiguration) conf;
-                oconf.setSpecification(SPEC_JPA);
+                Object persistenceVersion = 
+                    getProperties().get(
+                        PersistenceUnitInfoImpl.PERSISTENCE_VERSION);
+                if (persistenceVersion == null) {
+                    oconf.setSpecification(SPEC_JPA);
+                } else {
+                    // Set the spec level based on the persistence version
+                    oconf.setSpecification("jpa " + 
+                        persistenceVersion.toString());
+                    getProperties().remove(
+                        PersistenceUnitInfoImpl.PERSISTENCE_VERSION);
+                }
+                    
 
                 // we merge several persistence.xml elements into the 
                 // MetaDataFactory property implicitly.  if the user has a

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java?rev=800951&r1=800950&r2=800951&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java
Tue Aug  4 20:32:49 2009
@@ -62,6 +62,7 @@
     public static final String KEY_PROVIDER = "javax.persistence.provider";
     public static final String VALIDATION_MODE =
         "javax.persistence.validation.mode";
+    public static final String PERSISTENCE_VERSION = "PersistenceVersion";
 
     private static final Localizer s_loc = Localizer.forPackage
         (PersistenceUnitInfoImpl.class);
@@ -460,6 +461,10 @@
         if (info.getValidationMode() != null)
             map.put(VALIDATION_MODE, String.valueOf(info.getValidationMode()));
 
+        if (info.getPersistenceXMLSchemaVersion() != null) {
+            map.put(PERSISTENCE_VERSION, info.getPersistenceXMLSchemaVersion());
+        }
+        
         return map;
     }
 

Modified: openjpa/trunk/openjpa-project/src/doc/manual/migration_considerations.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/migration_considerations.xml?rev=800951&r1=800950&r2=800951&view=diff
==============================================================================
--- openjpa/trunk/openjpa-project/src/doc/manual/migration_considerations.xml (original)
+++ openjpa/trunk/openjpa-project/src/doc/manual/migration_considerations.xml Tue Aug  4 20:32:49
2009
@@ -31,8 +31,13 @@
     		</title>
     		<para>
     		The following sections indicate changes that are incompatible between
-    		OpenJPA 1.x.x releases and the 2.0 release. Some of these may
-    		require application changes.
+    		OpenJPA 1.x.x releases and the 2.0 release. Some of may
+    		require application changes. Others can be remedied through the use
+            of compatibility options.  If your application uses a version 1.0 persistence.xml,
+            compatibility options will be set appropriately to maintain backward 
+            compatibility.  OpenJPA 2.0 applications using a version 2.0 persistence.xml
+            and require OpenJPA 1.x.x compatibility may need to configure the appropriate
+            compatibility options to get the desired behavior.
     		</para>
     		<section id="getProperties">
     			<title>
@@ -88,7 +93,9 @@
 					</itemizedlist>
     			</para>
     			<para>
-    				It is possible to revert back to the 1.x.x behavior for
+    				Applications that use a 1.0 persistence.xml will automatically 
+                    maintain OpenJPA 1.0 behavior.  It is possible for a version 2.0 
+                    application to revert back to the 1.x.x behavior for
     				some of these items by setting the openjpa.Compatibility
     				property as follows:
     				<simplelist>
@@ -120,8 +127,9 @@
                     persistent by default.
                 </para>
                 <para>
-                    It is possible to revert back to the 1.x.x behavior which
-                    allowed private properties to be persistent by setting the 
+                    Applications that use a 1.0 persistence.xml will automatically 
+                    maintain OpenJPA 1.x.x behavior. It is possible for a version 2.0 
+                    application to revert back to the 1.x.x behavior by setting the 
                     value of the <literal>openjpa.Compatibility</literal> 
                     property <literal>PrivatePersistentProperties</literal> to

                     <literal>true</literal>.  If compile time enhancement is




Mime
View raw message