gdamour 2005/10/01 04:44:09
Modified: modules/core/src/java/org/openejb/entity/cmp
CMPEntityInterceptorBuilder.java
InTxCacheInterceptor.java
Added: modules/core/src/java/org/openejb/entity/cmp
CMPEJBContainer.java
Log:
GERONIMO-188 Entity instance caching
Add support for caching of CMP entities across Tx.
An entity cache is defined for each CMP. It is queried and updated each
time that a CMP or CMR field is accessed or updated respectively. Also, this
cache is queried when a CMP is faulted if not already associated to the
transactional cache.
An isolation level is defined by an entity cache. Two isolation levels are
currently supported, namely read-uncommitted and read-committed.
read-committed has not yet been tested.
Revision Changes Path
1.5 +13 -2
openejb/modules/core/src/java/org/openejb/entity/cmp/CMPEntityInterceptorBuilder.java
Index: CMPEntityInterceptorBuilder.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/CMPEntityInterceptorBuilder.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CMPEntityInterceptorBuilder.java 18 Apr 2005 19:05:09 -0000 1.4
+++ CMPEntityInterceptorBuilder.java 1 Oct 2005 08:44:09 -0000 1.5
@@ -62,6 +62,8 @@
import org.openejb.security.PolicyContextHandlerEJBInterceptor;
import org.openejb.transaction.TransactionContextInterceptor;
import org.tranql.cache.CacheFlushStrategyFactory;
+import org.tranql.cache.cache.Cache;
+import org.tranql.cache.cache.FrontEndCache;
/**
*
@@ -70,6 +72,7 @@
*/
public class CMPEntityInterceptorBuilder extends AbstractInterceptorBuilder {
private CacheFlushStrategyFactory strategyFactory;
+ private FrontEndCache cache;
private boolean reentrant;
public CacheFlushStrategyFactory getCacheFlushStrategyFactory() {
@@ -80,6 +83,14 @@
this.strategyFactory = strategyFactory;
}
+ public FrontEndCache getFrontEndCache() {
+ return cache;
+ }
+
+ public void setFrontEndCache(FrontEndCache cache) {
+ this.cache = cache;
+ }
+
public boolean isReentrant() {
return reentrant;
}
@@ -123,7 +134,7 @@
firstInterceptor = new
ConnectionTrackingInterceptor(firstInterceptor, trackedConnectionAssociator);
}
firstInterceptor = new EntityInstanceInterceptor(firstInterceptor,
containerId, instancePool, reentrant);
- firstInterceptor = new InTxCacheInterceptor(firstInterceptor,
strategyFactory);
+ firstInterceptor = new InTxCacheInterceptor(firstInterceptor,
strategyFactory, cache);
firstInterceptor = new
TransactionContextInterceptor(firstInterceptor, transactionContextManager,
transactionPolicyManager);
firstInterceptor = new SystemExceptionInterceptor(firstInterceptor,
ejbName);
return new TwoChains(firstInterceptor, systemChain);
1.3 +10 -3
openejb/modules/core/src/java/org/openejb/entity/cmp/InTxCacheInterceptor.java
Index: InTxCacheInterceptor.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/InTxCacheInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InTxCacheInterceptor.java 13 Sep 2005 02:31:44 -0000 1.2
+++ InTxCacheInterceptor.java 1 Oct 2005 08:44:09 -0000 1.3
@@ -56,6 +56,8 @@
import org.tranql.cache.CacheFlushStrategyFactory;
import org.tranql.cache.InTxCache;
import org.tranql.cache.CacheFlushStrategy;
+import org.tranql.cache.cache.FrontEndCache;
+import org.tranql.cache.cache.InTxCacheTracker;
/**
* This interceptor defines, if required, the InTxCache of the
@@ -68,17 +70,21 @@
public final class InTxCacheInterceptor implements Interceptor {
private final Interceptor next;
private final CacheFlushStrategyFactory strategyFactory;
+ private final FrontEndCache cache;
- public InTxCacheInterceptor(Interceptor next, CacheFlushStrategyFactory
strategyFactory) {
+ public InTxCacheInterceptor(Interceptor next, CacheFlushStrategyFactory
strategyFactory, FrontEndCache cache) {
this.next = next;
this.strategyFactory = strategyFactory;
+ this.cache = cache;
}
public InvocationResult invoke(final Invocation invocation) throws
Throwable {
EJBInvocation ejbInvocation = (EJBInvocation) invocation;
TransactionContext transactionContext =
ejbInvocation.getTransactionContext();
if ( null == transactionContext.getInTxCache() ) {
- transactionContext.setInTxCache(new
GeronimoInTxCache(strategyFactory.createCacheFlushStrategy()));
+ CacheFlushStrategy strategy =
strategyFactory.createCacheFlushStrategy();
+ strategy = new InTxCacheTracker(cache, strategy);
+ transactionContext.setInTxCache(new GeronimoInTxCache(strategy));
}
return next.invoke(invocation);
@@ -90,5 +96,6 @@
super(flushStrategy);
}
+
}
}
1.1
openejb/modules/core/src/java/org/openejb/entity/cmp/CMPEJBContainer.java
Index: CMPEJBContainer.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 the
* above copyright notice, 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.
*
* Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: CMPEJBContainer.java,v 1.1 2005/10/01 08:44:09 gdamour Exp $
*/
package org.openejb.entity.cmp;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Map;
import javax.ejb.EJBHome;
import javax.ejb.EJBLocalHome;
import javax.security.auth.Subject;
import javax.transaction.TransactionManager;
import org.apache.geronimo.core.service.Invocation;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.management.J2EEManagedObject;
import org.apache.geronimo.security.deploy.DefaultPrincipal;
import org.apache.geronimo.timer.ThreadPooledTimer;
import org.apache.geronimo.transaction.TrackedConnectionAssociator;
import org.apache.geronimo.transaction.context.TransactionContextManager;
import org.apache.geronimo.transaction.context.UserTransactionImpl;
import org.openejb.EJBContainer;
import org.openejb.GenericEJBContainer;
import org.openejb.InstanceContextFactory;
import org.openejb.InterceptorBuilder;
import org.openejb.cache.InstancePool;
import org.openejb.corba.TSSBean;
import org.openejb.dispatch.InterfaceMethodSignature;
import org.openejb.proxy.ProxyInfo;
import org.tranql.cache.cache.Cache;
import org.tranql.cache.cache.CacheFactory;
import org.tranql.cache.cache.FrontEndCache;
import org.tranql.cache.cache.FrontEndCacheDelegate;
import org.tranql.cache.cache.FrontEndToCacheAdaptor;
/**
*
* @version $Revision: 1.1 $ $Date: 2005/10/01 08:44:09 $
*/
public class CMPEJBContainer extends GenericEJBContainer {
private final TransactionContextManager transactionContextManager;
private final FrontEndCacheDelegate delegate;
private final CacheFactory factory;
public CMPEJBContainer(Object containerId, String ejbName, ProxyInfo
proxyInfo, InterfaceMethodSignature[] signatures, InstanceContextFactory
contextFactory, InterceptorBuilder interceptorBuilder, InstancePool pool, Map
componentContext, UserTransactionImpl userTransaction, String[] jndiNames,
String[] localJndiNames, TransactionContextManager transactionContextManager,
TrackedConnectionAssociator trackedConnectionAssociator, ThreadPooledTimer
timer, String objectName, Kernel kernel, DefaultPrincipal defaultPrincipal,
Subject runAsSubject, TSSBean tssBean, Serializable homeTxPolicyConfig,
Serializable remoteTxPolicyConfig, ClassLoader classLoader,
FrontEndCacheDelegate delegate, CacheFactory factory) throws Exception {
super(containerId, ejbName, proxyInfo, signatures, contextFactory,
interceptorBuilder, pool, componentContext, userTransaction,
jndiNames,
localJndiNames, transactionContextManager,
trackedConnectionAssociator,
timer, objectName, kernel, defaultPrincipal, runAsSubject,
tssBean,
homeTxPolicyConfig, remoteTxPolicyConfig, classLoader);
this.transactionContextManager = transactionContextManager;
this.delegate = delegate;
this.factory = factory;
}
public void doStart() throws Exception {
super.doStart();
TransactionManager tm =
transactionContextManager.getTransactionManager();
Cache cache = factory.factory();
FrontEndCache frontEndCache = new FrontEndToCacheAdaptor(tm, cache);
delegate.setFrontEndCache(frontEndCache);
}
public void doStop() throws Exception {
super.doStop();
delegate.setFrontEndCache(null);
}
public void doFail() {
super.doFail();
delegate.setFrontEndCache(null);
}
public static final GBeanInfo GBEAN_INFO;
static {
GBeanInfoBuilder infoFactory = new
GBeanInfoBuilder(CMPEJBContainer.class);
infoFactory.addAttribute("containerID", Object.class, true);
infoFactory.addAttribute("ejbName", String.class, true);
infoFactory.addAttribute("proxyInfo", ProxyInfo.class, true);
infoFactory.addAttribute("signatures",
InterfaceMethodSignature[].class, true);
infoFactory.addAttribute("contextFactory",
InstanceContextFactory.class, true);
infoFactory.addAttribute("interceptorBuilder",
InterceptorBuilder.class, true);
infoFactory.addAttribute("pool", InstancePool.class, true);
infoFactory.addAttribute("componentContext", Map.class, true);
infoFactory.addAttribute("userTransaction",
UserTransactionImpl.class, true);
infoFactory.addAttribute("jndiNames", String[].class, true);
infoFactory.addAttribute("localJndiNames", String[].class, true);
infoFactory.addAttribute("defaultPrincipal", DefaultPrincipal.class,
true);
infoFactory.addAttribute("runAsSubject", Subject.class, true);
infoFactory.addAttribute("homeTxPolicyConfig", Serializable.class,
true);
infoFactory.addAttribute("remoteTxPolicyConfig", Serializable.class,
true);
infoFactory.addReference("TransactionContextManager",
TransactionContextManager.class, NameFactory.TRANSACTION_CONTEXT_MANAGER);
infoFactory.addReference("TrackedConnectionAssociator",
TrackedConnectionAssociator.class, NameFactory.JCA_CONNECTION_TRACKER);
infoFactory.addReference("Timer", ThreadPooledTimer.class,
NameFactory.GERONIMO_SERVICE);
infoFactory.addReference("TSSBean", TSSBean.class);
infoFactory.addAttribute("objectName", String.class, false);
infoFactory.addInterface(J2EEManagedObject.class);
infoFactory.addAttribute("kernel", Kernel.class, false);
infoFactory.addAttribute("ejbHome", EJBHome.class, false);
infoFactory.addAttribute("ejbLocalHome", EJBLocalHome.class, false);
infoFactory.addAttribute("unmanagedReference", EJBContainer.class,
false);
infoFactory.addAttribute("classLoader", ClassLoader.class, false);
infoFactory.addAttribute("frontEndCacheDelegate",
FrontEndCacheDelegate.class, true);
infoFactory.addAttribute("cacheFactory", CacheFactory.class, true);
infoFactory.addOperation("getMethodIndex", new Class[]{Method.class});
infoFactory.addOperation("getEjbObject", new Class[]{Object.class});
infoFactory.addOperation("getEjbLocalObject", new
Class[]{Object.class});
infoFactory.addOperation("invoke", new Class[]{Invocation.class});
infoFactory.addOperation("invoke", new Class[]{Method.class,
Object[].class, Object.class});
infoFactory.addOperation("getTimerById", new Class[]{Long.class});
infoFactory.setConstructor(new String[]{
"containerID",
"ejbName",
"proxyInfo",
"signatures",
"contextFactory",
"interceptorBuilder",
"pool",
"componentContext",
"userTransaction",
"jndiNames",
"localJndiNames",
"TransactionContextManager",
"TrackedConnectionAssociator",
"Timer",
"objectName",
"kernel",
"defaultPrincipal",
"runAsSubject",
"TSSBean",
"homeTxPolicyConfig",
"remoteTxPolicyConfig",
"classLoader",
"frontEndCacheDelegate",
"cacheFactory"});
GBEAN_INFO = infoFactory.getBeanInfo();
}
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
}