openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r900231 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/
Date Sun, 17 Jan 2010 22:39:33 GMT
Author: faywang
Date: Sun Jan 17 22:39:32 2010
New Revision: 900231

URL: http://svn.apache.org/viewvc?rev=900231&view=rev
Log:
OPENJPA-931: support nesting EmbeddedId in IdClass

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Dependent5.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/DependentId5.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Employee5.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/EmployeeId5.java
  (with props)
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java?rev=900231&r1=900230&r2=900231&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
Sun Jan 17 22:39:32 2010
@@ -37,6 +37,7 @@
 import org.apache.openjpa.jdbc.meta.FieldStrategy;
 import org.apache.openjpa.jdbc.meta.Joinable;
 import org.apache.openjpa.jdbc.meta.MappingInfo;
+import org.apache.openjpa.jdbc.meta.ValueHandler;
 import org.apache.openjpa.jdbc.meta.ValueMapping;
 import org.apache.openjpa.jdbc.meta.ValueMappingImpl;
 import org.apache.openjpa.jdbc.meta.ValueMappingInfo;
@@ -65,6 +66,7 @@
 import org.apache.openjpa.util.ImplHelper;
 import org.apache.openjpa.util.InternalException;
 import org.apache.openjpa.util.MetaDataException;
+import org.apache.openjpa.util.ObjectId;
 import org.apache.openjpa.util.OpenJPAId;
 import org.apache.openjpa.util.UnsupportedException;
 
@@ -994,6 +996,8 @@
         col = field.getForeignKey().getPrimaryKeyColumn(col);
         if (col == null)
             throw new InternalException();
+        
+        Object savedFieldVal = fieldVal;
 
         ClassMapping relmapping = field.getTypeMapping();
         Joinable j = field.getTypeMapping().assertJoinable(col);
@@ -1006,6 +1010,9 @@
             Object[] pks = ApplicationIds.toPKValues(fieldVal, relmapping);
             fieldVal = pks[relmapping.getField(j.getFieldIndex()).
                 getPrimaryKeyIndex()];
+        } else if (relmapping.getObjectIdType() == ObjectId.class && 
+            relmapping.getPrimaryKeyFieldMappings()[0].getValueMapping().isEmbedded()) {
+            return j.getJoinValue(savedFieldVal, col, store);
         }
         return j.getJoinValue(fieldVal, col, store);
     }

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Dependent5.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Dependent5.java?rev=900231&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Dependent5.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Dependent5.java
Sun Jan 17 22:39:32 2010
@@ -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.enhance.identity;
+import java.io.Serializable;
+
+import javax.persistence.*;
+
+@Entity
+@IdClass(DependentId5.class)
+public class Dependent5 implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+    @Id
+    String name;
+    
+    @Id
+    @JoinColumns({
+       @JoinColumn(name="FIRSTNAME", referencedColumnName="FIRSTNAME"),
+       @JoinColumn(name="LASTNAME", referencedColumnName="LASTNAME")
+    })
+    @ManyToOne
+    Employee5 emp;
+
+    public Dependent5(String name, Employee5 emp) {
+        this.name = name;
+        this.emp = emp;
+    }
+
+    public Dependent5(DependentId5 dId, Employee5 emp){
+        this.name = dId.getName();
+        this.emp = emp;
+    } 
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/DependentId5.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/DependentId5.java?rev=900231&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/DependentId5.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/DependentId5.java
Sun Jan 17 22:39:32 2010
@@ -0,0 +1,60 @@
+/*
+ * 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.enhance.identity;
+
+public class DependentId5 {
+    String name;
+    EmployeeId5 emp;
+
+    public DependentId5() {
+    }
+
+    public DependentId5(String name, EmployeeId5 emp) {
+        this.name = name;
+        this.emp = emp;
+    }
+    
+    public String getName() {
+        return name;
+    }
+    
+    public void setName(String name) {
+        this.name = name;
+    }
+    
+    public EmployeeId5 getEmp() {
+        return emp;
+    }
+    
+    public void setEmp(EmployeeId5 emp) {
+        this.emp = emp;
+    }
+    
+    public int hashCode() {
+        return name.hashCode() + emp.hashCode();
+    }
+    
+    public boolean equals(Object o) {
+        if (!(o instanceof DependentId5)) return false;
+        DependentId5 d = (DependentId5) o;
+        if (!emp.equals(d.emp)) return false;
+        if (!name.equals(d.name)) return false;
+        return true;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/DependentId5.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Employee5.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Employee5.java?rev=900231&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Employee5.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Employee5.java
Sun Jan 17 22:39:32 2010
@@ -0,0 +1,40 @@
+/*
+ * 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.enhance.identity;
+
+import javax.persistence.*;
+import java.io.*;
+
+@Entity
+public class Employee5 implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @EmbeddedId 
+    EmployeeId5 empId;
+
+    public Employee5() {
+    }
+
+    public Employee5(EmployeeId5 eId) {
+        this.empId=eId;
+    }
+    
+    
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Employee5.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/EmployeeId5.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/EmployeeId5.java?rev=900231&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/EmployeeId5.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/EmployeeId5.java
Sun Jan 17 22:39:32 2010
@@ -0,0 +1,70 @@
+/*
+ * 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.enhance.identity;
+
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class EmployeeId5 implements java.io.Serializable {
+
+    String firstName;
+    String lastName;
+
+    public EmployeeId5() {
+    }
+
+    public EmployeeId5(String firstName, String lastName) {
+        this.firstName = firstName;
+        this.lastName = lastName;
+    }
+
+    public void setFirstName(String firstName) {
+        this.firstName = firstName;
+    }
+    
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+    
+    public String getFirstName() {
+        return firstName;
+    }
+    
+    public String getLastName() {
+        return lastName;
+    }
+    
+    public boolean equals(Object o) {
+        if (!(o instanceof EmployeeId5))
+            return false;
+        EmployeeId5 other = (EmployeeId5) o;
+        if (firstName.equals(other.firstName) && 
+                lastName.equals(other.lastName))
+            return true;
+        return false;
+    }
+    
+    public int hashCode() {
+        int ret = 0;
+        ret += firstName.hashCode();
+        ret = 31 * ret + lastName.hashCode();
+        return ret;
+    }
+}
+

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/EmployeeId5.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java?rev=900231&r1=900230&r2=900231&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java
Sun Jan 17 22:39:32 2010
@@ -87,7 +87,8 @@
             Person4.class, PersonId4.class, MedicalHistory4.class,
             Dependent3.class, Employee3.class, DependentId3.class, 
             Parent3.class, Dependent4.class, Employee4.class, PhoneNumber.class,
-            BeneContact.class, BeneContactId.class, Beneficiary.class);
+            BeneContact.class, BeneContactId.class, Beneficiary.class,
+            Dependent5.class, Employee5.class, EmployeeId5.class);
     }
 
     /**
@@ -186,6 +187,24 @@
         em.close();
     }
     
+    public void testEmbeddedIdContainedInIdClass() {
+        EntityManager em = emf.createEntityManager();
+        EmployeeId5 eId1 = new EmployeeId5("Java", "Duke");
+        Employee5 employee1 = new Employee5(eId1);
+        Dependent5 dep1 = new Dependent5("1", employee1);
+
+        em.persist(dep1);
+        em.persist(employee1);
+
+        em.getTransaction().begin();
+        em.flush();
+        em.getTransaction().commit();
+        em.clear();
+        
+        DependentId5 depId1 = new DependentId5("1", eId1);
+        Dependent5 newDep = em.find(Dependent5.class, depId1);
+        assertNotNull(newDep);
+    }
     
     public void createObj1() {
         EntityManager em = emf.createEntityManager();



Mime
View raw message