org.datanucleus.store.rdbms.table
Class AbstractTable

java.lang.Object
  extended by org.datanucleus.store.rdbms.table.AbstractTable
All Implemented Interfaces:
org.datanucleus.store.mapped.DatastoreContainerObject, Table
Direct Known Subclasses:
TableImpl, ViewImpl

public abstract class AbstractTable
extends java.lang.Object
implements Table

Abstract implementation of a table in the datastore. The table exists in various states. After initialisation it can be created in the datastore by calling create. At any point after initialisation it can be modified, but only by addition of columns. The table can be dropped from the datastore by calling drop.


Field Summary
protected  java.util.List<Column> columns
          Columns for this table.
protected  java.util.HashMap<org.datanucleus.store.mapped.DatastoreIdentifier,Column> columnsByName
          Index to the columns, keyed by name.
protected  RDBMSAdapter dba
          Database Adapter being used.
protected  java.lang.Boolean existsInDatastore
          Cache what we learned in a call to exists()
protected  org.datanucleus.store.mapped.DatastoreIdentifier identifier
          Identifier name for the table.
protected static org.datanucleus.util.Localiser LOCALISER
          Localiser for messages.
protected  int state
          State of the table
protected  RDBMSManager storeMgr
          Manager for this table.
 
Constructor Summary
AbstractTable(org.datanucleus.store.mapped.DatastoreIdentifier identifier, RDBMSManager storeMgr)
          Constructor taking the table name and the RDBMSManager managing this table.
 
Method Summary
protected  void addColumnInternal(Column col)
          Utility method to add a column to the internal representation
 org.datanucleus.store.mapped.DatastoreField addDatastoreField(java.lang.String storedJavaType, org.datanucleus.store.mapped.DatastoreIdentifier name, org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping, org.datanucleus.metadata.MetaData colmd)
          Creates a new column in the table.
protected  boolean allowDDLOutput()
          Determine whether we or our concrete class allow DDL to be written into a file instead of sending it to the DB.
protected  void assertIsInitialized()
           
protected  void assertIsInitializedModified()
           
protected  void assertIsPKInitialized()
           
protected  void assertIsPKUninitialized()
           
protected  void assertIsUninitialized()
           
protected  void assertIsValidated()
           
 boolean create(java.sql.Connection conn)
          Method to create this table.
 void drop(java.sql.Connection conn)
          Method to drop this table.
 boolean equals(java.lang.Object obj)
          Equality operator.
protected  void executeDdlStatement(java.sql.Statement stmt, java.lang.String stmtText)
          Execute a single DDL SQL statement with appropriate logging.
protected  void executeDdlStatementList(java.util.List stmts, java.sql.Connection conn)
          Method to perform the required SQL statements.
 boolean exists(java.sql.Connection conn, boolean auto_create)
          Method to check the existence of the table/view, optionally auto creating it where required.
 java.lang.String getCatalogName()
          Accessor for the Catalog Name.
 org.datanucleus.store.mapped.DatastoreField getDatastoreField(org.datanucleus.store.mapped.DatastoreIdentifier identifier)
          Accessor for the Datastore field with the specified identifier.
 org.datanucleus.store.mapped.DatastoreField[] getDatastoreFields()
          Accessor for the DatastoreFields infered from the java and metadata files.
 org.datanucleus.store.mapped.DatastoreIdentifier getDatastoreIdentifierFullyQualified()
          Method that operates like toString except it returns a fully-qualified name that will always be fully-qualified even when the user hasnt specified the catalog/schema in PMF or MetaData.
 org.datanucleus.store.mapped.mapping.JavaTypeMapping getDiscriminatorMapping(boolean allowSuperclasses)
          Accessor for the discriminator mapping specified .
 org.datanucleus.metadata.DiscriminatorMetaData getDiscriminatorMetaData()
          Accessor for Discriminator MetaData
 org.datanucleus.store.mapped.DatastoreIdentifier getIdentifier()
          Accessor for the SQL identifier (the table name).
 java.lang.String getSchemaName()
          Accessor for the Schema Name.
protected abstract  java.util.List getSQLCreateStatements(java.util.Properties props)
          Accessor for the SQL create statements.
protected abstract  java.util.List getSQLDropStatements()
          Accessor for the SQL drop statements.
 org.datanucleus.store.mapped.MappedStoreManager getStoreManager()
          Accessor for the Store Manager.
 org.datanucleus.store.mapped.mapping.JavaTypeMapping getVersionMapping(boolean allowSuperclasses)
          Accessor for the version mapping specified.
 org.datanucleus.metadata.VersionMetaData getVersionMetaData()
          Accessor for Version MetaData
protected  boolean hasColumnName(org.datanucleus.store.mapped.DatastoreIdentifier colName)
          Utility to return if a column of this name exists.
 boolean hasDatastoreField(org.datanucleus.store.mapped.DatastoreIdentifier identifier)
          Checks if there is a DatastoreField for the identifier
 int hashCode()
          Accessor for the hascode of this table.
 boolean isInitialized()
          Accessor for whether the table is initialised.
 boolean isInitializedModified()
          Accessor for whether the table has been modified since initialisation.
 boolean isPKInitialized()
          Accessor for whether the primary key of the table is initialised.
 boolean isValidated()
          Accessor for whether the table is validated.
protected  boolean tableExistsInDatastore(java.sql.Connection conn)
          Determine whether our table exists in the datastore (without modifying datastore).
 java.lang.String toString()
          Method to return a string version of this table.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.datanucleus.store.rdbms.table.Table
initialize, postInitialize, preInitialize, validate
 
Methods inherited from interface org.datanucleus.store.mapped.DatastoreContainerObject
getIDMapping, getMemberMapping
 

Field Detail

LOCALISER

protected static final org.datanucleus.util.Localiser LOCALISER
Localiser for messages.


storeMgr

protected final RDBMSManager storeMgr
Manager for this table.


dba

protected final RDBMSAdapter dba
Database Adapter being used.


identifier

protected final org.datanucleus.store.mapped.DatastoreIdentifier identifier
Identifier name for the table. Includes the catalog/schema internally (if defined by the user).


state

protected int state
State of the table


columns

protected java.util.List<Column> columns
Columns for this table.


columnsByName

protected java.util.HashMap<org.datanucleus.store.mapped.DatastoreIdentifier,Column> columnsByName
Index to the columns, keyed by name.


existsInDatastore

protected java.lang.Boolean existsInDatastore
Cache what we learned in a call to exists()

Constructor Detail

AbstractTable

public AbstractTable(org.datanucleus.store.mapped.DatastoreIdentifier identifier,
                     RDBMSManager storeMgr)
Constructor taking the table name and the RDBMSManager managing this table.

Parameters:
identifier - Name of the table
storeMgr - The RDBMS Manager
Method Detail

isInitialized

public boolean isInitialized()
Accessor for whether the table is initialised.

Specified by:
isInitialized in interface Table
Returns:
Whether it is initialised

isPKInitialized

public boolean isPKInitialized()
Accessor for whether the primary key of the table is initialised.

Returns:
Whether the primary key of the table is initialised

isValidated

public boolean isValidated()
Accessor for whether the table is validated.

Specified by:
isValidated in interface Table
Returns:
Whether it is validated.

isInitializedModified

public boolean isInitializedModified()
Accessor for whether the table has been modified since initialisation.

Specified by:
isInitializedModified in interface Table
Returns:
Whether it is modified since initialisation.

getStoreManager

public org.datanucleus.store.mapped.MappedStoreManager getStoreManager()
Accessor for the Store Manager.

Specified by:
getStoreManager in interface org.datanucleus.store.mapped.DatastoreContainerObject
Returns:
Store Manager

getCatalogName

public java.lang.String getCatalogName()
Accessor for the Catalog Name. This will be part of the fully qualified name IF the user has specified the catalog in the MetaData, OR if they have specified the catalog in the PMF.

Specified by:
getCatalogName in interface Table
Returns:
Catalog Name

getSchemaName

public java.lang.String getSchemaName()
Accessor for the Schema Name. This will be part of the fully qualified name IF the user has specified the schema in the MetaData, OR if they have specified the schema in the PMF.

Specified by:
getSchemaName in interface Table
Returns:
Schema Name

getIdentifier

public org.datanucleus.store.mapped.DatastoreIdentifier getIdentifier()
Accessor for the SQL identifier (the table name).

Specified by:
getIdentifier in interface org.datanucleus.store.mapped.DatastoreContainerObject
Returns:
The name

getDiscriminatorMetaData

public org.datanucleus.metadata.DiscriminatorMetaData getDiscriminatorMetaData()
Accessor for Discriminator MetaData

Specified by:
getDiscriminatorMetaData in interface org.datanucleus.store.mapped.DatastoreContainerObject
Returns:
Returns the Discriminator MetaData.

getDiscriminatorMapping

public org.datanucleus.store.mapped.mapping.JavaTypeMapping getDiscriminatorMapping(boolean allowSuperclasses)
Accessor for the discriminator mapping specified .

Specified by:
getDiscriminatorMapping in interface org.datanucleus.store.mapped.DatastoreContainerObject
Returns:
The mapping for the discriminator datastore field

getVersionMetaData

public org.datanucleus.metadata.VersionMetaData getVersionMetaData()
Accessor for Version MetaData

Specified by:
getVersionMetaData in interface org.datanucleus.store.mapped.DatastoreContainerObject
Returns:
Returns the Version MetaData.

getVersionMapping

public org.datanucleus.store.mapped.mapping.JavaTypeMapping getVersionMapping(boolean allowSuperclasses)
Accessor for the version mapping specified.

Specified by:
getVersionMapping in interface org.datanucleus.store.mapped.DatastoreContainerObject
Returns:
The mapping for the version datastore field

addDatastoreField

public org.datanucleus.store.mapped.DatastoreField addDatastoreField(java.lang.String storedJavaType,
                                                                     org.datanucleus.store.mapped.DatastoreIdentifier name,
                                                                     org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping,
                                                                     org.datanucleus.metadata.MetaData colmd)
Creates a new column in the table. Will add the new Column and return it. If the new column clashes in name with an existing column of the required name will throw a DuplicateColumnNameException except when :-

Specified by:
addDatastoreField in interface org.datanucleus.store.mapped.DatastoreContainerObject
Parameters:
storedJavaType - the java type of the datastore field
name - the SQL identifier for the column to be added
mapping - the mapping for the column to be added
colmd - ColumnMetaData for the column to be added to the table
Returns:
the new Column
Throws:
org.datanucleus.store.mapped.exceptions.DuplicateDatastoreFieldException - if a column already exists with same name and not a supported situation.

hasDatastoreField

public boolean hasDatastoreField(org.datanucleus.store.mapped.DatastoreIdentifier identifier)
Checks if there is a DatastoreField for the identifier

Specified by:
hasDatastoreField in interface org.datanucleus.store.mapped.DatastoreContainerObject
Parameters:
identifier - the identifier of the DatastoreField
Returns:
true if the DatastoreField exists for the identifier

getDatastoreField

public org.datanucleus.store.mapped.DatastoreField getDatastoreField(org.datanucleus.store.mapped.DatastoreIdentifier identifier)
Accessor for the Datastore field with the specified identifier. Returns null if has no column of this name.

Specified by:
getDatastoreField in interface org.datanucleus.store.mapped.DatastoreContainerObject
Parameters:
identifier - The name of the column
Returns:
The column

getDatastoreFields

public org.datanucleus.store.mapped.DatastoreField[] getDatastoreFields()
Accessor for the DatastoreFields infered from the java and metadata files.

Specified by:
getDatastoreFields in interface org.datanucleus.store.mapped.DatastoreContainerObject
Returns:
the DatastoreField[]

create

public boolean create(java.sql.Connection conn)
               throws java.sql.SQLException
Method to create this table.

Specified by:
create in interface Table
Parameters:
conn - Connection to the datastore.
Returns:
true if the table was created
Throws:
java.sql.SQLException - Thrown if an error occurs creating the table.

drop

public void drop(java.sql.Connection conn)
          throws java.sql.SQLException
Method to drop this table.

Specified by:
drop in interface Table
Parameters:
conn - Connection to the datastore.
Throws:
java.sql.SQLException - Thrown if an error occurs dropping the table.

exists

public boolean exists(java.sql.Connection conn,
                      boolean auto_create)
               throws java.sql.SQLException
Method to check the existence of the table/view, optionally auto creating it where required. If it doesn't exist and auto creation isn't specified this throws a MissingTableException.

Specified by:
exists in interface Table
Parameters:
conn - The JDBC Connection
auto_create - Whether to auto create the table if not existing
Returns:
Whether the table was added
Throws:
java.sql.SQLException - Thrown when an error occurs in the JDBC calls

equals

public final boolean equals(java.lang.Object obj)
Equality operator.

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

hashCode

public final int hashCode()
Accessor for the hascode of this table.

Overrides:
hashCode in class java.lang.Object
Returns:
The hash code.

toString

public final java.lang.String toString()
Method to return a string version of this table. This name is the fully-qualified name of the table,including catalog/schema names, where these are appropriate. They are included where the user has either specified the catalog/schema for the PMF, or in the MetaData. They are also only included where the datastore adapter supports their use.

Overrides:
toString in class java.lang.Object
Returns:
String name of the table (catalog.schema.table)

getDatastoreIdentifierFullyQualified

public org.datanucleus.store.mapped.DatastoreIdentifier getDatastoreIdentifierFullyQualified()
Method that operates like toString except it returns a fully-qualified name that will always be fully-qualified even when the user hasnt specified the catalog/schema in PMF or MetaData. That is, it will add on any auto-calculated catalog/schema for the datastore. Note that this will never include any quoting strings required for insert/select etc.

Returns:
The fully qualified name

addColumnInternal

protected void addColumnInternal(Column col)
Utility method to add a column to the internal representation

Parameters:
col - The column

hasColumnName

protected boolean hasColumnName(org.datanucleus.store.mapped.DatastoreIdentifier colName)
Utility to return if a column of this name exists.

Parameters:
colName - The column name
Returns:
Whether the column of this name exists

getSQLCreateStatements

protected abstract java.util.List getSQLCreateStatements(java.util.Properties props)
Accessor for the SQL create statements.

Parameters:
props - Properties controlling the table creation
Returns:
The SQL Create statements

getSQLDropStatements

protected abstract java.util.List getSQLDropStatements()
Accessor for the SQL drop statements.

Returns:
The SQL Drop statements

assertIsPKUninitialized

protected void assertIsPKUninitialized()

assertIsUninitialized

protected void assertIsUninitialized()

assertIsInitialized

protected void assertIsInitialized()

assertIsInitializedModified

protected void assertIsInitializedModified()

assertIsPKInitialized

protected void assertIsPKInitialized()

assertIsValidated

protected void assertIsValidated()

allowDDLOutput

protected boolean allowDDLOutput()
Determine whether we or our concrete class allow DDL to be written into a file instead of sending it to the DB. Defaults to true.

Returns:
Whether it allows DDL outputting

executeDdlStatementList

protected void executeDdlStatementList(java.util.List stmts,
                                       java.sql.Connection conn)
                                throws java.sql.SQLException
Method to perform the required SQL statements.

Parameters:
stmts - A List of statements
conn - The Connection to the datastore
Throws:
java.sql.SQLException - Any exceptions thrown by the statements

executeDdlStatement

protected void executeDdlStatement(java.sql.Statement stmt,
                                   java.lang.String stmtText)
                            throws java.sql.SQLException
Execute a single DDL SQL statement with appropriate logging. If ddlWriter is set, do not actually execute the SQL but write it to that Writer.

Parameters:
stmt - The JDBC Statement object to execute on
stmtText - The actual SQL statement text
Throws:
java.sql.SQLException - Thrown if an error occurs

tableExistsInDatastore

protected boolean tableExistsInDatastore(java.sql.Connection conn)
                                  throws java.sql.SQLException
Determine whether our table exists in the datastore (without modifying datastore). Result is cached

Parameters:
conn - The Connection
Returns:
Whether the table exists in the datastore
Throws:
java.sql.SQLException - Thrown if an error occurs


Copyright © 2009. All Rights Reserved.