|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.is.jrf.AbstractColumnSpec
Subclass instances of this abstract class represent columns in the table represented by the domain class. This abstract class is subclassed for different java data types (like Integer, String, Boolean, Timestamp, etc). Adding another data type is as simple as subclassing, reimplementing the constructors, and implementing the formatForSql(anObject,aDatabasePolicy), getColumnClass(), and getColumnValueFrom(aJDBCHelper) methods.
Options that can go together..
Examples:
For an Integer sequenced primary key use something like this: (REQUIRED
and UNIQUE are ignored when SEQUENCED_PRIMARY_KEY is present so don't
use them)
For a String natural primary key use something like this: (As opposed
to SEQUENCED_PRIMARY_KEY, the REQUIRED and UNIQUE options are implied
when NATURAL_PRIMARY_KEY is present so you don't need to specify them)
new IntegerColumnSpec(
"PersonId",
"getPersonId",
"setPersonId",
DEFAULT_TO_NULL,
SEQUENCED_PRIMARY_KEY);
For a String attribute that is required and unique use something like
this:
new StringColumnSpec(
"PersonCode",
"getPersonCode",
"setPersonCode",
DEFAULT_TO_NULL,
NATURAL_PRIMARY_KEY);
For an attribute that has a non-null default, use something like
this:
new StringColumnSpec(
"Name",
"getName",
"setName",
DEFAULT_TO_NULL,
REQUIRED,
UNIQUE);
or any Integer:
new IntegerColumnSpec(
"Age",
"getAge",
"setAge",
DEFAULT_TO_ZERO);
For a Timestamp that is used as an optimistic lock, use something like
this: (REQUIRED and UNIQUE are ignored when OPTIMISTIC_LOCK is present
so don't use them)
new IntegerColumnSpec(
"Age",
"getAge",
"setAge",
new Integer(99));
Here is an example of an AbstractDomain#buildColumnSpecs() method
for a table with a compound primary key. ColumnSpecs in a compound
primary key do not need any options (REQUIRED or UNIQUE) specified.
new TimestampColumnSpec(
"UpdatedOn",
"getUpdatedOn",
"setUpdatedOn",
DEFAULT_TO_NOW,
OPTIMISTIC_LOCK);
public List buildColumnSpecs()
{
List returnValue = new ArrayList();
returnValue.add(
new CompoundPrimaryKeyColumnSpec(
new IntegerColumnSpec(
"Id",
"getId",
"setId",
DEFAULT_TO_NULL),
new StringColumnSpec(
"Code",
"getCode",
"setCode",
DEFAULT_TO_NULL)));
returnValue.add(
new StringColumnSpec(
"Name",
"getName",
"setName",
DEFAULT_TO_NULL,
REQUIRED,
UNIQUE));
return returnValue;
}
Field Summary | |
protected static java.lang.String |
EQUALS
|
protected java.lang.String |
i_columnName
|
protected java.lang.Object |
i_default
|
protected java.lang.String |
i_getter
|
protected boolean |
i_naturalPrimaryKey
|
protected boolean |
i_optimisticLock
|
protected boolean |
i_required
|
protected boolean |
i_sequencedPrimaryKey
|
protected java.lang.String |
i_setter
|
protected boolean |
i_subtypeIdentifier
|
protected boolean |
i_unique
|
protected static java.lang.String |
NOT_EQUALS
|
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, NATURAL_PRIMARY_KEY, NO_POST_FIND, OPTIMISTIC_LOCK, REQUIRED, SEQUENCED_PRIMARY_KEY, SUBTYPE_IDENTIFIER, UNIQUE |
Constructor Summary | |
AbstractColumnSpec(java.lang.String columnName,
java.lang.String getter,
java.lang.String setter,
java.lang.Object defaultValue)
|
|
AbstractColumnSpec(java.lang.String columnName,
java.lang.String getter,
java.lang.String setter,
java.lang.Object defaultValue,
int option1)
|
|
AbstractColumnSpec(java.lang.String columnName,
java.lang.String getter,
java.lang.String setter,
java.lang.Object defaultValue,
int option1,
int option2)
|
|
AbstractColumnSpec(java.lang.String columnName,
java.lang.String getter,
java.lang.String setter,
java.lang.Object defaultValue,
int option1,
int option2,
int option3)
|
Method Summary | |
abstract JoinColumn |
buildJoinColumn()
|
java.lang.String |
buildNameValuePair(java.lang.Object pkOrPersistentObject,
java.lang.String separator,
java.lang.String tableAlias,
DatabasePolicy dbPolicy)
This method is used to build an equals (or not-equals) String for WHERE clauses and UPDATE statements. |
java.lang.String |
buildWhereClause(java.lang.Object pkOrPersistentObject,
java.lang.String separator,
java.lang.String tableAlias,
DatabasePolicy dbPolicy)
Note: This method is overridden by CompoundPrimaryKeyColumnSpec to include " AND " between each name-value pair. |
java.lang.String |
columnDefinitionString(DatabasePolicy dbPolicy)
Return something like: "Age INTEGER NOT NULL" |
void |
copyAttribute(PersistentObject aPO1,
PersistentObject aPO2)
Copy the attribute I represent from one persistent object to another. |
void |
copyColumnValueToPersistentObject(JDBCHelper helper,
PersistentObject aPO)
Copy the value of my column to the appropriate attribute for this persistent object. |
protected abstract java.lang.Object |
decode(java.lang.String aString)
See IntegerColumnSpec for example of how to implement: |
void |
decodeToPersistentObject(java.lang.String aString,
PersistentObject aPO)
This method is similar in concept to the copyColumnValueToPersistentObject(...) method, but gets it's value from a String instead of a JDBCHelper. |
java.lang.String |
encode(java.lang.Object obj)
"Encode" the given object into a string representation that can be decoded later. |
java.lang.String |
encodeFromPersistentObject(PersistentObject aPO)
Convert the attribute for this object to a String that can be unconverted later by the decodeToPersistentObject(...) method. |
abstract java.lang.String |
formatForSql(java.lang.Object obj,
DatabasePolicy dbPolicy)
Returns a string representing the given attribute value. |
abstract java.lang.Class |
getColumnClass()
See IntegerColumnSpec for example of how to implement: |
java.lang.String |
getColumnName()
|
abstract java.lang.Object |
getColumnValueFrom(JDBCHelper helper)
See IntegerColumnSpec for example of how to implement: |
java.lang.Object |
getDefault()
|
java.lang.String |
getFullyQualifiedColumnName(java.lang.String tableAlias)
|
java.lang.String |
getGetter()
|
java.lang.String |
getSetter()
|
abstract java.lang.String |
getSQLColumnType(DatabasePolicy dbPolicy)
Return the type of column to be used in a CREATE TABLE or ALTER TABLE statement. |
java.lang.String |
getSqlValueFrom(PersistentObject aPO,
DatabasePolicy dbPolicy)
Get a string representation of the value of this attribute from aPO. |
java.lang.Object |
getValueFrom(PersistentObject aPO)
Get the value of this attribute from aPO. |
static java.lang.Object |
getValueFrom(PersistentObject aPO,
java.lang.String getter,
java.lang.Object defaultValue)
Get the value of this attribute from aPO. |
boolean |
isNaturalPrimaryKey()
|
boolean |
isOptimisticLock()
|
boolean |
isPrimaryKey()
|
boolean |
isRequired()
|
boolean |
isSequencedPrimaryKey()
|
boolean |
isSubtypeIdentifier()
|
boolean |
isUnique()
|
java.lang.Object |
optimisticLockDefaultValue()
Unless this is overridden, an exception will be thrown. |
void |
setRequired(boolean b)
CompoundPrimaryKeyColumnSpec uses this to force it's children to "REQUIRED". |
void |
setValueTo(java.lang.Object aValue,
PersistentObject aPO)
This is a pass-through method that passes along my setter and column class. |
static void |
setValueTo(java.lang.Object aValue,
PersistentObject aPO,
java.lang.String setter,
java.lang.Class valueClass)
Sets the attribute value of a given persistent object using reflection. |
java.lang.Object |
validateRequired(PersistentObject aPO)
Make sure the PersistentObject object has this attribute (if required). |
static void |
validateUnique(PersistentObject aPO,
JDBCHelper helper,
ColumnSpec pkColumnSpec,
ColumnSpec attrColumnSpec,
DatabasePolicy dbPolicy,
java.lang.String tableName)
If Column is declared UNIQUE, make sure it doesn't already exist in the table. |
void |
validateUnique(PersistentObject aPO,
JDBCHelper helper,
ColumnSpec pkColumnSpec,
DatabasePolicy dbPolicy,
java.lang.String tableName)
If this is a unique column (or columns), make sure the value doesn't already exist. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final java.lang.String EQUALS
protected static final java.lang.String NOT_EQUALS
protected java.lang.String i_columnName
protected java.lang.String i_getter
protected java.lang.String i_setter
protected java.lang.Object i_default
protected boolean i_required
protected boolean i_sequencedPrimaryKey
protected boolean i_naturalPrimaryKey
protected boolean i_unique
protected boolean i_subtypeIdentifier
protected boolean i_optimisticLock
Constructor Detail |
public AbstractColumnSpec(java.lang.String columnName, java.lang.String getter, java.lang.String setter, java.lang.Object defaultValue, int option1, int option2, int option3)
public AbstractColumnSpec(java.lang.String columnName, java.lang.String getter, java.lang.String setter, java.lang.Object defaultValue)
public AbstractColumnSpec(java.lang.String columnName, java.lang.String getter, java.lang.String setter, java.lang.Object defaultValue, int option1)
public AbstractColumnSpec(java.lang.String columnName, java.lang.String getter, java.lang.String setter, java.lang.Object defaultValue, int option1, int option2)
Method Detail |
public abstract java.lang.String formatForSql(java.lang.Object obj, DatabasePolicy dbPolicy)
formatForSql
in interface ColumnSpec
obj
- a value of type 'Object'public abstract java.lang.Class getColumnClass()
getColumnClass
in interface ColumnSpec
public abstract java.lang.Object getColumnValueFrom(JDBCHelper helper) throws java.sql.SQLException
getColumnValueFrom
in interface ColumnSpec
protected abstract java.lang.Object decode(java.lang.String aString)
public abstract java.lang.String getSQLColumnType(DatabasePolicy dbPolicy)
dbPolicy
- a value of type 'DatabasePolicy'public static void setValueTo(java.lang.Object aValue, PersistentObject aPO, java.lang.String setter, java.lang.Class valueClass)
aValue
- a value of type 'Object'aPO
- a value of type 'PersistentObject'setter
- a value of type 'String'valueClass
- a value of type 'Class'public static java.lang.Object getValueFrom(PersistentObject aPO, java.lang.String getter, java.lang.Object defaultValue)
Note: The getter can be of the form: "getCustomer.getId"
aPO
- a value of type 'PersistentObject'getter
- a value of type 'String' - can be of the form:
"getCustomer.getId"defaultValue
- a value of type 'Object'public static void validateUnique(PersistentObject aPO, JDBCHelper helper, ColumnSpec pkColumnSpec, ColumnSpec attrColumnSpec, DatabasePolicy dbPolicy, java.lang.String tableName) throws DuplicateRowException
aPO
- a value of type 'PersistentObject'helper
- a value of type 'JDBCHelper'pkColumnSpec
- a value of type 'ColumnSpec'DuplicateRowException
- if a row with this value already exists.public java.lang.String encode(java.lang.Object obj)
obj
- a value of type 'Object'public void decodeToPersistentObject(java.lang.String aString, PersistentObject aPO)
decodeToPersistentObject
in interface ColumnSpec
aString
- a value of type 'String'aPO
- a value of type 'PersistentObject'encodeFromPersistentObject(com.is.jrf.PersistentObject)
public java.lang.String encodeFromPersistentObject(PersistentObject aPO)
encodeFromPersistentObject
in interface ColumnSpec
aPO
- a value of type 'PersistentObject'decodeToPersistentObject(java.lang.String, com.is.jrf.PersistentObject)
public void copyColumnValueToPersistentObject(JDBCHelper helper, PersistentObject aPO) throws java.sql.SQLException
copyColumnValueToPersistentObject
in interface ColumnSpec
helper
- a value of type 'JDBCHelper'aPO
- a value of type 'PersistentObject'java.sql.SQLException
- if an error occurspublic void copyAttribute(PersistentObject aPO1, PersistentObject aPO2)
copyAttribute
in interface ColumnSpec
aPO1
- a value of type 'PersistentObject'aPO2
- a value of type 'PersistentObject'public java.lang.String buildWhereClause(java.lang.Object pkOrPersistentObject, java.lang.String separator, java.lang.String tableAlias, DatabasePolicy dbPolicy)
buildWhereClause
in interface ColumnSpec
pkOrPersistentObject
- a value of type 'Object'dbPolicy
- a value of type 'DatabasePolicy'public java.lang.String buildNameValuePair(java.lang.Object pkOrPersistentObject, java.lang.String separator, java.lang.String tableAlias, DatabasePolicy dbPolicy)
buildNameValuePair
in interface ColumnSpec
pkOrPersistentObject
- a value of type 'Object'separator
- a value of type 'String' - use EQUALS or NOT_EQUALS
static final variables.tableName
- a value of type 'String'dbPolicy
- a value of type 'DatabasePolicy'public java.lang.Object validateRequired(PersistentObject aPO) throws MissingAttributeException
validateRequired
in interface ColumnSpec
aPO
- a value of type 'PersistentObject'MissingAttributeException
- if attribute should be populated
and it is not.public void validateUnique(PersistentObject aPO, JDBCHelper helper, ColumnSpec pkColumnSpec, DatabasePolicy dbPolicy, java.lang.String tableName) throws DuplicateRowException
validateUnique
in interface ColumnSpec
aPO
- a value of type 'PersistentObject'helper
- a value of type 'JDBCHelper'pkColumnSpec
- a value of type 'ColumnSpec'dbPolicy
- a value of type 'DatabasePolicy'tableName
- a value of type 'String'DuplicateRowException
- if an error occurspublic java.lang.String getSqlValueFrom(PersistentObject aPO, DatabasePolicy dbPolicy)
getSqlValueFrom
in interface ColumnSpec
aPO
- a value of type 'PersistentObject'public java.lang.Object getValueFrom(PersistentObject aPO)
getValueFrom
in interface ColumnSpec
aPO
- a value of type 'PersistentObject'public void setValueTo(java.lang.Object aValue, PersistentObject aPO)
setValueTo
in interface ColumnSpec
aValue
- a value of type 'Object'aPO
- a value of type 'PersistentObject'public java.lang.String columnDefinitionString(DatabasePolicy dbPolicy)
columnDefinitionString
in interface ColumnSpec
public java.lang.String getFullyQualifiedColumnName(java.lang.String tableAlias)
getFullyQualifiedColumnName
in interface ColumnSpec
public java.lang.String getColumnName()
getColumnName
in interface ColumnSpec
public java.lang.String getGetter()
getGetter
in interface ColumnSpec
public java.lang.String getSetter()
getSetter
in interface ColumnSpec
public boolean isRequired()
isRequired
in interface ColumnSpec
public boolean isSequencedPrimaryKey()
isSequencedPrimaryKey
in interface ColumnSpec
public boolean isNaturalPrimaryKey()
isNaturalPrimaryKey
in interface ColumnSpec
public boolean isPrimaryKey()
isPrimaryKey
in interface ColumnSpec
public boolean isUnique()
isUnique
in interface ColumnSpec
public boolean isSubtypeIdentifier()
isSubtypeIdentifier
in interface ColumnSpec
public java.lang.Object getDefault()
getDefault
in interface ColumnSpec
public boolean isOptimisticLock()
isOptimisticLock
in interface ColumnSpec
public void setRequired(boolean b)
setRequired
in interface ColumnSpec
public java.lang.Object optimisticLockDefaultValue()
public abstract JoinColumn buildJoinColumn()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |