org.datanucleus.store.rdbms.table
Class TableImpl

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

public abstract class TableImpl
extends AbstractTable

Class representing a table in a datastore (RDBMS). Provides a series of methods for validating the aspects of the table, namely


Field Summary
 
Fields inherited from class org.datanucleus.store.rdbms.table.AbstractTable
columns, columnsByName, dba, existsInDatastore, identifier, LOCALISER, state, storeMgr
 
Constructor Summary
TableImpl(org.datanucleus.store.mapped.DatastoreIdentifier name, RDBMSManager storeMgr)
          Constructor.
 
Method Summary
 boolean createConstraints(java.sql.Connection conn, java.util.Collection autoCreateErrors, org.datanucleus.ClassLoaderResolver clr)
          Method used to create all constraints for a brand new table.
 void dropConstraints(java.sql.Connection conn)
          Method to drop the constraints for the table from the datastore.
protected  java.util.List getExpectedCandidateKeys()
          Accessor for the expected candidate keys for this table in the datastore.
protected  java.util.List getExpectedForeignKeys(org.datanucleus.ClassLoaderResolver clr)
          Accessor for the expected foreign keys for this table in the datastore.
protected  java.util.Set getExpectedIndices(org.datanucleus.ClassLoaderResolver clr)
          Accessor for the indices for this table in the datastore.
 PrimaryKey getPrimaryKey()
          Accessor for the primary key for this table.
protected  java.util.Map getSQLAddCandidateKeyStatements(java.util.Map actualCandidateKeysByName)
          Get SQL statements to add expected Candidate Keys that are not yet on the table.
protected  java.util.Map getSQLAddFKStatements(java.util.Map actualForeignKeysByName, org.datanucleus.ClassLoaderResolver clr)
          Get SQL statements to add expected Foreign Keys that are not yet at the table.
protected  java.util.Map getSQLCreateIndexStatements(java.util.Map actualIndicesByName, org.datanucleus.ClassLoaderResolver clr)
          Accessor for the CREATE INDEX statements for this table.
protected  java.util.List getSQLCreateStatements(java.util.Properties props)
          Accessor for the SQL CREATE statements for this table.
protected  java.util.List getSQLDropStatements()
          Accessor for the DROP statements for this table.
 void initializeColumnInfoForPrimaryKeyColumns(java.sql.Connection conn)
          Utility to load the structure/metadata of primary key columns of the table.
 void initializeColumnInfoFromDatastore(java.sql.Connection conn)
          Initialize the default value for columns if null using the values from the datastore.
 void postInitialize(org.datanucleus.ClassLoaderResolver clr)
          Post initilize.
 void preInitialize(org.datanucleus.ClassLoaderResolver clr)
          Pre-initilize.
 boolean validate(java.sql.Connection conn, boolean validateColumnStructure, boolean autoCreate, java.util.Collection autoCreateErrors)
          Method to validate the table in the datastore.
 boolean validateColumns(java.sql.Connection conn, boolean validateColumnStructure, boolean autoCreate, java.util.Collection autoCreateErrors)
          Utility to validate the columns of the table.
 boolean validateConstraints(java.sql.Connection conn, boolean autoCreate, java.util.Collection autoCreateErrors, org.datanucleus.ClassLoaderResolver clr)
          Method to validate any constraints, and auto create them if required.
protected  boolean validatePrimaryKey(java.sql.Connection conn)
          Utility method to validate the primary key of the table.
 
Methods inherited from class org.datanucleus.store.rdbms.table.AbstractTable
addColumnInternal, addDatastoreField, allowDDLOutput, assertIsInitialized, assertIsInitializedModified, assertIsPKInitialized, assertIsPKUninitialized, assertIsUninitialized, assertIsValidated, create, drop, equals, executeDdlStatement, executeDdlStatementList, exists, getCatalogName, getDatastoreField, getDatastoreFields, getDatastoreIdentifierFullyQualified, getDiscriminatorMapping, getDiscriminatorMetaData, getIdentifier, getSchemaName, getStoreManager, getVersionMapping, getVersionMetaData, hasColumnName, hasDatastoreField, hashCode, isInitialized, isInitializedModified, isPKInitialized, isValidated, tableExistsInDatastore, toString
 
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
 
Methods inherited from interface org.datanucleus.store.mapped.DatastoreContainerObject
getIDMapping, getMemberMapping
 

Constructor Detail

TableImpl

public TableImpl(org.datanucleus.store.mapped.DatastoreIdentifier name,
                 RDBMSManager storeMgr)
Constructor.

Parameters:
name - The name of the table (in SQL).
storeMgr - The StoreManager for this table.
Method Detail

preInitialize

public void preInitialize(org.datanucleus.ClassLoaderResolver clr)
Pre-initilize. For things that must be initialized right after constructor

Parameters:
clr - the ClassLoaderResolver

postInitialize

public void postInitialize(org.datanucleus.ClassLoaderResolver clr)
Post initilize. For things that must be set after all classes have been initialized before

Parameters:
clr - the ClassLoaderResolver

getPrimaryKey

public PrimaryKey getPrimaryKey()
Accessor for the primary key for this table. Will always return a PrimaryKey but if we have defined no columns, the pk.size() will be 0.

Returns:
The primary key.

validate

public boolean validate(java.sql.Connection conn,
                        boolean validateColumnStructure,
                        boolean autoCreate,
                        java.util.Collection autoCreateErrors)
                 throws java.sql.SQLException
Method to validate the table in the datastore.

Parameters:
conn - The JDBC Connection
validateColumnStructure - Whether to validate the column structure, or just the column existence
autoCreate - Whether to update the table to fix any validation errors. Only applies to missing columns.
autoCreateErrors - Exceptions found in the "auto-create" process
Returns:
Whether the database was modified
Throws:
java.sql.SQLException - Thrown when an error occurs in the JDBC calls

validateColumns

public boolean validateColumns(java.sql.Connection conn,
                               boolean validateColumnStructure,
                               boolean autoCreate,
                               java.util.Collection autoCreateErrors)
                        throws java.sql.SQLException
Utility to validate the columns of the table. Will throw a MissingColumnException if a column is not found (and is not required to auto create it)

Parameters:
conn - Connection to use for validation
validateColumnStructure - Whether to validate down to the structure of the columns, or just their existence
autoCreate - Whether to auto create any missing columns
autoCreateErrors - Exceptions found in the "auto-create" process
Returns:
Whether it validates
Throws:
java.sql.SQLException - Thrown if an error occurs in the validation process

initializeColumnInfoForPrimaryKeyColumns

public void initializeColumnInfoForPrimaryKeyColumns(java.sql.Connection conn)
                                              throws java.sql.SQLException
Utility to load the structure/metadata of primary key columns of the table.

Parameters:
conn - Connection to use for validation
Throws:
java.sql.SQLException - Thrown if an error occurs in the initialization process

initializeColumnInfoFromDatastore

public void initializeColumnInfoFromDatastore(java.sql.Connection conn)
                                       throws java.sql.SQLException
Initialize the default value for columns if null using the values from the datastore.

Parameters:
conn - The JDBC Connection
Throws:
java.sql.SQLException - Thrown if an error occurs in the default initialisation.

validatePrimaryKey

protected boolean validatePrimaryKey(java.sql.Connection conn)
                              throws java.sql.SQLException
Utility method to validate the primary key of the table. Will throw a WrongPrimaryKeyException if the PK is incorrect. TODO Add an auto_create parameter on this

Parameters:
conn - Connection to use
Returns:
Whether it validates
Throws:
java.sql.SQLException - When an error occurs in the valdiation

validateConstraints

public boolean validateConstraints(java.sql.Connection conn,
                                   boolean autoCreate,
                                   java.util.Collection autoCreateErrors,
                                   org.datanucleus.ClassLoaderResolver clr)
                            throws java.sql.SQLException
Method to validate any constraints, and auto create them if required.

Parameters:
conn - The JDBC Connection
autoCreate - Whether to auto create the constraints if not existing
autoCreateErrors - Errors found in the "auto-create" process
clr - The ClassLoaderResolver
Returns:
Whether the database was modified
Throws:
java.sql.SQLException - Thrown when an error occurs in the JDBC calls

createConstraints

public boolean createConstraints(java.sql.Connection conn,
                                 java.util.Collection autoCreateErrors,
                                 org.datanucleus.ClassLoaderResolver clr)
                          throws java.sql.SQLException
Method used to create all constraints for a brand new table.

Parameters:
conn - The JDBC Connection
autoCreateErrors - Errors found in the "auto-create" process
clr - The ClassLoaderResolver
Returns:
Whether the database was modified
Throws:
java.sql.SQLException - Thrown when an error occurs in the JDBC calls

dropConstraints

public void dropConstraints(java.sql.Connection conn)
                     throws java.sql.SQLException
Method to drop the constraints for the table from the datastore.

Parameters:
conn - The JDBC Connection
Throws:
java.sql.SQLException - Thrown when an error occurs in the JDBC call.

getExpectedForeignKeys

protected java.util.List getExpectedForeignKeys(org.datanucleus.ClassLoaderResolver clr)
Accessor for the expected foreign keys for this table in the datastore. Currently only checks the columns for referenced tables (i.e relationships) and returns those.

Parameters:
clr - The ClassLoaderResolver
Returns:
List of foreign keys.

getExpectedCandidateKeys

protected java.util.List getExpectedCandidateKeys()
Accessor for the expected candidate keys for this table in the datastore. Currently returns an empty list.

Returns:
List of candidate keys.

getExpectedIndices

protected java.util.Set getExpectedIndices(org.datanucleus.ClassLoaderResolver clr)
Accessor for the indices for this table in the datastore.

Parameters:
clr - The ClassLoaderResolver
Returns:
Set of indices expected.

getSQLCreateStatements

protected java.util.List getSQLCreateStatements(java.util.Properties props)
Accessor for the SQL CREATE statements for this table.

Specified by:
getSQLCreateStatements in class AbstractTable
Parameters:
props - Properties for controlling the table creation
Returns:
List of statements.

getSQLAddFKStatements

protected java.util.Map getSQLAddFKStatements(java.util.Map actualForeignKeysByName,
                                              org.datanucleus.ClassLoaderResolver clr)
Get SQL statements to add expected Foreign Keys that are not yet at the table. If the returned Map is empty, the current FK setup is correct.

Parameters:
actualForeignKeysByName - Actual Map of foreign keys
clr - The ClassLoaderResolver
Returns:
a Map with the SQL statements

getSQLAddCandidateKeyStatements

protected java.util.Map getSQLAddCandidateKeyStatements(java.util.Map actualCandidateKeysByName)
Get SQL statements to add expected Candidate Keys that are not yet on the table. If the returned Map is empty, the current Candidate Key setup is correct.

Parameters:
actualCandidateKeysByName - Actual Map of candidate keys
Returns:
a Map with the SQL statements

getSQLCreateIndexStatements

protected java.util.Map getSQLCreateIndexStatements(java.util.Map actualIndicesByName,
                                                    org.datanucleus.ClassLoaderResolver clr)
Accessor for the CREATE INDEX statements for this table.

Parameters:
actualIndicesByName - Map of actual indexes
clr - The ClassLoaderResolver
Returns:
Map of statements

getSQLDropStatements

protected java.util.List getSQLDropStatements()
Accessor for the DROP statements for this table.

Specified by:
getSQLDropStatements in class AbstractTable
Returns:
List of statements


Copyright © 2009. All Rights Reserved.