openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ss...@apache.org
Subject svn commit: r719479 - in /openjpa/branches/1.1.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/exception/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persist...
Date Fri, 21 Nov 2008 05:03:29 GMT
Author: ssegu
Date: Thu Nov 20 21:03:29 2008
New Revision: 719479

URL: http://svn.apache.org/viewvc?rev=719479&view=rev
Log:
OPENJPA-678, OPENJPA-680, OPENJPA-722 - Merge back from trunk

Added:
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestRefresh.java
Modified:
    openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
    openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java
    openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java
    openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/exception/TestException.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerClear.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
    openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
    openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/MetaDataParsers.java
    openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceListenerAdapter.java
    openjpa/branches/1.1.x/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreManager.java
    openjpa/branches/1.1.x/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java

Modified: openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java?rev=719479&r1=719478&r2=719479&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
(original)
+++ openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
Thu Nov 20 21:03:29 2008
@@ -3163,8 +3163,8 @@
         beginOperation(true);
         try {
             // If a flush is desired (based on input parm), then check if the
-            //   "dirty" flag is set before calling flush().
-            if ((flush) && ((_flags & FLAG_FLUSH_REQUIRED) != 0))
+            // "dirty" flag is set before calling flush().
+            if (flush && (_flags & FLAG_FLUSH_REQUIRED) != 0)
                 flush();
             detachAllInternal(call);
         } catch (OpenJPAException ke) {

Modified: openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java?rev=719479&r1=719478&r2=719479&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java
(original)
+++ openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java
Thu Nov 20 21:03:29 2008
@@ -446,7 +446,8 @@
         // detach fields and set detached variables
         DetachedStateManager detSM = null;
         if (_opts.getDetachedStateManager()
-            && useDetachedStateManager(sm, _opts))
+            && useDetachedStateManager(sm, _opts)
+            && !(sm.isNew() && !sm.isDeleted() && !sm.isFlushed()))
             detSM = new DetachedStateManager(detachedPC, sm, fields,
                 _opts.getAccessUnloaded(), _broker.getMultithreaded());
         if (_full) {

Modified: openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java?rev=719479&r1=719478&r2=719479&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java
(original)
+++ openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java
Thu Nov 20 21:03:29 2008
@@ -79,7 +79,10 @@
         _embedded = sm.isEmbedded();
         _loaded = load;
         _access = access;
-        _dirty = new BitSet(_loaded.length());
+        if (!sm.isFlushed())
+            _dirty = (BitSet) sm.getDirty().clone();
+        else
+            _dirty = new BitSet(_loaded.length());
         _oid = sm.fetchObjectId();
         _version = sm.getVersion();
         if (multithreaded)

Modified: openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?rev=719479&r1=719478&r2=719479&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
(original)
+++ openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
Thu Nov 20 21:03:29 2008
@@ -360,7 +360,8 @@
      */
     protected boolean load(FetchConfiguration fetch, int loadMode,
         BitSet exclude, Object sdata, boolean forWrite) {
-        if (!forWrite && (!isPersistent() || isNew() || isDeleted()))
+        if (!forWrite
+            && (!isPersistent() || (isNew() && !isFlushed()) || isDeleted()))
             return false;
 
         // if any fields being loaded, do state transitions for read

Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/exception/TestException.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/exception/TestException.java?rev=719479&r1=719478&r2=719479&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/exception/TestException.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/exception/TestException.java
Thu Nov 20 21:03:29 2008
@@ -26,11 +26,13 @@
 import javax.persistence.EntityManager;
 import javax.persistence.EntityNotFoundException;
 import javax.persistence.OptimisticLockException;
+import javax.persistence.Query;
 import javax.persistence.TransactionRequiredException;
 
 import org.apache.openjpa.jdbc.sql.DBDictionary;
 import org.apache.openjpa.jdbc.sql.SQLErrorCodeReader;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.util.UserException;
 
 /**
  * Tests proper JPA exceptions are raised by the implementation. 
@@ -158,6 +160,32 @@
 	}
 	
 	/**
+	 * Invalid query throws IllegalArgumentException on construction 
+	 * as per JPA spec.
+	 */
+	public void testIllegalArgumennExceptionOnInvalidQuery() {
+	    EntityManager em = emf.createEntityManager();
+	    try {
+	      em.createQuery("This is not a valid JPQL query");
+        fail("Did not throw IllegalArgumentException for invalid query.");
+	    } catch (Throwable t) {
+		   assertException(t, IllegalArgumentException.class);
+	    }
+	}
+	
+	/**
+	 * Invalid named query fails as per spec on factory based construction. 
+	 */
+     public void testIllegalArgumennExceptionOnInvalidNamedQuery() {
+         EntityManager em = emf.createEntityManager();
+         try {
+             Query query = em.createNamedQuery("This is invalid Named query");
+         } catch (Throwable t) {
+             assertException(t, IllegalArgumentException.class);
+         }
+      }
+	
+	/**
 	 * Asserts that the given expected type of the exception is equal to or a
 	 * subclass of the given throwable or any of its nested exception.
 	 * Otherwise fails assertion and prints the given throwable and its nested

Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerClear.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerClear.java?rev=719479&r1=719478&r2=719479&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerClear.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerClear.java
Thu Nov 20 21:03:29 2008
@@ -20,6 +20,7 @@
 
 import junit.textui.TestRunner;
 import org.apache.openjpa.persistence.test.SingleEMTestCase;
+import java.math.BigDecimal;
 
 /**
  * Test case to ensure that the proper JPA clear semantics are processed.
@@ -30,7 +31,7 @@
     extends SingleEMTestCase {
 
     public void setUp() {
-        setUp(AllFieldTypes.class);
+        setUp(AllFieldTypes.class, Item.class,CLEAR_TABLES);
     }
 
     public void testDetach() {
@@ -94,6 +95,148 @@
         rollback();
     }
 
+    public void testNewClearMerge() {
+        // Create EntityManager and Start a transaction (1)
+        begin();
+
+        // Insert a new object then clear persistent context
+        AllFieldTypes testObject1 = new AllFieldTypes();
+        testObject1.setStringField("my test object1");
+        persist(testObject1);
+        //Object1 is not flushed to DB but only detached by clear().
+        em.clear();
+
+        assertEquals(0, query("select x from AllFieldTypes x "
+                + "where x.stringField = 'my test object1'").
+                    getResultList().size());
+        em.merge(testObject1);
+        commit();
+
+        //Start a new transaction
+        begin();
+
+        // Expect Object1 is persisted after merge and commit.
+        assertEquals(1, query("select x from AllFieldTypes x "
+            + "where x.stringField = 'my test object1'").
+                getResultList().size());
+
+        // Rollback the transaction and close everything
+        rollback();
+    }
+
+    public void testUpdateClearMerge() {
+        // Create EntityManager and Start a transaction (1)
+        begin();
+
+        // Insert a new object
+        Item i = new Item();
+        i.setItemName("cup");
+        persist(i);
+        commit();
+        int id = i.getItemId();
+
+        begin();
+        Item i2 = em.find(Item.class, id);
+        i2.setItemName("fancy cup");
+        //Updated item is not flushed to DB but only detached by clear().
+        em.clear();
+        assertEquals(0, query("select x from Item x "
+                + "where x.itemName = 'fancy cup'").
+                    getResultList().size());
+        em.merge(i2);
+        commit();
+
+        //Start a new transaction
+        begin();
+
+        //should be changed by previous commit
+        assertEquals(1, query("select x from Item x "
+            + "where x.itemName = 'fancy cup'").
+                getResultList().size());
+
+        // Rollback the transaction and close everything
+        rollback();
+    }
+
+    /**
+     * Test modify entity then clear context which cause unflushed modified entity detached.
+     * Do more modification on detached entity, merge back and commit.
+     * Expect both changes before clear and after clear are persisted.
+     *
+     */
+    public void testUpdateClearUpdateMerge() {
+        // Create EntityManager and Start a transaction (1)
+        begin();
+
+        // Insert a new object
+        Item i = new Item();
+        i.setItemName("cup");
+        i.setItemPrice(new BigDecimal(100.00));
+        persist(i);
+        commit();
+        int id = i.getItemId();
+
+        begin();
+        Item i2 = em.find(Item.class, id);
+        i2.setItemName("fancy cup");
+        //Updated item is not flushed to DB but only detached by clear().
+        em.clear();
+        assertEquals(0, query("select x from Item x "
+                + "where x.itemName = 'fancy cup'").
+                    getResultList().size());
+        i2.setItemPrice(new BigDecimal(120.00));
+        em.merge(i2);
+        commit();
+
+        //Start a new transaction
+        begin();
+
+        //should be changed by previous commit
+        assertEquals(1, query("select x from Item x "
+            + "where x.itemName = 'fancy cup' and x.itemPrice = 120.00").
+                getResultList().size());
+
+        // Rollback the transaction and close everything
+        rollback();
+    }
+
+    public void testUpdateFlushClearUpdateMerge() {
+        // Create EntityManager and Start a transaction (1)
+        begin();
+
+        // Insert a new object
+        Item i = new Item();
+        i.setItemName("cup");
+        i.setItemPrice(new BigDecimal(100.00));
+        persist(i);
+        commit();
+        int id = i.getItemId();
+
+        begin();
+        Item i2 = em.find(Item.class, id);
+        i2.setItemName("fancy cup");
+        em.flush();
+        em.clear();
+        //it is updated because it is flushed before clear();
+        assertEquals(1, query("select x from Item x "
+                + "where x.itemName = 'fancy cup'").
+                    getResultList().size());
+        i2.setItemPrice(new BigDecimal(120.00));
+        i2.setItemName("red cup");
+        em.merge(i2);
+        commit();
+
+        //Start a new transaction
+        begin();
+
+        //should be changed by previous commit
+        assertEquals(1, query("select x from Item x "
+            + "where x.itemName = 'red cup' and x.itemPrice = 120.00").
+                getResultList().size());
+
+        // Rollback the transaction and close everything
+        rollback();
+    }
     public static void main(String[] args) {
         TestRunner.run(TestEntityManagerClear.class);
     }

Added: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestRefresh.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestRefresh.java?rev=719479&view=auto
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestRefresh.java
(added)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestRefresh.java
Thu Nov 20 21:03:29 2008
@@ -0,0 +1,39 @@
+/*
+ * 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.simple;
+
+import org.apache.openjpa.persistence.test.SingleEMTestCase;
+
+public class TestRefresh extends SingleEMTestCase {
+
+    public void setUp() {
+        super.setUp(CLEAR_TABLES, Item.class, "openjpa.AutoDetach", "commit");
+    }
+
+    public void testFlushRefreshNewInstance() {
+        em.getTransaction().begin();
+        Item item = new Item();
+        item.setItemData("Test Data");
+        em.persist(item);
+        em.flush();
+        em.refresh(item);
+        em.getTransaction().commit();
+        assertEquals("Test Data", item.getItemData());
+    }
+}

Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java?rev=719479&r1=719478&r2=719479&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
Thu Nov 20 21:03:29 2008
@@ -18,6 +18,11 @@
  */
 package org.apache.openjpa.persistence.test;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -238,4 +243,19 @@
         else if (o1.equals(o2))
             fail("expected args to be different; compared equal.");
     }
+
+    /**
+     * Round-trip a serializable object to bytes.
+     */
+    public static Object roundtrip(Object o) 
+        throws ClassNotFoundException, IOException {
+        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream(bytes);
+        out.writeObject(o);
+        out.flush();
+        ObjectInputStream in = new ObjectInputStream(
+            new ByteArrayInputStream(bytes.toByteArray()));
+        return in.readObject();
+    }
+
 }

Modified: openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java?rev=719479&r1=719478&r2=719479&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
Thu Nov 20 21:03:29 2008
@@ -87,7 +87,7 @@
     private Map<FetchConfiguration,FetchPlan> _plans =
         new IdentityHashMap<FetchConfiguration,FetchPlan>(1);
 
-    private RuntimeExceptionTranslator ret =
+    private RuntimeExceptionTranslator _ret =
         PersistenceExceptions.getRollbackTranslator(this);
 
     public EntityManagerImpl() {
@@ -104,8 +104,8 @@
 
     private void initialize(EntityManagerFactoryImpl factory, Broker broker) {
         _emf = factory;
-        _broker = new DelegatingBroker(broker, ret);
-        _broker.setImplicitBehavior(this, ret);
+        _broker = new DelegatingBroker(broker, _ret);
+        _broker.setImplicitBehavior(this, _ret);
     }
 
     /**
@@ -867,7 +867,16 @@
 
     public OpenJPAQuery createQuery(String language, String query) {
         assertNotCloseInvoked();
-        return new QueryImpl(this, ret, _broker.newQuery(language, query));
+        try {
+            org.apache.openjpa.kernel.Query q = _broker.newQuery(language, 
+                query);
+            // have to validate JPQL according to spec
+            if (JPQLParser.LANG_JPQL.equals(language))
+                q.compile(); 
+            return new QueryImpl(this, _ret, q);
+        } catch (RuntimeException re) {
+            throw PersistenceExceptions.toPersistenceException(re);
+        }
     }
 
     public OpenJPAQuery createQuery(Query query) {
@@ -875,7 +884,7 @@
             return createQuery((String) null);
         assertNotCloseInvoked();
         org.apache.openjpa.kernel.Query q = ((QueryImpl) query).getDelegate();
-        return new QueryImpl(this, ret, _broker.newQuery(q.getLanguage(),
+        return new QueryImpl(this, _ret, _broker.newQuery(q.getLanguage(),
             q));
     }
 
@@ -891,7 +900,7 @@
             meta.setInto(del);
             del.compile();
 
-            OpenJPAQuery q = new QueryImpl(this, ret, del);
+            OpenJPAQuery q = new QueryImpl(this, _ret, del);
             String[] hints = meta.getHintKeys();
             Object[] values = meta.getHintValues();
             for (int i = 0; i < hints.length; i++)
@@ -917,7 +926,7 @@
         org.apache.openjpa.kernel.Query kernelQuery = _broker.newQuery(
             QueryLanguages.LANG_SQL, query);
         kernelQuery.setResultMapping(null, mappingName);
-        return new QueryImpl(this, ret, kernelQuery);
+        return new QueryImpl(this, _ret, kernelQuery);
     }
 
     /**
@@ -1235,7 +1244,7 @@
     public void readExternal(ObjectInput in)
         throws IOException, ClassNotFoundException {
         try {
-            ret = PersistenceExceptions.getRollbackTranslator(this);
+            _ret = PersistenceExceptions.getRollbackTranslator(this);
 
             // this assumes that serialized Brokers are from something
             // that extends AbstractBrokerFactory.
@@ -1254,7 +1263,7 @@
             initialize(emf, broker);
         } catch (RuntimeException re) {
             try {
-                re = ret.translate(re);
+                re = _ret.translate(re);
             } catch (Exception e) {
                 // ignore
             }
@@ -1276,7 +1285,7 @@
             out.writeObject(baos.toByteArray());
         } catch (RuntimeException re) {
             try {
-                re = ret.translate(re);
+                re = _ret.translate(re);
             } catch (Exception e) {
                 // ignore
             }

Modified: openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/MetaDataParsers.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/MetaDataParsers.java?rev=719479&r1=719478&r2=719479&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/MetaDataParsers.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/MetaDataParsers.java
Thu Nov 20 21:03:29 2008
@@ -57,8 +57,7 @@
             case POST_UPDATE:
                 return new int[]{ LifecycleEvent.AFTER_UPDATE_PERFORMED };
             case POST_LOAD:
-                return new int[]{ LifecycleEvent.AFTER_LOAD,
-                    LifecycleEvent.AFTER_REFRESH };
+                return new int[]{ LifecycleEvent.AFTER_LOAD };
             default:
                 return null;
         }

Modified: openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceListenerAdapter.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceListenerAdapter.java?rev=719479&r1=719478&r2=719479&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceListenerAdapter.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceListenerAdapter.java
Thu Nov 20 21:03:29 2008
@@ -98,7 +98,7 @@
     }
 
     public void afterRefresh(LifecycleEvent event) {
-        makeCallback(event);
+        // no analagous callback
     }
 
     public void beforeUpdate(LifecycleEvent event) {

Modified: openjpa/branches/1.1.x/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreManager.java?rev=719479&r1=719478&r2=719479&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreManager.java
(original)
+++ openjpa/branches/1.1.x/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreManager.java
Thu Nov 20 21:03:29 2008
@@ -102,6 +102,10 @@
     public DistributedJDBCConfiguration getConfiguration() {
         return _conf;
     }
+    
+    public SliceStoreManager getSlice(int i) {
+    	return _slices.get(i);
+    }
 
     /**
      * Decides the index of the StoreManager by first looking at the

Modified: openjpa/branches/1.1.x/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java?rev=719479&r1=719478&r2=719479&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
(original)
+++ openjpa/branches/1.1.x/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
Thu Nov 20 21:03:29 2008
@@ -32,6 +32,7 @@
 import org.apache.openjpa.kernel.FetchConfiguration;
 import org.apache.openjpa.kernel.OrderingMergedResultObjectProvider;
 import org.apache.openjpa.kernel.QueryContext;
+import org.apache.openjpa.kernel.StoreManager;
 import org.apache.openjpa.kernel.StoreQuery;
 import org.apache.openjpa.kernel.exps.ExpressionParser;
 import org.apache.openjpa.lib.rop.MergedResultObjectProvider;
@@ -61,17 +62,15 @@
 		_queries.add(q);
 	}
 	
+	public DistributedStoreManager getDistributedStore() {
+		return (DistributedStoreManager)getStore();
+	}
+	
     public Executor newDataStoreExecutor(ClassMetaData meta, boolean subs) {
     	ParallelExecutor ex = new ParallelExecutor(this, meta, subs, _parser, 
     			ctx.getCompilation());
-    	
-    	FetchConfiguration fetch = getContext().getFetchConfiguration();
-    	DistributedStoreManager store = (DistributedStoreManager)getContext()
-    	    .getStoreContext().getStoreManager().getInnermostDelegate();
-        List<SliceStoreManager> targets = store.getTargets(fetch);
-        for (StoreQuery q:_queries) {
-            if (targets.contains(((JDBCStoreQuery)q).getStore()))
-                ex.addExecutor(q.newDataStoreExecutor(meta, subs));
+        for (StoreQuery q : _queries) {
+            ex.addExecutor(q.newDataStoreExecutor(meta, subs));
         }
         return ex;
     }
@@ -117,19 +116,23 @@
          */
         public ResultObjectProvider executeQuery(StoreQuery q,
                 final Object[] params, final Range range) {
-        	ResultObjectProvider[] tmp = new ResultObjectProvider[executors.size()];
-        	final Iterator<StoreQuery> qs = owner._queries.iterator();
         	final List<Future<ResultObjectProvider>> futures = 
         		new ArrayList<Future<ResultObjectProvider>>();
-        	int i = 0;
-        	for (Executor ex:executors)  {
+        	List<SliceStoreManager> targets = findTargets();
+        	for (int i = 0; i < owner._queries.size(); i++) {
+        		StoreQuery query = owner._queries.get(i);
+        		StoreManager sm  = owner.getDistributedStore().getSlice(i);
+        		if (!targets.contains(sm))
+        			continue;
         		QueryExecutor call = new QueryExecutor();
-        		call.executor = ex;
-        		call.query    = qs.next();
+        		call.executor = executors.get(i);
+        		call.query    = query;
         		call.params   = params;
         		call.range    = range;
         		futures.add(threadPool.submit(call)); 
         	}
+        	int i = 0;
+        	ResultObjectProvider[] tmp = new ResultObjectProvider[futures.size()];
         	for (Future<ResultObjectProvider> future:futures) {
         		try {
 					tmp[i++] = future.get();
@@ -210,6 +213,11 @@
         	}
         	return new Integer(N);
         }
+        
+        List<SliceStoreManager> findTargets() {
+        	FetchConfiguration fetch = owner.getContext().getFetchConfiguration();
+        	return owner.getDistributedStore().getTargets(fetch);
+        }
 
 	}
 	



Mime
View raw message