org.jpox.store.rdbms.table
Class AbstractTable

java.lang.Object
  extended byorg.jpox.store.rdbms.table.AbstractTable
All Implemented Interfaces:
DatastoreContainerObject, DatastoreObject, 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.

Version:
$Revision: 1.30 $

Field Summary
protected  java.util.List columns
          Columns for this table.
protected  java.util.HashMap columnsByName
          Index to the columns, keyed by name.
protected  RDBMSAdapter dba
          Database Adapter being used.
protected static java.io.FileWriter ddlDumpWriter
          Writer to output any DDL.
protected  DatastoreIdentifier identifier
          Identifier name for the table.
protected static Localiser LOCALISER
          Localiser for messages.
protected  int state
          State of the table
protected  RDBMSManager storeMgr
          Manager for this table.
 
Fields inherited from interface org.jpox.store.rdbms.table.Table
TABLE_STATE_INITIALIZED, TABLE_STATE_INITIALIZED_MODIFIED, TABLE_STATE_NEW, TABLE_STATE_PK_INITIALIZED, TABLE_STATE_VALIDATED, TABLE_TYPE_MISSING, TABLE_TYPE_TABLE, TABLE_TYPE_UNKNOWN, TABLE_TYPE_VIEW
 
Constructor Summary
AbstractTable(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
 DatastoreField addDatastoreField(java.lang.String storedJavaType, DatastoreIdentifier name, JavaTypeMapping mapping, ExtendableMetaData colmd)
          Creates a new column.
protected  boolean allowDdlDump()
          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()
           
 void 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.
 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.
 JavaTypeMapping getDiscriminatorMapping()
          Accessor for the discriminator mapping specified .
 DiscriminatorMetaData getDiscriminatorMetaData()
          Accessor for Discriminator MetaData
 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.
 StoreManager getStoreManager()
          Accessor for the Store Manager.
 JavaTypeMapping getVersionMapping()
          Accessor for the version mapping specified.
 VersionMetaData getVersionMetaData()
          Accessor for Version MetaData
protected  boolean hasColumnName(DatastoreIdentifier colName)
          Utility to return if a column of this name exists.
 boolean hasDatastoreField(DatastoreIdentifier identifier)
          Checks if there is a DatastoreField for the identifier
 int hashCode()
          Accessor for the hascode of this table.
static boolean isDumpingDdl()
          Whether a writer is defined to dump DDL
 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.
static void setDdlDumpWriter(java.io.FileWriter fileWriter)
          Set the file where any subsequent DDL SQL commands will be written to instead of issuing them to the database.
 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.jpox.store.rdbms.table.Table
initialize, postInitialize, preInitialize, validate
 
Methods inherited from interface org.jpox.store.DatastoreContainerObject
getFieldMapping, getIDMapping
 

Field Detail

LOCALISER

protected static final 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 DatastoreIdentifier identifier
Identifier name for the table. This will include the catalog/schema internally (if defined by the user).


state

protected int state
State of the table


columns

protected java.util.List columns
Columns for this table.


columnsByName

protected java.util.HashMap columnsByName
Index to the columns, keyed by name.


ddlDumpWriter

protected static java.io.FileWriter ddlDumpWriter
Writer to output any DDL. TODO Refactor this out and provide cleaner interface to DDL

Constructor Detail

AbstractTable

public AbstractTable(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 StoreManager getStoreManager()
Accessor for the Store Manager.

Specified by:
getStoreManager in interface DatastoreObject
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 DatastoreIdentifier getIdentifier()
Accessor for the SQL identifier (the table name).

Specified by:
getIdentifier in interface DatastoreObject
Returns:
The name

addDatastoreField

public DatastoreField addDatastoreField(java.lang.String storedJavaType,
                                        DatastoreIdentifier name,
                                        JavaTypeMapping mapping,
                                        ExtendableMetaData colmd)
Creates a new column.

Specified by:
addDatastoreField in interface DatastoreContainerObject
Parameters:
storedJavaType - the type of the field that this represents.
name - the SQL identifier
mapping - the mapping for this column
colmd - the ExtendableMetadata (ColumnMetaData for RDBMS)
Returns:
the new Column
Throws:
DuplicateColumnNameException - if a column already exists with same name

hasDatastoreField

public boolean hasDatastoreField(DatastoreIdentifier identifier)
Checks if there is a DatastoreField for the identifier

Specified by:
hasDatastoreField in interface DatastoreContainerObject
Parameters:
identifier - the identifier of the DatastoreField
Returns:
true if the DatastoreField exists for the identifier

create

public void 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.
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.

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.

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.

Returns:
String name of the table (catalog.schema.table)

getDatastoreIdentifierFullyQualified

public 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(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()

allowDdlDump

protected boolean allowDdlDump()
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 dumping

isDumpingDdl

public static boolean isDumpingDdl()
Whether a writer is defined to dump DDL

Returns:
true if a writer is set

setDdlDumpWriter

public static void setDdlDumpWriter(java.io.FileWriter fileWriter)
Set the file where any subsequent DDL SQL commands will be written to instead of issuing them to the database. The default null means normal operation, i.e. DDL SQL commands will be sent to the DB.

Parameters:
fileWriter - The File writer to use for outputting DDL

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 ddlDumpWriter is set, do not actually execute the SQL but write it to that FileWriter.

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

getDiscriminatorMetaData

public DiscriminatorMetaData getDiscriminatorMetaData()
Accessor for Discriminator MetaData

Specified by:
getDiscriminatorMetaData in interface DatastoreContainerObject
Returns:
Returns the Discriminator MetaData.

getDiscriminatorMapping

public JavaTypeMapping getDiscriminatorMapping()
Accessor for the discriminator mapping specified .

Specified by:
getDiscriminatorMapping in interface DatastoreContainerObject
Returns:
The mapping for the discriminator datastore field

getVersionMetaData

public VersionMetaData getVersionMetaData()
Accessor for Version MetaData

Specified by:
getVersionMetaData in interface DatastoreContainerObject
Returns:
Returns the Version MetaData.

getVersionMapping

public JavaTypeMapping getVersionMapping()
Accessor for the version mapping specified.

Specified by:
getVersionMapping in interface DatastoreContainerObject
Returns:
The mapping for the version datastore field


Copyright © -2007 . All Rights Reserved.