User: dsundstrom
Date: 01/08/05 12:32:19
Modified: src/main/org/jboss/ejb Application.java EntityContainer.java
Log:
Fixed remove problem.
* Moved tx entity map to application
* Moved synchronize entities in tx method to application
* Moved sync call to entity container find and remove methods
Revision Changes Path
1.14 +36 -1 jboss/src/main/org/jboss/ejb/Application.java
Index: Application.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/Application.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Application.java 2001/08/03 17:15:43 1.13
+++ Application.java 2001/08/05 19:32:19 1.14
@@ -7,12 +7,14 @@
package org.jboss.ejb;
import java.net.URL;
+import java.rmi.RemoteException;
import java.util.Iterator;
import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
import javax.ejb.EJBLocalHome;
+import javax.transaction.Transaction;
import org.jboss.util.Service;
@@ -23,7 +25,7 @@
* @see Container
* @see ContainerFactory
* @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>
- * @version $Revision: 1.13 $
+ * @version $Revision: 1.14 $
*/
public class Application
implements Service
@@ -45,6 +47,13 @@
// url where this application was deployed from
URL url;
+ /**
+ * This provides a way to find the entities that are part of a given
+ * transaction EntitySynchronizationInterceptor and InstanceSynchronization
+ * manage this instance.
+ */
+ private TxEntityMap txEntityMap = new TxEntityMap();
+
// Static --------------------------------------------------------
// Public --------------------------------------------------------
@@ -185,6 +194,32 @@
name = url.toString();
}
+ /**
+ * Gets the transaction to entity map object, which contains a map from
+ * a transaction to every entity used in that transaction.
+ * @return the transaction to entity map for this application
+ */
+ public TxEntityMap getTxEntityMap() {
+ return txEntityMap;
+ }
+
+ /**
+ * Stores all of the entities associated with the specified transaction.
+ * @param tx the transaction that associated entites will be stored
+ * @throws Exception if an problem occures while storing the entities
+ */
+ public void synchronizeEntitiesWithinTransaction(Transaction tx) throws
RemoteException {
+ // If there is no transaction, there is nothing to synchronize.
+ if(tx != null) {
+ Object[] entities = getTxEntityMap().getEntities(tx);
+ for (int i = 0; i < entities.length; i++) {
+ EntityEnterpriseContext ctx =
(EntityEnterpriseContext)entities[i];
+ EntityContainer container =
(EntityContainer)ctx.getContainer();
+ container.getPersistenceManager().storeEntity(ctx);
+ }
+ }
+ }
+
// Service implementation ----------------------------------------
/**
1.49 +18 -14 jboss/src/main/org/jboss/ejb/EntityContainer.java
Index: EntityContainer.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/EntityContainer.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- EntityContainer.java 2001/08/03 17:15:43 1.48
+++ EntityContainer.java 2001/08/05 19:32:19 1.49
@@ -46,7 +46,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel OConnor</a>
* @author <a href="[EMAIL PROTECTED]">Bill Burke</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a>
- * @version $Revision: 1.48 $
+ * @version $Revision: 1.49 $
*
* <p><b>Revisions:</b>
*
@@ -98,13 +98,6 @@
protected InstancePool instancePool;
/**
- * This provides a way to find the entities that are part of a given
- * transaction EntitySynchronizationInterceptor and InstanceSynchronization
- * manage this instance.
- */
- protected TxEntityMap txEntityMap = new TxEntityMap();
-
- /**
* This is the first interceptor in the chain. The last interceptor must
* be provided by the container itself.
*/
@@ -168,11 +161,6 @@
return persistenceManager;
}
- public TxEntityMap getTxEntityMap()
- {
- return txEntityMap;
- }
-
public void setPersistenceManager(EntityPersistenceManager pm)
{
if (pm == null)
@@ -397,6 +385,10 @@
public void remove(MethodInvocation mi)
throws RemoteException, RemoveException
{
+ // synchronize entities with the datastore before the bean is removed
+ // this will write queued updates so datastore will be consistent
before removal
+
getApplication().synchronizeEntitiesWithinTransaction(mi.getTransaction());
+
// Get the persistence manager to do the dirty work
getPersistenceManager().removeEntity((EntityEnterpriseContext)mi.getEnterpriseContext());
@@ -482,6 +474,12 @@
public Object findLocal(MethodInvocation mi)
throws Exception
{
+ /**
+ * As per the spec 9.6.4, entities must be synchronized with the
datastore
+ * when an ejbFind<METHOD> is called.
+ */
+
getApplication().synchronizeEntitiesWithinTransaction(mi.getTransaction());
+
// Multi-finder?
if (!mi.getMethod().getReturnType().equals(getLocalClass()))
{
@@ -527,7 +525,13 @@
* found.
*/
public Object find(MethodInvocation mi) throws Exception
- {
+ {
+ /**
+ * As per the spec 9.6.4, entities must be synchronized with the
datastore
+ * when an ejbFind<METHOD> is called.
+ */
+
getApplication().synchronizeEntitiesWithinTransaction(mi.getTransaction());
+
// Multi-finder?
if (!mi.getMethod().getReturnType().equals(getRemoteClass()))
{
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development