gdamour 2005/10/08 00:45:58
Modified: modules/openejb-builder/src/java/org/openejb/deployment
CMPContainerBuilder.java CMPEntityBuilder.java
SchemataBuilder.java
Log:
GERONIMO-188 Entity instance caching
o The same FrontEndCacheDelegate needs to be shared across the CMP containers.
o Add the repeatable-read isolation level.
o findByPrimaryKey also queries the cache prior to hit the database.
o Remove two redundant cache queries when retrieving CMP and CMR fields.
Revision Changes Path
1.30 +15 -6
openejb/modules/openejb-builder/src/java/org/openejb/deployment/CMPContainerBuilder.java
Index: CMPContainerBuilder.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/java/org/openejb/deployment/CMPContainerBuilder.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- CMPContainerBuilder.java 1 Oct 2005 08:44:09 -0000 1.29
+++ CMPContainerBuilder.java 8 Oct 2005 04:45:58 -0000 1.30
@@ -105,6 +105,7 @@
import org.tranql.cache.cache.CacheFactory;
import org.tranql.cache.cache.CacheFaultHandler;
import org.tranql.cache.cache.CacheFieldFaultTransform;
+import org.tranql.cache.cache.FindByPKCacheQueryCommand;
import org.tranql.cache.cache.FrontEndCacheDelegate;
import org.tranql.ejb.CMPFieldAccessor;
import org.tranql.ejb.CMPFieldFaultTransform;
@@ -210,6 +211,14 @@
this.tm = tm;
}
+ public FrontEndCacheDelegate getFrontEndCacheDelegate() {
+ return cache;
+ }
+
+ public void setFrontEndCacheDelegate(FrontEndCacheDelegate cache) {
+ this.cache = cache;
+ }
+
public boolean isReentrant() {
return reentrant;
}
@@ -232,7 +241,6 @@
if (ejb == null) {
throw new DeploymentException("Schema does not contain EJB: " +
name);
}
- cache = new FrontEndCacheDelegate();
CacheTable cacheTable = globalSchema.getCacheTable(name);
factory = cacheTable.getCacheFactory();
}
@@ -276,8 +284,10 @@
// findByPrimaryKey
QueryCommand localProxyLoad =
queryBuilder.buildFindByPrimaryKey(getEJBName(), true);
+ localProxyLoad = new FindByPKCacheQueryCommand(cache,
primaryKeyTransform, localProxyLoad);
QueryCommand remoteProxyLoad =
queryBuilder.buildFindByPrimaryKey(getEJBName(), false);
-
+ remoteProxyLoad = new FindByPKCacheQueryCommand(cache,
primaryKeyTransform, remoteProxyLoad);
+
Class pkClass = ejb.isUnknownPK() ? Object.class :
ejb.getPrimaryKeyClass();
FinderEJBQLQuery pkFinder = new FinderEJBQLQuery("findByPrimaryKey",
new Class[] {pkClass}, "UNDEFINED");
QueryCommand[] commands = new QueryCommand[]{localProxyLoad,
remoteProxyLoad};
@@ -388,7 +398,6 @@
FieldTransform attAccessor =
command.getQuery().getResultAccessors()[0];
EmptySlotLoader[] loaders = new EmptySlotLoader[] {new
EmptySlotLoader(i, attAccessor)};
FaultHandler faultHandler = new QueryFaultHandler(command,
identityDefiner, loaders);
- faultHandler = new CacheFaultHandler(cache, faultHandler,
new int[] {i});
accessor = new CMPFieldFaultTransform(accessor,
faultHandler, new int[]{i});
accessor = new CacheFieldFaultTransform(cache, accessor, i);
}
@@ -422,9 +431,10 @@
CMPFieldTransform accessor = new CMPFieldAccessor(new
CacheRowAccessor(i, null), name);
FaultHandler faultHandler = buildFaultHandler(queryBuilder, ejb,
field, i, prefetch);
- faultHandler = new CacheFaultHandler(cache, faultHandler, new
int[] {i});
accessor = new CMPFieldFaultTransform(accessor, faultHandler,
new int[]{i});
+ accessor = new CacheFieldFaultTransform(cache, accessor, i);
+
int relatedIndex = relatedEJB.getAttributes().size() +
relatedEJB.getAssociationEnds().indexOf(relatedField);
FaultHandler relatedFaultHandler =
buildFaultHandler(queryBuilder, relatedEJB, relatedField, relatedIndex,
prefetch);
CMPFieldTransform relatedAccessor = new CMPFieldAccessor(new
CacheRowAccessor(relatedIndex, null), name);
@@ -444,7 +454,6 @@
boolean isRight =
association.getRightJoinDefinition().getPKEntity() == ejb;
accessor = new ManyToManyCMR(accessor, relatedAccessor,
relatedIdentityDefiner, mtm, isRight);
}
- accessor = new CacheFieldFaultTransform(cache, accessor, i);
cmrFaultAccessors.put(name, accessor);
1.43 +7 -3
openejb/modules/openejb-builder/src/java/org/openejb/deployment/CMPEntityBuilder.java
Index: CMPEntityBuilder.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/java/org/openejb/deployment/CMPEntityBuilder.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- CMPEntityBuilder.java 13 Sep 2005 13:04:59 -0000 1.42
+++ CMPEntityBuilder.java 8 Oct 2005 04:45:58 -0000 1.43
@@ -69,6 +69,7 @@
import org.openejb.xbeans.ejbjar.OpenejbOpenejbJarType;
import org.openejb.xbeans.pkgen.EjbKeyGeneratorType;
import org.tranql.cache.GlobalSchema;
+import org.tranql.cache.cache.FrontEndCacheDelegate;
import org.tranql.ejb.EJBProxyFactory;
import org.tranql.ejb.EJBSchema;
import org.tranql.ejb.TransactionManagerDelegate;
@@ -93,6 +94,8 @@
* Create GBeans for all the CMP entity beans in the EJB JAR.
*/
public void buildBeans(EARContext earContext, J2eeContext
moduleJ2eeContext, ClassLoader cl, EJBModule ejbModule, EJBSchema ejbSchema,
SQLSchema sqlSchema, GlobalSchema globalSchema, Map openejbBeans,
TransactionPolicyHelper transactionPolicyHelper, EnterpriseBeansType
enterpriseBeans, TransactionManagerDelegate tmDelegate, ComponentPermissions
componentPermissions, String policyContextID) throws DeploymentException {
+ FrontEndCacheDelegate cacheDelegate = new FrontEndCacheDelegate();
+
// CMP Entity Beans
EntityBeanType[] entityBeans = enterpriseBeans.getEntityArray();
for (int i = 0; i < entityBeans.length; i++) {
@@ -105,7 +108,7 @@
OpenejbEntityBeanType openejbEntityBean =
(OpenejbEntityBeanType) openejbBeans.get(getString(entityBean.getEjbName()));
ObjectName entityObjectName =
super.createEJBObjectName(moduleJ2eeContext, entityBean);
- GBeanData entityGBean = createBean(earContext, ejbModule,
entityObjectName, entityBean, openejbEntityBean, ejbSchema, sqlSchema,
globalSchema, transactionPolicyHelper, cl, tmDelegate, componentPermissions,
policyContextID);
+ GBeanData entityGBean = createBean(earContext, ejbModule,
entityObjectName, entityBean, openejbEntityBean, ejbSchema, sqlSchema,
globalSchema, transactionPolicyHelper, cl, tmDelegate, cacheDelegate,
componentPermissions, policyContextID);
earContext.addGBean(entityGBean);
}
@@ -152,7 +155,7 @@
}
- public GBeanData createBean(EARContext earContext, EJBModule ejbModule,
ObjectName containerObjectName, EntityBeanType entityBean,
OpenejbEntityBeanType openejbEntityBean, EJBSchema ejbSchema, SQLSchema
sqlSchema, GlobalSchema globalSchema, TransactionPolicyHelper
transactionPolicyHelper, ClassLoader cl, TransactionManagerDelegate tmDelegate,
ComponentPermissions componentPermissions, String policyContextID) throws
DeploymentException {
+ public GBeanData createBean(EARContext earContext, EJBModule ejbModule,
ObjectName containerObjectName, EntityBeanType entityBean,
OpenejbEntityBeanType openejbEntityBean, EJBSchema ejbSchema, SQLSchema
sqlSchema, GlobalSchema globalSchema, TransactionPolicyHelper
transactionPolicyHelper, ClassLoader cl, TransactionManagerDelegate tmDelegate,
FrontEndCacheDelegate cacheDelegate, ComponentPermissions componentPermissions,
String policyContextID) throws DeploymentException {
String ejbName = getString(entityBean.getEjbName());
CMPContainerBuilder builder = new CMPContainerBuilder();
builder.setClassLoader(cl);
@@ -180,6 +183,7 @@
builder.setSQLSchema(sqlSchema);
builder.setGlobalSchema(globalSchema);
builder.setTransactionManagerDelegate(tmDelegate);
+ builder.setFrontEndCacheDelegate(cacheDelegate);
try {
GBeanData gbean =
builder.createConfiguration(containerObjectName,
earContext.getTransactionContextManagerObjectName(),
earContext.getConnectionTrackerObjectName(),
getTssBeanObjectName(openejbEntityBean, earContext));
1.3 +5 -2
openejb/modules/openejb-builder/src/java/org/openejb/deployment/SchemataBuilder.java
Index: SchemataBuilder.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/java/org/openejb/deployment/SchemataBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SchemataBuilder.java 1 Oct 2005 08:44:09 -0000 1.2
+++ SchemataBuilder.java 8 Oct 2005 04:45:58 -0000 1.3
@@ -90,6 +90,7 @@
import org.tranql.cache.cache.CacheFactory;
import org.tranql.cache.cache.ReadCommittedCacheFactory;
import org.tranql.cache.cache.ReadUncommittedCacheFactory;
+import org.tranql.cache.cache.RepeatableReadCacheFactory;
import org.tranql.ejb.CMPField;
import org.tranql.ejb.CMRField;
import org.tranql.ejb.EJB;
@@ -200,6 +201,8 @@
factory = new ReadCommittedCacheFactory(size);
} else if (Cache.IsolationLevel.READ_UNCOMMITTED ==
cache.getIsolationLevel()) {
factory = new ReadUncommittedCacheFactory(size);
+ } else if (Cache.IsolationLevel.REPEATABLE_READ ==
cache.getIsolationLevel()) {
+ factory = new RepeatableReadCacheFactory(size);
} else {
throw new AssertionError();
}