|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.is.jrf.AbstractDomain
Subclasses of AbstractDomain are generally table-specific objects.
If you have questions, make sure you read the documentation. (see Package.html).
Note: The "current date/time" function will be inserted into the update SQL whenever a JRFConstants.CURRENT_TIMESTAMP is encountered for an attribute.
Note: For an example of how to use the executeSQLQuery() method, see the implementation of the findCustom(sqlString,jdbcHelper) method.
Note: If any of the superclass methods should never be used, you can override them with a method that throws an exception.
JDBCHelperPool is now supported (version 1.5). Find methods handle the pools differently than the Update (save,delete) methods. The find methods "manually" return the JDBCHelper to the pool (if the JDBCHelper is not part of a transaction). The update methods depend upon the endTransaction and rollback methods to return the connection to the pool.
Inner Class Summary | |
protected static interface |
AbstractDomain.RowHandler
|
Fields inherited from interface com.is.jrf.JRFConstants |
CURRENT_DATE, CURRENT_TIMESTAMP, DEFAULT_TO_EMPTY_STRING, DEFAULT_TO_FALSE, DEFAULT_TO_NOW, DEFAULT_TO_NULL, DEFAULT_TO_ONE, DEFAULT_TO_TODAY, DEFAULT_TO_TRUE, DEFAULT_TO_ZERO, EQUALS, NATURAL_PRIMARY_KEY, NO_POST_FIND, NOT_EQUALS, OPTIMISTIC_LOCK, REQUIRED, SEQUENCED_PRIMARY_KEY, SUBTYPE_IDENTIFIER, UNIQUE |
Constructor Summary | |
AbstractDomain()
This constructor must be executed whether implicitly or explicitly. |
|
AbstractDomain(int option)
The option argument affects the behavior of this framework. |
Method Summary | |
void |
addColumnSpec(ColumnSpec aColumnSpec)
|
void |
addJoinTable(JoinTable aJoinTable)
|
void |
addSubtypeColumnSpec(AbstractColumnSpec aColumnSpec)
Cannot add CompoundPrimaryKeyColumnSpec using this |
static void |
addSubtypeDomain(java.lang.Object subtypeIdentifierValue,
java.lang.Class domainClass)
Inform this supertype domain class of a subtype domain class |
void |
beginTransaction()
This is a pass-through method that adds the default JDBCHelper to the argument list. |
void |
beginTransaction(JDBCHelper aJDBCHelper)
This is a helper method that goes with the endTransaction() method. |
protected PersistentObject |
convertToPersistentObject(JDBCHelper aJDBCHelper)
The reflection in Java 2 makes this method almost as efficient as hard-coding the gets and sets in a subclass. |
PersistentObject |
convertToSubtypePersistentObject(PersistentObject aPO1)
Copy the attribute values from a supertype instance to a subtype instance. |
void |
copyAttributes(PersistentObject aPO1,
PersistentObject aPO2)
Copy the ColumnSpec attributes from one PersistentObject to another. Note: If this is a subtype Domain instance then the subtype fields will be copied as well. |
void |
createTable()
|
void |
createTable(JDBCHelper aJDBCHelper)
Build and execute SQL to create a table with default column types for this domain. |
PersistentObject |
decodePrimaryKey(java.lang.String aString)
Encode the primary key for the given PersistentObject instance as a string that can be decoded later. |
int |
delete(PersistentObject aPO)
This is a pass-through method that adds the default JDBCHelper to the argument list. |
int |
delete(PersistentObject aPO,
JDBCHelper aJDBCHelper)
Delete one row from the database. |
java.lang.String |
delimitString(java.lang.String aString)
This is a helper method for use by subclasses that are creating SQL. |
void |
dropTable(boolean ignoreErrors)
Execute SQL to drop the table for this domain object - use the default JDBCHelper. |
void |
dropTable(boolean ignoreErrors,
JDBCHelper aJDBCHelper)
Execute SQL to drop the table for this domain object. |
java.lang.String |
encodePrimaryKey(PersistentObject aPO)
Encode the primary key for the given PersistentObject instance as a string that can be decoded later. |
void |
endTransaction()
This method commits the transaction and closes the JDBCHelper. |
void |
endTransaction(JDBCHelper aJDBCHelper)
This method commits the transaction and closes the JDBCHelper. |
protected void |
executeSQLQuery(java.lang.String sql,
AbstractDomain.RowHandler aRowHandler)
Execute the SQL and pass each row to the given RowHandler. |
protected void |
executeSQLQuery(java.lang.String sql,
AbstractDomain.RowHandler aRowHandler,
JDBCHelper aJDBCHelper)
Execute the SQL and pass each row to the given RowHandler. |
protected int |
executeSQLUpdate(java.lang.String sql)
This is a pass-through method that adds the default JDBCHelper to the argument list. |
protected int |
executeSQLUpdate(java.lang.String sql,
JDBCHelper aJDBCHelper)
Execute SQL that updates, deletes, or inserts. |
protected PersistentObject |
finalFind(java.lang.Object pkOrPersistentObject,
JDBCHelper aJDBCHelper)
This is a protected method that cannot be overridden. |
PersistentObject |
find(java.lang.Object pkOrPersistentObject)
This is a pass-through method that adds the default JDBCHelper to the argument list. |
PersistentObject |
find(java.lang.Object pkOrPersistentObject,
JDBCHelper aJDBCHelper)
Find and return one PersistentObject using either the raw primary key or the primary key attribute(s) from a PersistentObject object. |
java.util.List |
find(SelectSQLBuilder builder)
|
java.util.List |
find(SelectSQLBuilder builder,
JDBCHelper aJDBCHelper)
|
java.util.List |
findAll()
This is a pass-through method that adds the default JDBCHelper to the argument list. |
java.util.List |
findAll(JDBCHelper aJDBCHelper)
Find all PersistentObject values found in my table. |
java.sql.Timestamp |
findCurrentTimestamp()
Execute SQL that will return the current date and time from the database. |
java.sql.Timestamp |
findCurrentTimestamp(JDBCHelper aJDBCHelper)
Execute SQL that will find the current timestamp value from the database. |
java.util.List |
findCustom(java.lang.String sql)
This is a pass-through method that adds the default JDBCHelper to the argument list. |
java.util.List |
findCustom(java.lang.String sql,
JDBCHelper aJDBCHelper)
This method should *rarely*, if ever, be used by subclasses. |
protected java.lang.Integer |
findInteger(java.lang.String sql)
This is a pass-through method that adds the default JDBCHelper to the parameter list. |
protected java.lang.Integer |
findInteger(java.lang.String sql,
JDBCHelper aJDBCHelper)
This method calls findLong and casts the result down to an Integer. |
protected java.lang.Long |
findLong(java.lang.String sql)
This is a pass-through method that adds the default JDBCHelper to the parameter list. |
protected java.lang.Long |
findLong(java.lang.String sql,
JDBCHelper aJDBCHelper)
Execute SQL that returns a Long. |
java.util.List |
findOrderBy(java.lang.String orderByString)
This method adds an ORDER BY clause to the basic findAll SQL. |
java.util.List |
findOrderBy(java.lang.String orderByString,
JDBCHelper aJDBCHelper)
This method adds an ORDER BY clause to the basic findAll SQL. |
java.util.List |
findWhere(java.lang.String whereString)
This method adds a where clause to the basic findAll SQL. |
java.util.List |
findWhere(java.lang.String whereString,
JDBCHelper aJDBCHelper)
This method adds a where clause to the basic findAll SQL. |
java.util.List |
findWhereOrderBy(java.lang.String whereString,
java.lang.String orderByString)
This method adds both a WHERE and an ORDER BY clause to the basic findAll SQL. |
java.util.List |
findWhereOrderBy(java.lang.String whereString,
java.lang.String orderByString,
JDBCHelper aJDBCHelper)
This method adds both a WHERE and an ORDER BY clause to the basic findAll SQL. |
java.util.List |
getAllColumnSpecs()
|
java.util.List |
getColumnSpecs()
|
CreateTableSQLBuilder |
getCreateTableSQLBuilder()
|
DatabasePolicy |
getDatabasePolicy()
|
int |
getEndingIndex()
Return the index of the last row to be converted to an object and returned. |
InsertSQLBuilder |
getInsertSQLBuilder()
|
protected JDBCHelper |
getJDBCHelper()
Return a JDBCHelper instance from the pool or return the default instance. |
JDBCHelperPool |
getJDBCHelperPool()
|
java.util.List |
getJoinTables()
|
ColumnSpec |
getPrimaryKeyColumnSpec()
|
boolean |
getReturnSavedObject()
If true, the object is retrieved from the database and is returned to the user at the end of the save operation. |
SelectSQLBuilder |
getSelectSQLBuilder()
|
boolean |
getShouldAutoCommit()
The default is false. |
int |
getStartingIndex()
Return the index of the first row to be converted to an object and returned. |
java.util.List |
getSubtypeColumnSpecs()
|
JoinTable |
getSubtypeTable()
|
java.lang.String |
getSubtypeTableName()
|
java.lang.String |
getTableAlias()
|
java.lang.String |
getTableName()
|
UpdateSQLBuilder |
getUpdateSQLBuilder()
|
boolean |
getValidateBeforeSaving()
If false, no validation will be done on this object before saving it. |
abstract PersistentObject |
newPersistentObject()
Subclasses must implement this to create a new PersistentObject. |
protected java.lang.Long |
nextSequence(JDBCHelper aJDBCHelper)
Use JDBC to call a stored procedure to get a the next available sequence id. |
protected void |
postDelete(PersistentObject aPO,
JDBCHelper aJDBCHelper)
This is the default, no-operation implementation. |
protected void |
postFind(PersistentObject aPO,
JDBCHelper aJDBCHelper)
This is the default, no-operation implementation which is executed for all found objects. |
protected void |
postSave(PersistentObject aPO,
JDBCHelper aJDBCHelper)
This is the default, no-operation implementation. |
protected void |
preDelete(PersistentObject aPO,
JDBCHelper aJDBCHelper)
This is the default, no-operation implementation. |
protected void |
preSave(PersistentObject aPO,
JDBCHelper aJDBCHelper)
This is the default, no-operation implementation. |
protected void |
preValidate(PersistentObject aPO,
JDBCHelper aJDBCHelper)
This is the default, no-operation implementation. |
void |
quietlyRollbackAndClose(JDBCHelper aJDBCHelper)
If the rollback doesn't work, we don't need to know about it. |
void |
resetStartingAndEndingIndexes()
Reset the starting and ending indexes so the whole resultset will be returned the next time a query is called. |
PersistentObject |
save(PersistentObject aPO)
This is a pass-through method that adds the default JDBCHelper to the argument list. |
PersistentObject |
save(PersistentObject aPO,
JDBCHelper aJDBCHelper)
Save the PersistentObject to the database after validating the object with this.validate(aPO,aJDBCHelper). |
void |
setDatabasePolicy(DatabasePolicy dbPolicy)
|
void |
setEndingIndex(int v)
Set the index of the last row to be converted to an object and returned. |
void |
setJDBCHelper(JDBCHelper aJDBCHelper)
Set the default JDBCHelper instance. |
void |
setJDBCHelperPool(JDBCHelperPool aJDBCHelperPool)
|
void |
setJDBCHelperPoolName(java.lang.String poolName)
|
void |
setReturnSavedObject(boolean b)
|
void |
setShouldAutoCommit(boolean b)
|
void |
setStartingIndex(int v)
Set the index of the first row to be converted to an object and returned. |
void |
setSubtypeTableName(java.lang.String s)
If the name looks like this: 'Customer c', then 'Customer' will be the tableName and 'c' will be the tableAlias. |
void |
setTableAlias(java.lang.String alias)
|
void |
setTableName(java.lang.String s)
If the name looks like this: 'Customer c', then 'Customer' will be the tableName and 'c' will be the tableAlias. |
protected abstract void |
setup()
This method is called by the constructors. |
void |
setUseANSIJoins(boolean b)
|
void |
setUsePostFind(boolean b)
|
void |
setValidateBeforeSaving(boolean b)
|
boolean |
useANSIJoins()
If true, ANSI JOIN clauses will be used |
boolean |
usePostFind()
If true, the postFind() method will be called. |
void |
validate(PersistentObject aPO)
This is a pass-through method that adds the default JDBCHelper to the argument list. |
void |
validate(PersistentObject aPO,
JDBCHelper aJDBCHelper)
This method validates a PersistentObject using the ColumnSpec objects. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public AbstractDomain(int option)
option
- a value of type 'int'public AbstractDomain()
Method Detail |
public static void addSubtypeDomain(java.lang.Object subtypeIdentifierValue, java.lang.Class domainClass)
subtypeIdentifierValue
- - value of the SUBTYPE_IDENTIFIER fielddomainClass
- - value of the SUBTYPE_IDENTIFIER fieldpublic boolean getValidateBeforeSaving()
setValidateBeforeSaving(boolean)
public void setValidateBeforeSaving(boolean b)
getValidateBeforeSaving()
public boolean getReturnSavedObject()
setReturnSavedObject(boolean)
public void setReturnSavedObject(boolean b)
getReturnSavedObject()
public boolean useANSIJoins()
setUseANSIJoins(boolean)
public void setUseANSIJoins(boolean b)
useANSIJoins()
public boolean usePostFind()
setUsePostFind(boolean)
public void setUsePostFind(boolean b)
usePostFind()
public boolean getShouldAutoCommit()
public void setShouldAutoCommit(boolean b)
public java.lang.String getTableName()
public void setTableName(java.lang.String s)
s
- a value of type 'String'public java.lang.String getSubtypeTableName()
public void setSubtypeTableName(java.lang.String s)
s
- a value of type 'String'public JoinTable getSubtypeTable()
public void setTableAlias(java.lang.String alias)
public java.lang.String getTableAlias()
public DatabasePolicy getDatabasePolicy()
public void setDatabasePolicy(DatabasePolicy dbPolicy)
protected JDBCHelper getJDBCHelper()
public void setJDBCHelper(JDBCHelper aJDBCHelper)
aJDBCHelper
- a value of type 'JDBCHelper'public JDBCHelperPool getJDBCHelperPool()
public void setJDBCHelperPool(JDBCHelperPool aJDBCHelperPool)
aJDBCHelperPool
- a value of type 'JDBCHelperPool'public void setJDBCHelperPoolName(java.lang.String poolName)
aJDBCHelperPool
- a value of type 'JDBCHelperPool'public void addColumnSpec(ColumnSpec aColumnSpec)
public java.util.List getColumnSpecs()
public void addSubtypeColumnSpec(AbstractColumnSpec aColumnSpec)
public java.util.List getSubtypeColumnSpecs()
public java.util.List getAllColumnSpecs()
public void addJoinTable(JoinTable aJoinTable)
public java.util.List getJoinTables()
public ColumnSpec getPrimaryKeyColumnSpec()
public int getStartingIndex()
public void setStartingIndex(int v)
resetStartingAndEndingIndexes()
public int getEndingIndex()
public void setEndingIndex(int v)
resetStartingAndEndingIndexes()
public void resetStartingAndEndingIndexes()
protected abstract void setup()
public abstract PersistentObject newPersistentObject()
protected void postFind(PersistentObject aPO, JDBCHelper aJDBCHelper)
The JDBCHelper is an argument so that we have the flexibility to do our own object manipulation using the current row in the result set.
Note: If you wish to use the JDBCHelper to do another SQL call, you must first clone it to get a new connection.
aPO
- a value of type 'PersistentObject'protected void preValidate(PersistentObject aPO, JDBCHelper aJDBCHelper) throws ObjectHasChangedException, MissingAttributeException, DuplicateRowException
aPO
- a value of type 'PersistentObject'protected void preSave(PersistentObject aPO, JDBCHelper aJDBCHelper) throws ObjectHasChangedException, MissingAttributeException, DuplicateRowException
aPO
- a value of type 'PersistentObject'protected void postSave(PersistentObject aPO, JDBCHelper aJDBCHelper) throws ObjectHasChangedException, MissingAttributeException, DuplicateRowException
aPO
- a value of type 'PersistentObject'protected void preDelete(PersistentObject aPO, JDBCHelper aJDBCHelper)
aPO
- a value of type 'PersistentObject'protected void postDelete(PersistentObject aPO, JDBCHelper aJDBCHelper)
aPO
- a value of type 'PersistentObject'protected PersistentObject convertToPersistentObject(JDBCHelper aJDBCHelper) throws java.lang.Exception
aJDBCHelper
- a value of type 'JDBCHelper'java.lang.Exception
- if an error occurspublic final PersistentObject find(java.lang.Object pkOrPersistentObject)
pkOrPersistentObject
- a value of type 'Object'public PersistentObject find(java.lang.Object pkOrPersistentObject, JDBCHelper aJDBCHelper)
This method can be overridden.
pk
- a value of type 'Object'. This can be a PersistentObject
with it's primary key field(s) filled in or it can be a single primary
key value (i.e. a String or an Integer).aJDBCHelper
- a value of type 'JDBCHelper'protected final PersistentObject finalFind(java.lang.Object pkOrPersistentObject, JDBCHelper aJDBCHelper)
pk
- a value of type 'Object'. This can be a PersistentObject
with it's primary key attribute(s) filled in or a singular primary key
value (like String or Integer).aJDBCHelper
- a value of type 'JDBCHelper'public java.util.List findAll()
public java.util.List findAll(JDBCHelper aJDBCHelper)
aJDBCHelper
- a value of type 'JDBCHelper'public final java.util.List findWhere(java.lang.String whereString)
public final java.util.List findWhere(java.lang.String whereString, JDBCHelper aJDBCHelper)
public final java.util.List findOrderBy(java.lang.String orderByString)
public final java.util.List findOrderBy(java.lang.String orderByString, JDBCHelper aJDBCHelper)
public final java.util.List findWhereOrderBy(java.lang.String whereString, java.lang.String orderByString)
public final java.util.List findWhereOrderBy(java.lang.String whereString, java.lang.String orderByString, JDBCHelper aJDBCHelper)
public java.util.List find(SelectSQLBuilder builder)
public java.util.List find(SelectSQLBuilder builder, JDBCHelper aJDBCHelper)
public SelectSQLBuilder getSelectSQLBuilder()
public InsertSQLBuilder getInsertSQLBuilder()
public UpdateSQLBuilder getUpdateSQLBuilder()
public CreateTableSQLBuilder getCreateTableSQLBuilder()
public java.util.List findCustom(java.lang.String sql)
sql
- a value of type 'String'public java.util.List findCustom(java.lang.String sql, JDBCHelper aJDBCHelper)
sql
- a value of type 'String'aJDBCHelper
- a value of type 'JDBCHelper'public final void validate(PersistentObject aPO) throws MissingAttributeException, DuplicateRowException
aPO
- a value of type 'PersistentObject'MissingAttributeException
- if an error occursDuplicateRowException
- if an error occursvalidate(PersistentObject, JDBCHelper)
public void validate(PersistentObject aPO, JDBCHelper aJDBCHelper) throws MissingAttributeException, DuplicateRowException
aPO
- a value of type 'PersistentObject'MissingAttributeException
- if a required attribute is missing.DuplicateRowException
- if this row is already in the database.public final PersistentObject save(PersistentObject aPO) throws ObjectHasChangedException, MissingAttributeException, DuplicateRowException
aPO
- a value of type 'PersistentObject'ObjectHasChangedException
- if an error occursMissingAttributeException
- if an error occursDuplicateRowException
- if an error occurspublic PersistentObject save(PersistentObject aPO, JDBCHelper aJDBCHelper) throws ObjectHasChangedException, MissingAttributeException, DuplicateRowException
aPO
- a value of type 'PersistentObject'
if the primary key attribute is null, then this does a SQL insert.ObjectHasChangedException
- if an error occursMissingAttributeException
- if an error occursDuplicateRowException
- if an error occurspublic final int delete(PersistentObject aPO)
aPO
- a value of type 'PersistentObject'public int delete(PersistentObject aPO, JDBCHelper aJDBCHelper)
aPO
- a value of type 'PersistentObject'public void createTable()
public void createTable(JDBCHelper aJDBCHelper)
aJDBCHelper
- a value of type 'JDBCHelper'public void dropTable(boolean ignoreErrors)
ignoreErrors
- a value of type 'boolean'public void dropTable(boolean ignoreErrors, JDBCHelper aJDBCHelper)
ignoreErrors
- a value of type 'boolean' - It is often that
we don't want to know if the table wasn't there.aJDBCHelper
- a value of type 'JDBCHelper'protected void executeSQLQuery(java.lang.String sql, AbstractDomain.RowHandler aRowHandler)
sql
- a value of type 'String'aRowHandler
- a value of type 'RowHandler'protected void executeSQLQuery(java.lang.String sql, AbstractDomain.RowHandler aRowHandler, JDBCHelper aJDBCHelper)
sql
- a value of type 'String'aRowHandler
- a value of type 'RowHandler' - This is an inner
class that gets called for each row in the result set.aJDBCHelper
- a value of type 'JDBCHelper'protected int executeSQLUpdate(java.lang.String sql)
sql
- a value of type 'String'protected int executeSQLUpdate(java.lang.String sql, JDBCHelper aJDBCHelper)
protected java.lang.Long nextSequence(JDBCHelper aJDBCHelper)
protected java.lang.Integer findInteger(java.lang.String sql)
sql
- a value of type 'String'protected java.lang.Integer findInteger(java.lang.String sql, JDBCHelper aJDBCHelper)
sql
- a value of type 'String'protected java.lang.Long findLong(java.lang.String sql)
sql
- a value of type 'String'protected java.lang.Long findLong(java.lang.String sql, JDBCHelper aJDBCHelper)
sql
- a value of type 'String'aJDBCHelper
- a value of type 'JDBCHelper'public java.sql.Timestamp findCurrentTimestamp()
public java.sql.Timestamp findCurrentTimestamp(JDBCHelper aJDBCHelper)
aJDBCHelper
- a value of type 'JDBCHelper'public java.lang.String encodePrimaryKey(PersistentObject aPO)
aPO
- a value of type 'PersistentObject'public PersistentObject decodePrimaryKey(java.lang.String aString)
aString
- a value of type 'String'public void quietlyRollbackAndClose(JDBCHelper aJDBCHelper)
aJDBCHelper
- a value of type 'JDBCHelper'public void beginTransaction()
public void beginTransaction(JDBCHelper aJDBCHelper)
aJDBCHelper
- a value of type 'JDBCHelper'public void endTransaction()
beginTransaction()
public void endTransaction(JDBCHelper aJDBCHelper)
aJDBCHelper
- a value of type 'JDBCHelper'beginTransaction()
,
endTransaction()
public java.lang.String delimitString(java.lang.String aString)
aString
- a value of type 'String'public PersistentObject convertToSubtypePersistentObject(PersistentObject aPO1)
aPO
- a PersistentObject (this is the supertype instance)public void copyAttributes(PersistentObject aPO1, PersistentObject aPO2)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |