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 Details

    • PK

      private static final byte PK
      See Also:
    • NULLABLE

      private static final byte NULLABLE
      See Also:
    • UNIQUE

      private static final byte UNIQUE
      See Also:
    • DEFAULTABLE

      private static final byte DEFAULTABLE
      See Also:
    • IDENTITY

      private static final byte IDENTITY
      See Also:
    • 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 Details

    • 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 column
      identifier - The identifier of the column (in the datastore).
      colmd - The ColumnMetaData for this column
  • Method Details

    • getName

      public String getName()
      Specified by:
      getName in interface org.datanucleus.store.schema.table.Column
    • getMemberColumnMapping

      public org.datanucleus.store.schema.table.MemberColumnMapping getMemberColumnMapping()
      Specified by:
      getMemberColumnMapping in interface org.datanucleus.store.schema.table.Column
    • getColumnType

      public org.datanucleus.store.schema.naming.ColumnType getColumnType()
      Specified by:
      getColumnType in interface org.datanucleus.store.schema.table.Column
    • setJdbcType

      public Column setJdbcType(org.datanucleus.metadata.JdbcType jdbcType)
      Specified by:
      setJdbcType in interface org.datanucleus.store.schema.table.Column
    • getJdbcType

      public org.datanucleus.metadata.JdbcType getJdbcType()
      Specified by:
      getJdbcType in interface org.datanucleus.store.schema.table.Column
    • setTypeName

      public Column setTypeName(String type)
      Specified by:
      setTypeName in interface org.datanucleus.store.schema.table.Column
    • getTypeName

      public String getTypeName()
      Specified by:
      getTypeName in interface org.datanucleus.store.schema.table.Column
    • setPosition

      public Column setPosition(int pos)
      Specified by:
      setPosition in interface org.datanucleus.store.schema.table.Column
    • getPosition

      public int getPosition()
      Specified by:
      getPosition in interface org.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 interface Column
      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 interface Column
      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 interface Column
      Parameters:
      identifier - The identifier
    • getTable

      public Table getTable()
      Description copied from interface: Column
      Accessor for the table for this column
      Specified by:
      getTable in interface Column
      Specified by:
      getTable in interface org.datanucleus.store.schema.table.Column
      Returns:
      The table
    • getColumnMapping

      public ColumnMapping getColumnMapping()
      Description copied from interface: Column
      Accessor for the column mapping that this column relates to.
      Specified by:
      getColumnMapping in interface Column
      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 interface Column
      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 interface Column
      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 interface Column
      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 interface Column
      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 interface Column
      Returns:
      The type info
    • getStoreManager

      public RDBMSStoreManager getStoreManager()
      Description copied from interface: Column
      Accessor for the StoreManager for this column.
      Specified by:
      getStoreManager in interface Column
      Returns:
      The StoreManager.
    • getSQLPrecision

      private int getSQLPrecision()
      Accessor for the precision of data in the column.
      Returns:
      The precision of data in the column
    • getSQLDefinition

      public String getSQLDefinition()
      Description copied from interface: Column
      Accessor for the SQL definition of this column.
      Specified by:
      getSQLDefinition in interface Column
      Returns:
      The SQL definition of the column
    • getDefaultDefinition

      private String getDefaultDefinition()
      Convenience method to return the "DEFAULT" part of the column definition.
      Returns:
      The default part of the column definition.
    • initializeColumnInfoFromDatastore

      public void initializeColumnInfoFromDatastore(RDBMSColumnInfo ci)
      Description copied from interface: Column
      Initialize the default column value and auto increment
      Specified by:
      initializeColumnInfoFromDatastore in interface Column
      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.
      Specified by:
      validate in interface Column
      Parameters:
      ci - The column information taken from the database
    • setCheckConstraints

      public final Column setCheckConstraints(String constraints)
      Description copied from interface: Column
      Mutator for the CHECK constraints of the column.
      Specified by:
      setCheckConstraints in interface Column
      Parameters:
      constraints - The constraints
      Returns:
      The column with the updated info
    • setPrimaryKey

      public final Column setPrimaryKey()
      Specified by:
      setPrimaryKey in interface org.datanucleus.store.schema.table.Column
    • setNullable

      public final Column setNullable(boolean flag)
      Specified by:
      setNullable in interface org.datanucleus.store.schema.table.Column
    • setDefaultable

      public final Column setDefaultable(Object defaultValue)
      Specified by:
      setDefaultable in interface org.datanucleus.store.schema.table.Column
    • setUnique

      public final Column setUnique(boolean flag)
      Specified by:
      setUnique in interface org.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 interface Column
      Parameters:
      identity - True if column is identity
      Returns:
      The Column
    • isPrimaryKey

      public final boolean isPrimaryKey()
      Specified by:
      isPrimaryKey in interface org.datanucleus.store.schema.table.Column
    • isNullable

      public final boolean isNullable()
      Specified by:
      isNullable in interface org.datanucleus.store.schema.table.Column
    • isDefaultable

      public final boolean isDefaultable()
      Specified by:
      isDefaultable in interface org.datanucleus.store.schema.table.Column
    • isUnique

      public final boolean isUnique()
      Specified by:
      isUnique in interface org.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 interface Column
      Returns:
      true if column is identity.
    • getDefaultValue

      public Object getDefaultValue()
      Specified by:
      getDefaultValue in interface org.datanucleus.store.schema.table.Column
    • getColumnMetaData

      public final org.datanucleus.metadata.ColumnMetaData getColumnMetaData()
      Specified by:
      getColumnMetaData in interface org.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 interface Column
      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 interface org.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 interface Column
      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 interface Column
      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 interface Column
      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 interface Column
      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 interface Column
      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 interface Column
      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 interface Column
      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 example
      SQRT(?) generates: SQRT(COLUMN)
      Specified by:
      setWrapperFunction in interface Column
      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 interface Column
      Parameters:
      wrapperMode - whether select, insert or update
      Returns:
      Returns the wrapperFunction.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object