You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by br...@apache.org on 2004/04/09 03:34:51 UTC
cvs commit: db-ojb/src/test/org/apache/ojb/jdo TestQueries.java
brianm 2004/04/08 18:34:50
Modified: src/java/org/apache/ojb/jdo PersistenceManagerImpl.java
src/test/org/apache/ojb/jdo TestQueries.java
Log:
Fix error were clearing caches via evictAll through an NPE when outside transaction
Revision Changes Path
1.9 +15 -15 db-ojb/src/java/org/apache/ojb/jdo/PersistenceManagerImpl.java
Index: PersistenceManagerImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/jdo/PersistenceManagerImpl.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- PersistenceManagerImpl.java 9 Apr 2004 01:06:00 -0000 1.8
+++ PersistenceManagerImpl.java 9 Apr 2004 01:34:50 -0000 1.9
@@ -17,6 +17,8 @@
import org.apache.ojb.broker.Identity;
import org.apache.ojb.broker.PBKey;
import org.apache.ojb.broker.PersistenceBrokerFactory;
+import org.apache.ojb.jdo.spi.StateManagerImpl;
+import org.apache.ojb.otm.EditingContext;
import org.apache.ojb.otm.OTMConnection;
import org.apache.ojb.otm.OTMKit;
import org.apache.ojb.otm.copy.ObjectCopyStrategy;
@@ -24,7 +26,6 @@
import org.apache.ojb.otm.lock.LockType;
import org.apache.ojb.otm.lock.LockingException;
import org.apache.ojb.otm.states.State;
-import org.apache.ojb.jdo.spi.StateManagerImpl;
import javax.jdo.*;
import javax.jdo.spi.StateManager;
@@ -32,7 +33,7 @@
import java.util.Iterator;
/**
- * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird</a>
+ * @author Matthew Baird, Brian McCallister
*/
public class PersistenceManagerImpl implements PersistenceManager
@@ -47,7 +48,6 @@
private String m_alias;
private Object m_usersObject;
private TransactionImpl m_tx;
- private StateManager m_stateManager;
public PersistenceManagerImpl(PersistenceManagerFactory factory, String alias, String userid, String password)
{
@@ -68,7 +68,6 @@
PBKey key = new PBKey(m_alias, m_userID, m_password);
m_conn = m_kit.acquireConnection(key);
}
- m_stateManager = new StateManagerImpl(this);
m_tx = new TransactionImpl(this, m_kit, m_conn);
}
@@ -202,13 +201,14 @@
{
throw new JDOFatalUserException(generateIsClosedErrorMessage("evictAll()"));
}
- Collection collection = m_conn.getEditingContext().getAllObjectsInContext();
- Iterator it = collection.iterator();
- while (it.hasNext())
+ EditingContext ctx = m_conn.getEditingContext();
+ if (ctx != null)
{
- evict(it.next());
+ for (Iterator i = ctx.getAllObjectsInContext().iterator(); i.hasNext();)
+ {
+ evict(i.next());
+ }
}
-
/**
* clear the rest of the global cache
*/
@@ -307,7 +307,7 @@
}
try
{
- return ((QueryImpl)o).ojbClone();
+ return ((QueryImpl) o).ojbClone();
}
catch (ClassCastException e)
{
@@ -398,11 +398,10 @@
}
/**
- * @todo figure out how to implement, may have to query all and filter objects
- *
* @param aClass top level class
- * @param b include subclasses
+ * @param b include subclasses
* @return
+ * @todo figure out how to implement, may have to query all and filter objects
*/
public Extent getExtent(Class aClass, boolean b)
{
@@ -568,6 +567,7 @@
/**
* Right now this makes the object non-transactional.
+ *
* @todo figure out what this is supposed to really do
*/
public void makeTransient(Object o)
@@ -705,8 +705,8 @@
}
/**
- * @todo What does this do?
* @param o
+ * @todo What does this do?
*/
public void retrieve(Object o)
{
@@ -718,8 +718,8 @@
}
/**
- * @todo What does this do?
* @param collection
+ * @todo What does this do?
*/
public void retrieveAll(Collection collection)
{
1.2 +6 -0 db-ojb/src/test/org/apache/ojb/jdo/TestQueries.java
Index: TestQueries.java
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/jdo/TestQueries.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestQueries.java 9 Apr 2004 01:06:00 -0000 1.1
+++ TestQueries.java 9 Apr 2004 01:34:50 -0000 1.2
@@ -49,6 +49,8 @@
pm.makePersistent(p);
pm.currentTransaction().commit();
+ pm.evictAll();
+
pm.currentTransaction().begin();
Query q = pm.newQuery(Person.class);
Collection results = (Collection) q.execute();
@@ -64,6 +66,8 @@
pm.makePersistent(p);
pm.currentTransaction().commit();
+ pm.evictAll();
+
pm.currentTransaction().begin();
Query q = pm.newQuery();
q.setCandidates(pm.getExtent(Person.class, true));
@@ -79,6 +83,8 @@
pm.currentTransaction().begin();
pm.makePersistent(p);
pm.currentTransaction().commit();
+
+ pm.evictAll();
pm.currentTransaction().begin();
Query q = pm.newQuery(Person.class);
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org