openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1626916 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/ openjpa-persistence-jdb...
Date Mon, 22 Sep 2014 23:06:18 GMT
Author: hthomann
Date: Mon Sep 22 23:06:18 2014
New Revision: 1626916

URL: http://svn.apache.org/r1626916
Log:
OPENJPA-2494: A default Schema defined in a PU default (<persistence-unit-defaults>)
in an orm.xml file is not being honored.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUDefaultSchemaEntity.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInSequenceAnnotationEntity.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInSequenceMappingEntity.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInTableAnnotationEntity.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInTableMappingEntity.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/TestSchemaPUDefault.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/pudefaults-orm.xml
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/pudefaults2-orm.xml
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/SequenceMetaData.java
    openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java?rev=1626916&r1=1626915&r2=1626916&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java
Mon Sep 22 23:06:18 2014
@@ -31,6 +31,7 @@ import java.util.Map.Entry;
 
 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.meta.strats.FullClassStrategy;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.ForeignKey;
@@ -306,6 +307,13 @@ public class ClassMappingInfo
      */
     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);
+        }        
+        
         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/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java?rev=1626916&r1=1626915&r2=1626916&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
Mon Sep 22 23:06:18 2014
@@ -127,4 +127,16 @@ public interface MetaDataDefaults
      */
     public boolean isNonDefaultMappingAllowed(OpenJPAConfiguration conf);
     
+
+    /**
+     * Returns the default schema.
+     * @since 2.2.3
+     */
+    public String getDefaultSchema();
+    
+    /**
+     * Sets the default schema.
+     * @since 2.2.3
+     */
+    public void setDefaultSchema(String schema);
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java?rev=1626916&r1=1626915&r2=1626916&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
Mon Sep 22 23:06:18 2014
@@ -169,4 +169,8 @@ public class NoneMetaDataFactory
     public boolean isNonDefaultMappingAllowed(OpenJPAConfiguration conf) {
         return false;
     }
+
+    public String getDefaultSchema(){return null;}
+    
+    public void setDefaultSchema(String schema){}
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/SequenceMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/SequenceMetaData.java?rev=1626916&r1=1626915&r2=1626916&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/SequenceMetaData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/SequenceMetaData.java
Mon Sep 22 23:06:18 2014
@@ -323,6 +323,13 @@ public class SequenceMetaData
      * Set/Get the schema name
      */
     public void setSchema(String schema) {
+        // If the schema name is empty, check to see if a system 
+        // level default exists and if so use it.
+        if (schema == null || "".equals(schema)){
+            String tmp = getRepository().getMetaDataFactory().getDefaults().getDefaultSchema();
+            schema = (tmp != null ? tmp : ""); 
+        }
+        
         this._schema = schema;
     }
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java?rev=1626916&r1=1626915&r2=1626916&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
Mon Sep 22 23:06:18 2014
@@ -209,8 +209,10 @@ public class XMLPersistenceMappingParser
         throws SAXException {
         MappingTag tag = _elems.get(name);
         if (tag == null) {
-            if ("schema".equals(name))
-                _schema = currentText();
+            if ("schema".equals(name)) {
+                _schema = currentText();                
+                getRepository().getMetaDataFactory().getDefaults().setDefaultSchema(_schema);
               
+            }
             return;
         }
 

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUDefaultSchemaEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUDefaultSchemaEntity.java?rev=1626916&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUDefaultSchemaEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUDefaultSchemaEntity.java
Mon Sep 22 23:06:18 2014
@@ -0,0 +1,47 @@
+/*
+ * 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 java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.SequenceGenerator;
+
+/*
+ * An entity which has a sequence where the sequence doesn't defined a schema,
+ * as such the persistence-unit-default schema (see pudefaults-orm.xml file)
+ * should be used when SQL operations are performed on the sequence. 
+ */
+@Entity
+public class PUDefaultSchemaEntity implements Serializable {
+
+    private static final long serialVersionUID = 2134948659397762341L;
+
+    @Id
+    @SequenceGenerator(name = "Seq_4DefaultSchema", sequenceName = "SeqName_4DefaultSchema")
+    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Seq_4DefaultSchema")
+    @Column(name = "ID")
+    private long id;
+
+    public long getId() { return id; }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInSequenceAnnotationEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInSequenceAnnotationEntity.java?rev=1626916&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInSequenceAnnotationEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInSequenceAnnotationEntity.java
Mon Sep 22 23:06:18 2014
@@ -0,0 +1,48 @@
+/*
+ * 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 java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.SequenceGenerator;
+
+/*
+ * An entity which has a sequence where the sequence defines a schema,
+ * as such the schema in the sequence annotation should take precedence over 
+ * the persistence-unit-default schema (see pudefaults-orm.xml file).
+ */
+@Entity
+public class PUSchemaInSequenceAnnotationEntity implements Serializable {
+
+    private static final long serialVersionUID = 2472845479260320080L;
+
+    @Id
+    @SequenceGenerator(name = "Seq_4AnnoSequenceSchema", sequenceName = "SeqName_4AnnoSequenceSchema",

+                       schema = "schemaInSequenceAnnotation")
+    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Seq_4AnnoSequenceSchema")
+    @Column(name = "ID")
+    private long id;
+
+    public long getId() { return id; }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInSequenceMappingEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInSequenceMappingEntity.java?rev=1626916&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInSequenceMappingEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInSequenceMappingEntity.java
Mon Sep 22 23:06:18 2014
@@ -0,0 +1,48 @@
+/*
+ * 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 java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.SequenceGenerator;
+
+/*
+ * An entity which has a sequence where the sequence defines a schema,
+ * as such the schema in the sequence annotation should take precedence over 
+ * the persistence-unit-default schema (see pudefaults-orm.xml file).
+ */
+@Entity
+public class PUSchemaInSequenceMappingEntity implements Serializable {
+
+    private static final long serialVersionUID = 2472845479260320080L;
+
+    @Id
+    @SequenceGenerator(name = "Seq_4SequenceMappingSchema", sequenceName = "SeqName_4SequenceMappingSchema",

+                       schema = "schemaInSequenceAnnotation")
+    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Seq_4SequenceMappingSchema")
+    @Column(name = "ID")
+    private long id;
+
+    public long getId() { return id; }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInTableAnnotationEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInTableAnnotationEntity.java?rev=1626916&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInTableAnnotationEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInTableAnnotationEntity.java
Mon Sep 22 23:06:18 2014
@@ -0,0 +1,49 @@
+/*
+ * 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 java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+/*
+ * An entity which has a @Table annotation which contains a schema name, 
+ * as such schema in the annotation should take precedence over the 
+ * persistence-unit-default schema (see pudefaults-orm.xml file).
+ */
+@Entity
+@Table(name = "PUSchemaInTable", schema = "schemaInTableAnnotation")
+public class PUSchemaInTableAnnotationEntity implements Serializable {
+
+    private static final long serialVersionUID = -566154189043208199L;
+
+    @Id
+    @SequenceGenerator(name = "Seq_4AnnoTableSchema", sequenceName = "SeqName_4AnnoTableSchema")
+    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Seq_4AnnoTableSchema")
+    @Column(name = "ID")
+    private long id;
+
+    public long getId() { return id; }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInTableMappingEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInTableMappingEntity.java?rev=1626916&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInTableMappingEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/PUSchemaInTableMappingEntity.java
Mon Sep 22 23:06:18 2014
@@ -0,0 +1,51 @@
+/*
+ * 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 java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+/*
+ * An entity which has a @Table annotation which contains a schema name, 
+ * as such schema in the annotation should take precedence over the 
+ * persistence-unit-default schema (see pudefaults-orm.xml file).  However,
+ * the schema has been overridden in the mapping file as such the
+ * schema in the mapping file trumps all.
+ */
+@Entity
+@Table(name = "PUSchemaInTableMapping", schema = "schemaInTableAnnotation")
+public class PUSchemaInTableMappingEntity implements Serializable {
+
+    private static final long serialVersionUID = -566154189043208199L;
+
+    @Id
+    @SequenceGenerator(name = "Seq_4TableMappingSchema", sequenceName = "SeqName_4TableMappingSchema")
+    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Seq_4TableMappingSchema")
+    @Column(name = "ID")
+    private long id;
+
+    public long getId() { return id; }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/TestSchemaPUDefault.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/TestSchemaPUDefault.java?rev=1626916&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/TestSchemaPUDefault.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/pudefaults/TestSchemaPUDefault.java
Mon Sep 22 23:06:18 2014
@@ -0,0 +1,101 @@
+/*
+ * 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-2494: This test verifies that a schema defined in an orm's 
+ * persistence-unit-default is used in certain scenarios, and overridden
+ * in other scenarios.  
+ */
+public class TestSchemaPUDefault 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 "puDefault";
+    }
+
+    public void testSchemaInPUDefault() {
+        persist(new PUDefaultSchemaEntity());
+
+        // The Sequence and Table SQL should use the PU default schema
+        assertContainsSQL("ALTER SEQUENCE schemaInPUDefaults.SeqName_4DefaultSchema");
+        assertContainsSQL("INSERT INTO schemaInPUDefaults.PUDefaultSchemaEntity");
+    }
+
+    public void testSchemaInSequenceAnnotation() {
+        persist(new PUSchemaInSequenceAnnotationEntity());
+
+        // The Sequence SQL should use the schema defined in the annotation
+        assertContainsSQL("ALTER SEQUENCE schemaInSequenceAnnotation.SeqName_4AnnoSequenceSchema");
+        // The Table SQL should use the schema defined in the PU default schema
+        assertContainsSQL("INSERT INTO schemaInPUDefaults.PUSchemaInSequenceAnnotationEntity");
+    }
+
+    public void testSchemaInTableAnnotation() {
+        persist(new PUSchemaInTableAnnotationEntity());
+
+        // The Sequence SQL should use the schema defined in the PU default schema
+        assertContainsSQL("ALTER SEQUENCE schemaInPUDefaults.SeqName_4AnnoTableSchema");
+        // The Table SQL should use the schema defined in the annotation
+        assertContainsSQL("INSERT INTO schemaInTableAnnotation.PUSchemaInTable");
+    }
+    
+    public void testSchemaInTableMapping() {
+        persist(new PUSchemaInTableMappingEntity());
+
+        // The Sequence SQL should use the schema defined in the PU default schema
+        assertContainsSQL("ALTER SEQUENCE schemaInPUDefaults.SeqName_4TableMappingSchema");
+        // The Table SQL should use the schema defined in the mapping file
+        assertContainsSQL("INSERT INTO schemaInTableMapping.PUSchemaInTableMapping");
+    }
+
+    public void testSchemaInSequenceMapping() {
+        persist(new PUSchemaInSequenceMappingEntity());
+
+        // The Sequence SQL should use the schema defined in the mapping file
+        assertContainsSQL("ALTER SEQUENCE schemaInSequenceMapping.SeqName_4SequenceMappingSchema");
+        // The Table SQL should use the schema defined in the PU default schema
+        assertContainsSQL("INSERT INTO schemaInPUDefaults.PUSchemaInSequenceMappingEntity");
+    }
+    
+    public void persist(Object ent){
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tx = em.getTransaction();
+        tx.begin();
+        em.persist(ent);
+        tx.commit();
+        em.close();
+    }    
+}

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml?rev=1626916&r1=1626915&r2=1626916&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml Mon
Sep 22 23:06:18 2014
@@ -488,4 +488,16 @@
 		</properties>
 	</persistence-unit>
 
+    <persistence-unit name="puDefault" 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.SynchronizeMappings"
+                value="buildSchema(ForeignKeys=true)"/>
+                
+    </properties>
+        
+    </persistence-unit>      
+
 </persistence>
\ No newline at end of file

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/pudefaults-orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/pudefaults-orm.xml?rev=1626916&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/pudefaults-orm.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/pudefaults-orm.xml
Mon Sep 22 23:06:18 2014
@@ -0,0 +1,36 @@
+<?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.
+-->
+
+<entity-mappings version="2.0" xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">
+
+<!-- This file contains some mappings, and its close cousin, pudefaults2-orm.xml, contains
some mappings as
+     well to verify that mappings can be spread accross multiple mapping files. -->
+     
+	<persistence-unit-metadata>
+		<persistence-unit-defaults>
+			<schema>schemaInPUDefaults</schema>
+		</persistence-unit-defaults>
+	</persistence-unit-metadata>
+	
+	<entity class="org.apache.openjpa.persistence.pudefaults.PUSchemaInTableMappingEntity">
+		<table name="PUSchemaInTableMappingEntity" schema="schemaInTableMapping"></table>
+	</entity>
+
+</entity-mappings>

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/pudefaults2-orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/pudefaults2-orm.xml?rev=1626916&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/pudefaults2-orm.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/pudefaults2-orm.xml
Mon Sep 22 23:06:18 2014
@@ -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.
+-->
+
+<entity-mappings version="2.0" xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">
+
+	<entity class="org.apache.openjpa.persistence.pudefaults.PUSchemaInSequenceMappingEntity">
+  		<sequence-generator name="Seq_4SequenceMappingSchema"
+  			sequence-name="SeqName_4SequenceMappingSchema" schema="schemaInSequenceMapping">
+  		</sequence-generator>
+	</entity>
+	 
+</entity-mappings>

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=1626916&r1=1626915&r2=1626916&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
Mon Sep 22 23:06:18 2014
@@ -133,6 +133,7 @@ public class PersistenceMetaDataDefaults
     protected SetterFilter setterFilter = new SetterFilter();
     private Boolean _isAbstractMappingUniDirectional = null;
     private Boolean _isNonDefaultMappingAllowed = null;
+    private String _defaultSchema;
     
     public PersistenceMetaDataDefaults() {
         setCallbackMode(CALLBACK_RETHROW | CALLBACK_ROLLBACK |
@@ -949,4 +950,14 @@ public class PersistenceMetaDataDefaults
         _isNonDefaultMappingAllowed = conf.getCompatibilityInstance().
             isNonDefaultMappingAllowed();
     }
+
+    @Override
+    public String getDefaultSchema() {
+        return _defaultSchema;
+    }
+
+    @Override
+    public void setDefaultSchema(String schema) {
+        _defaultSchema=schema;        
+    }
 }



Mime
View raw message