openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From allee8...@apache.org
Subject svn commit: r1392662 - 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/meta/
Date Mon, 01 Oct 2012 22:15:46 GMT
Author: allee8285
Date: Mon Oct  1 22:15:46 2012
New Revision: 1392662

URL: http://svn.apache.org/viewvc?rev=1392662&view=rev
Log:
OPENJPA-2247 Complete fix for 1x1 bi and mx1 uni relationships of the described problem.

Added:
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/PChild.java
  (with props)
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/PChildBi.java
  (with props)
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Parent.java
  (with props)
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestSecondaryTable.java
  (with props)
Modified:
    openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java

Modified: openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java?rev=1392662&r1=1392661&r2=1392662&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
(original)
+++ openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
Mon Oct  1 22:15:46 2012
@@ -88,7 +88,6 @@ import org.apache.openjpa.jdbc.sql.JoinS
 import org.apache.openjpa.lib.conf.Configurable;
 import org.apache.openjpa.lib.conf.Configurations;
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
-import org.apache.openjpa.lib.util.JavaVersions;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
@@ -1084,7 +1083,10 @@ public class MappingRepository extends M
             field.getAssociationType() == FieldMetaData.MANY_TO_ONE &&
             hasJoinTable(field) && 
             !isBidirectional(field))  {
-            field.getValueMapping().getValueInfo().setColumns(field.getElementMapping().getValueInfo().getColumns());
+            List<Column> cols = field.getElementMapping().getValueInfo().getColumns();
+            if (cols != null && cols.size() > 0) {
+                field.getValueMapping().getValueInfo().setColumns(cols);
+            }
             return true;
         }
         return false;
@@ -1095,7 +1097,10 @@ public class MappingRepository extends M
             field.getAssociationType() == FieldMetaData.ONE_TO_ONE && 
             hasJoinTable(field) && 
             !isBidirectional(field)) {
-            field.getValueMapping().getValueInfo().setColumns(field.getElementMapping().getValueInfo().getColumns());
+            List<Column> cols = field.getElementMapping().getValueInfo().getColumns();
+            if (cols != null && cols.size() > 0) {
+                field.getValueMapping().getValueInfo().setColumns(cols);
+            }
             return true;
         }
         return false;
@@ -1106,7 +1111,10 @@ public class MappingRepository extends M
             field.getAssociationType() == FieldMetaData.ONE_TO_ONE && 
             hasJoinTable(field) && 
             isBidirectional(field)) {
-            field.getValueMapping().getValueInfo().setColumns(field.getElementMapping().getValueInfo().getColumns());
+            List<Column> cols = field.getElementMapping().getValueInfo().getColumns();
+            if (cols != null && cols.size() > 0) {
+                field.getValueMapping().getValueInfo().setColumns(cols);
+            }
             return true;
         }
         return false;

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/PChild.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/PChild.java?rev=1392662&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/PChild.java
(added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/PChild.java
Mon Oct  1 22:15:46 2012
@@ -0,0 +1,38 @@
+/*
+ * 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.meta;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+@Entity
+public class PChild {
+    @Id
+    @GeneratedValue
+    int idChild;
+    
+    @Version
+    int version;
+    
+    @Basic
+    String basic;
+}

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

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/PChildBi.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/PChildBi.java?rev=1392662&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/PChildBi.java
(added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/PChildBi.java
Mon Oct  1 22:15:46 2012
@@ -0,0 +1,42 @@
+/*
+ * 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.meta;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+import javax.persistence.Version;
+
+@Entity
+public class PChildBi {
+    @Id
+    @GeneratedValue
+    int idChild;
+    
+    @Version
+    int version;
+    
+    @Basic
+    String basic;
+    
+    @OneToOne
+    Parent parent;
+}

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

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Parent.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Parent.java?rev=1392662&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Parent.java
(added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Parent.java
Mon Oct  1 22:15:46 2012
@@ -0,0 +1,52 @@
+/*
+ * 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.meta;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToOne;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.SecondaryTable;
+
+@Entity(name="META_PARENT")
+@SecondaryTable(name = "ParentSecondaryTable", pkJoinColumns = 
+    { @PrimaryKeyJoinColumn(name = "idParent", referencedColumnName = "idParent") })
+public class Parent {
+
+    @Id
+    @GeneratedValue
+    int idParent;
+
+    String child_ref;
+
+    @OneToOne
+    @JoinColumn(name = "CHILD_REF", table = "ParentSecondaryTable", referencedColumnName
= "idChild")
+    PChild child;
+
+    @OneToOne
+    @JoinColumn(name = "CHILDBI_REF", table = "ParentSecondaryTable", referencedColumnName
= "idChild")
+    PChildBi childbi;
+
+    @ManyToOne
+    @JoinColumn(name = "CHILDREN_REF", table = "ParentSecondaryTable", referencedColumnName
= "idChild")
+    PChild children;
+}

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

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestSecondaryTable.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestSecondaryTable.java?rev=1392662&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestSecondaryTable.java
(added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestSecondaryTable.java
Mon Oct  1 22:15:46 2012
@@ -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.meta;
+
+import org.apache.openjpa.jdbc.meta.FieldMapping;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestSecondaryTable extends SingleEMFTestCase {
+    public void setUp() {
+        setUp(Parent.class, PChild.class, PChildBi.class
+        // Hard code to 2.0 p.xml value. If the p.xml is 1.0, this value will be changed
to false, and the test
+        // won't fail.
+            , "openjpa.Compatibility", "NonDefaultMappingAllowed=true");
+    }
+
+    /**
+     * Added for OPENJPA-2247.
+     */
+    public void testMappingInfo() {
+        FieldMapping fm = getMapping(Parent.class).getFieldMapping("child");
+        assertNotNull(fm);
+        assertEquals("CHILD_REF", fm.getColumns()[0].getIdentifier().getName());
+
+        fm = getMapping(Parent.class).getFieldMapping("childbi");
+        assertNotNull(fm);
+        assertEquals("CHILDBI_REF", fm.getColumns()[0].getIdentifier().getName());
+
+        fm = getMapping(Parent.class).getFieldMapping("children");
+        assertNotNull(fm);
+        assertEquals("CHILDREN_REF", fm.getColumns()[0].getIdentifier().getName());
+    }
+}

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



Mime
View raw message