org.jpox.store.rdbms
Class Column

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

public class Column
extends java.lang.Object
implements org.jpox.store.mapped.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.65 $

Field Summary
protected  boolean autoIncrement
          Whether this is to use AUTOINCREMENT/IDENTITY.
protected  org.jpox.metadata.ColumnMetaData columnMetaData
          ColumnMetaData for this column.
protected  java.lang.String constraints
          Optional constraints to apply to this column in its SQL specification.
protected  org.jpox.store.mapped.mapping.DatastoreMapping datastoreMapping
          Datastore mapping for this column.
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  org.jpox.store.mapped.DatastoreIdentifier identifier
          Identifier for the column in the datastore.
protected  java.lang.String storedJavaType
          Java type that this column is storing.
protected  org.jpox.store.mapped.MappedStoreManager storeMgr
          Manager for the store into which we are persisting.
protected  org.jpox.store.mapped.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(org.jpox.store.mapped.DatastoreContainerObject table, java.lang.String javaType, org.jpox.store.mapped.DatastoreIdentifier identifier, org.jpox.metadata.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 as a decimal.
 void checkInteger()
          Checks the column definition as an integer.
 void checkPrimitive()
          Checks the column definition as a primitive.
 void checkString()
          Checks the column definition as a string.
 void copyConfigurationTo(org.jpox.store.mapped.DatastoreField field)
           
 boolean equals(java.lang.Object obj)
          Equality method.
 org.jpox.metadata.ColumnMetaData getColumnMetaData()
          Accessor for the columnOptions
 java.lang.String getConstraints()
           
 org.jpox.store.mapped.DatastoreContainerObject getDatastoreContainerObject()
          Accessor for the DatastoreObject.
 org.jpox.store.mapped.mapping.DatastoreMapping getDatastoreMapping()
          Accessor for the datastore mapping that this datastore field relates to.
 java.lang.Object getDefaultValue()
          Accessor for the default Value
 org.jpox.metadata.AbstractMemberMetaData getFieldMetaData()
          Accessor for the MetaData of the field that this is the datastore field for.
 org.jpox.store.mapped.DatastoreIdentifier getIdentifier()
          Accessor for the identifier of the datastore column.
 int getJdbcType()
          Accessor for the JDBC type being used for this Column
 org.jpox.store.mapped.mapping.JavaTypeMapping getMapping()
          Accessor for the Mapping.
 org.jpox.metadata.MetaData getMetaData()
          Access the metadata definition defining this DatastoreField.
 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.
 org.jpox.store.mapped.MappedStoreManager 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()
          Accessor for the 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.
 void setDatastoreMapping(org.jpox.store.mapped.mapping.DatastoreMapping mapping)
          Method to associate this datastore field with its mapping.
 org.jpox.store.mapped.DatastoreField setDefaultable()
          Mutator for the defaultability of the column.
 void setDefaultValue(java.lang.Object object)
          Mutator for the default Value
 void setIdentifier(org.jpox.store.mapped.DatastoreIdentifier identifier)
          Mutator for the identifier of the column.
 void setMetaData(org.jpox.metadata.MetaData md)
          Method to update the MetaData for this datastore field.
 org.jpox.store.mapped.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()
          Accessor for a string form of this Column.
 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

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

identifier

protected org.jpox.store.mapped.DatastoreIdentifier identifier
Identifier for the column in the datastore.


columnMetaData

protected org.jpox.metadata.ColumnMetaData columnMetaData
ColumnMetaData for this column.


table

protected final org.jpox.store.mapped.DatastoreContainerObject table
Table containing this column in the datastore.


datastoreMapping

protected org.jpox.store.mapped.mapping.DatastoreMapping datastoreMapping
Datastore mapping for this column.


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 org.jpox.store.mapped.MappedStoreManager 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)).

Constructor Detail

Column

public Column(org.jpox.store.mapped.DatastoreContainerObject table,
              java.lang.String javaType,
              org.jpox.store.mapped.DatastoreIdentifier identifier,
              org.jpox.metadata.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
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 org.jpox.store.mapped.DatastoreIdentifier getIdentifier()
Accessor for the identifier of the datastore column.

Specified by:
getIdentifier in interface org.jpox.store.mapped.DatastoreObject
Returns:
The identifier of the column in the datastore.

setIdentifier

public void setIdentifier(org.jpox.store.mapped.DatastoreIdentifier identifier)
Mutator for the identifier of the column. This is only required when we are overriding details of the column, during the initialisation process.

Specified by:
setIdentifier in interface org.jpox.store.mapped.DatastoreField
Parameters:
identifier - The identifier

getDatastoreContainerObject

public org.jpox.store.mapped.DatastoreContainerObject getDatastoreContainerObject()
Accessor for the DatastoreObject. The table owning this Column.

Specified by:
getDatastoreContainerObject in interface org.jpox.store.mapped.DatastoreField
Returns:
The DatastoreObject aka the table

getDatastoreMapping

public org.jpox.store.mapped.mapping.DatastoreMapping getDatastoreMapping()
Accessor for the datastore mapping that this datastore field relates to.

Specified by:
getDatastoreMapping in interface org.jpox.store.mapped.DatastoreField
Returns:
The datastore mapping

setDatastoreMapping

public void setDatastoreMapping(org.jpox.store.mapped.mapping.DatastoreMapping mapping)
Method to associate this datastore field with its mapping.

Specified by:
setDatastoreMapping in interface org.jpox.store.mapped.DatastoreField
Parameters:
mapping - The mapping for this datastore field

getMapping

public org.jpox.store.mapped.mapping.JavaTypeMapping getMapping()
Accessor for the Mapping.

Specified by:
getMapping in interface org.jpox.store.mapped.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 org.jpox.store.mapped.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 org.jpox.store.mapped.MappedStoreManager getStoreManager()
Accessor for the Store Manager.

Specified by:
getStoreManager in interface org.jpox.store.mapped.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 taken from the database

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 org.jpox.store.mapped.DatastoreField

setNullable

public final org.jpox.store.mapped.DatastoreField setNullable()
Mutator for the nullability of the column.

Specified by:
setNullable in interface org.jpox.store.mapped.DatastoreField
Returns:
The column with the updated info

setDefaultable

public final org.jpox.store.mapped.DatastoreField setDefaultable()
Mutator for the defaultability of the column.

Specified by:
setDefaultable in interface org.jpox.store.mapped.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 org.jpox.store.mapped.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 org.jpox.store.mapped.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.

Overrides:
equals in class java.lang.Object
Parameters:
obj - The Object to compare against
Returns:
Whether they are considered equal.

hashCode

public int hashCode()
Accessor for the hashcode.

Overrides:
hashCode in class java.lang.Object
Returns:
The hashcode

toString

public java.lang.String toString()
Accessor for a string form of this Column. Returns a fully-qualified form of the column name (including table prefix).

Overrides:
toString in class java.lang.Object
Returns:
String form of the Column

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 org.jpox.store.mapped.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 org.jpox.metadata.ColumnMetaData getColumnMetaData()
Accessor for the columnOptions

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

getMetaData

public org.jpox.metadata.MetaData getMetaData()
Access the metadata definition defining this DatastoreField. For RDBMS this will return an instance of ColumnMetaData.

Specified by:
getMetaData in interface org.jpox.store.mapped.DatastoreField
Returns:
the MetaData

getFieldMetaData

public org.jpox.metadata.AbstractMemberMetaData getFieldMetaData()
Accessor for the MetaData of the field that this is the datastore field for.

Specified by:
getFieldMetaData in interface org.jpox.store.mapped.DatastoreField
Returns:
MetaData of the field (if representing a field of a class).

setMetaData

public void setMetaData(org.jpox.metadata.MetaData md)
Method to update the MetaData for this datastore field. Only called before initialisation has completed and is called when overriding the definition of an already created column.

Specified by:
setMetaData in interface org.jpox.store.mapped.DatastoreField
Parameters:
md - The MetaData

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 org.jpox.store.mapped.DatastoreFieldDefinitionException
Checks the column definition as a primitive.

Throws:
org.jpox.store.mapped.DatastoreFieldDefinitionException

checkInteger

public final void checkInteger()
                        throws org.jpox.store.mapped.DatastoreFieldDefinitionException
Checks the column definition as an integer.

Throws:
org.jpox.store.mapped.DatastoreFieldDefinitionException

checkDecimal

public final void checkDecimal()
                        throws org.jpox.store.mapped.DatastoreFieldDefinitionException
Checks the column definition as a decimal.

Throws:
org.jpox.store.mapped.DatastoreFieldDefinitionException

checkString

public final void checkString()
                       throws org.jpox.store.mapped.DatastoreFieldDefinitionException
Checks the column definition as a string.

Throws:
org.jpox.store.mapped.DatastoreFieldDefinitionException

copyConfigurationTo

public void copyConfigurationTo(org.jpox.store.mapped.DatastoreField field)
Specified by:
copyConfigurationTo in interface org.jpox.store.mapped.DatastoreField

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. For 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 © -2008 . All Rights Reserved.