bill.util.persist
Class EntityCollection

java.lang.Object
  |
  +--bill.util.persist.EntityCollection
Direct Known Subclasses:
EntityCollectionConfig, EntityCollectionRDBMS

public abstract class EntityCollection
extends Object

Holds a collection of related entities. Used for 'queries' that retrieve multiple entities of the same type (i.e. Users, Cars, Trucks, etc).


Field Summary
protected  Hashtable _criteria
           
protected  Vector _entities
           
protected  String _entityName
           
protected  EntityData _sampleEntity
          Sample EntityData of the type contained in the list.
 
Constructor Summary
EntityCollection()
          Default creator, normally only used when creating an object via introspection.
EntityCollection(String entityName, Hashtable criteria)
          Main creator, takes the selection criteria for populating the entity collection as input.
 
Method Summary
protected  EntityData createSampleEntity()
          Creates an instance of the entity that is contained in this collecion.
 Hashtable getCriteria()
          Retrieves the selection criteria used to populate the entity colleciton.
 Vector getEntities()
          Retrieves the list of entities that make up the collection.
 EntityData getEntity(int index)
          Retrieve a specific entity from the collection.
 String getEntityName()
          Gets the class name of the entities that are contained in this collection.
abstract  void populateCollection()
          Must be implemented by the subclass, this is the method that actually performs the read from the persistent data store and populates the collection with it's entities.
 void save()
          Loops through all the entities in the collection and calls their save method so they are updated in the persistent store.
 void setAllDeleted()
          Marks all entities in the collection as deleted.
 void setCriteria(Hashtable criteria)
          Sets the selection criteria used to populate the entity colleciton.
 void setEntityName(String entityName)
          Sets the class name of the entity that is contained in this collection.
 int size()
          Returns the number of entities contained in this collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_entityName

protected String _entityName

_entities

protected Vector _entities

_criteria

protected Hashtable _criteria

_sampleEntity

protected EntityData _sampleEntity
Sample EntityData of the type contained in the list. Needed so we know details about the entity such as its elements.
Constructor Detail

EntityCollection

public EntityCollection()
Default creator, normally only used when creating an object via introspection. When an object is created using this creator, the setEntityName and setCriteria must be called as well to complete the setting of the data required by this class.

EntityCollection

public EntityCollection(String entityName,
                        Hashtable criteria)
                 throws PersistException
Main creator, takes the selection criteria for populating the entity collection as input.
Parameters:
entityName - Name of the entity that is contained in this collection. Must match the entitiy's Java class name as we will use introspection to create one. Use the full package name if neccessary, such as com.mycompany.UserData.
criteria - The criteria to use to populate the entity collection. Keyed by the element name, the result is the element value.
Method Detail

setEntityName

public void setEntityName(String entityName)
                   throws PersistException
Sets the class name of the entity that is contained in this collection. Also creates a sample entity of that entity name.
Parameters:
entityName - Value to set the entity name to.
Throws:
PersistException - Thrown when a sample entity cannot be created.

getEntityName

public String getEntityName()
Gets the class name of the entities that are contained in this collection.
Returns:
The class name of the entities.

setCriteria

public void setCriteria(Hashtable criteria)
Sets the selection criteria used to populate the entity colleciton.
Parameters:
criteria - The cirteria to use to populate the entity collection. Keyed by the element name, the result is the element value.

getCriteria

public Hashtable getCriteria()
Retrieves the selection criteria used to populate the entity colleciton.
Returns:
The selection criteria.

getEntities

public Vector getEntities()
Retrieves the list of entities that make up the collection.
Returns:
The collection's entities.

getEntity

public EntityData getEntity(int index)
Retrieve a specific entity from the collection.
Parameters:
index - The index of the entity to be retrieved, this is a 0 based index.

setAllDeleted

public void setAllDeleted()
Marks all entities in the collection as deleted. If the collection is then save (or if an item in the collection is saved), the entities will then be deleted from their persistent store.

save

public void save()
          throws PersistException
Loops through all the entities in the collection and calls their save method so they are updated in the persistent store.
Throws:
PersistException - Thrown when the save method fails, forwards on the exception from the save method.
See Also:
EntityData.save()

createSampleEntity

protected EntityData createSampleEntity()
                                 throws PersistException
Creates an instance of the entity that is contained in this collecion. We create most of the entities in the collection via introspection, and this is the method that does this.
Returns:
A newly created instance of the entity.
Throws:
PersistException - Thrown when we cannot instantiate the new entity object.

size

public int size()
Returns the number of entities contained in this collection.
Returns:
The number of entities.

populateCollection

public abstract void populateCollection()
                                 throws PersistException
Must be implemented by the subclass, this is the method that actually performs the read from the persistent data store and populates the collection with it's entities.