Class ColumnImpl
- java.lang.Object
-
- org.datanucleus.store.rdbms.table.ColumnImpl
-
- All Implemented Interfaces:
Column
,org.datanucleus.store.schema.table.Column
public class ColumnImpl extends Object implements Column
Implementation of a Column in an RDBMS datastore. Contains the full definition of the column, its type, size, whether it is identity, nullable, part of the PK etc. The SQL column definition is generated here.
-
-
Field Summary
Fields Modifier and Type Field Description protected String
checkConstraints
CHECK constraints to apply to this column in its SQL specification (optional).protected ColumnMapping
columnMapping
Mapping for this column.protected org.datanucleus.metadata.ColumnMetaData
columnMetaData
ColumnMetaData for this column.protected Object
defaultValue
Default value accepted by the datastore for this column, from DatabaseMetaData.protected byte
flags
Operational flags, for nullability, PK, autoinc, etc.protected DatastoreIdentifier
identifier
Identifier for the column in the datastore.protected String
storedJavaType
Java type that this column is storing.protected Table
table
Table containing this column in the datastore.protected SQLTypeInfo
typeInfo
SQL Type info for the JDBC type being stored in this columnprotected String
typeName
Manual override of the type name for this column (optional).protected String[]
wrapperFunction
Function wrapping the column (for example, SQRT(COLUMN)).-
Fields inherited from interface org.datanucleus.store.rdbms.table.Column
WRAPPER_FUNCTION_INSERT, WRAPPER_FUNCTION_SELECT, WRAPPER_FUNCTION_UPDATE
-
-
Constructor Summary
Constructors Constructor Description ColumnImpl(Table table, String javaType, DatastoreIdentifier identifier, org.datanucleus.metadata.ColumnMetaData colmd)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
applySelectFunction(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(Column colIn)
Copy the configuration of this field to another fieldboolean
equals(Object obj)
String
getCheckConstraints()
Accessor for CHECK constraints for this column.ColumnMapping
getColumnMapping()
Accessor for the column mapping that this column relates to.org.datanucleus.metadata.ColumnMetaData
getColumnMetaData()
org.datanucleus.store.schema.naming.ColumnType
getColumnType()
Object
getDefaultValue()
DatastoreIdentifier
getIdentifier()
Accessor for the identifier for this object.JavaTypeMapping
getJavaTypeMapping()
Accessor for the JavaTypeMapping for the field/property that owns this column.org.datanucleus.metadata.JdbcType
getJdbcType()
org.datanucleus.store.schema.table.MemberColumnMapping
getMemberColumnMapping()
org.datanucleus.metadata.AbstractMemberMetaData
getMemberMetaData()
Accessor for the MetaData of the field/property that this is the column for.String
getName()
int
getPosition()
String
getSQLDefinition()
Accessor for the SQL definition of this column.String
getStoredJavaType()
Accessor for the type of data stored in this field.RDBMSStoreManager
getStoreManager()
Accessor for the StoreManager for this column.Table
getTable()
Accessor for the table for this columnSQLTypeInfo
getTypeInfo()
Accessor for the type info for this column.String
getTypeName()
String
getWrapperFunction(int wrapperMode)
Gets the wrapper for parameters.int
hashCode()
void
initializeColumnInfoFromDatastore(RDBMSColumnInfo ci)
Initialize the default column value and auto incrementboolean
isDefaultable()
boolean
isIdentity()
Accessor for the whether this column is an identity column.boolean
isNullable()
boolean
isPrimaryKey()
boolean
isUnique()
boolean
isUnlimitedLength()
Convenience method to check if the length is required to be unlimited (BLOB/CLOB).Column
setCheckConstraints(String constraints)
Mutator for the CHECK constraints of the column.void
setColumnMapping(ColumnMapping mapping)
Method to associate this column with its mapping.Column
setColumnMetaData(org.datanucleus.metadata.ColumnMetaData colmd)
Column
setDefaultable(Object defaultValue)
void
setIdentifier(DatastoreIdentifier identifier)
Mutator for the identifier of the column.Column
setIdentity(boolean identity)
Mutator for whether we set this column as an identity column.Column
setJdbcType(org.datanucleus.metadata.JdbcType jdbcType)
Column
setNullable(boolean flag)
Column
setPosition(int pos)
Column
setPrimaryKey()
Column
setTypeInfo(SQLTypeInfo typeInfo)
Mutator for the type information of the column.Column
setTypeName(String type)
Column
setUnique(boolean flag)
void
setWrapperFunction(String wrapperFunction, int wrapperMode)
Sets a function to wrap the column.String
toString()
void
validate(RDBMSColumnInfo ci)
Method to validate the contents of the column.
-
-
-
Field Detail
-
identifier
protected DatastoreIdentifier identifier
Identifier for the column in the datastore.
-
columnMetaData
protected org.datanucleus.metadata.ColumnMetaData columnMetaData
ColumnMetaData for this column.
-
table
protected final Table table
Table containing this column in the datastore.
-
columnMapping
protected ColumnMapping columnMapping
Mapping for this column.
-
storedJavaType
protected final String storedJavaType
Java type that this column is storing. (can we just get this from the mapping above ?)
-
typeName
protected String typeName
Manual override of the type name for this column (optional).
-
typeInfo
protected SQLTypeInfo typeInfo
SQL Type info for the JDBC type being stored in this column
-
checkConstraints
protected String checkConstraints
CHECK constraints to apply to this column in its SQL specification (optional).
-
flags
protected byte flags
Operational flags, for nullability, PK, autoinc, etc.
-
defaultValue
protected Object defaultValue
Default value accepted by the datastore for this column, from DatabaseMetaData.
-
wrapperFunction
protected String[] wrapperFunction
Function wrapping the column (for example, SQRT(COLUMN)).
-
-
Constructor Detail
-
ColumnImpl
public ColumnImpl(Table table, String javaType, DatastoreIdentifier identifier, org.datanucleus.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 columnidentifier
- The identifier of the column (in the datastore).colmd
- The ColumnMetaData for this column
-
-
Method Detail
-
getName
public String getName()
- Specified by:
getName
in interfaceorg.datanucleus.store.schema.table.Column
-
getMemberColumnMapping
public org.datanucleus.store.schema.table.MemberColumnMapping getMemberColumnMapping()
- Specified by:
getMemberColumnMapping
in interfaceorg.datanucleus.store.schema.table.Column
-
getColumnType
public org.datanucleus.store.schema.naming.ColumnType getColumnType()
- Specified by:
getColumnType
in interfaceorg.datanucleus.store.schema.table.Column
-
setJdbcType
public Column setJdbcType(org.datanucleus.metadata.JdbcType jdbcType)
- Specified by:
setJdbcType
in interfaceorg.datanucleus.store.schema.table.Column
-
getJdbcType
public org.datanucleus.metadata.JdbcType getJdbcType()
- Specified by:
getJdbcType
in interfaceorg.datanucleus.store.schema.table.Column
-
setTypeName
public Column setTypeName(String type)
- Specified by:
setTypeName
in interfaceorg.datanucleus.store.schema.table.Column
-
getTypeName
public String getTypeName()
- Specified by:
getTypeName
in interfaceorg.datanucleus.store.schema.table.Column
-
setPosition
public Column setPosition(int pos)
- Specified by:
setPosition
in interfaceorg.datanucleus.store.schema.table.Column
-
getPosition
public int getPosition()
- Specified by:
getPosition
in interfaceorg.datanucleus.store.schema.table.Column
-
isUnlimitedLength
public boolean isUnlimitedLength()
Description copied from interface:Column
Convenience method to check if the length is required to be unlimited (BLOB/CLOB).- Specified by:
isUnlimitedLength
in interfaceColumn
- Returns:
- Whether unlimited length required.
-
getIdentifier
public DatastoreIdentifier getIdentifier()
Description copied from interface:Column
Accessor for the identifier for this object.- Specified by:
getIdentifier
in interfaceColumn
- Returns:
- The identifier.
-
setIdentifier
public void setIdentifier(DatastoreIdentifier identifier)
Description copied from interface:Column
Mutator for the identifier of the column.- Specified by:
setIdentifier
in interfaceColumn
- Parameters:
identifier
- The identifier
-
getTable
public Table getTable()
Description copied from interface:Column
Accessor for the table for this column
-
getColumnMapping
public ColumnMapping getColumnMapping()
Description copied from interface:Column
Accessor for the column mapping that this column relates to.- Specified by:
getColumnMapping
in interfaceColumn
- Returns:
- The column mapping
-
setColumnMapping
public void setColumnMapping(ColumnMapping mapping)
Description copied from interface:Column
Method to associate this column with its mapping.- Specified by:
setColumnMapping
in interfaceColumn
- Parameters:
mapping
- The mapping for this column
-
getJavaTypeMapping
public JavaTypeMapping getJavaTypeMapping()
Description copied from interface:Column
Accessor for the JavaTypeMapping for the field/property that owns this column.- Specified by:
getJavaTypeMapping
in interfaceColumn
- Returns:
- The JavaTypeMapping
-
getStoredJavaType
public String getStoredJavaType()
Description copied from interface:Column
Accessor for the type of data stored in this field.- Specified by:
getStoredJavaType
in interfaceColumn
- Returns:
- The type of data in the field.
-
setTypeInfo
public final Column setTypeInfo(SQLTypeInfo typeInfo)
Description copied from interface:Column
Mutator for the type information of the column.- Specified by:
setTypeInfo
in interfaceColumn
- Parameters:
typeInfo
- The type info- Returns:
- The column with the updated info
-
getTypeInfo
public final SQLTypeInfo getTypeInfo()
Description copied from interface:Column
Accessor for the type info for this column.- Specified by:
getTypeInfo
in interfaceColumn
- Returns:
- The type info
-
getStoreManager
public RDBMSStoreManager getStoreManager()
Description copied from interface:Column
Accessor for the StoreManager for this column.- Specified by:
getStoreManager
in interfaceColumn
- Returns:
- The StoreManager.
-
getSQLDefinition
public String getSQLDefinition()
Description copied from interface:Column
Accessor for the SQL definition of this column.- Specified by:
getSQLDefinition
in interfaceColumn
- Returns:
- The SQL definition of the column
-
initializeColumnInfoFromDatastore
public void initializeColumnInfoFromDatastore(RDBMSColumnInfo ci)
Description copied from interface:Column
Initialize the default column value and auto increment- Specified by:
initializeColumnInfoFromDatastore
in interfaceColumn
- Parameters:
ci
- The column information
-
validate
public void validate(RDBMSColumnInfo ci)
Description copied from interface:Column
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.
-
setCheckConstraints
public final Column setCheckConstraints(String constraints)
Description copied from interface:Column
Mutator for the CHECK constraints of the column.- Specified by:
setCheckConstraints
in interfaceColumn
- Parameters:
constraints
- The constraints- Returns:
- The column with the updated info
-
setPrimaryKey
public final Column setPrimaryKey()
- Specified by:
setPrimaryKey
in interfaceorg.datanucleus.store.schema.table.Column
-
setNullable
public final Column setNullable(boolean flag)
- Specified by:
setNullable
in interfaceorg.datanucleus.store.schema.table.Column
-
setDefaultable
public final Column setDefaultable(Object defaultValue)
- Specified by:
setDefaultable
in interfaceorg.datanucleus.store.schema.table.Column
-
setUnique
public final Column setUnique(boolean flag)
- Specified by:
setUnique
in interfaceorg.datanucleus.store.schema.table.Column
-
setIdentity
public Column setIdentity(boolean identity)
Description copied from interface:Column
Mutator for whether we set this column as an identity column. An "identity" column is typically treated differently in the datastore being given a value by the datastore itself. In RDBMS this would mean that the column is "AUTO_INCREMENT", "SERIAL" etc- Specified by:
setIdentity
in interfaceColumn
- Parameters:
identity
- True if column is identity- Returns:
- The Column
-
isPrimaryKey
public final boolean isPrimaryKey()
- Specified by:
isPrimaryKey
in interfaceorg.datanucleus.store.schema.table.Column
-
isNullable
public final boolean isNullable()
- Specified by:
isNullable
in interfaceorg.datanucleus.store.schema.table.Column
-
isDefaultable
public final boolean isDefaultable()
- Specified by:
isDefaultable
in interfaceorg.datanucleus.store.schema.table.Column
-
isUnique
public final boolean isUnique()
- Specified by:
isUnique
in interfaceorg.datanucleus.store.schema.table.Column
-
isIdentity
public boolean isIdentity()
Description copied from interface:Column
Accessor for the whether this column is an identity column.- Specified by:
isIdentity
in interfaceColumn
- Returns:
- true if column is identity.
-
getDefaultValue
public Object getDefaultValue()
- Specified by:
getDefaultValue
in interfaceorg.datanucleus.store.schema.table.Column
-
getColumnMetaData
public final org.datanucleus.metadata.ColumnMetaData getColumnMetaData()
- Specified by:
getColumnMetaData
in interfaceorg.datanucleus.store.schema.table.Column
-
getMemberMetaData
public org.datanucleus.metadata.AbstractMemberMetaData getMemberMetaData()
Description copied from interface:Column
Accessor for the MetaData of the field/property that this is the column for.- Specified by:
getMemberMetaData
in interfaceColumn
- Returns:
- MetaData of the field/property (if representing a field/property of a class).
-
setColumnMetaData
public Column setColumnMetaData(org.datanucleus.metadata.ColumnMetaData colmd)
- Specified by:
setColumnMetaData
in interfaceorg.datanucleus.store.schema.table.Column
-
getCheckConstraints
public String getCheckConstraints()
Description copied from interface:Column
Accessor for CHECK constraints for this column.- Specified by:
getCheckConstraints
in interfaceColumn
- Returns:
- Returns any CHECK constraints.
-
checkPrimitive
public final void checkPrimitive() throws ColumnDefinitionException
Description copied from interface:Column
Checks the column definition as a primitive.- Specified by:
checkPrimitive
in interfaceColumn
- Throws:
ColumnDefinitionException
- if an error occurs
-
checkInteger
public final void checkInteger() throws ColumnDefinitionException
Description copied from interface:Column
Checks the column definition as an integer.- Specified by:
checkInteger
in interfaceColumn
- Throws:
ColumnDefinitionException
- if an error occurs
-
checkDecimal
public final void checkDecimal() throws ColumnDefinitionException
Description copied from interface:Column
Checks the column definition as a decimal.- Specified by:
checkDecimal
in interfaceColumn
- Throws:
ColumnDefinitionException
- if an error occurs
-
checkString
public final void checkString() throws ColumnDefinitionException
Description copied from interface:Column
Checks the column definition as a string.- Specified by:
checkString
in interfaceColumn
- Throws:
ColumnDefinitionException
- if an error occurs
-
copyConfigurationTo
public void copyConfigurationTo(Column colIn)
Description copied from interface:Column
Copy the configuration of this field to another field- Specified by:
copyConfigurationTo
in interfaceColumn
- Parameters:
colIn
- the column to copy
-
applySelectFunction
public String applySelectFunction(String replacementValue)
Description copied from interface:Column
Wraps the column name with a FUNCTION.example: SQRT(?) generates: SQRT(columnName)
- Specified by:
applySelectFunction
in interfaceColumn
- 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
-
setWrapperFunction
public void setWrapperFunction(String wrapperFunction, int wrapperMode)
Description copied from interface:Column
Sets a function to wrap the column. The wrapper function String must use "?" to be replaced later by the column name. For exampleSQRT(?) generates: SQRT(COLUMN)
- Specified by:
setWrapperFunction
in interfaceColumn
- Parameters:
wrapperFunction
- The wrapperFunction to set.wrapperMode
- whether select, insert or update
-
getWrapperFunction
public String getWrapperFunction(int wrapperMode)
Description copied from interface:Column
Gets the wrapper for parameters.- Specified by:
getWrapperFunction
in interfaceColumn
- Parameters:
wrapperMode
- whether select, insert or update- Returns:
- Returns the wrapperFunction.
-
-