svn commit: r1802534 - in /openjpa/branches/2.2.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/ openjpa-persistence-jdbc/src/test/resources/META-INF/

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

svn commit: r1802534 - in /openjpa/branches/2.2.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/ openjpa-persistence-jdbc/src/test/resources/META-INF/

jgrassel
Author: jgrassel
Date: Thu Jul 20 21:14:13 2017
New Revision: 1802534

URL: http://svn.apache.org/viewvc?rev=1802534&view=rev
Log:
OPENJPA-2704: The openjpa.jdbc.Schema no longer overrides orm.xml default (commit on wdazeys behalf)

Added:
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/TestOpenJPASchemaPUDefault.java   (with props)
Modified:
    openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java
    openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml

Modified: openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java?rev=1802534&r1=1802533&r2=1802534&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java (original)
+++ openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java Thu Jul 20 21:14:13 2017
@@ -306,14 +306,8 @@ public class ClassMappingInfo
      * Return the named table for the given class.
      */
     public Table getTable(final ClassMapping cls, DBIdentifier tableName,
-     boolean adapt) {
-        // If the schemaName is NULL type then check for a system default schema name
-        // and if available use it.
-        if (_schemaName != null && _schemaName.getType() == DBIdentifierType.NULL){            
-            String name = cls.getMappingRepository().getMetaDataFactory().getDefaults().getDefaultSchema();
-            _schemaName = (name != null ? DBIdentifier.newSchema(name) : _schemaName);
-        }        
-        
+            boolean adapt) {
+
         Table t = createTable(cls, new TableDefaults() {
             public String get(Schema schema) {
                 // delay this so that we don't do schema reflection for unique

Modified: openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java?rev=1802534&r1=1802533&r2=1802534&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java (original)
+++ openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java Thu Jul 20 21:14:13 2017
@@ -29,6 +29,7 @@ import org.apache.openjpa.jdbc.conf.JDBC
 import org.apache.openjpa.jdbc.identifier.Normalizer;
 import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.ColumnIO;
 import org.apache.openjpa.jdbc.schema.ForeignKey;
@@ -499,10 +500,19 @@ public abstract class MappingInfo
             && !repos.getMappingDefaults().defaultMissingInfo())))
             throw new MetaDataException(_loc.get("no-table", context));
 
-        if (DBIdentifier.isNull(schemaName))
+        if (DBIdentifier.isNull(schemaName)) {
+            //Check the configuration first for a set Schema to use
             schemaName = Schemas.getNewTableSchemaIdentifier((JDBCConfiguration)
                 repos.getConfiguration());
 
+            // If the schemaName is still NULL type then check for a system default schema name
+            // and if available use it.
+            if (schemaName != null && (schemaName.getType() == DBIdentifierType.NULL)) {
+                String name = repos.getMetaDataFactory().getDefaults().getDefaultSchema();
+                schemaName = (name != null ? DBIdentifier.newSchema(name) : schemaName);
+            }
+        }
+
         // if no given and adapting or defaulting missing info, use template
         SchemaGroup group = repos.getSchemaGroup();
         Schema schema = null;

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/TestOpenJPASchemaPUDefault.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/TestOpenJPASchemaPUDefault.java?rev=1802534&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/TestOpenJPASchemaPUDefault.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/TestOpenJPASchemaPUDefault.java Thu Jul 20 21:14:13 2017
@@ -0,0 +1,65 @@
+/*
+ * 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.pudefaults;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+/*
+ * OPENJPA-2704: These tests expand on TestSchemaPUDefault to verify
+ * that a schema defined in an orm's persistence-unit-default is
+ * overriden by the "openjpa.jdbc.Schema" property .  
+ */
+public class TestOpenJPASchemaPUDefault extends SQLListenerTestCase {
+
+    public void setUp() throws Exception {
+        super.setUp(PUDefaultSchemaEntity.class, PUSchemaInSequenceAnnotationEntity.class,
+            PUSchemaInTableAnnotationEntity.class, PUSchemaInTableMappingEntity.class,
+            PUSchemaInSequenceMappingEntity.class);
+        setSupportedDatabases(org.apache.openjpa.jdbc.sql.DB2Dictionary.class);
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    @Override
+    protected String getPersistenceUnitName() {
+        return "overrideMappingSchema";
+    }
+
+    public void testOpenJPASchemaOverridesORM() {
+        persist(new PUDefaultSchemaEntity());
+
+        // The Sequence and Table SQL should use the PU default schema
+        assertContainsSQL("ALTER SEQUENCE PUSCHEMA.SeqName_4DefaultSchema");
+        assertContainsSQL("INSERT INTO PUSCHEMA.PUDefaultSchemaEntity");
+    }
+
+    public void persist(Object ent){
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tx = em.getTransaction();
+        tx.begin();
+        em.persist(ent);
+        tx.commit();
+        em.close();
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/TestOpenJPASchemaPUDefault.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml?rev=1802534&r1=1802533&r2=1802534&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml (original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml Thu Jul 20 21:14:13 2017
@@ -466,10 +466,18 @@
         <mapping-file>META-INF/pudefaults-orm.xml</mapping-file>
         <mapping-file>META-INF/pudefaults2-orm.xml</mapping-file>
     <properties>
-    
                     <property name="openjpa.jdbc.SynchronizeMappings"
                 value="buildSchema(ForeignKeys=true)"/>
-                
+    </properties>
+  </persistence-unit>
+
+      <persistence-unit name="overrideMappingSchema" transaction-type="RESOURCE_LOCAL">
+        <mapping-file>META-INF/pudefaults-orm.xml</mapping-file>
+        <mapping-file>META-INF/pudefaults2-orm.xml</mapping-file>
+    <properties>
+                    <property name="openjpa.jdbc.Schema" value="PUSCHEMA" />
+                    <property name="openjpa.jdbc.SynchronizeMappings"
+                value="buildSchema(ForeignKeys=true)"/>
     </properties>
   </persistence-unit>
 


Loading...