dain 2005/02/25 18:06:11
Modified: modules/core/src/java/org/openejb/entity/cmp
CMPCreateMethod.java CMPInstanceContext.java
CMPInstanceContextFactory.java
Added: modules/core/src/java/org/openejb/entity/cmp
CMPMethodInterceptor.java
Log:
Added support for in-tx cacheing back in
This unturned a load of places that were not handling transaction contexts
properly and bugs in the context itself
Changed instance contexts so they track entrancy and can be killed as
required by the spec
Made all instance context fields final
Revision Changes Path
1.13 +2 -1
openejb/modules/core/src/java/org/openejb/entity/cmp/CMPCreateMethod.java
Index: CMPCreateMethod.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/CMPCreateMethod.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- CMPCreateMethod.java 20 Feb 2005 15:44:27 -0000 1.12
+++ CMPCreateMethod.java 25 Feb 2005 23:06:10 -0000 1.13
@@ -202,6 +202,7 @@
ctx.setId(primaryKeyTransform.getDomainIdentity(globalId));
// associate the new cmp instance with the tx context
+ ctx.setLoaded(true);
transactionContext.associate(ctx);
// call the post create method
1.15 +46 -22
openejb/modules/core/src/java/org/openejb/entity/cmp/CMPInstanceContext.java
Index: CMPInstanceContext.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/CMPInstanceContext.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- CMPInstanceContext.java 14 Oct 2004 07:07:16 -0000 1.14
+++ CMPInstanceContext.java 25 Feb 2005 23:06:10 -0000 1.15
@@ -47,13 +47,10 @@
*/
package org.openejb.entity.cmp;
-import java.lang.reflect.Method;
import java.util.Set;
-
+import javax.ejb.EntityBean;
import javax.ejb.NoSuchEntityException;
-import net.sf.cglib.proxy.MethodInterceptor;
-import net.sf.cglib.proxy.MethodProxy;
import org.apache.geronimo.core.service.Interceptor;
import org.apache.geronimo.transaction.context.TransactionContext;
import org.apache.geronimo.transaction.context.TransactionContextManager;
@@ -73,22 +70,39 @@
*
* @version $Revision$ $Date$
*/
-public final class CMPInstanceContext extends EntityInstanceContext
implements MethodInterceptor {
+public final class CMPInstanceContext extends EntityInstanceContext {
private final CMP1Bridge cmp1Bridge;
- private final InstanceOperation[] itable;
private final FaultHandler loadFault;
private final IdentityTransform primaryKeyTransform;
private CacheRow cacheRow;
private TransactionContext transactionContext;
- public CMPInstanceContext(Object containerId, EJBProxyFactory
proxyFactory, CMP1Bridge cmp1Bridge, InstanceOperation[] itable, FaultHandler
loadFault, IdentityTransform primaryKeyTransform, CMPInstanceContextFactory
contextFactory, Interceptor lifecycleInterceptorChain, SystemMethodIndices
systemMethodIndices, Set unshareableResources, Set
applicationManagedSecurityResources, TransactionContextManager
transactionContextManager, BasicTimerService timerService) throws Exception {
- super(containerId, proxyFactory, null, lifecycleInterceptorChain,
systemMethodIndices, unshareableResources, applicationManagedSecurityResources,
transactionContextManager, timerService);
+ public CMPInstanceContext(Object containerId,
+ EJBProxyFactory proxyFactory,
+ EntityBean entityBean,
+ CMP1Bridge cmp1Bridge,
+ FaultHandler loadFault,
+ IdentityTransform primaryKeyTransform,
+ Interceptor lifecycleInterceptorChain,
+ SystemMethodIndices systemMethodIndices,
+ Set unshareableResources,
+ Set applicationManagedSecurityResources,
+ TransactionContextManager transactionContextManager,
+ BasicTimerService timerService) throws Exception {
+
+ super(containerId,
+ proxyFactory,
+ entityBean,
+ lifecycleInterceptorChain,
+ systemMethodIndices,
+ unshareableResources,
+ applicationManagedSecurityResources,
+ transactionContextManager,
+ timerService);
+
this.cmp1Bridge = cmp1Bridge;
- this.itable = itable;
this.loadFault = loadFault;
this.primaryKeyTransform = primaryKeyTransform;
- //too bad we can't call this from the constructor
- instance = contextFactory.createCMPBeanInstance(this);
}
public CacheRow getCacheRow() {
@@ -107,15 +121,21 @@
this.transactionContext = transactionContext;
}
- public Object intercept(Object o, Method method, Object[] objects,
MethodProxy methodProxy) throws Throwable {
- int index = methodProxy.getSuperIndex();
- InstanceOperation iop = itable[index];
- return iop.invokeInstance(this, objects);
- }
-
public void associate() throws Throwable {
+ //
+ // don't call super because it activates and
+ // loads the ejb and we want to controll that
+ //
+
+ if (isDead()) {
+ throw new IllegalStateException("Context is dead: container=" +
getContainerId() + ", id=" + getId());
+ }
+
Object id = getId();
- if (id != null) {
+ if (id != null && !isLoaded()) {
+ // acitvate the instance
+ ejbActivate();
+
// locate the cache row for this instance
GlobalIdentity globalId =
primaryKeyTransform.getGlobalIdentity(id);
InTxCache inTxCache = transactionContext.getInTxCache();
@@ -141,11 +161,15 @@
if (cmp1Bridge != null) {
cmp1Bridge.loadEntityBean(cacheRow, this);
}
+
+ // call ejbLoad
+ ejbLoad();
+ setLoaded(true);
}
- super.associate();
}
public void flush() throws Throwable {
+ // calls ejbStore
super.flush();
// copy data from instance into tranql
@@ -154,9 +178,9 @@
}
}
- public void afterCommit(boolean status) {
- transactionContext = null;
+ public void afterCommit(boolean status) throws Throwable {
super.afterCommit(status);
+ transactionContext = null;
}
public void addRelation(int slot, Object primaryKey) {
1.16 +19 -4
openejb/modules/core/src/java/org/openejb/entity/cmp/CMPInstanceContextFactory.java
Index: CMPInstanceContextFactory.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/CMPInstanceContextFactory.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- CMPInstanceContextFactory.java 14 Oct 2004 07:07:16 -0000 1.15
+++ CMPInstanceContextFactory.java 25 Feb 2005 23:06:10 -0000 1.16
@@ -158,13 +158,28 @@
if (proxyFactory == null) {
throw new IllegalStateException("ProxyFactory has not been set");
}
- return new CMPInstanceContext(containerId, proxyFactory, cmp1Bridge,
itable, loadFault, primaryKeyTransform, this, systemChain, systemMethodIndices,
unshareableResources, applicationManagedSecurityResources,
transactionContextManager, timerService);
+ CMPMethodInterceptor cmpMethodInterceptor = new
CMPMethodInterceptor(itable);
+ EntityBean instance = createCMPBeanInstance(cmpMethodInterceptor);
+ CMPInstanceContext context = new CMPInstanceContext(containerId,
+ proxyFactory,
+ instance,
+ cmp1Bridge,
+ loadFault,
+ primaryKeyTransform,
+ systemChain,
+ systemMethodIndices,
+ unshareableResources,
+ applicationManagedSecurityResources,
+ transactionContextManager,
+ timerService);
+ cmpMethodInterceptor.setInstanceContext(context);
+ return context;
}
- public EntityBean createCMPBeanInstance(CMPInstanceContext
instanceContext) {
+ private EntityBean createCMPBeanInstance(CMPMethodInterceptor
cmpMethodInterceptor) {
if (cmp1Bridge == null) {
synchronized (this) {
- enhancer.setCallbacks(new Callback[]{NoOp.INSTANCE,
instanceContext});
+ enhancer.setCallbacks(new Callback[]{NoOp.INSTANCE,
cmpMethodInterceptor});
return (EntityBean) enhancer.create();
}
} else {
1.1
openejb/modules/core/src/java/org/openejb/entity/cmp/CMPMethodInterceptor.java
Index: CMPMethodInterceptor.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.entity.cmp;
import java.lang.reflect.Method;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
/**
* @version $Revision: 1.1 $ $Date: 2005/02/25 23:06:10 $
*/
final class CMPMethodInterceptor implements MethodInterceptor {
private final InstanceOperation[] itable;
private CMPInstanceContext instanceContext;
public CMPMethodInterceptor(InstanceOperation[] itable) {
this.itable = itable;
}
public void setInstanceContext(CMPInstanceContext instanceContext) {
assert this.instanceContext == null: "instanceContext already set";
assert instanceContext != null: "instance context is null";
this.instanceContext = instanceContext;
}
public Object intercept(Object o, Method method, Object[] objects,
MethodProxy methodProxy) throws Throwable {
int index = methodProxy.getSuperIndex();
InstanceOperation iop = itable[index];
return iop.invokeInstance(instanceContext, objects);
}
}