com.is.jrf
Class StringArrayColumnSpec
java.lang.Object
|
+--com.is.jrf.AbstractColumnSpec
|
+--com.is.jrf.StringArrayColumnSpec
- All Implemented Interfaces:
- ColumnSpec, JRFConstants
- public class StringArrayColumnSpec
- extends AbstractColumnSpec
Subclass of AbstractColumnSpec that handles arrays of strings.
This Column Spec will take an array of Strings from a Persistent
Object and convert it to a comma delimited string back in the database.
Similarly, a commma delimited String in a database column will be
reconstituted back into an array of Strings.
The default delimiter is a comma, but this can be dynamically reset.
The underlying field in the PersistentObject will be an Array of Strings.
If this array is null, the corresponding column in the database will be
set to null. Similarly, a null column in the database will reconstitute
itself as a null String[] object.
However, a String[] of zero length will be saved as an empty String,
and an empty String will reconstitute itself as an zero length array.
Null objects in the String Array, or strings which are empty or contain
only spaces, will be ignored when being converted.
Fields inherited from class com.is.jrf.AbstractColumnSpec |
EQUALS, i_columnName, i_default, i_getter, i_naturalPrimaryKey, i_optimisticLock, i_required, i_sequencedPrimaryKey, i_setter, i_subtypeIdentifier, i_unique, 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 |
StringArrayColumnSpec(java.lang.String columnName,
java.lang.String getter,
java.lang.String setter,
java.lang.Object defaultValue)
|
StringArrayColumnSpec(java.lang.String columnName,
java.lang.String getter,
java.lang.String setter,
java.lang.Object defaultValue,
int option1)
|
StringArrayColumnSpec(java.lang.String columnName,
java.lang.String getter,
java.lang.String setter,
java.lang.Object defaultValue,
int option1,
int option2)
|
StringArrayColumnSpec(java.lang.String columnName,
java.lang.String getter,
java.lang.String setter,
java.lang.Object defaultValue,
int option1,
int option2,
int option3)
|
Method Summary |
protected static java.lang.String[] |
arrayFromDelimitedString(java.lang.String values,
java.lang.String delimiter)
Takes a delimited string of values and
converts it into an array of string values. |
protected static java.lang.String |
arrayToDelimitedString(java.lang.String[] values,
java.lang.String delimiter)
Takes an array of Strings and converts them into a single
delimited String. |
JoinColumn |
buildJoinColumn()
|
java.lang.Object |
decode(java.lang.String aString)
Decodes an Array of Strings from an encoded String.
Note that null String[] objects are encoded as the string "'null",
so this method does not work correctly for an Array of Strings
consisting of a single String with a value of "null" |
java.lang.String |
encode(java.lang.Object obj)
Overidden method that matches with decode().
Note that null String[] objects are encoded as the string "'null",
so this method does not work correctly for an Array of Strings
consisting of a single String with a value of "null". |
java.lang.String |
formatForSql(java.lang.Object obj,
DatabasePolicy dbPolicy)
This method overrides the superclass implementation. |
java.lang.Class |
getColumnClass()
See IntegerColumnSpec for example of how to implement: |
java.lang.Object |
getColumnValueFrom(JDBCHelper helper)
Return a String[] from JDBCHelper. |
java.lang.String |
getSQLColumnType(DatabasePolicy dbPolicy)
Return the ANSI standard SQL column type. |
void |
setDelimiter(java.lang.String delimiter)
Sets the delimiter used to delimit the String stored
in the database.
The default delimiter is the comma, ",". |
java.lang.Object |
validateRequired(PersistentObject aPO)
This is an override of the superclass implementation. |
Methods inherited from class com.is.jrf.AbstractColumnSpec |
buildNameValuePair, buildWhereClause, columnDefinitionString, copyAttribute, copyColumnValueToPersistentObject, decodeToPersistentObject, encodeFromPersistentObject, getColumnName, getDefault, getFullyQualifiedColumnName, getGetter, getSetter, getSqlValueFrom, getValueFrom, getValueFrom, isNaturalPrimaryKey, isOptimisticLock, isPrimaryKey, isRequired, isSequencedPrimaryKey, isSubtypeIdentifier, isUnique, optimisticLockDefaultValue, setRequired, setValueTo, setValueTo, validateUnique, validateUnique |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
EMPTY_STRING
public static final java.lang.String EMPTY_STRING
EMPTY_ARRAY
public static final java.lang.String[] EMPTY_ARRAY
COMMA
public static final java.lang.String COMMA
s_class
protected static java.lang.Class s_class
i_delimiter
protected java.lang.String i_delimiter
StringArrayColumnSpec
public StringArrayColumnSpec(java.lang.String columnName,
java.lang.String getter,
java.lang.String setter,
java.lang.Object defaultValue)
StringArrayColumnSpec
public StringArrayColumnSpec(java.lang.String columnName,
java.lang.String getter,
java.lang.String setter,
java.lang.Object defaultValue,
int option1)
StringArrayColumnSpec
public StringArrayColumnSpec(java.lang.String columnName,
java.lang.String getter,
java.lang.String setter,
java.lang.Object defaultValue,
int option1,
int option2)
StringArrayColumnSpec
public StringArrayColumnSpec(java.lang.String columnName,
java.lang.String getter,
java.lang.String setter,
java.lang.Object defaultValue,
int option1,
int option2,
int option3)
setDelimiter
public void setDelimiter(java.lang.String delimiter)
- Sets the delimiter used to delimit the String stored
in the database.
The default delimiter is the comma, ",".
arrayToDelimitedString
protected static java.lang.String arrayToDelimitedString(java.lang.String[] values,
java.lang.String delimiter)
- Takes an array of Strings and converts them into a single
delimited String. If the array is empty, or contains only
null or empty objects an empty string is returned "".
If the Array is null, then a null String is returned.
External spaces are removed from each array item.
If an array object is null, empty or constains only
white space, it is ignored.
- See Also:
ListToFromDelimitedString(List list)
arrayFromDelimitedString
protected static java.lang.String[] arrayFromDelimitedString(java.lang.String values,
java.lang.String delimiter)
- Takes a delimited string of values and
converts it into an array of string values.
If the original String is empty or null, a zero length Array is returned
- See Also:
(String[] values)
formatForSql
public java.lang.String formatForSql(java.lang.Object obj,
DatabasePolicy dbPolicy)
- This method overrides the superclass implementation. A string of
"null" is returned if object is null, otherwise it returns a String
with quotes around it. Internal single quotes are converted to two
single quotes and the string is wrapped in single quotes.
- Overrides:
formatForSql
in class AbstractColumnSpec
- Parameters:
aValueObject
- a value of type 'ValueObject'- Returns:
- a value of type 'String'
decode
public java.lang.Object decode(java.lang.String aString)
- Decodes an Array of Strings from an encoded String.
Note that null String[] objects are encoded as the string "'null",
so this method does not work correctly for an Array of Strings
consisting of a single String with a value of "null"
- Overrides:
decode
in class AbstractColumnSpec
- Parameters:
aString
- a value of type 'String'- Returns:
- a value of type 'Object' (This actually will be a String or null)
encode
public java.lang.String encode(java.lang.Object obj)
- Overidden method that matches with decode().
Note that null String[] objects are encoded as the string "'null",
so this method does not work correctly for an Array of Strings
consisting of a single String with a value of "null".
- Overrides:
encode
in class AbstractColumnSpec
- Parameters:
obj
- the object (String[]) to encode to a String'- Returns:
- an encoded string)
getColumnClass
public java.lang.Class getColumnClass()
- Description copied from class:
AbstractColumnSpec
- See IntegerColumnSpec for example of how to implement:
- Overrides:
getColumnClass
in class AbstractColumnSpec
getColumnValueFrom
public java.lang.Object getColumnValueFrom(JDBCHelper helper)
throws java.sql.SQLException
- Return a String[] from JDBCHelper. Reconstitute an Array of Strings
from a delimited String. The strange behaviour with SQLServer (and
maybe Sybase) that keeps returning empty or whitespace strings as one
blank character can be ignored, as any white spaced is trimmed out
before creating the array.
- Overrides:
getColumnValueFrom
in class AbstractColumnSpec
- Parameters:
helper
- a value of type 'JDBCHelper'- Returns:
- a value of type 'Object'
- Throws:
java.sql.SQLException
- if an error occurs in JDBCHelper
validateRequired
public java.lang.Object validateRequired(PersistentObject aPO)
throws MissingAttributeException
- This is an override of the superclass implementation. This method adds
a check to make sure the string is not empty or blank.
- Overrides:
validateRequired
in class AbstractColumnSpec
- Parameters:
aPO
- a value of type 'PersistentObject'- Returns:
- a value of type 'Object'
- Throws:
MissingAttributeException
- if an error occurs
getSQLColumnType
public java.lang.String getSQLColumnType(DatabasePolicy dbPolicy)
- Return the ANSI standard SQL column type. This was written to support
the test suites. If there is no standard that will work across
platforms, then we'll add a method to dbPolicy and return its value.
- Overrides:
getSQLColumnType
in class AbstractColumnSpec
- Parameters:
dbPolicy
- a value of type 'DatabasePolicy'- Returns:
- a value of type 'String'
buildJoinColumn
public JoinColumn buildJoinColumn()
- Overrides:
buildJoinColumn
in class AbstractColumnSpec
- Following copied from class:
com.is.jrf.AbstractColumnSpec
- Returns:
- a JoinColumn subclass instance with data from myself.