Author: awhite
Date: Tue Sep 12 14:39:01 2006
New Revision: 442718

URL: http://svn.apache.org/viewvc?view=rev&rev=442718
Log:
Delete child object(s) before parent when cascading delete.  Also fix case where
an interface field uses targetEntity to declare itself as a concrete entity 
relation, and add test case for fix.


Added:
    
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IFace.java
    
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TargetedIFaceRelationParent.java
   (with props)
    
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestTargetedIFaceRelations.java
Modified:
    
incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
    
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3.java
    
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassBase.java
    
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassL2.java
    
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/CascadingOneManyChild.java
    
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/CascadingOneManyParent.java
    
incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java

Modified: 
incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java?view=diff&rev=442718&r1=442717&r2=442718
==============================================================================
--- 
incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
 (original)
+++ 
incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
 Tue Sep 12 14:39:01 2006
@@ -2404,9 +2404,9 @@
         if (sm != null) {
             if (sm.isDetached())
                 throw newDetachedException(obj, "delete");
-            sm.delete();
             if ((action & OpCallbacks.ACT_CASCADE) != 0)
                 sm.cascadeDelete(call);
+            sm.delete();
         } else if (assertPersistenceCapable(obj).pcIsDetached() == 
Boolean.TRUE)
             throw newDetachedException(obj, "delete");
     }

Modified: 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3.java
URL: 
http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3.java?view=diff&rev=442718&r1=442717&r2=442718
==============================================================================
--- 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3.java
 (original)
+++ 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3.java
 Tue Sep 12 14:39:01 2006
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.inheritance;
 
 import javax.persistence.Entity;

Modified: 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassBase.java
URL: 
http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassBase.java?view=diff&rev=442718&r1=442717&r2=442718
==============================================================================
--- 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassBase.java
 (original)
+++ 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassBase.java
 Tue Sep 12 14:39:01 2006
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.inheritance;
 
 import javax.persistence.GeneratedValue;

Modified: 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassL2.java
URL: 
http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassL2.java?view=diff&rev=442718&r1=442717&r2=442718
==============================================================================
--- 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassL2.java
 (original)
+++ 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassL2.java
 Tue Sep 12 14:39:01 2006
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.inheritance;
 
 import javax.persistence.MappedSuperclass;

Modified: 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/CascadingOneManyChild.java
URL: 
http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/CascadingOneManyChild.java?view=diff&rev=442718&r1=442717&r2=442718
==============================================================================
--- 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/CascadingOneManyChild.java
 (original)
+++ 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/CascadingOneManyChild.java
 Tue Sep 12 14:39:01 2006
@@ -1,3 +1,18 @@
+/*

+ * Copyright 2006 The Apache Software Foundation.

+ *

+ * Licensed 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.relations;

 

 import javax.persistence.Column;

@@ -22,7 +37,7 @@
     private String name;

 

     @ManyToOne(optional=false)

-    @JoinColumn(name="PARENT_ID")

+    @JoinColumn(name="PARENT_ID", nullable=false)

     @ForeignKey

     private CascadingOneManyParent parent;

 


Modified: 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/CascadingOneManyParent.java
URL: 
http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/CascadingOneManyParent.java?view=diff&rev=442718&r1=442717&r2=442718
==============================================================================
--- 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/CascadingOneManyParent.java
 (original)
+++ 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/CascadingOneManyParent.java
 Tue Sep 12 14:39:01 2006
@@ -1,3 +1,18 @@
+/*

+ * Copyright 2006 The Apache Software Foundation.

+ *

+ * Licensed 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.relations;

 

 import java.util.ArrayList;


Added: 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IFace.java
URL: 
http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IFace.java?view=auto&rev=442718
==============================================================================
--- 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IFace.java
 (added)
+++ 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IFace.java
 Tue Sep 12 14:39:01 2006
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.relations;
+
+public interface IFace {
+
+    public String getName();
+}

Added: 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TargetedIFaceRelationParent.java
URL: 
http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TargetedIFaceRelationParent.java?view=auto&rev=442718
==============================================================================
--- 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TargetedIFaceRelationParent.java
 (added)
+++ 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TargetedIFaceRelationParent.java
 Tue Sep 12 14:39:01 2006
@@ -0,0 +1,61 @@
+/*

+ * Copyright 2006 The Apache Software Foundation.

+ *

+ * Licensed 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.relations;

+

+import javax.persistence.CascadeType;

+import javax.persistence.Entity;

+import javax.persistence.GeneratedValue;

+import javax.persistence.Id;

+import javax.persistence.ManyToOne;

+import javax.persistence.Version;

+

[EMAIL PROTECTED]

+public class TargetedIFaceRelationParent 

+    implements IFace {

+

+    @Id

+    @GeneratedValue

+    private long id;

+

+    private String name;

+

+    @ManyToOne(targetEntity=TargetedIFaceRelationParent.class,

+        cascade=CascadeType.ALL)

+    private IFace iface;

+

+    @Version

+    private Integer optLock;

+

+    public long getId() { 

+        return id; 

+    }

+

+    public IFace getIFace() {

+        return iface; 

+    }

+

+    public void setIFace(IFace iface) {

+        this.iface = iface; 

+    }

+

+    public String getName() { 

+        return name; 

+    }

+

+    public void setName(String name) { 

+        this.name = name; 

+    }

+}


Propchange: 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TargetedIFaceRelationParent.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestTargetedIFaceRelations.java
URL: 
http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestTargetedIFaceRelations.java?view=auto&rev=442718
==============================================================================
--- 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestTargetedIFaceRelations.java
 (added)
+++ 
incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestTargetedIFaceRelations.java
 Tue Sep 12 14:39:01 2006
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.relations;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Persistence;
+
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+
+/**
+ * Perform basic operations on an entity with interface relations that use
+ * the targetEntity attribute to set a concrete related type.
+ *
+ * @author Abe White
+ */
+public class TestTargetedIFaceRelations
+    extends TestCase {
+
+    private EntityManagerFactory emf;
+
+    public void setUp() {
+        Map props = new HashMap();
+        props.put("openjpa.MetaDataFactory", "jpa(Types=" 
+            + TargetedIFaceRelationParent.class.getName() + ")");
+        emf = Persistence.createEntityManagerFactory("test", props);
+    }
+
+    public void tearDown() {
+        if (emf == null)
+            return;
+        try {
+            EntityManager em = emf.createEntityManager();
+            em.getTransaction().begin();
+            em.createQuery("delete from TargetedIFaceRelationParent").
+                executeUpdate();
+            em.getTransaction().commit();
+            em.close();
+            emf.close();
+        } catch (Exception e) {
+        }
+    }
+
+    public void testPersist() {
+        TargetedIFaceRelationParent parent = new TargetedIFaceRelationParent();
+        parent.setName("parent");
+        TargetedIFaceRelationParent child = new TargetedIFaceRelationParent();
+        child.setName("child");
+        parent.setIFace(child);
+        
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        em.persist(parent);
+        em.getTransaction().commit();
+        long id = parent.getId();
+        assertTrue(id != 0);
+        em.close();
+
+        em = emf.createEntityManager();
+        parent = em.find(TargetedIFaceRelationParent.class, id);
+        assertNotNull(parent);
+        assertEquals("parent", parent.getName());
+        assertNotNull(parent.getIFace());
+        assertEquals("child", parent.getIFace().getName());
+        assertEquals(TargetedIFaceRelationParent.class, 
+            parent.getIFace().getClass());
+        assertNull(((TargetedIFaceRelationParent) parent.getIFace()).
+            getIFace());
+        em.close();
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(TestTargetedIFaceRelations.class);
+    }
+}
+

Modified: 
incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL: 
http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?view=diff&rev=442718&r1=442717&r2=442718
==============================================================================
--- 
incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
 (original)
+++ 
incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
 Tue Sep 12 14:39:01 2006
@@ -1200,7 +1200,7 @@
         if (!anno.optional())
             fmd.setNullValue(FieldMetaData.NULL_EXCEPTION);
         if (anno.targetEntity() != void.class)
-            fmd.setDeclaredType(anno.targetEntity());
+            fmd.setTypeOverride(anno.targetEntity());
         setCascades(fmd, anno.cascade());
     }
 
@@ -1223,7 +1223,7 @@
         if (isMappingOverrideMode() && !StringUtils.isEmpty(anno.mappedBy()))
             fmd.setMappedBy(anno.mappedBy());
         if (anno.targetEntity() != void.class)
-            fmd.setDeclaredType(anno.targetEntity());
+            fmd.setTypeOverride(anno.targetEntity());
         setCascades(fmd, anno.cascade());
     }
 


Reply via email to