org.jboss.ejb.plugins
Class CMPFilePersistenceManager

java.lang.Object
  extended byorg.jboss.mx.util.JBossNotificationBroadcasterSupport (src) 
      extended byorg.jboss.system.ServiceMBeanSupport (src) 
          extended byorg.jboss.ejb.plugins.CMPFilePersistenceManager
All Implemented Interfaces:
AllowedOperationsFlags (src) , ContainerPlugin (src) , EntityPersistenceStore (src) , MBeanRegistration (src) , NotificationBroadcaster (src) , NotificationEmitter (src) , Service (src) , ServiceMBean (src)

public class CMPFilePersistenceManager
extends ServiceMBeanSupport (src)
implements EntityPersistenceStore (src)

A file-based CMP entity bean persistence manager.

Reads and writes entity bean objects to files by using the standard Java serialization mechanism.

Enitiy state files are stored under: jboss-server-data-dir/storeDirectoryName/ejb-name.

Note, currently the name of the entity must be unique across the server, or unless the store directory is changed, to avoid data collisions.

jason: disabled because XDoclet can not handle right now _@_jmx:mbean extends="org.jboss.system.ServiceMBean"


Field Summary
static java.lang.String DEFAULT_STORE_DIRECTORY_NAME
          The default store directory name ("entities").
 
Fields inherited from class org.jboss.system.ServiceMBeanSupport (src)
log, server, SERVICE_CONTROLLER_SIG, serviceName
 
Fields inherited from interface org.jboss.ejb.AllowedOperationsFlags (src)
IN_AFTER_BEGIN, IN_AFTER_COMPLETION, IN_BEFORE_COMPLETION, IN_BUSINESS_METHOD, IN_EJB_ACTIVATE, IN_EJB_CREATE, IN_EJB_FIND, IN_EJB_HOME, IN_EJB_LOAD, IN_EJB_PASSIVATE, IN_EJB_POST_CREATE, IN_EJB_REMOVE, IN_EJB_STORE, IN_EJB_TIMEOUT, IN_INTERCEPTOR_METHOD, IN_SERVICE_ENDPOINT_METHOD, IN_SET_ENTITY_CONTEXT, IN_SET_MESSAGE_DRIVEN_CONTEXT, IN_SET_SESSION_CONTEXT, IN_UNSET_ENTITY_CONTEXT, NOT_ALLOWED
 
Fields inherited from interface org.jboss.system.ServiceMBean (src)
CREATE_EVENT, CREATED, DESTROY_EVENT, DESTROYED, FAILED, REGISTERED, START_EVENT, STARTED, STARTING, states, STOP_EVENT, STOPPED, STOPPING, UNREGISTERED
 
Constructor Summary
CMPFilePersistenceManager()
           
 
Method Summary
 void activateEntity(EntityEnterpriseContext (src)  ctx)
          Non-operation.
 java.lang.Object createBeanClassInstance()
          Returns a new instance of the bean class or a subclass of the bean class.
 java.lang.Object createEntity(java.lang.reflect.Method m, java.lang.Object[] args, EntityEnterpriseContext (src)  ctx)
          This method is called whenever an entity is to be created.
protected  void createService()
          Sub-classes should override this method to provide custum 'create' logic.
protected  void destroyService()
          Try to remove the store directory, if we can't then ignore.
 java.util.Collection findEntities(java.lang.reflect.Method finderMethod, java.lang.Object[] args, EntityEnterpriseContext (src)  ctx, GenericEntityObjectFactory (src)  factory)
          This method is called when collections of entities are to be found.
 java.lang.Object findEntity(java.lang.reflect.Method finderMethod, java.lang.Object[] args, EntityEnterpriseContext (src)  ctx, GenericEntityObjectFactory (src)  factory)
          This method is called when single entities are to be found.
protected  java.io.File getFile(java.lang.Object id)
           
 java.io.File getStoreDirectory()
          Returns the directory used to store entity state files.
 java.lang.String getStoreDirectoryName()
          Get the sub-directory name under the server data directory where entity data is stored.
 void initEntity(EntityEnterpriseContext (src)  ctx)
          Reset all attributes to default value
 boolean isModified(EntityEnterpriseContext (src)  ctx)
          This method is used to determined whether the instance was modified.
 boolean isStoreRequired(EntityEnterpriseContext (src)  ctx)
          This method is used to determine if an entity should be stored.
 void loadEntity(EntityEnterpriseContext (src)  ctx)
          This method is called whenever an entity shall be load from the underlying storage.
 void passivateEntity(EntityEnterpriseContext (src)  ctx)
          Non-operation.
 java.lang.Object postCreateEntity(java.lang.reflect.Method m, java.lang.Object[] args, EntityEnterpriseContext (src)  ctx)
          This method is called after the createEntity.
 void removeEntity(EntityEnterpriseContext (src)  ctx)
          This method is called when an entity shall be removed from the underlying storage.
 void setContainer(Container (src)  c)
          Saves a reference to the EntityContainer (src) for its bean type.
 void setStoreDirectoryName(java.lang.String dirName)
          Set the sub-directory name under the server data directory where entity data will be stored.
 void storeEntity(EntityEnterpriseContext (src)  ctx)
          This method is called whenever an entity shall be stored to the underlying storage.
 
Methods inherited from class org.jboss.system.ServiceMBeanSupport (src)
create, destroy, getLog, getName, getNextNotificationSequenceNumber, getObjectName, getServer, getServiceName, getState, getStateString, jbossInternalCreate, jbossInternalDescription, jbossInternalDestroy, jbossInternalLifecycle, jbossInternalStart, jbossInternalStop, postDeregister, postRegister, preDeregister, preRegister, start, startService, stop, stopService
 
Methods inherited from class org.jboss.mx.util.JBossNotificationBroadcasterSupport (src)
addNotificationListener, getNotificationInfo, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.system.Service (src)
create, destroy, start, stop
 

Field Detail

DEFAULT_STORE_DIRECTORY_NAME

public static final java.lang.String DEFAULT_STORE_DIRECTORY_NAME
The default store directory name ("entities").

See Also:
Constant Field Values (src)
Constructor Detail

CMPFilePersistenceManager

public CMPFilePersistenceManager()
Method Detail

setContainer

public void setContainer(Container (src)  c)
Saves a reference to the EntityContainer (src) for its bean type.

Specified by:
setContainer in interface ContainerPlugin (src)
Parameters:
c - The container using this plugin. This may be null if the plugin is being disassociated from a container.
Throws:
java.lang.ClassCastException - Container is not a EntityContainer.

setStoreDirectoryName

public void setStoreDirectoryName(java.lang.String dirName)
Set the sub-directory name under the server data directory where entity data will be stored.

This value will be appened to the value of jboss-server-data-dir.

This value is only used during creation and will not dynamically change the store directory when set after the create step has finished.

Parameters:
dirName - A sub-directory name.

getStoreDirectoryName

public java.lang.String getStoreDirectoryName()
Get the sub-directory name under the server data directory where entity data is stored.

Returns:
A sub-directory name.
See Also:
setStoreDirectoryName(java.lang.String)

getStoreDirectory

public java.io.File getStoreDirectory()
Returns the directory used to store entity state files.

Returns:
The directory used to store entity state files.

createService

protected void createService()
                      throws java.lang.Exception
Description copied from class: ServiceMBeanSupport (src)
Sub-classes should override this method to provide custum 'create' logic.

This method is empty, and is provided for convenience when concrete service classes do not need to perform anything specific for this state change.

Overrides:
createService in class ServiceMBeanSupport (src)
Throws:
java.lang.Exception

destroyService

protected void destroyService()
                       throws java.lang.Exception
Try to remove the store directory, if we can't then ignore.

Overrides:
destroyService in class ServiceMBeanSupport (src)
Throws:
java.lang.Exception

createBeanClassInstance

public java.lang.Object createBeanClassInstance()
                                         throws java.lang.Exception
Description copied from interface: EntityPersistenceStore (src)
Returns a new instance of the bean class or a subclass of the bean class.

Specified by:
createBeanClassInstance in interface EntityPersistenceStore (src)
Returns:
the new instance
Throws:
java.lang.Exception

initEntity

public void initEntity(EntityEnterpriseContext (src)  ctx)
Reset all attributes to default value

The EJB 1.1 specification is not entirely clear about this, the EJB 2.0 spec is, see page 169. Robustness is more important than raw speed for most server applications, and not resetting atrribute values result in *very* weird errors (old states re-appear in different instances and the developer thinks he's on drugs).

Specified by:
initEntity in interface EntityPersistenceStore (src)
Parameters:
ctx -

createEntity

public java.lang.Object createEntity(java.lang.reflect.Method m,
                                     java.lang.Object[] args,
                                     EntityEnterpriseContext (src)  ctx)
                              throws java.lang.Exception
Description copied from interface: EntityPersistenceStore (src)
This method is called whenever an entity is to be created. The persistence manager is responsible for handling the results properly wrt the persistent store.

Specified by:
createEntity in interface EntityPersistenceStore (src)
Parameters:
m - the create method in the home interface that was called
args - any create parameters
ctx - the instance being used for this create call
Returns:
The primary key computed by CMP PM or null for BMP
Throws:
java.lang.Exception

postCreateEntity

public java.lang.Object postCreateEntity(java.lang.reflect.Method m,
                                         java.lang.Object[] args,
                                         EntityEnterpriseContext (src)  ctx)
                                  throws java.lang.Exception
Description copied from interface: EntityPersistenceStore (src)
This method is called after the createEntity. The persistence manager is responsible for handling the results properly wrt the persistent store.

Specified by:
postCreateEntity in interface EntityPersistenceStore (src)
Parameters:
m - the ejbPostCreate method in the bean class that was called
args - any create parameters
ctx - the instance being used for this create call
Returns:
null
Throws:
java.lang.Exception

findEntity

public java.lang.Object findEntity(java.lang.reflect.Method finderMethod,
                                   java.lang.Object[] args,
                                   EntityEnterpriseContext (src)  ctx,
                                   GenericEntityObjectFactory (src)  factory)
                            throws FinderException (src) 
Description copied from interface: EntityPersistenceStore (src)
This method is called when single entities are to be found. The persistence manager must find out whether the wanted instance is available in the persistence store, if so it returns the primary key of the object.

Specified by:
findEntity in interface EntityPersistenceStore (src)
Parameters:
finderMethod - the find method in the home interface that was called
args - any finder parameters
ctx - the instance to use for the finder call
Returns:
a primary key representing the found entity
Throws:
FinderException (src)

findEntities

public java.util.Collection findEntities(java.lang.reflect.Method finderMethod,
                                         java.lang.Object[] args,
                                         EntityEnterpriseContext (src)  ctx,
                                         GenericEntityObjectFactory (src)  factory)
Description copied from interface: EntityPersistenceStore (src)
This method is called when collections of entities are to be found. The persistence manager must find out whether the wanted instances are available in the persistence store, and if so it must return a collection of primaryKeys.

Specified by:
findEntities in interface EntityPersistenceStore (src)
Parameters:
finderMethod - the find method in the home interface that was called
args - any finder parameters
ctx - the instance to use for the finder call
Returns:
an primary key collection representing the found entities

activateEntity

public void activateEntity(EntityEnterpriseContext (src)  ctx)
Non-operation.

Specified by:
activateEntity in interface EntityPersistenceStore (src)
Parameters:
ctx - the instance to use for the activation

loadEntity

public void loadEntity(EntityEnterpriseContext (src)  ctx)
Description copied from interface: EntityPersistenceStore (src)
This method is called whenever an entity shall be load from the underlying storage. The persistence manager must load the state from the underlying storage and then call ejbLoad on the supplied instance.

Specified by:
loadEntity in interface EntityPersistenceStore (src)
Parameters:
ctx - the instance to synchronize

isStoreRequired

public boolean isStoreRequired(EntityEnterpriseContext (src)  ctx)
                        throws java.lang.Exception
Description copied from interface: EntityPersistenceStore (src)
This method is used to determine if an entity should be stored.

Specified by:
isStoreRequired in interface EntityPersistenceStore (src)
Parameters:
ctx - the instance to check
Returns:
true, if the entity has been modified
Throws:
java.lang.Exception - thrown if some system exception occurs

isModified

public boolean isModified(EntityEnterpriseContext (src)  ctx)
                   throws java.lang.Exception
Description copied from interface: EntityPersistenceStore (src)
This method is used to determined whether the instance was modified. NOTE, even if the method returns true the isStoreRequired for this same instance might return false, e.g. a CMR field that doesn't have a foreign key was modified.

Specified by:
isModified in interface EntityPersistenceStore (src)
Parameters:
ctx -
Returns:
Throws:
java.lang.Exception

storeEntity

public void storeEntity(EntityEnterpriseContext (src)  ctx)
Description copied from interface: EntityPersistenceStore (src)
This method is called whenever an entity shall be stored to the underlying storage. The persistence manager must call ejbStore on the supplied instance and then store the state to the underlying storage.

Specified by:
storeEntity in interface EntityPersistenceStore (src)
Parameters:
ctx - the instance to synchronize

passivateEntity

public void passivateEntity(EntityEnterpriseContext (src)  ctx)
Non-operation.

Specified by:
passivateEntity in interface EntityPersistenceStore (src)
Parameters:
ctx - the instance to passivate

removeEntity

public void removeEntity(EntityEnterpriseContext (src)  ctx)
                  throws RemoveException (src) 
Description copied from interface: EntityPersistenceStore (src)
This method is called when an entity shall be removed from the underlying storage. The persistence manager must call ejbRemove on the instance and then remove its state from the underlying storage.

Specified by:
removeEntity in interface EntityPersistenceStore (src)
Parameters:
ctx - the instance to remove
Throws:
RemoveException (src) - thrown if the instance could not be removed

getFile

protected java.io.File getFile(java.lang.Object id)