openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r727744 - in /openjpa/branches/1.2.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/
Date Thu, 18 Dec 2008 15:22:43 GMT
Author: mikedd
Date: Thu Dec 18 07:22:42 2008
New Revision: 727744

URL: http://svn.apache.org/viewvc?rev=727744&view=rev
Log:
OPENJPA-777 merged to 1.2.x

Added:
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EmbedB.java
  (with props)
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityA.java
  (with props)
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityA1.java
  (with props)
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityB.java
  (with props)
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityC.java
  (with props)
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestPersistentCollection.java
  (with props)
Modified:
    openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java

Modified: openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java?rev=727744&r1=727743&r2=727744&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
(original)
+++ openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
Thu Dec 18 07:22:42 2008
@@ -964,7 +964,13 @@
 
         if (oid == null)
             sm.storeObject(field.getIndex(), null);
-        else
-            sm.setIntermediate(field.getIndex(), oid);
+        else {
+            if (JavaTypes.maybePC(field.getValue()) &&
+                !field.getValue().getDeclaredTypeMetaData().isEmbeddedOnly()) {
+                Object obj = store.find(oid, field, fetch);
+                sm.storeObject(field.getIndex(), obj);
+            } else    
+                sm.setIntermediate(field.getIndex(), oid);
+        }
     }
 }

Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EmbedB.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EmbedB.java?rev=727744&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EmbedB.java
(added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EmbedB.java
Thu Dec 18 07:22:42 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.annotations;
+import javax.persistence.CascadeType;
+import javax.persistence.Embeddable;
+import javax.persistence.ManyToOne;
+
+@Embeddable
+public class PColl_EmbedB {
+    private String name;
+    
+    @ManyToOne(cascade = CascadeType.PERSIST)
+    private PColl_EntityC m2oC;
+
+    public String getName() {
+        return name;
+    }
+    
+    public void setName(String name) {
+        this.name = name;
+    }
+    
+    public PColl_EntityC getM2oC() {
+        return m2oC;
+    }
+
+    public void setM2oC(PColl_EntityC m2oC) {
+        this.m2oC = m2oC;
+    }
+}

Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EmbedB.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityA.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityA.java?rev=727744&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityA.java
(added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityA.java
Thu Dec 18 07:22:42 2008
@@ -0,0 +1,68 @@
+/*
+ * 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.annotations;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Version;
+
+import org.apache.openjpa.persistence.PersistentCollection;
+
+@Entity
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+public class PColl_EntityA {
+
+    @Id
+    private int id;
+
+    @PersistentCollection(elementEmbedded = true)
+    private Set<PColl_EmbedB> embedCollection = new HashSet<PColl_EmbedB>();
+
+    @Version
+    private int version;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public Set<PColl_EmbedB> getEmbedCollection() {
+        return embedCollection;
+    }
+
+    public void setEmbedCollection(Set<PColl_EmbedB> embedCollection) {
+        this.embedCollection = embedCollection;
+    }
+
+    public void addEmbedElement(PColl_EmbedB element) {
+        this.embedCollection.add(element);
+    }
+
+    public String toString() {
+        return "PColl_EntityD<id=" + id + ",ver=" + version
+            + ",embedBCollection#=" + embedCollection.size() + ">";
+    }
+}

Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityA.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityA1.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityA1.java?rev=727744&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityA1.java
(added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityA1.java
Thu Dec 18 07:22:42 2008
@@ -0,0 +1,68 @@
+/*
+ * 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.annotations;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Version;
+
+import org.apache.openjpa.persistence.PersistentCollection;
+
+@Entity
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+public class PColl_EntityA1 {
+
+    @Id
+    private int id;
+
+    @PersistentCollection(elementEmbedded = true)
+    private Set<PColl_EntityB> embedCollection = new HashSet<PColl_EntityB>();
+
+    @Version
+    private int version;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public Set<PColl_EntityB> getEmbedCollection() {
+        return embedCollection;
+    }
+
+    public void setEmbedCollection(Set<PColl_EntityB> embedCollection) {
+        this.embedCollection = embedCollection;
+    }
+
+    public void addEmbedElement(PColl_EntityB element) {
+        this.embedCollection.add(element);
+    }
+
+    public String toString() {
+        return "PColl_EntityD<id=" + id + ",ver=" + version
+            + ",embedBCollection#=" + embedCollection.size() + ">";
+    }
+}

Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityA1.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityB.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityB.java?rev=727744&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityB.java
(added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityB.java
Thu Dec 18 07:22:42 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.annotations;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.ManyToOne;
+
+@Entity
+public class PColl_EntityB {
+    private String name;
+    
+    @ManyToOne(cascade = CascadeType.PERSIST)
+    private PColl_EntityC m2oC;
+
+    public String getName() {
+        return name;
+    }
+    
+    public void setName(String name) {
+        this.name = name;
+    }
+    
+    public PColl_EntityC getM2oC() {
+        return m2oC;
+    }
+
+    public void setM2oC(PColl_EntityC m2oC) {
+        this.m2oC = m2oC;
+    }
+}

Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityB.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityC.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityC.java?rev=727744&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityC.java
(added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityC.java
Thu Dec 18 07:22:42 2008
@@ -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.annotations;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Version;
+
+@Entity
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+public class PColl_EntityC {
+    @Id
+    private int id;
+
+    @Version
+    private int version;
+
+    public int getId() {
+        return id;
+
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String toString() {
+        return "PColl_EntityC<id=" + id + ",ver=" + version + ">";
+    }
+}

Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityC.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestPersistentCollection.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestPersistentCollection.java?rev=727744&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestPersistentCollection.java
(added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestPersistentCollection.java
Thu Dec 18 07:22:42 2008
@@ -0,0 +1,116 @@
+/*
+ * 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.annotations;
+
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * Test for PersistentCollection Annotation
+ * 
+ * @author Albert Lee
+ */
+public class TestPersistentCollection extends SingleEMFTestCase {
+
+    public void setUp() {
+        setUp(PColl_EntityA.class, PColl_EmbedB.class, PColl_EntityC.class,
+                PColl_EntityA1.class, PColl_EntityB.class, CLEAR_TABLES);
+    }
+
+    public void testPersistentCollectionOfEmbeddables() {
+        try {
+            EntityManager em = emf.createEntityManager();
+
+            em.getTransaction().begin();
+
+            PColl_EntityC c = new PColl_EntityC();
+            c.setId(101);
+
+            PColl_EmbedB b01 = new PColl_EmbedB();
+            b01.setName("b01");
+            b01.setM2oC(c);
+
+            PColl_EntityA a = new PColl_EntityA();
+            a.setId(1);
+            a.getEmbedCollection().add(b01);
+            em.persist(a);
+            em.getTransaction().commit();
+            em.close();
+
+            em = emf.createEntityManager();
+            Query q = em.createQuery("SELECT o FROM PColl_EntityA o"); 
+            List<PColl_EntityA> oList = q.getResultList();
+            PColl_EntityA d1 = oList.get(0);
+            
+            Set<PColl_EmbedB> b1s = d1.getEmbedCollection();
+
+            PColl_EmbedB b1 = b1s.iterator().next();
+            PColl_EntityC c1 = b1.getM2oC();
+            assertEquals("b01", b1.getName());
+            assertEquals(101, c1.getId());
+            assertEquals(1, d1.getId());
+            em.close();
+        } catch (Throwable t) {
+            fail(t.getMessage());
+        }
+    }
+
+    public void testPersistentCollectionOfEntities() {
+        try {
+            EntityManager em = emf.createEntityManager();
+
+            em.getTransaction().begin();
+
+            PColl_EntityC c = new PColl_EntityC();
+            c.setId(101);
+
+            PColl_EntityB b01 = new PColl_EntityB();
+            b01.setName("b01");
+            b01.setM2oC(c);
+
+            PColl_EntityA1 a = new PColl_EntityA1();
+            a.setId(1);
+            a.getEmbedCollection().add(b01);
+            em.persist(a);
+            em.getTransaction().commit();
+            em.close();
+
+            em = emf.createEntityManager();
+            Query q = em.createQuery("SELECT o FROM PColl_EntityA1 o"); 
+            List<PColl_EntityA1> oList = q.getResultList();
+            PColl_EntityA1 a1 = oList.get(0);
+            
+            Set<PColl_EntityB> b1s = a1.getEmbedCollection();
+
+            PColl_EntityB b1 = b1s.iterator().next();
+            PColl_EntityC c1 = b1.getM2oC();
+            assertEquals("b01", b1.getName());
+            assertEquals(101, c1.getId());
+            assertEquals(1, a1.getId());
+            em.close();
+        } catch (Throwable t) {
+            fail(t.getMessage());
+        }
+    }    
+}

Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestPersistentCollection.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message