|
PAJES 3.0.21 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.pajes.db.entity.Manager
public abstract class Manager
Provides the data access layer for Entity instances.
Sub-classes must define an Attributes field for each column in
the database table that is to be considered as part of the entity.
For example, given following SQL table:
create table client
(
client int not null,
clientName varchar(50) not null,
constraint clientPK primary key (client)
)
you would create an Manager sub-class as:
import org.pajes.db.entity.Manager;
import org.pajes.db.entity.Attributes;
import org.pajes.db.entity.Registry;
import java.sql.Types;
public class ClientManager extends Manager {
private Attributes client = new Attributes(this, "client", "client", Types.INTEGER, true, false);
private Attributes clientName = new Attributes(this, "clientName", "client", Types.VARCHAR, false, false);
public ClientManager(ConnectionPool pool) {
super(Client.class, "client", pool);
this.setOrderByColumns("client");
}
}
| Field Summary | |
|---|---|
static java.lang.String |
EDITOR_FACTORY
Deprecated. Moved to DefaultEditor.EDITOR_FACTORY |
static java.lang.String |
LISTER_FACTORY
Deprecated. Moved to DefaultLister.LISTER_FACTORY |
| Constructor Summary | |
|---|---|
Manager(java.lang.Class<? extends Entity> entity,
java.lang.String table,
ConnectionManager manager)
Creates an Manager for managing the specified Entity objects. |
|
Manager(java.lang.Class<? extends Entity> entity,
java.lang.String table,
ConnectionPool pool)
Creates an Manager for managing the specified Entity objects. |
|
| Method Summary | |
|---|---|
Entity |
create()
Creates a new Entity instance. |
int |
delete(Entity entity)
Deletes an entity from the database table. |
int |
delete(Entity entity,
java.sql.Connection connection)
Deletes an entity from the database table. |
int |
delete(Scope scope)
Delete entities that match the specified Scope from the table. |
int |
delete(Scope scope,
java.sql.Connection connection)
Delete entities that match the specified Scope from the table. |
java.lang.String |
getAdminServletName()
Returns the MaintenanceServlet class name that is used to administer the Entity objects managed by this class. |
URI |
getAdminServletURI()
Returns the URI of the MaintenanceServlet that is used to administer the Entity objects managed by this class. |
java.util.HashMap<java.lang.String,Attributes> |
getAttributes()
Returns the entity attributes as a HashMap, with the UPPER CASE column name as the key and the Attributes objects as the
associated value. |
java.lang.String[] |
getColumnNames()
Returns the names of all the defined columns. |
protected int |
getColumnPosition(java.lang.Class<? extends MaintenanceDisplayElement> defaultClass,
Attributes attributes)
Called when an Attributes object is registered with the Manager
to determine the default location of the column in the
DefaultEditor, DefaultLister and DefaultViewer. |
ConnectionPool |
getConnectionPool()
Returns the connection pool from which a database connection may be requested. |
java.sql.Connection |
getDBConnection()
Convenience method to return a free connection from the connection pool. |
Paje |
getEditor(javax.servlet.ServletContext context,
javax.servlet.http.HttpServletRequest request,
boolean isNew)
Returns a Paje to display and/or edit an Entity object. |
protected java.lang.Class<? extends Entity> |
getEntity()
Returns the class from which a new instance will be returned when creating a new entity. |
Paje |
getLister(javax.servlet.ServletContext context,
javax.servlet.http.HttpServletRequest request)
Returns a Paje to display a list of Entity objects. |
java.lang.String |
getOrderByClause()
Returns the ORDER BY clause to sort the result set. |
java.lang.String[] |
getPrimaryKeys()
Returns the names of the defined primary keys, or if no primary keys have been defined, the names of all columns. |
java.lang.String |
getPrimaryKeyValues(Entity entity)
Returns a String that should uniquely identify the specified
Entity. |
java.lang.String |
getPrimaryKeyValues(javax.servlet.http.HttpServletRequest request)
Returns a String that should uniquely identify an Entity. |
protected java.sql.PreparedStatement |
getSQLDeleteStatement(Entity entity,
java.sql.Connection connection)
Returns the SQL PreparedStatement string that will deletes the specified entity from the table. |
protected java.sql.PreparedStatement |
getSQLDeleteStatement(Scope scope,
java.sql.Connection connection)
Returns the SQL PreparedStatement string that will delete entities that match the specified Scope from the table. |
protected java.sql.PreparedStatement |
getSQLInsertStatement(Entity entity,
java.sql.Connection connection)
Returns the SQL PreparedStatement string that will inserts the specified entity into the table. |
protected java.sql.PreparedStatement |
getSQLSelectStatement(Scope scope,
java.sql.Connection connection)
Returns the SQL PreparedStatement string that will select entities that match the specified Scope from the table. |
protected java.sql.PreparedStatement |
getSQLUpdateStatement(Entity entity,
java.sql.Connection connection)
Returns the SQL PreparedStatement string that will updates the specified entity in the table. |
java.lang.String |
getTableName()
Retrieves the name of the database table that this object manages. |
Paje |
getViewer(javax.servlet.ServletContext context,
javax.servlet.http.HttpServletRequest request)
Returns a Paje to display an Entity object. |
int |
insert(Entity entity)
Inserts an entity into the database table. |
int |
insert(Entity entity,
java.sql.Connection connection)
Inserts an entity into the database table. |
protected static java.lang.String |
makePrimaryKeyString(java.lang.Class<? extends Entity> entity,
java.lang.String[] keys,
java.lang.Object[] values)
Returns a String that should uniquely identify an Entity. |
protected void |
onCacheEntity(Entity entity)
Called immediately after an individual entity is cached. |
protected void |
onCacheRefresh(java.sql.Connection connection)
Called immediately after a cache refresh. |
void |
recache()
Refreshes the local cache, it one exists. |
void |
recache(java.sql.Connection connection)
Refreshes the local cache, it one exists. |
Entity |
retrieve(Scope scope)
Retrieves a single entity. |
Entity |
retrieve(Scope scope,
int record)
Retrieves a single entity. |
Entity |
retrieve(Scope scope,
int record,
java.sql.Connection connection)
Retrieves a single entity. |
int |
retrieveCount(Scope scope)
Retrieves the count of Entities that meet the scope criteria. |
int |
retrieveCount(Scope scope,
java.sql.Connection connection)
Retrieves the count of Entities that meet the scope criteria. |
protected Entity |
retrievedEntityProcessing(Entity entity,
Scope scope,
int record)
Deprecated. use retrievedEntityProcessing(Entity, Scope, int, Connection) instead. |
protected Entity |
retrievedEntityProcessing(Entity entity,
Scope scope,
int record,
java.sql.Connection connection)
Processes retrieved Entities before they are returned by retrieve(org.pajes.db.entity.Scope) or added to the set of Entities by retrieveSet(org.pajes.db.entity.Scope)
. |
protected Entity[] |
retrieveSet(java.sql.Connection connection,
java.sql.ResultSet resultSet,
Scope scope,
int firstRecord,
int setSize)
Retrieves rows from the database table and converts them into Entity objects. |
Entity[] |
retrieveSet(Scope scope)
Selects entities from the database table. |
Entity[] |
retrieveSet(Scope scope,
int firstRecord,
int setSize)
Selects entities from the database table. |
Entity[] |
retrieveSet(Scope scope,
int firstRecord,
int setSize,
java.sql.Connection connection)
Selects entities from the database table. |
java.sql.ResultSet |
select(Scope scope,
java.sql.Connection connection)
Selects a ResultSet from the database table. |
protected void |
setCaching(Attributes column)
Determines whether the Entity caching mechanism is enabled or not. |
protected void |
setEditor(java.lang.Class<? extends Editor> editor)
Sets the Editor sub-class from which Editor instances can be created. |
protected void |
setEntity(java.lang.Class<? extends Entity> entity)
Sets the class that from which a new instance will be returned when creating a new entity. |
protected void |
setLister(java.lang.Class<? extends Lister> lister)
Sets the Lister sub-class from which Lister instances can be created. |
Manager |
setOrderByColumns(java.lang.String columns)
Sets the default sort order when multiple entities are retrieved. |
Manager |
setTableName(java.lang.String table)
Sets the name of the database table that this object manages. |
protected void |
setViewer(java.lang.Class<? extends Viewer> viewer)
Sets the Viewer sub-class from which Viewer instances can be created. |
java.lang.String |
toString()
Returns a String representation of this Manager. |
int |
update(Entity entity)
Updates an entity in the database table. |
int |
update(Entity entity,
java.sql.Connection connection)
Updates an entity in the database table. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
@Deprecated public static final java.lang.String EDITOR_FACTORY
DefaultEditor.EDITOR_FACTORYPajeFactory instance that will generate generic
forms for displaying and editing Entity objects.
@Deprecated public static final java.lang.String LISTER_FACTORY
DefaultLister.LISTER_FACTORYPajeFactory instance that will generate generic
lists to displaying Entity objects.
| Constructor Detail |
|---|
public Manager(java.lang.Class<? extends Entity> entity,
java.lang.String table,
ConnectionManager manager)
Entity objects.
entity - the Entity sub-class to be managed by this manager.table - the name of the database table that this class manages.manager - the ConnectionPoolManager that will provide the connection
pool through which database access will occur.
public Manager(java.lang.Class<? extends Entity> entity,
java.lang.String table,
ConnectionPool pool)
Entity objects.
entity - the Entity sub-class to be managed by this manager.table - the name of the database table that this class manages.pool - the connection pool through which database access will occur.| Method Detail |
|---|
protected static java.lang.String makePrimaryKeyString(java.lang.Class<? extends Entity> entity,
java.lang.String[] keys,
java.lang.Object[] values)
String that should uniquely identify an Entity.
entity - the Entity class.keys - the array of primary key names.values - the array of primary key values.
String that should uniquely identify an Entity.public Entity create()
Sub-classes may over-ride this method to do any Entity-specific
initialisation, such as the assigning of default values. In this case,
the sub-class must call super.create() before anythig
else.
public int delete(Entity entity)
throws java.sql.SQLException
entity - the Entity object to be deleted from the table.
java.sql.SQLException - if any errors occur processing the request.
public int delete(Entity entity,
java.sql.Connection connection)
throws java.sql.SQLException
entity - the Entity object to be deleted from the table.connection - the connection on which the statement is to be executed.
java.sql.SQLException - if any errors occur processing the request.
public int delete(Scope scope)
throws java.sql.SQLException
scope - an object that determines the scope of the entities that will
be affected by this action.
java.sql.SQLException - if any errors occur processing the request.
public int delete(Scope scope,
java.sql.Connection connection)
throws java.sql.SQLException
scope - an object that determines the scope of the entities that will
be affected by this action.connection - the connection on which the statement is to be executed.
java.sql.SQLException - if any errors occur processing the request.public java.lang.String getAdminServletName()
public URI getAdminServletURI()
public java.util.HashMap<java.lang.String,Attributes> getAttributes()
Attributes objects as the
associated value.
public java.lang.String[] getColumnNames()
public ConnectionPool getConnectionPool()
public java.sql.Connection getDBConnection()
throws java.sql.SQLException
connection pool.
java.sql.SQLException - if an error occurs accessing the database.
public Paje getEditor(javax.servlet.ServletContext context,
javax.servlet.http.HttpServletRequest request,
boolean isNew)
throws EntityException,
java.io.IOException
Paje to display and/or edit an Entity object.
context - the ServletContext.request - the request object.isNew - true if the edit form is to be returned empty so that a new
Entity may be defined, or false if an Entity is to be
retrieved based on the request parameters, and
then used to populate the form input fields.
EntityException - if an error occurs instantiating the Editor.
java.io.IOException - if an error occurs creating the Paje.DefaultEditor,
setEditor(java.lang.Class extends org.pajes.db.entity.Editor>)
public Paje getLister(javax.servlet.ServletContext context,
javax.servlet.http.HttpServletRequest request)
throws EntityException,
java.io.IOException
Paje to display a list of Entity objects.
context - the ServletContext.request - the request object.
EntityException - if an error occurs instantiating the Lister.
java.io.IOException - if an error occurs creating the Paje.DefaultLister,
setLister(java.lang.Class extends org.pajes.db.entity.Lister>)public java.lang.String getOrderByClause()
setOrderByColumns(java.lang.String)public java.lang.String[] getPrimaryKeys()
public java.lang.String getPrimaryKeyValues(Entity entity)
String that should uniquely identify the specified
Entity.
entity - the Entity from which the key values will be
extracted.
String that should uniquely identify the specified
Entity.public java.lang.String getPrimaryKeyValues(javax.servlet.http.HttpServletRequest request)
String that should uniquely identify an Entity.
request - the servlet request containing the values.
String that should uniquely identify an Entity.public java.lang.String getTableName()
public Paje getViewer(javax.servlet.ServletContext context,
javax.servlet.http.HttpServletRequest request)
throws EntityException,
java.io.IOException
Paje to display an Entity object.
context - the ServletContext.request - the request object.
EntityException - if an error occurs instantiating the Editor.
java.io.IOException - if an error occurs creating the Paje.DefaultEditor,
setEditor(java.lang.Class extends org.pajes.db.entity.Editor>)
public int insert(Entity entity)
throws java.sql.SQLException
entity - the Entity object to be inserted into the table.
java.sql.SQLException - if any errors occur processing the request.
public int insert(Entity entity,
java.sql.Connection connection)
throws java.sql.SQLException
entity - the Entity object to be inserted into the table.connection - the connection on which the statement is to be executed.
java.sql.SQLException - if any errors occur processing the request.
public void recache()
throws java.sql.SQLException
java.sql.SQLException - if any errors occur processing the request.
public void recache(java.sql.Connection connection)
throws java.sql.SQLException
connection - the connection on which the query will be executed.
java.sql.SQLException - if any errors occur processing the request.
public Entity retrieve(Scope scope)
throws EntityNotFoundException,
java.sql.SQLException
scope - an object that determines the scope of the entities that will
be affected by this action.
EntityNotFoundException
java.sql.SQLException - if any errors occur processing the request.
public Entity retrieve(Scope scope,
int record)
throws EntityNotFoundException,
java.sql.SQLException
scope - an object that determines the scope of the entities that will
be affected by this action.record - the record number within the scope to retrieve. Use -1 to
retrieve the last record in the set.
EntityNotFoundException - if the Entity requested by the Scope does not exist.
java.sql.SQLException - if any errors occur processing the request.
public Entity retrieve(Scope scope,
int record,
java.sql.Connection connection)
throws EntityNotFoundException,
java.sql.SQLException
scope - an object that determines the scope of the entities that will
be affected by this action.record - the record number within the scope to retrieve. Use -1 to
retrieve the last record in the set.connection - the connection on which the query is to be performed.
EntityNotFoundException - if the Entity requested by the Scope does not exist.
java.sql.SQLException - if any errors occur processing the request.
public int retrieveCount(Scope scope)
throws java.sql.SQLException
scope - an object that determines the scope of the entities that will
be affected by this action.
java.sql.SQLException - if any errors occur processing the request.
public int retrieveCount(Scope scope,
java.sql.Connection connection)
throws java.sql.SQLException
scope - an object that determines the scope of the entities that will
be affected by this action.connection - the connection on which the query is to be performed.
java.sql.SQLException - if any errors occur processing the request.
public Entity[] retrieveSet(Scope scope)
throws java.sql.SQLException
scope - an object that determines the scope of the entities that will
be retrieved.
java.sql.SQLException - if any errors occur processing the request.
public Entity[] retrieveSet(Scope scope,
int firstRecord,
int setSize)
throws java.sql.SQLException
scope - an object that determines the scope of the entities that will
be retrieved.firstRecord - the first record number to retrieve. Use -1 to retrieve the
last row of the set.setSize - the maximum number of rows to return. Use -1 to return all
rows in the set.
java.sql.SQLException - if any errors occur processing the request.
public Entity[] retrieveSet(Scope scope,
int firstRecord,
int setSize,
java.sql.Connection connection)
throws java.sql.SQLException
scope - an object that determines the scope of the entities that will
be retrieved.firstRecord - the first record number to retrieve. Use -1 to retrieve the
last row of the set.setSize - the maximum number of rows to return. Use -1 to return all
rows in the set.connection - the connection on which the query is to be performed.
java.sql.SQLException - if any errors occur processing the request.
public java.sql.ResultSet select(Scope scope,
java.sql.Connection connection)
throws java.sql.SQLException
NOTE: If you elect to use this method, you MUST manually
call ResultSet.getStatement().close() when you finished
processing the returned result set!
scope - an object that determines the scope of the entities that will
be retrieved.connection - the connection on which the query is to be performed.
java.sql.SQLException - if any errors occur processing the request.public Manager setOrderByColumns(java.lang.String columns)
Scope.setOrderByColumns(java.lang.String).
columns - the comma separated list of columns that will be used in the
ORDER BY clause.
public Manager setTableName(java.lang.String table)
table - the name of the database table.
public java.lang.String toString()
String representation of this Manager.
toString in class java.lang.ObjectString.
public int update(Entity entity)
throws java.sql.SQLException
entity - the Entity object to be updated in the table.
java.sql.SQLException - if an error occurs accessing the database.
public int update(Entity entity,
java.sql.Connection connection)
throws java.sql.SQLException
entity - the Entity object to be updated in the table.connection - the connection on which the statement is to be executed.
java.sql.SQLException - if an error occurs accessing the database.
protected int getColumnPosition(java.lang.Class<? extends MaintenanceDisplayElement> defaultClass,
Attributes attributes)
Attributes object is registered with the Manager
to determine the default location of the column in the
DefaultEditor, DefaultLister and DefaultViewer.
This method is only called if the position returned by the
Attributes object is 0.
The default implementation returns a sequential number, starting with 0, for each column registered.
defaultClass - one of DefaultEditor.class, DefaultLister
.class or DefaultViewer.class.attributes - The Attributes being registered.
protected java.lang.Class<? extends Entity> getEntity()
protected java.sql.PreparedStatement getSQLDeleteStatement(Entity entity,
java.sql.Connection connection)
throws java.sql.SQLException
entity - the Entity object to be deleted from the table.connection - the database connection on which the SQL will be executed.
java.sql.SQLException - if an error occurs accessing the database.
protected java.sql.PreparedStatement getSQLDeleteStatement(Scope scope,
java.sql.Connection connection)
throws java.sql.SQLException
scope - an object that determines the scope of the entities that will
be affected by this action.connection - the database connection on which the SQL will be executed.
java.sql.SQLException - if an error occurs accessing the database.
protected java.sql.PreparedStatement getSQLInsertStatement(Entity entity,
java.sql.Connection connection)
throws java.sql.SQLException
entity - the Entity object to be inserted into the table.connection - the database connection on which the SQL will be executed.
java.sql.SQLException - if an error occurs accessing the database.
protected java.sql.PreparedStatement getSQLSelectStatement(Scope scope,
java.sql.Connection connection)
throws java.sql.SQLException
scope - an object that determines the scope of the entities that will
be affected by this action.connection - the database connection on which the SQL will be executed.
java.sql.SQLException - if an error occurs accessing the database.
protected java.sql.PreparedStatement getSQLUpdateStatement(Entity entity,
java.sql.Connection connection)
throws java.sql.SQLException
entity - the Entity object to be updated in the table.connection - the database connection on which the SQL will be executed.
java.sql.SQLException - if an error occurs accessing the database.protected void onCacheEntity(Entity entity)
Sub-classes may over-ride this method to perform any Manager specific processing.
entity - the Entity being cached.
protected void onCacheRefresh(java.sql.Connection connection)
throws java.sql.SQLException
Sub-classes may over-ride this method to perform any Manager specific processing.
connection - the connection on which the cache was refreshed.
java.sql.SQLException - if a database exception occurs.
@Deprecated
protected Entity retrievedEntityProcessing(Entity entity,
Scope scope,
int record)
throws java.sql.SQLException
entity - the Entity to be returned to the request.scope - an object that determines the scope of the Entities that were
requested.record - the ordinal position of this Entity in the set.
java.sql.SQLException - if any errors occur processing the request.
protected Entity retrievedEntityProcessing(Entity entity,
Scope scope,
int record,
java.sql.Connection connection)
throws java.sql.SQLException
retrieve(org.pajes.db.entity.Scope) or added to the set of Entities by retrieveSet(org.pajes.db.entity.Scope)
.
Allows sub-classes to modify the Entity prior to it being returned.
The default implementation does nothing except return the Entity passed as a parameter.
entity - the Entity to be returned to the request.scope - an object that determines the scope of the Entities that were
requested.record - the ordinal position of this Entity in the set.connection - the connection on whicht the Entity was retrieved.
java.sql.SQLException - if any errors occur processing the request.
protected Entity[] retrieveSet(java.sql.Connection connection,
java.sql.ResultSet resultSet,
Scope scope,
int firstRecord,
int setSize)
throws java.sql.SQLException
connection - the connection on which the result set was obtained.resultSet - the result set containing the rows to be converted into Entity
objects.scope - an object that determines the scope of the entities that were
retrieved.firstRecord - the first record number to retrieve. Use -1 to retrieve the
last row of the set.setSize - the maximum number of rows to return. Use -1 to return all
rows in the set.
java.sql.SQLException - if any errors occur processing the request.
protected void setCaching(Attributes column)
throws java.sql.SQLException
Note: caching is extemely simplistic, and is only suitable for very small reference tables. Caching should only be enabled from within the constructor.
column - the single column on which items may be retrieved from the
cache. If null, caching is disabled.
java.sql.SQLException - if an error occurs accessing the database.
protected void setEditor(java.lang.Class<? extends Editor> editor)
throws java.lang.ClassCastException,
java.lang.IllegalAccessException,
java.lang.InstantiationException
editor - the Editor class.
java.lang.ClassCastException - if the specified class is not a subclass of Editor.
java.lang.IllegalAccessException - if this class does not have access to instantiate the
Editor
java.lang.InstantiationException - if the class specified is an interface or an abstract class.DefaultEditorprotected void setEntity(java.lang.Class<? extends Entity> entity)
entity - the Class from which new Entity instance will be generated.
protected void setLister(java.lang.Class<? extends Lister> lister)
throws java.lang.ClassCastException,
java.lang.IllegalAccessException,
java.lang.InstantiationException
lister - the Lister class.
java.lang.ClassCastException - if the specified class is not a subclass of Lister.
java.lang.IllegalAccessException - if this class does not have access to instantiate the
Lister
java.lang.InstantiationException - if the class specified is an interfacce or an abstract class.DefaultLister
protected void setViewer(java.lang.Class<? extends Viewer> viewer)
throws java.lang.ClassCastException,
java.lang.IllegalAccessException,
java.lang.InstantiationException
viewer - the Viewer class.
java.lang.ClassCastException - if the specified class is not a subclass of Viewer.
java.lang.IllegalAccessException - if this class does not have access to instantiate the
Viewer
java.lang.InstantiationException - if the class specified is an interfacce or an abstract class.DefaultViewer
|
PAJES 3.0.21 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||