org.jpox.store.rdbms
Class Column

java.lang.Object
  extended byorg.jpox.store.rdbms.Column
All Implemented Interfaces:
DatastoreField, DatastoreObject

public class Column
extends java.lang.Object
implements DatastoreField

Definition of a Column in the datastore. Contains the full definition of the column, its type, size, whether it is autoincrement, nullable, part of the PK etc. The SQL column definition is generated here.

Version:
$Revision: 1.45 $

Field Summary
protected  boolean autoIncrement
          Whether this is to use AUTOINCREMENT/IDENTITY.
protected  java.lang.String constraints
          Optional constraints to apply to this column in its SQL specification.
protected  boolean defaultable
          Whether this column should be defaulted on inserts.
protected  java.lang.Object defaultValue
          Default value accepted by the datastore for this column, from DatabaseMetaData.
protected  int flags
           
protected  DatastoreIdentifier identifier
          Identifier for the column in the datastore.
protected  JavaTypeMapping mapping
          Mapping for the java type being stored.
protected  java.lang.String storedJavaType
          Java type that this column is storing.
protected  StoreManager storeMgr
          Manager for the store into which we are persisting.
protected  DatastoreContainerObject table
          Table containing this column in the datastore.
protected  TypeInfo typeInfo
          Type info for the JDBC type being stored in this column
static int WRAPPER_FUNCTION_INSERT
          wrapper function insert
static int WRAPPER_FUNCTION_SELECT
          wrapper function select
static int WRAPPER_FUNCTION_UPDATE
          wrapper function update
protected  java.lang.String[] wrapperFunction
          Function wrapping the column (for example, SQRT(COLUMN)).
 
Constructor Summary
Column(DatastoreContainerObject table, java.lang.String javaType, DatastoreIdentifier identifier, JavaTypeMapping mapping, ColumnMetaData colmd)
          Constructor.
 
Method Summary
 java.lang.String applySelectFunction(java.lang.String replacementValue)
          Wraps the column name with a FUNCTION.
 void checkDecimal()
          Checks the column definition
 void checkInteger()
          Checks the column definition
 void checkPrimitive()
          Checks the column definition
 void checkString()
          Checks the column definition
 void copyConfigurationTo(DatastoreField field)
          Copy the configuration of this field to another field
 boolean equals(java.lang.Object obj)
          Equality method.
 ColumnMetaData getColumnMetaData()
          Accessor for the columnOptions
 java.lang.String getConstraints()
           
 DatastoreContainerObject getDatastoreContainerObject()
          Accessor for the DatastoreObject.
 java.lang.Object getDefaultValue()
          Accessor for the default Value
 ExtendableMetaData getExtendableMetaData()
          Access the metadata definition for this DatastoreField.
 DatastoreIdentifier getIdentifier()
          Accessor for the identifier of the datastore column.
 int getJdbcType()
          Accessor for the JDBC type being used for this Column
 JavaTypeMapping getMapping()
          Accessor for the Mapping.
 java.lang.String getSQLDefinition()
          Accessor for the SQL definition of this column.
 java.lang.String getStoredJavaType()
          Accessor for the type of data stored in this column.
 StoreManager getStoreManager()
          Accessor for the Store Manager.
 TypeInfo getTypeInfo()
          Accessor for the type info for this column.
 java.lang.String getWrapperFunction(int wrapperMode)
          Gets the wrapper for parameters
 int hashCode()
           
 void initializeColumnInfoFromDatastore(ColumnInfo ci)
          Initialize the default column value and auto increment
 boolean isAutoIncrement()
          Accessor for the AutoIncrement.
 boolean isDefaultable()
          Accessor for whether the column is defaultable.
 boolean isExactPrecision()
          Accessor for whether the column has exact precision.
 boolean isNullable()
          Accessor for whether the column is nullable.
 boolean isPrimaryKey()
          Accessor for whether the column is the primary key.
 boolean isUnique()
          Accessor for whether the column is unique.
 boolean isUnlimitedLength()
          Convenience method to check if the length is required to be unlimited (BLOB/CLOB).
 void setAsPrimaryKey()
          Mutator to make the column (part of) the primary key
 void setAutoIncrement(boolean auto_increment)
          Mutator for whether we set this column as autoIncrement/identity.
 Column setConstraints(java.lang.String constraints)
          Mutator for the constraints of the column.
 DatastoreField setDefaultable()
          Mutator for the defaultability of the column.
 void setDefaultValue(java.lang.Object object)
          Mutator for the default Value
 DatastoreField setNullable()
          Mutator for the nullability of the column.
 Column setTypeInfo(TypeInfo typeInfo)
          Mutator for the type information of the column.
 Column setUnique()
          Mutator for the uniqueness of the column.
 void setWrapperFunction(java.lang.String wrapperFunction, int wrapperMode)
          Sets a function to wrap the column.
 java.lang.String toString()
           
 void validate(ColumnInfo ci)
          Method to validate the contents of the column.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

identifier

protected final DatastoreIdentifier identifier
Identifier for the column in the datastore.


table

protected final DatastoreContainerObject table
Table containing this column in the datastore.


mapping

protected final JavaTypeMapping mapping
Mapping for the java type being stored.


storedJavaType

protected final java.lang.String storedJavaType
Java type that this column is storing. (can we just get this from the mapping above ?)


storeMgr

protected final StoreManager storeMgr
Manager for the store into which we are persisting.


typeInfo

protected TypeInfo typeInfo
Type info for the JDBC type being stored in this column


constraints

protected java.lang.String constraints
Optional constraints to apply to this column in its SQL specification.


flags

protected int flags

defaultValue

protected java.lang.Object defaultValue
Default value accepted by the datastore for this column, from DatabaseMetaData.


defaultable

protected boolean defaultable
Whether this column should be defaulted on inserts.


autoIncrement

protected boolean autoIncrement
Whether this is to use AUTOINCREMENT/IDENTITY.


wrapperFunction

protected java.lang.String[] wrapperFunction
Function wrapping the column (for example, SQRT(COLUMN)).


WRAPPER_FUNCTION_SELECT

public static final int WRAPPER_FUNCTION_SELECT
wrapper function select

See Also:
Constant Field Values

WRAPPER_FUNCTION_INSERT

public static final int WRAPPER_FUNCTION_INSERT
wrapper function insert

See Also:
Constant Field Values

WRAPPER_FUNCTION_UPDATE

public static final int WRAPPER_FUNCTION_UPDATE
wrapper function update

See Also:
Constant Field Values
Constructor Detail

Column

public Column(DatastoreContainerObject table,
              java.lang.String javaType,
              DatastoreIdentifier identifier,
              JavaTypeMapping mapping,
              ColumnMetaData colmd)
Constructor.

Parameters:
table - The table in the datastore that this column belongs to.
javaType - The type of data being stored in this column
mapping - The mapping owning this column
identifier - The identifier of the column (in the datastore).
colmd - The ColumnMetaData for this column
Method Detail

isUnlimitedLength

public boolean isUnlimitedLength()
Convenience method to check if the length is required to be unlimited (BLOB/CLOB).

Returns:
Whether unlimited length required.

getIdentifier

public DatastoreIdentifier getIdentifier()
Accessor for the identifier of the datastore column.

Specified by:
getIdentifier in interface DatastoreObject
Returns:
The identifier of the column in the datastore.

getDatastoreContainerObject

public DatastoreContainerObject getDatastoreContainerObject()
Accessor for the DatastoreObject. The table owning this Column.

Specified by:
getDatastoreContainerObject in interface DatastoreField
Returns:
The DatastoreObject aka the table

getMapping

public JavaTypeMapping getMapping()
Accessor for the Mapping.

Specified by:
getMapping in interface DatastoreField
Returns:
The Mapping

getStoredJavaType

public java.lang.String getStoredJavaType()
Accessor for the type of data stored in this column.

Specified by:
getStoredJavaType in interface DatastoreField
Returns:
The type of data in the column

getTypeInfo

public final TypeInfo getTypeInfo()
Accessor for the type info for this column.

Returns:
The type info

getJdbcType

public int getJdbcType()
Accessor for the JDBC type being used for this Column

Returns:
The JDBC data type

getStoreManager

public StoreManager getStoreManager()
Accessor for the Store Manager.

Specified by:
getStoreManager in interface DatastoreObject
Returns:
Store Manager

getSQLDefinition

public java.lang.String getSQLDefinition()
Accessor for the SQL definition of this column.

Returns:
The SQL definition of the column

initializeColumnInfoFromDatastore

public void initializeColumnInfoFromDatastore(ColumnInfo ci)
Initialize the default column value and auto increment

Parameters:
ci - The column information

validate

public void validate(ColumnInfo ci)
Method to validate the contents of the column. This method can throw IncompatibleDataTypeException, WrongScaleException, WrongPrecisionException, IsNullableException if the data in the column is not compatible with the supplied ColumnInfo.

Parameters:
ci - The column information

setTypeInfo

public final Column setTypeInfo(TypeInfo typeInfo)
Mutator for the type information of the column.

Parameters:
typeInfo - The type info
Returns:
The column with the updated info

setConstraints

public final Column setConstraints(java.lang.String constraints)
Mutator for the constraints of the column.

Parameters:
constraints - The constraints
Returns:
The column with the updated info

setAsPrimaryKey

public final void setAsPrimaryKey()
Mutator to make the column (part of) the primary key

Specified by:
setAsPrimaryKey in interface DatastoreField

setNullable

public final DatastoreField setNullable()
Mutator for the nullability of the column.

Specified by:
setNullable in interface DatastoreField
Returns:
The column with the updated info

setDefaultable

public final DatastoreField setDefaultable()
Mutator for the defaultability of the column.

Specified by:
setDefaultable in interface DatastoreField
Returns:
The column with the updated info

setUnique

public final Column setUnique()
Mutator for the uniqueness of the column.

Returns:
The column with the updated info

isPrimaryKey

public final boolean isPrimaryKey()
Accessor for whether the column is the primary key.

Specified by:
isPrimaryKey in interface DatastoreField
Returns:
whether the column is (part of) the primary key

isExactPrecision

public final boolean isExactPrecision()
Accessor for whether the column has exact precision.

Returns:
whether the column has exact precision

isNullable

public final boolean isNullable()
Accessor for whether the column is nullable.

Specified by:
isNullable in interface DatastoreField
Returns:
whether the column is nullable

isDefaultable

public final boolean isDefaultable()
Accessor for whether the column is defaultable.

Returns:
whether the column is defaultable

isUnique

public final boolean isUnique()
Accessor for whether the column is unique.

Returns:
whether the column is unique

equals

public boolean equals(java.lang.Object obj)
Equality method.

Parameters:
obj - The Object to compare against
Returns:
Whether they are considered equal.

hashCode

public int hashCode()

toString

public java.lang.String toString()

applySelectFunction

public java.lang.String applySelectFunction(java.lang.String replacementValue)
Wraps the column name with a FUNCTION.
example: SQRT(?) generates: SQRT(columnName)

Specified by:
applySelectFunction in interface DatastoreField
Parameters:
replacementValue - the replacement to ?. Probably it's a column name, that may be fully qualified name or not
Returns:
a String with function taking as parameter the replacementValue

getDefaultValue

public java.lang.Object getDefaultValue()
Accessor for the default Value

Returns:
the default value

setDefaultValue

public void setDefaultValue(java.lang.Object object)
Mutator for the default Value

Parameters:
object - default value

getColumnMetaData

public final ColumnMetaData getColumnMetaData()
Accessor for the columnOptions

Returns:
The Column Options (length, scale, precision etc)

getExtendableMetaData

public ExtendableMetaData getExtendableMetaData()
Access the metadata definition for this DatastoreField. For RDBMS mapping it will return an instance of ColumnMetaData

Specified by:
getExtendableMetaData in interface DatastoreField
Returns:
the ExtendableMetaData

getConstraints

public java.lang.String getConstraints()
Returns:
Returns the constraints.

isAutoIncrement

public boolean isAutoIncrement()
Accessor for the AutoIncrement. Either set in the metadata, or retrieved from the DatabaseMetadata when validated

Returns:
true if column is autoincrement

setAutoIncrement

public void setAutoIncrement(boolean auto_increment)
Mutator for whether we set this column as autoIncrement/identity.

Parameters:
auto_increment - True if column is autoincrement/identity

checkPrimitive

public final void checkPrimitive()
                          throws DatastoreFieldDefinitionException
Checks the column definition

Throws:
DatastoreFieldDefinitionException

checkInteger

public final void checkInteger()
                        throws DatastoreFieldDefinitionException
Checks the column definition

Throws:
DatastoreFieldDefinitionException

checkDecimal

public final void checkDecimal()
                        throws DatastoreFieldDefinitionException
Checks the column definition

Throws:
DatastoreFieldDefinitionException

checkString

public final void checkString()
                       throws DatastoreFieldDefinitionException
Checks the column definition

Throws:
DatastoreFieldDefinitionException

copyConfigurationTo

public void copyConfigurationTo(DatastoreField field)
Description copied from interface: DatastoreField
Copy the configuration of this field to another field

Specified by:
copyConfigurationTo in interface DatastoreField
Parameters:
field - the datastore field

setWrapperFunction

public void setWrapperFunction(java.lang.String wrapperFunction,
                               int wrapperMode)
Sets a function to wrap the column. The wrapper function String must use ? to be replaced later by the column name example: SQRT(?) generates: SQRT(COLUMN)

Parameters:
wrapperFunction - The wrapperFunction to set.
wrapperMode - whether select, insert or update

getWrapperFunction

public java.lang.String getWrapperFunction(int wrapperMode)
Gets the wrapper for parameters

Parameters:
wrapperMode - whether select, insert or update
Returns:
Returns the wrapperFunction.


Copyright © -2007 . All Rights Reserved.