User: dsundstrom
Date: 01/06/23 20:23:14
Added: src/main/org/jboss/ejb/plugins/cmp
ActivateEntityCommand.java CMPStoreManager.java
CommandFactory.java CreateEntityCommand.java
DestroyCommand.java FindEntitiesCommand.java
FindEntityCommand.java InitCommand.java
InitEntityCommand.java LoadEntitiesCommand.java
LoadEntityCommand.java PassivateEntityCommand.java
RemoveEntityCommand.java StartCommand.java
StopCommand.java StoreEntityCommand.java
Log:
Initial revision of EJB 2.0 CMP.
Revision Changes Path
1.1
jboss/src/main/org/jboss/ejb/plugins/cmp/ActivateEntityCommand.java
Index: ActivateEntityCommand.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
import org.jboss.ejb.EntityEnterpriseContext;
import java.rmi.RemoteException;
/**
* ActivateEntityCommand handles the EntityBean activate message.
* This command is invoked after the bean's ejbActivate is invoked.
* This command notifies the store that a context has been assigned
* to an instance of the bean. This is a place where a store can
* initialize the "PersistenceContext" maintianed in the context.
*
* Life-cycle:
* Tied to CMPStoreManager.
*
* Multiplicity:
* One per CMPStore.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
* @version $Revision: 1.1 $
*/
public interface ActivateEntityCommand
{
// Public --------------------------------------------------------
public void execute(EntityEnterpriseContext ctx)
throws RemoteException;
}
1.1 jboss/src/main/org/jboss/ejb/plugins/cmp/CMPStoreManager.java
Index: CMPStoreManager.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.ejb.CreateException;
import javax.ejb.DuplicateKeyException;
import javax.ejb.FinderException;
import javax.ejb.RemoveException;
import org.jboss.ejb.Container;
import org.jboss.ejb.EntityContainer;
import org.jboss.ejb.EntityPersistenceStore2;
import org.jboss.ejb.EntityEnterpriseContext;
import org.jboss.ejb.plugins.cmp.jdbc.JDBCCommandFactory;
import org.jboss.logging.Log;
import org.jboss.util.FinderResults;
/**
* CMPStoreManager is a classic facade pattern [Gamma et. al, 1995].
* Currently the only client of this facade is CMPPersistenceManager.
* This is an abstract class, which is designed to allow plugable persistence
* storage. Currently there is only one implementation JDBCStoreManager.
*
* CMPStoreManager deligates messages from CMPPersistenceManager to a
* command object, which implements the command pattern [Gamma et. al, 1995].
* There are 2 basic types of messages: life cycle and entity.
* Life cycle messages are init, start, stop, and destroy. Entity messages
* are the classic EntityBean messages (e.g., activate, passivate...).
*
* Dependency:
* In general, this package depends as little as possible on other
packages.
* Specifically it depends on container information from org.jboss.ejb, such as
* EntityEnterpriseContext. Additionally, implementations of this class, will
* depend on org.jboss.metadata to aquire information about the entity.
*
* Life-cycle:
* Tied to the life-cycle of the entity container.
*
* Multiplicity:
* One per cmp entity bean. This could be less if another implementaion
of
* EntityPersistenceStore is created and thoes beans use the implementation
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @author <a href="mailto:[EMAIL PROTECTED]">danch (Dan Christopherson)</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Joe Shevland</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
* @see org.jboss.ejb.EntityPersistenceStore
* @version $Revision: 1.1 $
*/
public abstract class CMPStoreManager
implements EntityPersistenceStore2
{
// Attributes ----------------------------------------------------
protected EntityContainer container;
protected Log log = Log.createLog("CMP");
protected CommandFactory commandFactory;
protected InitCommand initCommand;
protected StartCommand startCommand;
protected StopCommand stopCommand;
protected DestroyCommand destroyCommand;
protected InitEntityCommand initEntityCommand;
protected FindEntityCommand findEntityCommand;
protected FindEntitiesCommand findEntitiesCommand;
protected CreateEntityCommand createEntityCommand;
protected RemoveEntityCommand removeEntityCommand;
protected LoadEntityCommand loadEntityCommand;
protected LoadEntitiesCommand loadEntitiesCommand;
protected StoreEntityCommand storeEntityCommand;
protected ActivateEntityCommand activateEntityCommand;
protected PassivateEntityCommand passivateEntityCommand;
// EntityPersistenceStore implementation -------------------------
public EntityContainer getContainer() {
return container;
}
public void setContainer(Container container) {
this.container = (EntityContainer)container;
}
public Log getLog() {
return log;
}
protected abstract CommandFactory createCommandFactory() throws Exception ;
// Container Life cycle commands -------------------------
public void init() throws Exception {
log.debug("Initializing CMP plugin for " +
container.getBeanMetaData().getEjbName());
// Set up Commands
commandFactory = createCommandFactory();
initCommand = commandFactory.createInitCommand();
startCommand = commandFactory.createStartCommand();
stopCommand = commandFactory.createStopCommand();
destroyCommand = commandFactory.createDestroyCommand();
initEntityCommand = commandFactory.createInitEntityCommand();
findEntityCommand = commandFactory.createFindEntityCommand();
findEntitiesCommand = commandFactory.createFindEntitiesCommand();
createEntityCommand = commandFactory.createCreateEntityCommand();
removeEntityCommand = commandFactory.createRemoveEntityCommand();
loadEntityCommand = commandFactory.createLoadEntityCommand();
loadEntitiesCommand = commandFactory.createLoadEntitiesCommand();
storeEntityCommand = commandFactory.createStoreEntityCommand();
activateEntityCommand = commandFactory.createActivateEntityCommand();
passivateEntityCommand = commandFactory.createPassivateEntityCommand();
// Execute the init Command
initCommand.execute();
}
public void start() throws Exception
{
startCommand.execute();
}
public void stop()
{
if(stopCommand != null) // On deploy errors, sometimes CMPStoreManager was
never initialized!
stopCommand.execute();
}
public void destroy()
{
if(destroyCommand != null) // On deploy errors, sometimes CMPStoreManager was
never initialized!
destroyCommand.execute();
}
// EJB Commands -------------------------
public void initEntity(EntityEnterpriseContext ctx) throws RemoteException
{
initEntityCommand.execute(ctx);
}
public Object createEntity(Method m,
Object[] args,
EntityEnterpriseContext ctx)
throws RemoteException, CreateException
{
return createEntityCommand.execute(m, args, ctx);
}
public Object findEntity(Method finderMethod,
Object[] args,
EntityEnterpriseContext ctx)
throws RemoteException, FinderException
{
return findEntityCommand.execute(finderMethod, args, ctx);
}
public FinderResults findEntities(Method finderMethod,
Object[] args,
EntityEnterpriseContext ctx)
throws RemoteException, FinderException
{
return findEntitiesCommand.execute(finderMethod, args, ctx);
}
public void activateEntity(EntityEnterpriseContext ctx)
throws RemoteException
{
activateEntityCommand.execute(ctx);
}
public void loadEntity(EntityEnterpriseContext ctx)
throws RemoteException
{
loadEntityCommand.execute(ctx);
}
public void loadEntities(FinderResults keys)
throws RemoteException
{
loadEntitiesCommand.execute(keys);
}
public void storeEntity(EntityEnterpriseContext ctx)
throws RemoteException
{
storeEntityCommand.execute(ctx);
}
public void passivateEntity(EntityEnterpriseContext ctx)
throws RemoteException
{
passivateEntityCommand.execute(ctx);
}
public void removeEntity(EntityEnterpriseContext ctx)
throws RemoteException, RemoveException
{
removeEntityCommand.execute(ctx);
}
// Inner classes -------------------------------------------------
// This class supports tuned updates and read-only entities
public static class PersistenceContext {
public Map fieldState = new HashMap();
public Object[] state;
public long lastRead = -1;
}
}
1.1 jboss/src/main/org/jboss/ejb/plugins/cmp/CommandFactory.java
Index: CommandFactory.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
/**
* CommandFactory follows an Abstract Factory pattern [Gamma et. al, 1995]
*
* Life-cycle:
* Tied to CMPStoreManager.
*
* Multiplicity:
* One per CMPStore.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
* @version $Revision: 1.1 $
*/
public interface CommandFactory
{
// Public --------------------------------------------------------
// lifecycle commands
public InitCommand createInitCommand();
public StartCommand createStartCommand();
public StopCommand createStopCommand();
public DestroyCommand createDestroyCommand();
// entity persistence-related commands
public InitEntityCommand createInitEntityCommand();
public FindEntityCommand createFindEntityCommand();
public FindEntitiesCommand createFindEntitiesCommand();
public CreateEntityCommand createCreateEntityCommand();
public RemoveEntityCommand createRemoveEntityCommand();
public LoadEntityCommand createLoadEntityCommand();
public LoadEntitiesCommand createLoadEntitiesCommand();
public StoreEntityCommand createStoreEntityCommand();
// entity activation and passivation commands
public ActivateEntityCommand createActivateEntityCommand();
public PassivateEntityCommand createPassivateEntityCommand();
}
1.1
jboss/src/main/org/jboss/ejb/plugins/cmp/CreateEntityCommand.java
Index: CreateEntityCommand.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
import java.lang.reflect.Method;
import org.jboss.ejb.EntityEnterpriseContext;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
/**
* CreateEntityCommand handles the EntityBean create message.
* This command is invoked after the bean's ejbCreate is invoked.
* This command should store the current state of the instance.
*
* Life-cycle:
* Tied to CMPStoreManager.
*
* Multiplicity:
* One per CMPStoreManager.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
* @version $Revision: 1.1 $
*/
public interface CreateEntityCommand
{
// Public --------------------------------------------------------
public Object execute(Method m,
Object[] args,
EntityEnterpriseContext ctx)
throws RemoteException, CreateException;
}
1.1 jboss/src/main/org/jboss/ejb/plugins/cmp/DestroyCommand.java
Index: DestroyCommand.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
/**
* DestroyCommand informs the store that the container is exiting.
*
* Life-cycle:
* Tied to CMPStoreManager.
*
* Multiplicity:
* One per CMPStoreManager.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
* @version $Revision: 1.1 $
*/
public interface DestroyCommand
{
// Public --------------------------------------------------------
public void execute();
}
1.1
jboss/src/main/org/jboss/ejb/plugins/cmp/FindEntitiesCommand.java
Index: FindEntitiesCommand.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
import java.util.Collection;
import java.lang.reflect.Method;
import org.jboss.ejb.EntityEnterpriseContext;
import java.rmi.RemoteException;
import javax.ejb.FinderException;
import org.jboss.util.FinderResults;
/**
* FindEntitiesCommand handles finders that return collections.
*
* Life-cycle:
* Tied to CMPStoreManager.
*
* Multiplicity:
* One per CMPStore.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
* @version $Revision: 1.1 $
*/
public interface FindEntitiesCommand
{
// Public --------------------------------------------------------
public FinderResults execute(Method finderMethod,
Object[] args,
EntityEnterpriseContext ctx)
throws RemoteException, FinderException;
}
1.1 jboss/src/main/org/jboss/ejb/plugins/cmp/FindEntityCommand.java
Index: FindEntityCommand.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
import java.lang.reflect.Method;
import org.jboss.ejb.EntityEnterpriseContext;
import java.rmi.RemoteException;
import javax.ejb.FinderException;
/**
* FindEntityCommand handles finders that return a single bean.
*
* Life-cycle:
* Tied to CMPStoreManager.
*
* Multiplicity:
* One per CMPStoreManager.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
* @version $Revision: 1.1 $
*/
public interface FindEntityCommand
{
// Public --------------------------------------------------------
public Object execute(Method finderMethod,
Object[] args,
EntityEnterpriseContext ctx)
throws RemoteException, FinderException;
}
1.1 jboss/src/main/org/jboss/ejb/plugins/cmp/InitCommand.java
Index: InitCommand.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
/**
* InitCommand at the end of the CMPStoreManager's init method.
* The store can use this command to initialize the store for
* the specific entity bean.
*
* Life-cycle:
* Tied to CMPStoreManager.
*
* Multiplicity:
* One per CMPStoreManager.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
* @version $Revision: 1.1 $
*/
public interface InitCommand
{
// Public --------------------------------------------------------
public void execute() throws Exception;
}
1.1 jboss/src/main/org/jboss/ejb/plugins/cmp/InitEntityCommand.java
Index: InitEntityCommand.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
import org.jboss.ejb.EntityEnterpriseContext;
import java.rmi.RemoteException;
/**
* InitEntityCommand informs the store that a new entity is about
* to be created. This command is invoked before the bean's ejbCreate
* is invoked. This command must reset the value of all cmpFields
* to 0 or null, as is required by the EJB 2.0 specification.
*
* Life-cycle:
* Tied to CMPStoreManager.
*
* Multiplicity:
* One per CMPStoreManager.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @version $Revision: 1.1 $
*/
public interface InitEntityCommand
{
// Public --------------------------------------------------------
public void execute(EntityEnterpriseContext ctx)
throws RemoteException;
}
1.1
jboss/src/main/org/jboss/ejb/plugins/cmp/LoadEntitiesCommand.java
Index: LoadEntitiesCommand.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
import java.rmi.RemoteException;
import java.util.Map;
import org.jboss.util.FinderResults;
/**
* LoadEntityCommand invoked after FindEntitiesCommand.
* This command should try to load the entites idetified
* in the finder results.
*
* Life-cycle:
* Tied to CMPStoreManager.
*
* Multiplicity:
* One per CMPStoreManager.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @author <a href="mailto:[EMAIL PROTECTED]">danch (Dan Christopherson)</a>
* @version $Revision: 1.1 $
*/
public interface LoadEntitiesCommand
{
// Public --------------------------------------------------------
public void execute(FinderResults keys)
throws RemoteException;
}
1.1 jboss/src/main/org/jboss/ejb/plugins/cmp/LoadEntityCommand.java
Index: LoadEntityCommand.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
import org.jboss.ejb.EntityEnterpriseContext;
import java.rmi.RemoteException;
/**
* LoadEntityCommand handles the EntityBean load message.
* This command is invoked before the bean's ejbLoad is invoked.
* This command should load the current state of the instance.
*
* Life-cycle:
* Tied to CMPStoreManager.
*
* Multiplicity:
* One per CMPStoreManager.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
* @version $Revision: 1.1 $
*/
public interface LoadEntityCommand
{
// Public --------------------------------------------------------
public void execute(EntityEnterpriseContext ctx)
throws RemoteException;
}
1.1
jboss/src/main/org/jboss/ejb/plugins/cmp/PassivateEntityCommand.java
Index: PassivateEntityCommand.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
import org.jboss.ejb.EntityEnterpriseContext;
import java.rmi.RemoteException;
/**
* PassivateEntityCommand handles the EntityBean passivate message.
* This command is invoked after the bean's ejbPassivate is invoked.
* This command notifies the store that the context has been revoked
* from an instance. The store should cleanup the "PersistenceContext"
* maintianed in the context. All data associated with the instance
* should be dumped here. If the container intends to keep the data
* cached (Commit options A and B) it will not call passivate.
*
* Life-cycle:
* Tied to CMPStoreManager.
*
* Multiplicity:
* One per CMPStore.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
* @version $Revision: 1.1 $
*/
public interface PassivateEntityCommand
{
// Public --------------------------------------------------------
public void execute(EntityEnterpriseContext ctx)
throws RemoteException;
}
1.1
jboss/src/main/org/jboss/ejb/plugins/cmp/RemoveEntityCommand.java
Index: RemoveEntityCommand.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
import org.jboss.ejb.EntityEnterpriseContext;
import java.rmi.RemoteException;
import javax.ejb.RemoveException;
/**
* RemoveEntityCommand handles the EntityBean remove message.
* This command is invoked after the bean's ejbRemove is invoked.
* This command should remove the current state of the instance.
*
* Life-cycle:
* Tied to CMPStoreManager.
*
* Multiplicity:
* One per CMPStoreManager.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
* @version $Revision: 1.1 $
*/
public interface RemoveEntityCommand
{
// Public --------------------------------------------------------
public void execute(EntityEnterpriseContext ctx)
throws RemoteException, RemoveException;
}
1.1 jboss/src/main/org/jboss/ejb/plugins/cmp/StartCommand.java
Index: StartCommand.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
/**
* StartCommand informs the store that the container is ready to
* start sending other messages to the store.
*
* Life-cycle:
* Tied to CMPStoreManager.
*
* Multiplicity:
* One per CMPStoreManager.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
* @version $Revision: 1.1 $
*/
public interface StartCommand
{
// Public --------------------------------------------------------
public void execute() throws Exception;
}
1.1 jboss/src/main/org/jboss/ejb/plugins/cmp/StopCommand.java
Index: StopCommand.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
/**
* StopCommand informs the store that the container will stop
* sending other messages to the store. The container may restart
* the store.
*
* Life-cycle:
* Tied to CMPStoreManager.
*
* Multiplicity:
* One per CMPStoreManager.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
* @version $Revision: 1.1 $
*/
public interface StopCommand
{
// Public --------------------------------------------------------
public void execute();
}
1.1 jboss/src/main/org/jboss/ejb/plugins/cmp/StoreEntityCommand.java
Index: StoreEntityCommand.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp;
import org.jboss.ejb.EntityEnterpriseContext;
import java.rmi.RemoteException;
/**
* StoreEntityCommand handles the EntityBean create message.
* This command is invoked after the bean's ejbStore is invoked.
* This command should update the current state of the instance.
*
* Life-cycle:
* Tied to CMPStoreManager.
*
* Multiplicity:
* One per CMPStoreManager.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
* @version $Revision: 1.1 $
*/
public interface StoreEntityCommand
{
// Public --------------------------------------------------------
public void execute(EntityEnterpriseContext ctx)
throws RemoteException;
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development