You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by il...@apache.org on 2018/07/03 07:40:44 UTC

svn commit: r1834927 - in /openjpa/branches/2.4.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/

Author: ilgrosso
Date: Tue Jul  3 07:40:44 2018
New Revision: 1834927

URL: http://svn.apache.org/viewvc?rev=1834927&view=rev
Log:
OPENJPA-2704: The openjpa.jdbc.Schema no longer overrides orm.xml default (backport from trunk - rev 1834900

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

Modified: openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java?rev=1834927&r1=1834926&r2=1834927&view=diff
==============================================================================
--- openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java (original)
+++ openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java Tue Jul  3 07:40:44 2018
@@ -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.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java?rev=1834927&r1=1834926&r2=1834927&view=diff
==============================================================================
--- openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java (original)
+++ openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java Tue Jul  3 07:40:44 2018
@@ -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.4.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/TestOpenJPASchemaPUDefault.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/TestOpenJPASchemaPUDefault.java?rev=1834927&view=auto
==============================================================================
--- openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/TestOpenJPASchemaPUDefault.java (added)
+++ openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/TestOpenJPASchemaPUDefault.java Tue Jul  3 07:40:44 2018
@@ -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();
+    }
+}

Modified: openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml?rev=1834927&r1=1834926&r2=1834927&view=diff
==============================================================================
--- openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml (original)
+++ openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml Tue Jul  3 07:40:44 2018
@@ -499,12 +499,22 @@
     </properties>
 </persistence-unit>
 
-	<persistence-unit name="TableNameInXml-PU" transaction-type="RESOURCE_LOCAL">
-		<mapping-file>META-INF/table-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>
+
+  <persistence-unit name="TableNameInXml-PU" transaction-type="RESOURCE_LOCAL">
+        <mapping-file>META-INF/table-orm.xml</mapping-file>
+    <properties>
+                    <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
+    </properties>
+  </persistence-unit>
 
     <persistence-unit name="TestPUDefaultCascadePersist" transaction-type="RESOURCE_LOCAL">
         <!--  <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> -->