openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jrba...@apache.org
Subject svn commit: r809797 - in /openjpa/trunk: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/ openjpa-persistence-jdbc/src/test/resources/META-INF/ openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/...
Date Tue, 01 Sep 2009 02:06:04 GMT
Author: jrbauer
Date: Tue Sep  1 02:06:03 2009
New Revision: 809797

URL: http://svn.apache.org/viewvc?rev=809797&view=rev
Log:
OPENJPA-1274 Support cascade detach specified in an XML mapping file

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Automobile.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Driver.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Owner.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Passenger.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/TestDetachXML.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-all-orm.xml
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-orm.xml
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-persistence.xml
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/no-detach-orm.xml
  (with props)
Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Automobile.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Automobile.java?rev=809797&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Automobile.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Automobile.java
Tue Sep  1 02:06:03 2009
@@ -0,0 +1,86 @@
+/*
+ * 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.detach.xml;
+
+import java.util.Collection;
+
+public class Automobile {
+    
+    private long id;
+    
+    private String make;
+    private String model;
+        
+    // Many To Many
+    private Collection<Passenger> passengers;
+    
+    // One to One
+    private Driver primaryDriver;
+
+    // Many to One
+    private Owner owner;
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public void setMake(String make) {
+        this.make = make;
+    }
+
+    public String getMake() {
+        return make;
+    }
+
+    public void setModel(String model) {
+        this.model = model;
+    }
+
+    public String getModel() {
+        return model;
+    }
+
+    public void setPassengers(Collection<Passenger> passengers) {
+        this.passengers = passengers;
+    }
+
+    public Collection<Passenger> getPassengers() {
+        return passengers;
+    }
+
+    public void setPrimaryDriver(Driver primaryDriver) {
+        this.primaryDriver = primaryDriver;
+    }
+
+    public Driver getPrimaryDriver() {
+        return primaryDriver;
+    }
+
+    public void setOwner(Owner owner) {
+        this.owner = owner;
+    }
+
+    public Owner getOwner() {
+        return owner;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Automobile.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Driver.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Driver.java?rev=809797&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Driver.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Driver.java
Tue Sep  1 02:06:03 2009
@@ -0,0 +1,59 @@
+/*
+ * 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.detach.xml;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="AUTO_DRIVER")
+public class Driver {
+
+    private long id;
+    
+    private String name;
+
+    // One To One
+    private Automobile auto;
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setAuto(Automobile auto) {
+        this.auto = auto;
+    }
+
+    public Automobile getAuto() {
+        return auto;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Driver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Owner.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Owner.java?rev=809797&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Owner.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Owner.java
Tue Sep  1 02:06:03 2009
@@ -0,0 +1,61 @@
+/*
+ * 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.detach.xml;
+
+import java.util.List;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="AUTO_OWNER")
+public class Owner {
+
+    private long id;
+    
+    private String name;
+    
+    // One-2-Many
+    private List<Automobile> autos;
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setAutos(List<Automobile> autos) {
+        this.autos = autos;
+    }
+
+    public List<Automobile> getAutos() {
+        return autos;
+    }
+    
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Owner.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Passenger.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Passenger.java?rev=809797&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Passenger.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Passenger.java
Tue Sep  1 02:06:03 2009
@@ -0,0 +1,61 @@
+/*
+ * 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.detach.xml;
+
+import java.util.Collection;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="AUTO_PASSENGER")
+public class Passenger {
+
+    private long id;
+    
+    private String name;
+
+    // Many To Many (mappedBy=passengers)
+    private Collection<Automobile> autos;
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setAutos(Collection<Automobile> autos) {
+        this.autos = autos;
+    }
+
+    public Collection<Automobile> getAutos() {
+        return autos;
+    }
+    
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/Passenger.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/TestDetachXML.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/TestDetachXML.java?rev=809797&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/TestDetachXML.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/TestDetachXML.java
Tue Sep  1 02:06:03 2009
@@ -0,0 +1,203 @@
+/*
+ * 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.detach.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase;
+
+/**
+ * These test verify the use of cascade-detach via orm.xml through
+ * the cascade-detach and cascade-all elements.  Within each variation, a 
+ * bi-directional entity graph containing all relationship types is made 
+ * persistent.  Detach is called iteratively on a full graph and cascade
+ * behavior is verified.
+ */
+public class TestDetachXML extends AbstractPersistenceTestCase {
+
+    /*
+     * Test the use of cascade-detach with all relationship types.  All entities
+     * in the graph should be detached when any entity is detached.
+     */
+    public void testDetach() throws Exception {
+        OpenJPAEntityManagerFactorySPI emf = 
+            (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
+            createEntityManagerFactory("DetachXMLPU",
+                "org/apache/openjpa/persistence/detach/" +
+                "detach-persistence.xml");
+        
+        try {
+            verifyCascadeDetach(emf, true);                        
+        } finally {
+            cleanupEMF(emf);
+        }      
+    }
+
+    /*
+     * Test the use of no cascade-detach with all relationship types.  The
+     * base object should become detached and no other entities should be
+     * detached.
+     */
+    public void testNoDetach()  throws Exception {
+        OpenJPAEntityManagerFactorySPI emf = 
+            (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
+            createEntityManagerFactory("NoDetachXMLPU",
+                "org/apache/openjpa/persistence/detach/" +
+                "detach-persistence.xml");
+        
+        try {
+            verifyCascadeDetach(emf, false);
+        } finally {
+            cleanupEMF(emf);
+        }      
+    }
+
+    /*
+     * Test the use of cascade-all with all relationship types.  All entities
+     * in the graph should be detached when a single entity is detached.
+     */
+    public void testAllDetach()  throws Exception {
+        OpenJPAEntityManagerFactorySPI emf = 
+            (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
+            createEntityManagerFactory("DetachAllXMLPU",
+                "org/apache/openjpa/persistence/detach/" +
+                "detach-persistence.xml");
+        
+        try {
+            verifyCascadeDetach(emf, true);
+        } finally {
+            cleanupEMF(emf);
+        }      
+    }
+    
+    private void verifyCascadeDetach(EntityManagerFactory emf, boolean cascade) {
+        EntityManager em = emf.createEntityManager();
+        List<Object> data = createData(em);
+        assertNotNull(data);
+        int size = data.size();
+        assertTrue(data.size() > 0);
+        
+        // Cycle through all PCs, verifying detach state
+        for (int i = 0; i < size; i++) {
+            Object entity = data.get(i);
+            em.detach(entity);
+            for (int j = 0; j < size; j++ ) {
+                if (j == i) {
+                    // Base entity should always be detached
+                    assertFalse(em.contains(entity));
+                } else {
+                    Object detent = data.get(j);
+                    assertEquals(!cascade, em.contains(detent));
+                }
+            }
+            // Populate new data
+            data = createData(em);
+        }
+        
+    }
+    
+    private List<Object> createData(EntityManager em) {
+        List<Object> data = new ArrayList<Object>();
+        Automobile auto = new Automobile();
+        auto.setMake("Ford");
+        auto.setModel("Pinto");
+        data.add(auto);
+                
+        Automobile auto2 = new Automobile();
+        auto2.setMake("Winnebago");
+        auto2.setModel("Sightseer");
+        data.add(auto2);
+        
+        List<Automobile> autos = new ArrayList<Automobile>();
+        autos.add(auto);
+        autos.add(auto2);
+
+        Passenger p1 = new Passenger();
+        p1.setName("Crash test dummy 0");
+        p1.setAutos(autos);
+        data.add(p1);
+        
+        Passenger p2 = new Passenger();
+        p2.setName("Crash test dummy 1");
+        p2.setAutos(autos);
+        data.add(p2);
+        
+        List<Passenger> passengers = new ArrayList<Passenger>();
+        passengers.add(p1);
+        passengers.add(p2);
+        auto.setPassengers(passengers);
+        auto2.setPassengers(passengers);
+        
+        Driver d1 = new Driver();
+        d1.setAuto(auto);
+        d1.setName("Crash test driver 0");
+        auto.setPrimaryDriver(d1);
+        data.add(d1);
+        
+        Driver d2 = new Driver();
+        d2.setAuto(auto2);
+        d2.setName("Crash test driver 1");
+        auto2.setPrimaryDriver(d2);
+        data.add(d2);
+        
+        Owner owner = new Owner();
+        owner.setName("DMV");
+        owner.setAutos(autos);
+        auto.setOwner(owner);
+        auto2.setOwner(owner);
+        data.add(owner);
+
+        // Persist the object graph
+        em.getTransaction().begin();        
+        em.persist(owner);
+        em.getTransaction().commit();
+        
+        return data;
+    }
+
+
+    /**
+     * Closes a specific entity manager factory and cleans up 
+     * associated tables.
+     */
+    private void cleanupEMF(OpenJPAEntityManagerFactorySPI emf1) 
+      throws Exception {
+
+        if (emf1 == null)
+            return;
+
+        try {
+            clear(emf1);
+        } catch (Exception e) {
+            // if a test failed, swallow any exceptions that happen
+            // during tear-down, as these just mask the original problem.
+            if (testResult.wasSuccessful())
+                throw e;
+        } finally {
+            closeEMF(emf1);
+        }
+    }    
+
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/xml/TestDetachXML.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=809797&r1=809796&r2=809797&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 Tue
Sep  1 02:06:03 2009
@@ -51,6 +51,7 @@
         <mapping-file>org/apache/openjpa/persistence/inheritance/orm.xml</mapping-file>
         <mapping-file>org/apache/openjpa/persistence/orm.xml</mapping-file>
         <mapping-file>org/apache/openjpa/persistence/embed/embed-assoc-over-orm.xml</mapping-file>
+        <mapping-file>org/apache/openjpa/persistence/detach/detach-orm.xml</mapping-file>
         <properties>
             <property name="openjpa.jdbc.SynchronizeMappings"
                 value="buildSchema(ForeignKeys=true)"/>

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-all-orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-all-orm.xml?rev=809797&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-all-orm.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-all-orm.xml
Tue Sep  1 02:06:03 2009
@@ -0,0 +1,96 @@
+<?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 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 orm_2_0.xsd"
+    version="2.0">
+    
+    <entity name="Automobile" 
+            class="org.apache.openjpa.persistence.detach.xml.Automobile" 
+            access="FIELD">
+        <attributes>
+            <id name="id">
+                <generated-value/>
+            </id>
+            <basic name="make"/>
+            <basic name="model"/>
+            <many-to-one name="owner">
+                <cascade>
+                    <cascade-all/>
+                </cascade>
+            </many-to-one>
+            <one-to-one name="primaryDriver">
+                <cascade>
+                    <cascade-all/>
+                </cascade>
+            </one-to-one>
+            <many-to-many name="passengers">
+                <cascade>
+                    <cascade-all/>
+                </cascade>
+            </many-to-many>
+        </attributes>
+    </entity>    
+    <entity name="Driver" 
+            class="org.apache.openjpa.persistence.detach.xml.Driver" 
+            access="FIELD">
+        <attributes>
+            <id name="id">
+                <generated-value/>
+            </id>
+            <basic name="name"/>
+            <one-to-one name="auto">
+                <cascade>
+                    <cascade-all/>
+                </cascade>
+            </one-to-one>
+        </attributes>
+    </entity>
+    <entity name="Passenger" 
+            class="org.apache.openjpa.persistence.detach.xml.Passenger" 
+            access="FIELD">
+        <attributes>
+            <id name="id">
+                <generated-value/>
+            </id>
+            <basic name="name"/>
+            <many-to-many name="autos">
+                <cascade>
+                    <cascade-all/>
+                </cascade>
+            </many-to-many>
+        </attributes>
+    </entity>
+    <entity name="Owner" 
+            class="org.apache.openjpa.persistence.detach.xml.Owner" 
+            access="FIELD">
+        <attributes>
+            <id name="id">
+                <generated-value/>
+            </id>
+            <basic name="name"/>
+            <one-to-many name="autos">
+                <cascade>
+                    <cascade-all/>
+                </cascade>
+            </one-to-many>
+        </attributes>
+    </entity>    
+</entity-mappings>

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-all-orm.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-orm.xml?rev=809797&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-orm.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-orm.xml
Tue Sep  1 02:06:03 2009
@@ -0,0 +1,102 @@
+<?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 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 orm_2_0.xsd"
+    version="2.0">
+    
+    <entity name="Automobile" 
+            class="org.apache.openjpa.persistence.detach.xml.Automobile" 
+            access="FIELD">
+        <attributes>
+            <id name="id">
+                <generated-value/>
+            </id>
+            <basic name="make"/>
+            <basic name="model"/>
+            <many-to-one name="owner">
+                <cascade>
+                    <cascade-persist/>
+                    <cascade-detach/>                    
+                </cascade>
+            </many-to-one>
+            <one-to-one name="primaryDriver">
+                <cascade>
+                    <cascade-persist/>
+                    <cascade-detach/>                    
+                </cascade>
+            </one-to-one>
+            <many-to-many name="passengers">
+                <cascade>
+                    <cascade-persist/>
+                    <cascade-detach/>                    
+                </cascade>
+            </many-to-many>
+        </attributes>
+    </entity>    
+    <entity name="Driver" 
+            class="org.apache.openjpa.persistence.detach.xml.Driver" 
+            access="FIELD">
+        <attributes>
+            <id name="id">
+                <generated-value/>
+            </id>
+            <basic name="name"/>
+            <one-to-one name="auto">
+                <cascade>
+                    <cascade-persist/>
+                    <cascade-detach/>                    
+                </cascade>
+            </one-to-one>
+        </attributes>
+    </entity>
+    <entity name="Passenger" 
+            class="org.apache.openjpa.persistence.detach.xml.Passenger" 
+            access="FIELD">
+        <attributes>
+            <id name="id">
+                <generated-value/>
+            </id>
+            <basic name="name"/>
+            <many-to-many name="autos">
+                <cascade>
+                    <cascade-persist/>
+                    <cascade-detach/>                    
+                </cascade>
+            </many-to-many>
+        </attributes>
+    </entity>
+    <entity name="Owner" 
+            class="org.apache.openjpa.persistence.detach.xml.Owner" 
+            access="FIELD">
+        <attributes>
+            <id name="id">
+                <generated-value/>
+            </id>
+            <basic name="name"/>
+            <one-to-many name="autos">
+                <cascade>
+                    <cascade-persist/>
+                    <cascade-detach/>                    
+                </cascade>
+            </one-to-many>
+        </attributes>
+    </entity>    
+</entity-mappings>

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-orm.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-persistence.xml?rev=809797&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-persistence.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-persistence.xml
Tue Sep  1 02:06:03 2009
@@ -0,0 +1,77 @@
+<?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.
+-->
+<persistence
+    xmlns="http://java.sun.com/xml/ns/persistence"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
+        http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+    version="2.0" >
+    <persistence-unit name="DetachXMLPU" transaction-type="RESOURCE_LOCAL">
+        <description>PU for cascade detach testing</description>
+        <provider>
+            org.apache.openjpa.persistence.PersistenceProviderImpl
+        </provider>
+        <mapping-file>
+            org/apache/openjpa/persistence/detach/detach-orm.xml
+        </mapping-file>
+        <class>org.apache.openjpa.persistence.detach.xml.Automobile</class>
+        <class>org.apache.openjpa.persistence.detach.xml.Driver</class>
+        <class>org.apache.openjpa.persistence.detach.xml.Owner</class>
+        <class>org.apache.openjpa.persistence.detach.xml.Passenger</class>
+        <properties>
+            <property name="openjpa.jdbc.SynchronizeMappings" 
+                value="buildSchema(SchemaAction='drop,add')"/> 
+        </properties>
+    </persistence-unit>
+    <persistence-unit name="NoDetachXMLPU" transaction-type="RESOURCE_LOCAL">
+        <description>PU for cascade detach testing</description>
+        <provider>
+            org.apache.openjpa.persistence.PersistenceProviderImpl
+        </provider>
+        <mapping-file>
+            org/apache/openjpa/persistence/detach/no-detach-orm.xml
+        </mapping-file>
+        <class>org.apache.openjpa.persistence.detach.xml.Automobile</class>
+        <class>org.apache.openjpa.persistence.detach.xml.Driver</class>
+        <class>org.apache.openjpa.persistence.detach.xml.Owner</class>
+        <class>org.apache.openjpa.persistence.detach.xml.Passenger</class>
+        <properties>
+            <property name="openjpa.jdbc.SynchronizeMappings" 
+                value="buildSchema(SchemaAction='drop,add')"/> 
+        </properties>
+    </persistence-unit>
+    <persistence-unit name="DetachAllXMLPU" transaction-type="RESOURCE_LOCAL">
+        <description>PU for cascade detach testing</description>
+        <provider>
+            org.apache.openjpa.persistence.PersistenceProviderImpl
+        </provider>
+        <mapping-file>
+            org/apache/openjpa/persistence/detach/detach-all-orm.xml
+        </mapping-file>
+        <class>org.apache.openjpa.persistence.detach.xml.Automobile</class>
+        <class>org.apache.openjpa.persistence.detach.xml.Driver</class>
+        <class>org.apache.openjpa.persistence.detach.xml.Owner</class>
+        <class>org.apache.openjpa.persistence.detach.xml.Passenger</class>
+        <properties>
+            <property name="openjpa.jdbc.SynchronizeMappings" 
+                value="buildSchema(SchemaAction='drop,add')"/> 
+        </properties>
+    </persistence-unit>
+</persistence>

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/detach-persistence.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/no-detach-orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/no-detach-orm.xml?rev=809797&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/no-detach-orm.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/no-detach-orm.xml
Tue Sep  1 02:06:03 2009
@@ -0,0 +1,96 @@
+<?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 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 orm_2_0.xsd"
+    version="2.0">
+    
+    <entity name="Automobile" 
+            class="org.apache.openjpa.persistence.detach.xml.Automobile" 
+            access="FIELD">
+        <attributes>
+            <id name="id">
+                <generated-value/>
+            </id>
+            <basic name="make"/>
+            <basic name="model"/>
+            <many-to-one name="owner">
+                <cascade>
+                    <cascade-persist/>
+                </cascade>
+            </many-to-one>
+            <one-to-one name="primaryDriver">
+                <cascade>
+                    <cascade-persist/>
+                </cascade>
+            </one-to-one>
+            <many-to-many name="passengers">
+                <cascade>
+                    <cascade-persist/>
+                </cascade>
+            </many-to-many>
+        </attributes>
+    </entity>    
+    <entity name="Driver" 
+            class="org.apache.openjpa.persistence.detach.xml.Driver" 
+            access="FIELD">
+        <attributes>
+            <id name="id">
+                <generated-value/>
+            </id>
+            <basic name="name"/>
+            <one-to-one name="auto">
+                <cascade>
+                    <cascade-persist/>
+                </cascade>
+            </one-to-one>
+        </attributes>
+    </entity>
+    <entity name="Passenger" 
+            class="org.apache.openjpa.persistence.detach.xml.Passenger" 
+            access="FIELD">
+        <attributes>
+            <id name="id">
+                <generated-value/>
+            </id>
+            <basic name="name"/>
+            <many-to-many name="autos">
+                <cascade>
+                    <cascade-persist/>
+                </cascade>
+            </many-to-many>
+        </attributes>
+    </entity>
+    <entity name="Owner" 
+            class="org.apache.openjpa.persistence.detach.xml.Owner" 
+            access="FIELD">
+        <attributes>
+            <id name="id">
+                <generated-value/>
+            </id>
+            <basic name="name"/>
+            <one-to-many name="autos">
+                <cascade>
+                    <cascade-persist/>
+                </cascade>
+            </one-to-many>
+        </attributes>
+    </entity>    
+</entity-mappings>

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/detach/no-detach-orm.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java?rev=809797&r1=809796&r2=809797&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
Tue Sep  1 02:06:03 2009
@@ -101,6 +101,7 @@
     protected static final String ELEM_CASCADE_MER = "cascade-merge";
     protected static final String ELEM_CASCADE_REM = "cascade-remove";
     protected static final String ELEM_CASCADE_REF = "cascade-refresh";
+    protected static final String ELEM_CASCADE_DET = "cascade-detach";
     protected static final String ELEM_PU_META = "persistence-unit-metadata";
     protected static final String ELEM_PU_DEF = "persistence-unit-defaults";
     protected static final String ELEM_XML_MAP_META_COMPLETE =
@@ -125,6 +126,7 @@
         _elems.put(ELEM_CASCADE_REM, ELEM_CASCADE_REM);
         _elems.put(ELEM_CASCADE_MER, ELEM_CASCADE_MER);
         _elems.put(ELEM_CASCADE_REF, ELEM_CASCADE_REF);
+        _elems.put(ELEM_CASCADE_DET, ELEM_CASCADE_DET);
         _elems.put(ELEM_PU_META, ELEM_PU_META);
         _elems.put(ELEM_PU_DEF, ELEM_PU_DEF);
         _elems.put(ELEM_XML_MAP_META_COMPLETE, ELEM_XML_MAP_META_COMPLETE);
@@ -570,7 +572,7 @@
             ret = isMetaDataMode();
         else if (tag == ELEM_CASCADE_ALL || tag == ELEM_CASCADE_PER
             || tag == ELEM_CASCADE_MER || tag == ELEM_CASCADE_REM
-            || tag == ELEM_CASCADE_REF)
+            || tag == ELEM_CASCADE_REF || tag == ELEM_CASCADE_DET)
             ret = startCascade(tag, attrs);
 
         if (ret)
@@ -718,7 +720,7 @@
             ret = isMetaDataMode();
         else if (tag == ELEM_CASCADE_ALL || tag == ELEM_CASCADE_PER
             || tag == ELEM_CASCADE_MER || tag == ELEM_CASCADE_REM
-            || tag == ELEM_CASCADE_REF)
+            || tag == ELEM_CASCADE_REF || tag == ELEM_CASCADE_DET)
             ret = startCascade(tag, attrs);
 
         if (ret)
@@ -1161,6 +1163,8 @@
             cascades.add(MERGE);
         if (all || ELEM_CASCADE_REF == tag)
             cascades.add(REFRESH);
+        if (all || ELEM_CASCADE_DET == tag)
+            cascades.add(DETACH);
         return true;
     }
 

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java?rev=809797&r1=809796&r2=809797&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java
Tue Sep  1 02:06:03 2009
@@ -1032,7 +1032,12 @@
                 cascades = new ArrayList<String>();
             cascades.add("cascade-refresh");
         }
-        if (cascades != null && cascades.size() == 4) // ALL
+        if (vmd.getCascadeDetach() == ValueMetaData.CASCADE_IMMEDIATE) {
+            if (cascades == null)
+                cascades = new ArrayList<String>();
+            cascades.add("cascade-detach");
+        }
+        if (cascades != null && cascades.size() == 5) // ALL
         {
             cascades.clear();
             cascades.add("cascade-all");



Mime
View raw message