Keel 2.1RC2

org.keel.services.persist.base
Class AbstractPersistentFactory

java.lang.Object
  extended byorg.keel.core.container.AbstractKeelServiceable
      extended byorg.keel.services.persist.base.AbstractPersistentFactory
All Implemented Interfaces:
Configurable, Disposable, Initializable, KeelContextualizable, LogEnabled, PersistentFactory, Poolable, Recyclable, Serviceable
Direct Known Subclasses:
DefaultPersistentFactory, HibernatePersistentFactory

public abstract class AbstractPersistentFactory
extends AbstractKeelServiceable
implements PersistentFactory, Configurable, Initializable, KeelContextualizable, LogEnabled, Poolable, Recyclable, Disposable

A PersistentFactory is a class that generates new Persistent objects, Transactions, and Queries

Version:
$Revision: 1.2 $ $Date: 2004/05/10 20:21:19 $

Field Summary
private  AuthorizationManager byPassAuthManager
           
private  boolean configured
           
protected  DatabaseType databaseType
          DatabaseType service we use.
protected  DataSourceComponent dataSource
          Data source service itself.
protected  java.lang.String dataSourceName
          The name of the data source we will access for all Persistent objects created with this factory.
private  java.lang.String dbTypeName
          The database type service we will use for all of our database-specific information defined with the element
private  boolean initialized
           
protected  Context keelContext
          The Keel context for getting user env.
protected static Logger log
           
protected  java.util.Map metas
           
private  Configuration myConfig
           
protected  java.lang.String myName
          Name of this instance of the PersistentFactory
protected  java.util.Map schemaDescrips
           
protected  java.util.Map schemas
          A HashMap of the schema configurations we have available, for rapid access to the correct schema
private  java.lang.String security
          The (optional) name of another persistent factory that should be used for all accesses to the keel standard security objects (e.g.
 
Fields inherited from class org.keel.core.container.AbstractKeelServiceable
 
Fields inherited from interface org.keel.services.persist.PersistentFactory
ROLE
 
Constructor Summary
AbstractPersistentFactory()
           
 
Method Summary
 void addInputs(ModelResponse res, Persistent p)
          Convenience method to add an Input ResponseElement to the specified ModelResponse for every field in the supplied Persistent.
 void addOutputs(ModelResponse res, Persistent p)
          Convenience method to add an Output ResponseElement to the specified ModelResponse for every field in the supplied Persistent.
protected  void addPersistentToOutput(java.lang.String[] fields, Persistent p, Output o, ModelResponse response)
          Adds the requested values of the Persistent to the given Output.
 void addQuery(ModelResponse res, Persistent p, java.lang.String outputName)
          Add an entire set of Persistents to a model reponse as Outputs, not just one.
 void addQuery(ModelResponse res, Persistent p, java.lang.String outputName, java.lang.String[] fieldNames)
          Convenience method to add a List of nested Output ResponseElements to the specified ModelRepsonse.
abstract  Transaction begin()
          Begin a new transaction and pass the transaction back to the caller.
 void configure(Configuration configuration)
          Pass the Configuration to the Configurable class.
abstract  Persistent create(java.lang.String name)
          Create a new persistent object with the specified name
 Persistent create(java.lang.String name, Transaction trx)
          Create a new Persistent which participates in a transaction
abstract  void createIndices()
           
abstract  void createIndices(java.lang.String schema)
           
protected  void createRecords(Configuration config, java.lang.String persistentName, PersistentMetaData pmd)
           
abstract  void createTables()
          Initialize all schemas defined in this persistent factory, creating all tables as required.
abstract  void createTables(java.lang.String schema)
          Initialize the specified schema, creating all tables as required.
 void dispose()
          The dispose operation is called at the end of a components lifecycle.
abstract  void dropIndices()
           
abstract  void dropIndices(java.lang.String schema)
           
 void enableLogging(Logger newLog)
          Provide component with a logger.
protected  AuthorizationManager getByPassAuthManager()
           
protected  Configuration getConfiguration()
           
 PersistentFactory getFactory(java.lang.String newName)
          A convenience method which gets another factory (other than the current one).
 java.lang.String getInstanceIdentifier()
           
 Context getKeelContext()
           
protected  PersistentMetaData getMetaData(java.lang.String persistentName)
           
 java.lang.String getName()
          A different factory is used to talk to each different database that the application requires.
 java.util.Set getPersistents(java.lang.String schemaName)
          Return a set of names, one for each persistent in the given schema
 Configuration getSchemaConfiguration(java.lang.String schemaName)
          Get the Configuration object for the specified schema, if this schema is defined in this PersistentFactory
 java.lang.String getSchemaDescription(java.lang.String schemaName)
          Get the human-readable description of the specified schema
 java.util.Set getSchemas()
          Return a set of Schema names this factory knows about.
 java.lang.String getSecurity()
          Return the name of an another persistent factory where we find the definitions of the Keel security persistent objects.
 void initialize()
          Initialize the component.
protected  boolean isConfigured()
           
private  java.lang.String processedAttribValue(java.lang.String attribValue)
           
 void recycle()
          The only thing that changes when we recycle an instance of a PersistentFactory is the context, specifying the user who's actually using this instance of the factory.
 void setKeelContext(Context keelContext)
           
protected  void setName(java.lang.String newName)
           
private  void setSecurity(java.lang.String newSec)
           
 
Methods inherited from class org.keel.core.container.AbstractKeelServiceable
getService, getService, getService, getService, getServiceManager, getServiceSelector, releaseService, releaseServices, service
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static Logger log

keelContext

protected Context keelContext
The Keel context for getting user env.


dataSourceName

protected java.lang.String dataSourceName
The name of the data source we will access for all Persistent objects created with this factory. Defined with the configuration element


dbTypeName

private java.lang.String dbTypeName
The database type service we will use for all of our database-specific information defined with the element


dataSource

protected DataSourceComponent dataSource
Data source service itself. Used for all connections from Persistent objects created from this factory


databaseType

protected DatabaseType databaseType
DatabaseType service we use. Gives us specific information about the particular database


myName

protected java.lang.String myName
Name of this instance of the PersistentFactory


schemas

protected java.util.Map schemas
A HashMap of the schema configurations we have available, for rapid access to the correct schema


schemaDescrips

protected java.util.Map schemaDescrips

metas

protected java.util.Map metas

configured

private boolean configured

initialized

private boolean initialized

byPassAuthManager

private AuthorizationManager byPassAuthManager

myConfig

private Configuration myConfig

security

private java.lang.String security
The (optional) name of another persistent factory that should be used for all accesses to the keel standard security objects (e.g. user, group and groupmembers)

Constructor Detail

AbstractPersistentFactory

public AbstractPersistentFactory()
Method Detail

getByPassAuthManager

protected AuthorizationManager getByPassAuthManager()

getConfiguration

protected Configuration getConfiguration()

recycle

public void recycle()
The only thing that changes when we recycle an instance of a PersistentFactory is the context, specifying the user who's actually using this instance of the factory. Leave everything else alone to re-use next time (until we're "disposed");

Specified by:
recycle in interface Recyclable

dispose

public void dispose()
Description copied from interface: Disposable
The dispose operation is called at the end of a components lifecycle. This method will be called after Startable.stop() method (if implemented by component). Components use this method to release and destroy any resources that the Component owns.

Specified by:
dispose in interface Disposable

getSchemas

public final java.util.Set getSchemas()
Description copied from interface: PersistentFactory
Return a set of Schema names this factory knows about.

Specified by:
getSchemas in interface PersistentFactory

getSchemaDescription

public final java.lang.String getSchemaDescription(java.lang.String schemaName)
Description copied from interface: PersistentFactory
Get the human-readable description of the specified schema

Specified by:
getSchemaDescription in interface PersistentFactory
Parameters:
schemaName - The name of the schema
Returns:
String The human-readable description of this schema

create

public abstract Persistent create(java.lang.String name)
                           throws PersistenceException
Create a new persistent object with the specified name

Specified by:
create in interface PersistentFactory
Throws:
PersistenceException

getSchemaConfiguration

public Configuration getSchemaConfiguration(java.lang.String schemaName)
Description copied from interface: PersistentFactory
Get the Configuration object for the specified schema, if this schema is defined in this PersistentFactory

Specified by:
getSchemaConfiguration in interface PersistentFactory
Parameters:
schemaName - The name of the schema to retrieve configuration for
Returns:
A Configuration for the named schema, or null if no such schema exists

getPersistents

public final java.util.Set getPersistents(java.lang.String schemaName)
                                   throws PersistenceException
Return a set of names, one for each persistent in the given schema

Specified by:
getPersistents in interface PersistentFactory
Throws:
PersistenceException

getMetaData

protected final PersistentMetaData getMetaData(java.lang.String persistentName)
                                        throws PersistenceException,
                                               ConfigurationException,
                                               ServiceException
Throws:
PersistenceException
ConfigurationException
ServiceException

create

public final Persistent create(java.lang.String name,
                               Transaction trx)
                        throws PersistenceException
Create a new Persistent which participates in a transaction

Specified by:
create in interface PersistentFactory
Throws:
PersistenceException

configure

public final void configure(Configuration configuration)
                     throws ConfigurationException
Description copied from interface: Configurable
Pass the Configuration to the Configurable class.

Specified by:
configure in interface Configurable
Parameters:
configuration - the class configurations. Must not be null.
Throws:
ConfigurationException - if an error occurs

getFactory

public final PersistentFactory getFactory(java.lang.String newName)
                                   throws PersistenceException
Description copied from interface: PersistentFactory
A convenience method which gets another factory (other than the current one).

Specified by:
getFactory in interface PersistentFactory
Parameters:
newName - The name of the factory being requested
Returns:
A new PersistentFactory
Throws:
PersistenceException - If the factory cannot be initialized, or there is no such factory configured

initialize

public void initialize()
                throws PersistenceException
Description copied from interface: Initializable
Initialize the component. Initialization includes allocating any resources required throughout the component's lifecycle.

Specified by:
initialize in interface Initializable
Throws:
PersistenceException

begin

public abstract Transaction begin()
                           throws PersistenceException
Begin a new transaction and pass the transaction back to the caller. Used when we want a number of database operations to be processed in a single transaction.

Specified by:
begin in interface PersistentFactory
Throws:
PersistenceException

setName

protected final void setName(java.lang.String newName)

getName

public final java.lang.String getName()
Description copied from interface: PersistentFactory
A different factory is used to talk to each different database that the application requires. Each factory has a unique name.

Specified by:
getName in interface PersistentFactory

enableLogging

public final void enableLogging(Logger newLog)
Description copied from interface: LogEnabled
Provide component with a logger.

Specified by:
enableLogging in interface LogEnabled
Parameters:
newLog - the logger. Must not be null.

createTables

public abstract void createTables(java.lang.String schema)
                           throws PersistenceException
Description copied from interface: PersistentFactory
Initialize the specified schema, creating all tables as required. Logs any differences between existing tables and specified tables.

Specified by:
createTables in interface PersistentFactory
Throws:
PersistenceException

createRecords

protected final void createRecords(Configuration config,
                                   java.lang.String persistentName,
                                   PersistentMetaData pmd)
                            throws ConfigurationException
Throws:
ConfigurationException

processedAttribValue

private java.lang.String processedAttribValue(java.lang.String attribValue)
                                       throws PersistenceException
Parameters:
attribValue -
Returns:
Throws:
PersistenceException

createTables

public abstract void createTables()
                           throws PersistenceException
Description copied from interface: PersistentFactory
Initialize all schemas defined in this persistent factory, creating all tables as required. Logs any differences between existing tables and specified tables.

Specified by:
createTables in interface PersistentFactory
Throws:
PersistenceException

addInputs

public final void addInputs(ModelResponse res,
                            Persistent p)
                     throws PersistenceException,
                            ModelException
Description copied from interface: PersistentFactory
Convenience method to add an Input ResponseElement to the specified ModelResponse for every field in the supplied Persistent. Each Input will have a default value the same as the current value of the field in the Persistent, and the Input will have valid values if the field has a list of supplied valid values.

Specified by:
addInputs in interface PersistentFactory
Parameters:
res - A ModelResponse object
p - A persistent to be used to create Inputs
Throws:
ModelException - If a problem occurs creating the Inputs
PersistenceException - If a problem occurs retrieving the fields

addOutputs

public final void addOutputs(ModelResponse res,
                             Persistent p)
                      throws PersistenceException,
                             ModelException
Description copied from interface: PersistentFactory
Convenience method to add an Output ResponseElement to the specified ModelResponse for every field in the supplied Persistent. Each output will be named according to the field name from the persistent, and the content of the output will be the value of the field.

Specified by:
addOutputs in interface PersistentFactory
Parameters:
res - A ModelResponse object
p - A persistent to be used to create Outputs
Throws:
ModelException - If an exception occurs creating the outputs.
PersistenceException - If an exception occurs retrieving the fields

addQuery

public final void addQuery(ModelResponse res,
                           Persistent p,
                           java.lang.String outputName)
                    throws PersistenceException,
                           ModelException
Add an entire set of Persistents to a model reponse as Outputs, not just one.

Specified by:
addQuery in interface PersistentFactory
Parameters:
res - The current model response being prepared for the UI
p - A persistent that has been used in a "query" (the method, not to be confused with the query service, which is something else)
outputName - The name of the top-level output inside which all the other outputs will be nested.
Throws:
PersistenceException
ModelException
See Also:
#addOutputs(ModelReponse, Persistent)

addQuery

public final void addQuery(ModelResponse res,
                           Persistent p,
                           java.lang.String outputName,
                           java.lang.String[] fieldNames)
                    throws PersistenceException,
                           ModelException
Convenience method to add a List of nested Output ResponseElements to the specified ModelRepsonse. Similiar to addOutputs, for the individiual rows. Each row is added to the "outer" Output as row # (useful for logic:iterate). Rows are added to the Output Response Element specified by outputName.

Specified by:
addQuery in interface PersistentFactory
Parameters:
res - A ModelResponse object
p - A persistent to be used to create Outputs
outputName - Name of Output ResponseElement to add the List to.
fieldNames - The fields to be added to the Output. Fields will be added in the same order as in the list. As an added bonus, the records will be sorted on the order of the fields in the list.
Throws:
PersistenceException - If an exception occurs retrieving the fields
ModelException - If an exception occurs creating the outputs.
See Also:
#addOutputs(ModelReponse, Persistent)

addPersistentToOutput

protected final void addPersistentToOutput(java.lang.String[] fields,
                                           Persistent p,
                                           Output o,
                                           ModelResponse response)
                                    throws ModelException,
                                           PersistenceException
Adds the requested values of the Persistent to the given Output.

Parameters:
fields - The names of the Database fields being added
p - The Peristent with the values being read
o - The Output to add the values to
response - The ModelResponse being used to generate the Outputs
Throws:
ModelException
PersistenceException

setSecurity

private void setSecurity(java.lang.String newSec)

getSecurity

public final java.lang.String getSecurity()
Description copied from interface: PersistentFactory
Return the name of an another persistent factory where we find the definitions of the Keel security persistent objects. If we get null we find them here.

Specified by:
getSecurity in interface PersistentFactory

getInstanceIdentifier

public final java.lang.String getInstanceIdentifier()

createIndices

public abstract void createIndices()
                            throws PersistenceException
Throws:
PersistenceException

createIndices

public abstract void createIndices(java.lang.String schema)
                            throws PersistenceException
Throws:
PersistenceException

dropIndices

public abstract void dropIndices()
                          throws PersistenceException
Throws:
PersistenceException

dropIndices

public abstract void dropIndices(java.lang.String schema)
                          throws PersistenceException
Throws:
PersistenceException

setKeelContext

public final void setKeelContext(Context keelContext)
                          throws ContextException
Specified by:
setKeelContext in interface KeelContextualizable
Throws:
ContextException
See Also:
KeelContextualizable.setKeelContext(org.apache.avalon.framework.context.Context)

getKeelContext

public final Context getKeelContext()
Specified by:
getKeelContext in interface KeelContextualizable
See Also:
KeelContextualizable.getKeelContext()

isConfigured

protected boolean isConfigured()

Keel 2.1RC2

Please see keelframework.org for information about new Keel releases.