openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r469429 - in /incubator/openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/datacache/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/ ...
Date Tue, 31 Oct 2006 09:43:44 GMT
Author: pcl
Date: Tue Oct 31 01:43:43 2006
New Revision: 469429

URL: http://svn.apache.org/viewvc?view=rev&rev=469429
Log:
made in-mem match queries fail faster; added another test case for new  DataCacheStoreManager
work

Added:
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestInMemoryQueryMatchEscapes.java
  (with props)
Modified:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/MatchesExpression.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheOptimisticLockRecovery.java

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java?view=diff&rev=469429&r1=469428&r2=469429
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
Tue Oct 31 01:43:43 2006
@@ -578,10 +578,11 @@
             switch (compareVersion(sm, sm.getVersion(), data.getVersion())) {
                 case StoreManager.VERSION_LATER:
                 case StoreManager.VERSION_SAME:
-                    // This tx's current version is later than the data cache 
-                    // version. In this case, the commit should have succeeded. 
-                    // Remove the instance from cache in the hopes that the 
-                    // cache is out of sync.
+                    // This tx's current version is later than or the same as 
+                    // the data cache version. In this case, the commit should 
+                    // have succeeded from the standpoint of the cache. Remove 
+                    // the instance from cache in the hopes that the cache is 
+                    // out of sync.
                     remove = true;
                     break;
                 case StoreManager.VERSION_EARLIER:

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/MatchesExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/MatchesExpression.java?view=diff&rev=469429&r1=469428&r2=469429
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/MatchesExpression.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/MatchesExpression.java
Tue Oct 31 01:43:43 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.openjpa.kernel.exps;
 
+import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.SimpleRegex;
 import serp.util.Strings;
 
@@ -26,9 +27,11 @@
 class MatchesExpression
     extends CompareExpression {
 
+    private static final Localizer _loc = Localizer.forPackage(
+        MatchesExpression.class);
+    
     private final String _single;
     private final String _multi;
-    private final String _escape; // ### in-memory queries are not using escapes
     private final boolean _affirmation;
 
     /**
@@ -39,7 +42,9 @@
         super(val1, val2);
         _single = single;
         _multi = multi;
-        _escape = escape;
+        if (escape != null)
+            throw new IllegalArgumentException(_loc.get(
+                "escape-for-inmem-query-not-supported").getMessage());
         _affirmation = affirmation;
     }
 

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheOptimisticLockRecovery.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheOptimisticLockRecovery.java?view=diff&rev=469429&r1=469428&r2=469429
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheOptimisticLockRecovery.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheOptimisticLockRecovery.java
Tue Oct 31 01:43:43 2006
@@ -20,6 +20,7 @@
     extends TestCase {
 
     private EntityManagerFactory emf;
+    private int pk;
 
     public void setUp() {
         Map options = new HashMap();
@@ -38,7 +39,16 @@
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
         em.createQuery("delete from OptimisticLockInstance");
-        em.getTransaction().commit();
+
+        OptimisticLockInstance oli = new OptimisticLockInstance("foo");
+        try {
+            em.persist(oli);
+            em.getTransaction().commit();
+        } finally {
+            if (em.getTransaction().isActive())
+                em.getTransaction().rollback();
+        }
+        pk = oli.getPK();
         em.close();
     }
 
@@ -51,26 +61,12 @@
 
         EntityManager em;
         
-        // 1. get the instance into the cache via this insert
-        em = emf.createEntityManager();
-        em.getTransaction().begin();
-        OptimisticLockInstance oli = new OptimisticLockInstance("foo");
-        try {
-            em.persist(oli);
-            em.getTransaction().commit();
-        } finally {
-            if (em.getTransaction().isActive())
-                em.getTransaction().rollback();
-        }
-        int pk = oli.getPK();
-        em.close();
-        
-        // 2. get the oplock value for the instance after commit and
+        // 1. get the oplock value for the instance after commit and
         // get a read lock to ensure that we check for the optimistic
         // lock column at tx commit.
         em = emf.createEntityManager();
         em.getTransaction().begin();
-        oli = em.find(OptimisticLockInstance.class, pk);
+        OptimisticLockInstance oli = em.find(OptimisticLockInstance.class, pk);
         int firstOpLockValue = oli.getOpLock();
         em.lock(oli, LockModeType.READ);
 
@@ -126,6 +122,33 @@
         } finally {
             if (em.getTransaction().isActive())
                 em.getTransaction().rollback();
+        }
+        em.close();
+    }
+    
+    public void testExpectedOptimisticLockException() {
+        EntityManager em;
+        
+        // 1. start a new tx
+        em = emf.createEntityManager();
+        em.getTransaction().begin();
+        em.lock(em.find(OptimisticLockInstance.class, pk), LockModeType.READ);
+        
+        // 2. start another tx, and cause a version increment
+        EntityManager em2 = emf.createEntityManager();
+        em2.getTransaction().begin();
+        em2.lock(em2.find(OptimisticLockInstance.class, pk), 
+            LockModeType.WRITE);
+        em2.getTransaction().commit();
+        em2.close();
+        
+        // 3. try to commit. this should fail, as this is a regular optimistic
+        // lock failure situation.
+        try {
+            em.getTransaction().commit();
+            fail("write lock in em2 should trigger an optimistic lock failure");
+        } catch (RollbackException pe) {
+            // expected
         }
         em.close();
     }

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestInMemoryQueryMatchEscapes.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestInMemoryQueryMatchEscapes.java?view=auto&rev=469429
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestInMemoryQueryMatchEscapes.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestInMemoryQueryMatchEscapes.java
Tue Oct 31 01:43:43 2006
@@ -0,0 +1,66 @@
+package org.apache.openjpa.persistence.query;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.FlushModeType;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+import org.apache.openjpa.persistence.OpenJPAQuery;
+import org.apache.openjpa.persistence.simple.AllFieldTypes;
+
+import junit.framework.TestCase;
+
+public class TestInMemoryQueryMatchEscapes
+    extends TestCase {
+
+    private EntityManagerFactory emf;
+
+    public void setUp() {
+        Map options = new HashMap();
+
+        // ensure that OpenJPA knows about our type, so that 
+        // auto-schema-creation works
+        options.put("openjpa.MetaDataFactory",
+            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
+
+        emf = Persistence.createEntityManagerFactory("test", options);
+    }
+    
+    public void testDatabaseEscape() {
+        OpenJPAQuery q = escapeHelper(false);
+        q.setFlushMode(FlushModeType.AUTO);
+        q.getEntityManager().flush();
+        AllFieldTypes aft = (AllFieldTypes) q.getSingleResult();
+        assertEquals("foo_bar", aft.getStringField());
+        q.getEntityManager().getTransaction().rollback();
+    }
+    
+    public void testInMemoryEscape() {
+        OpenJPAQuery q = escapeHelper(true);
+        q.setFlushMode(FlushModeType.COMMIT);
+        try {
+            q.getSingleResult();
+            fail("OpenJPA doesn't support escape syntax for in-mem queries");
+        } catch (Exception e) {
+            // expected
+        }
+    }
+    
+    private OpenJPAQuery escapeHelper(boolean inMem) {
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        AllFieldTypes aft = new AllFieldTypes();
+        aft.setStringField("foo_bar");
+        em.persist(aft);
+        aft = new AllFieldTypes();
+        aft.setStringField("foozbar");
+        em.persist(aft);
+
+        return (OpenJPAQuery) em.createQuery(
+            "select e from AllFieldTypes e where e.stringField " +
+            "like 'foox_bar' escape 'x'");
+    }
+}

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



Mime
View raw message