dain 2006/02/01 06:50:05
Modified: modules/core/src/java/org/openejb/entity BusinessMethod.java
EntityContextImpl.java EntityInstanceContext.java
EntityInstanceFactory.java
EntityInstanceInterceptor.java HomeMethod.java
Added: modules/core/src/java/org/openejb/entity
EntityCallbackInterceptor.java
Log:
Major refactor
Split container into an object to represent a deployed ejb and a set of
shared containers which process invocations
Introduced interface between CMP container and CMP engine
Revision Changes Path
1.3 +3 -3
openejb/modules/core/src/java/org/openejb/entity/BusinessMethod.java
Index: BusinessMethod.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/BusinessMethod.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BusinessMethod.java 21 Mar 2004 21:26:34 -0000 1.2
+++ BusinessMethod.java 1 Feb 2006 11:50:05 -0000 1.3
@@ -49,7 +49,7 @@
import org.apache.geronimo.core.service.InvocationResult;
-import org.openejb.EJBInvocation;
+import org.openejb.EjbInvocation;
import org.openejb.EJBOperation;
import org.openejb.dispatch.AbstractMethodOperation;
import org.openejb.dispatch.MethodSignature;
@@ -64,7 +64,7 @@
super(beanClass, signature);
}
- public InvocationResult execute(EJBInvocation invocation) throws
Throwable {
+ public InvocationResult execute(EjbInvocation invocation) throws
Throwable {
return invoke(invocation, EJBOperation.BIZMETHOD);
}
}
1.9 +4 -19
openejb/modules/core/src/java/org/openejb/entity/EntityContextImpl.java
Index: EntityContextImpl.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/EntityContextImpl.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- EntityContextImpl.java 9 Mar 2005 05:01:01 -0000 1.8
+++ EntityContextImpl.java 1 Feb 2006 11:50:05 -0000 1.9
@@ -47,24 +47,21 @@
*/
package org.openejb.entity;
-import java.security.Identity;
import java.security.Principal;
-import java.util.Properties;
-import javax.ejb.EJBException;
import javax.ejb.EJBHome;
import javax.ejb.EJBLocalHome;
import javax.ejb.EJBLocalObject;
import javax.ejb.EJBObject;
import javax.ejb.EntityContext;
import javax.ejb.TimerService;
-import javax.transaction.UserTransaction;
import javax.security.auth.Subject;
+import javax.transaction.UserTransaction;
+import org.apache.geronimo.transaction.context.TransactionContextManager;
import org.openejb.EJBContextImpl;
import org.openejb.EJBInstanceContext;
import org.openejb.EJBOperation;
import org.openejb.timer.TimerState;
-import org.apache.geronimo.transaction.context.TransactionContextManager;
/**
* @version $Revision$ $Date$
@@ -94,19 +91,7 @@
throw new IllegalStateException("getUserTransaction is not supported
for EntityBean");
}
- public Properties getEnvironment() {
- throw new EJBException("getEnvironment is no longer supported; use
JNDI instead");
- }
-
- public Identity getCallerIdentity() {
- throw new EJBException("getCallerIdentity is no longer supported;
use getCallerPrincipal instead");
- }
-
- public boolean isCallerInRole(Identity identity) {
- throw new EJBException("isCallerInRole(Identity role) is no longer
supported; use isCallerInRole(String roleName) instead");
- }
-
- public static abstract class EntityContextState extends
EJBContextImpl.EJBContextState {
+ public static abstract class EntityContextState extends EJBContextState {
public Object getPrimaryKey(EJBInstanceContext context) {
return context.getId();
}
1.15 +35 -32
openejb/modules/core/src/java/org/openejb/entity/EntityInstanceContext.java
Index: EntityInstanceContext.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/EntityInstanceContext.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- EntityInstanceContext.java 9 Mar 2005 05:01:01 -0000 1.14
+++ EntityInstanceContext.java 1 Feb 2006 11:50:05 -0000 1.15
@@ -48,45 +48,39 @@
package org.openejb.entity;
import java.util.Set;
-import javax.ejb.EnterpriseBean;
+import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
-import org.apache.geronimo.core.service.Interceptor;
import org.apache.geronimo.transaction.context.TransactionContext;
-import org.apache.geronimo.transaction.context.TransactionContextManager;
import org.openejb.AbstractInstanceContext;
-import org.openejb.EJBInvocation;
-import org.openejb.EJBOperation;
import org.openejb.EJBContextImpl;
+import org.openejb.EJBOperation;
+import org.openejb.EntityEjbContainer;
+import org.openejb.EntityEjbDeployment;
import org.openejb.cache.InstancePool;
-import org.openejb.dispatch.SystemMethodIndices;
import org.openejb.proxy.EJBProxyFactory;
-import org.openejb.timer.BasicTimerService;
/**
* @version $Revision$ $Date$
*/
public abstract class EntityInstanceContext extends AbstractInstanceContext {
- private final EntityContextImpl entityContext;
- private final EJBInvocation setContextInvocation;
- private final EJBInvocation unsetContextInvocation;
- private final EJBInvocation ejbActivateInvocation;
- private final EJBInvocation ejbPassivateInvocation;
- private final EJBInvocation loadInvocation;
- private final EJBInvocation storeInvocation;
+ private final EntityEjbContainer entityEjbContainer;
private Object id;
private boolean loaded = false;
private InstancePool pool;
+ private TransactionContext transactionContext;
+ private final EntityContextImpl entityContext;
+
+ public EntityInstanceContext(EntityEjbDeployment entityEjbDeployment,
+ EntityEjbContainer entityEjbContainer,
+ EntityBean instance,
+ EJBProxyFactory proxyFactory,
+ Set unshareableResources,
+ Set applicationManagedSecurityResources) {
+ super(entityEjbDeployment, instance, proxyFactory,
unshareableResources, applicationManagedSecurityResources);
+ this.entityEjbContainer = entityEjbContainer;
- public EntityInstanceContext(Object containerId, EJBProxyFactory
proxyFactory, EnterpriseBean instance, Interceptor lifecycleInterceptorChain,
SystemMethodIndices systemMethodIndices, Set unshareableResources, Set
applicationManagedSecurityResources, TransactionContextManager
transactionContextManager, BasicTimerService timerService) {
- super(containerId, instance, lifecycleInterceptorChain,
proxyFactory, timerService, unshareableResources,
applicationManagedSecurityResources);
- entityContext = new EntityContextImpl(this,
transactionContextManager);
- ejbActivateInvocation =
systemMethodIndices.getEjbActivateInvocation(this);
- ejbPassivateInvocation =
systemMethodIndices.getEjbPassivateInvocation(this);
- loadInvocation = systemMethodIndices.getEjbLoadInvocation(this);
- storeInvocation = systemMethodIndices.getEjbStoreInvocation(this);
- setContextInvocation =
systemMethodIndices.getSetContextInvocation(this, entityContext);
- unsetContextInvocation =
systemMethodIndices.getUnsetContextInvocation(this);
+ entityContext = new EntityContextImpl(this,
entityEjbContainer.getTransactionContextManager());
}
public Object getId() {
@@ -121,9 +115,12 @@
return entityContext;
}
+ public TransactionContext getTransactionContext() {
+ return transactionContext;
+ }
+
public void setTransactionContext(TransactionContext transactionContext)
{
- loadInvocation.setTransactionContext(transactionContext);
- storeInvocation.setTransactionContext(transactionContext);
+ this.transactionContext = transactionContext;
}
public boolean isLoaded() {
@@ -195,35 +192,41 @@
if (isDead()) {
throw new IllegalStateException("Context is dead: container=" +
getContainerId() + ", id=" + getId());
}
- systemChain.invoke(setContextInvocation);
+ entityEjbContainer.setContext(this, entityContext);
}
public void unsetContext() throws Throwable {
if (isDead()) {
throw new IllegalStateException("Context is dead: container=" +
getContainerId() + ", id=" + getId());
}
- systemChain.invoke(unsetContextInvocation);
+ entityEjbContainer.unsetContext(this);
}
protected void ejbActivate() throws Throwable {
if (isDead()) {
throw new IllegalStateException("Context is dead: container=" +
getContainerId() + ", id=" + getId());
}
- systemChain.invoke(ejbActivateInvocation);
+ entityEjbContainer.ejbActivate(this);
+
}
protected void ejbPassivate() throws Throwable {
if (isDead()) {
throw new IllegalStateException("Context is dead: container=" +
getContainerId() + ", id=" + getId());
}
- systemChain.invoke(ejbPassivateInvocation);
+ entityEjbContainer.ejbPassivate(this);
}
protected void ejbLoad() throws Throwable {
- systemChain.invoke(loadInvocation);
+ entityEjbContainer.load(this, transactionContext);
}
public void ejbStore() throws Throwable {
- systemChain.invoke(storeInvocation);
+ entityEjbContainer.store(this, transactionContext);
+ }
+
+ public void afterCommit(boolean status) throws Throwable {
+ super.afterCommit(status);
+ transactionContext = null;
}
}
1.7 +2 -2
openejb/modules/core/src/java/org/openejb/entity/EntityInstanceFactory.java
Index: EntityInstanceFactory.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/EntityInstanceFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- EntityInstanceFactory.java 25 Feb 2005 23:06:09 -0000 1.6
+++ EntityInstanceFactory.java 1 Feb 2006 11:50:05 -0000 1.7
@@ -48,7 +48,6 @@
package org.openejb.entity;
import java.io.Serializable;
-
import javax.naming.Context;
import org.apache.commons.logging.Log;
@@ -67,6 +66,7 @@
* @version $Revision$ $Date$
*/
public class EntityInstanceFactory implements InstanceFactory, Serializable {
+ private static final long serialVersionUID = -7127497820859468692L;
private static final Log log =
LogFactory.getLog(EntityInstanceFactory.class);
private final InstanceContextFactory factory;
1.16 +18 -13
openejb/modules/core/src/java/org/openejb/entity/EntityInstanceInterceptor.java
Index: EntityInstanceInterceptor.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/EntityInstanceInterceptor.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- EntityInstanceInterceptor.java 1 Mar 2005 23:34:15 -0000 1.15
+++ EntityInstanceInterceptor.java 1 Feb 2006 11:50:05 -0000 1.16
@@ -56,7 +56,9 @@
import org.apache.geronimo.core.service.InvocationResult;
import org.apache.geronimo.transaction.InstanceContext;
import org.apache.geronimo.transaction.context.TransactionContext;
-import org.openejb.EJBInvocation;
+import org.openejb.EjbDeployment;
+import org.openejb.EjbInvocation;
+import org.openejb.EntityEjbDeployment;
import org.openejb.NotReentrantException;
import org.openejb.NotReentrantLocalException;
import org.openejb.cache.InstancePool;
@@ -69,19 +71,22 @@
*/
public final class EntityInstanceInterceptor implements Interceptor {
private final Interceptor next;
- private final Object containerId;
- private final InstancePool pool;
- private final boolean reentrant;
- public EntityInstanceInterceptor(Interceptor next, Object containerId,
InstancePool pool, boolean reentrant) {
+ public EntityInstanceInterceptor(Interceptor next) {
this.next = next;
- this.containerId = containerId;
- this.pool = pool;
- this.reentrant = reentrant;
}
public InvocationResult invoke(final Invocation invocation) throws
Throwable {
- EJBInvocation ejbInvocation = (EJBInvocation) invocation;
+ EjbInvocation ejbInvocation = (EjbInvocation) invocation;
+ EjbDeployment deployment = ejbInvocation.getEjbDeployment();
+ if (!(deployment instanceof EntityEjbDeployment)) {
+ throw new IllegalArgumentException("EntityInstanceInterceptor
can only be used with a EntityEjbDeploymentContext: " +
deployment.getClass().getName());
+ }
+
+ EntityEjbDeployment entityEjbDeploymentContext =
((EntityEjbDeployment) deployment);
+ String containerId = entityEjbDeploymentContext.getContainerId();
+ InstancePool pool = entityEjbDeploymentContext.getInstancePool();
+
TransactionContext transactionContext =
ejbInvocation.getTransactionContext();
Object id = ejbInvocation.getId();
@@ -89,7 +94,7 @@
EntityInstanceContext ctx = null;
// if we have an id then check if there is already a context
associated with the transaction
- if ( id != null) {
+ if (id != null) {
ctx = (EntityInstanceContext)
transactionContext.getContext(containerId, id);
// if we have a dead context, the cached context was discarded,
so we need clean it up and get a new one
if (ctx != null && ctx.isDead()) {
@@ -110,7 +115,7 @@
ejbInvocation.setEJBInstanceContext(ctx);
// check reentrancy
- if (!reentrant && ctx.isInCall()) {
+ if (!entityEjbDeploymentContext.isReentrant() && ctx.isInCall()) {
if (ejbInvocation.getType().isLocal()) {
throw new NotReentrantLocalException("" + containerId);
} else {
@@ -135,7 +140,7 @@
try {
InvocationResult result = next.invoke(invocation);
return result;
- } catch(Throwable t) {
+ } catch (Throwable t) {
// we must kill the instance when a system exception is thrown
ctx.die();
// id may have been set during create
1.3 +3 -3
openejb/modules/core/src/java/org/openejb/entity/HomeMethod.java
Index: HomeMethod.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/HomeMethod.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HomeMethod.java 21 Mar 2004 21:26:34 -0000 1.2
+++ HomeMethod.java 1 Feb 2006 11:50:05 -0000 1.3
@@ -49,7 +49,7 @@
import org.apache.geronimo.core.service.InvocationResult;
-import org.openejb.EJBInvocation;
+import org.openejb.EjbInvocation;
import org.openejb.EJBOperation;
import org.openejb.dispatch.AbstractMethodOperation;
import org.openejb.dispatch.MethodSignature;
@@ -64,7 +64,7 @@
super(beanClass, signature);
}
- public InvocationResult execute(EJBInvocation invocation) throws
Throwable {
+ public InvocationResult execute(EjbInvocation invocation) throws
Throwable {
return invoke(invocation, EJBOperation.EJBHOME);
}
}
1.1
openejb/modules/core/src/java/org/openejb/entity/EntityCallbackInterceptor.java
Index: EntityCallbackInterceptor.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: EntityCallbackInterceptor.java,v 1.1 2006/02/01 11:50:05 dain Exp $
*/
package org.openejb.entity;
import org.openejb.CallbackMethod;
import org.openejb.EjbCallbackInvocation;
import org.openejb.entity.dispatch.EJBPassivateOperation;
import org.openejb.entity.dispatch.EJBActivateOperation;
import org.openejb.entity.dispatch.SetEntityContextOperation;
import org.openejb.entity.dispatch.EJBLoadOperation;
import org.openejb.entity.dispatch.EJBStoreOperation;
import org.openejb.entity.dispatch.UnsetEntityContextOperation;
import org.apache.geronimo.core.service.InvocationResult;
import org.apache.geronimo.core.service.Invocation;
import org.apache.geronimo.core.service.Interceptor;
/**
* @version $Revision: 1.1 $ $Date: 2006/02/01 11:50:05 $
*/
public class EntityCallbackInterceptor implements Interceptor {
public InvocationResult invoke(Invocation invocation) throws Throwable {
EjbCallbackInvocation ejbCallbackInvocation = (EjbCallbackInvocation)
invocation;
CallbackMethod callbackMethod =
ejbCallbackInvocation.getCallbackMethod();
if (callbackMethod == CallbackMethod.SET_CONTEXT) {
InvocationResult result =
SetEntityContextOperation.INSTANCE.execute(ejbCallbackInvocation);
return result;
} else if (callbackMethod == CallbackMethod.UNSET_CONTEXT) {
InvocationResult result =
UnsetEntityContextOperation.INSTANCE.execute(ejbCallbackInvocation);
return result;
} else if (callbackMethod == CallbackMethod.ACTIVATE) {
InvocationResult result =
EJBActivateOperation.INSTANCE.execute(ejbCallbackInvocation);
return result;
} else if (callbackMethod == CallbackMethod.PASSIVATE) {
InvocationResult result =
EJBPassivateOperation.INSTANCE.execute(ejbCallbackInvocation);
return result;
} else if (callbackMethod == CallbackMethod.LOAD) {
InvocationResult result =
EJBLoadOperation.INSTANCE.execute(ejbCallbackInvocation);
return result;
} else if (callbackMethod == CallbackMethod.STORE) {
InvocationResult result =
EJBStoreOperation.INSTANCE.execute(ejbCallbackInvocation);
return result;
} else {
throw new AssertionError("Unknown callback method " +
callbackMethod);
}
}
}