openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r746640 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/...
Date Sun, 22 Feb 2009 05:52:07 GMT
Author: ppoddar
Date: Sun Feb 22 05:52:06 2009
New Revision: 746640

URL: http://svn.apache.org/viewvc?rev=746640&view=rev
Log:
OPENJPA-935: Detect table for embedded PC to avoid extra select before delete.

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestNonstandardMappingAnnotations.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java?rev=746640&r1=746639&r2=746640&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
Sun Feb 22 05:52:06 2009
@@ -582,7 +582,8 @@
      * returns INVALID. Also returns INVALID if field is dependent.
      */
     private Table getTable(FieldMapping fm, Table table) {
-        if (fm.getCascadeDelete() != ValueMetaData.CASCADE_NONE)
+        if (fm.getCascadeDelete() != ValueMetaData.CASCADE_NONE 
+            && !fm.isEmbeddedPC())
             return INVALID;
 
         Column[] columns = fm.getColumns();

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java?rev=746640&r1=746639&r2=746640&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java
Sun Feb 22 05:52:06 2009
@@ -23,9 +23,10 @@
 import javax.persistence.EntityManager;
 import javax.persistence.EntityTransaction;
 
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
-public class TestEmbedded extends SingleEMFTestCase {
+public class TestEmbedded extends SQLListenerTestCase {
     public void setUp() {
         super.setUp(BaseEntity.class, Address.class, Geocode.class,
                 CLEAR_TABLES);
@@ -76,6 +77,47 @@
         
         assertEquals(a2.getGeocode().getLatitude(),1.0f);
     }
+    
+    public void testDeleteEmbeddedDoesNotSelectBeforeDelete() {
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        String[] streets = {"S1", "S2", "S3"};
+        String[] cities = {"C1", "C2", "C3"};
+        String[] states = {"AB", "CD", "EF"};
+        int[] zips = {123456, 345678, 456789};
+        
+        for (int i = 0; i < streets.length; i++) {
+            Address a = new Address();
+            a.setStreetAddress(streets[i]);
+            a.setCity(cities[i]);
+            a.setState(states[i]);
+            a.setZip(zips[i]);
+            Geocode g = new Geocode();
+            g.setLatitude(i+1.0f);
+            g.setLongtitude(i+6.0f);
+            a.setGeocode(g);
+            em.persist(a);
+        } 
+        em.getTransaction().commit();
+        
+        em = emf.createEntityManager();
+        em.getTransaction().begin();
+        sql.clear();
+        int count = em.createQuery("DELETE FROM Address a WHERE a.zip=:zip")
+            .setParameter("zip", zips[0])
+            .executeUpdate();
+        assertEquals(1, count);
+        em.getTransaction().commit();
+        assertEquals(1, sql.size());
+        
+        em.getTransaction().begin();
+        sql.clear();
+        count = em.createQuery("DELETE FROM Address").executeUpdate();
+        assertEquals(streets.length-1, count);
+        assertTrue(count>1);
+        em.getTransaction().commit();
+        assertEquals(1, sql.size());
+    }
 
     private void persistAddress(Address address) {
         final EntityManager em = emf.createEntityManager();

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestNonstandardMappingAnnotations.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestNonstandardMappingAnnotations.java?rev=746640&r1=746639&r2=746640&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestNonstandardMappingAnnotations.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestNonstandardMappingAnnotations.java
Sun Feb 22 05:52:06 2009
@@ -48,7 +48,7 @@
         setUp(NonstandardMappingEntity.class, ExtensionsEntity.class,
             NonstandardMappingMappedSuper.class, EmbedValue2.class,
             EmbedValue.class,
-            CLEAR_TABLES);
+            CLEAR_TABLES, RETAIN_DATA);
 
         // trigger complete resolution of metadata etc.
         emf.createEntityManager().close();

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java?rev=746640&r1=746639&r2=746640&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
Sun Feb 22 05:52:06 2009
@@ -61,6 +61,8 @@
     extends TestCase {
     private static FixedMap _emfs = new FixedMap();
     public static final String FRESH_EMF = "Creates new EntityManagerFactory";
+    public static final String RETAIN_DATA = "Retain data after test run";
+    private boolean retainDataOnTearDown; 
     /**
      * Marker object you pass to {@link #setUp} to indicate that the
      * database table rows should be cleared.
@@ -118,6 +120,10 @@
                 fresh = true;
                 continue;
             }
+            if (props[i] == RETAIN_DATA) {
+                retainDataOnTearDown= true;
+                continue;
+            }
             if (prop) {
                 map.put(props[i - 1], props[i]);
                 prop = false;
@@ -262,7 +268,8 @@
         // before issuing delete statements on a new entity manager.
         if (closeEMs)
             closeAllOpenEMs(emf);
-
+        if (retainDataOnTearDown)
+            return;
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
         for (ClassMetaData meta : types) {



Mime
View raw message