Class AbstractTable
java.lang.Object
org.datanucleus.store.rdbms.table.AbstractTable
- All Implemented Interfaces:
Table
,org.datanucleus.store.schema.table.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
FieldsModifier and TypeFieldDescriptionprotected List
<org.datanucleus.store.schema.table.Column> Columns for this table.protected Map
<DatastoreIdentifier, Column> Index to the columns, keyed by name identifier.protected final DatastoreAdapter
Database Adapter being used.protected Boolean
Cache what we learned in a call to exists()private String
Fully qualified name of this table.private final int
compute hashCode in advance to improve performanceprotected final DatastoreIdentifier
Identifier name for the table.protected short
State of the tableprotected final RDBMSStoreManager
Manager for this table.protected static final short
Table object has been initialised.protected static final short
Table object has been initialized but has had structural modifications since.protected static final short
Table object has just been created.protected static final short
Table object is created and PK initialised.protected static final short
Table object has been validated. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractTable
(DatastoreIdentifier identifier, RDBMSStoreManager storeMgr) Constructor taking the table name and the RDBMSManager managing this table. -
Method Summary
Modifier and TypeMethodDescriptionaddColumn
(String storedJavaType, DatastoreIdentifier name, JavaTypeMapping mapping, org.datanucleus.metadata.ColumnMetaData colmd) Creates a new column in the table.protected void
addColumnInternal
(Column col) Utility method to add a column to the internal representationprotected boolean
Determine whether we or our concrete class allow DDL to be written into a file instead of sending it to the DB.protected void
protected void
protected void
protected void
protected void
protected void
boolean
create
(Connection conn) Method to create the table in the datastore representation.void
drop
(Connection conn) Method to drop the table from the datastore representation.final boolean
protected void
executeDdlStatement
(Statement stmt, String stmtText) Execute a single DDL SQL statement with appropriate logging.protected void
executeDdlStatementList
(List<String> stmts, Connection conn) Method to perform the required SQL statements.boolean
exists
(Connection conn, boolean auto_create) Method to check the existence of the table/view, optionally auto creating it where required.Accessor for the Catalog Name.org.datanucleus.metadata.AbstractClassMetaData
getColumn
(DatastoreIdentifier identifier) Accessor for the column with the specified identifier.org.datanucleus.store.schema.table.Column
getColumnForName
(String name) org.datanucleus.store.schema.table.Column
getColumnForPosition
(int pos) List
<org.datanucleus.store.schema.table.Column> 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.metadata.DiscriminatorMetaData
Accessor for Discriminator MetaData.Accessor for the SQL identifier (the table name).org.datanucleus.store.schema.table.MemberColumnMapping
getMemberColumnMappingForEmbeddedMember
(List<org.datanucleus.metadata.AbstractMemberMetaData> mmds) org.datanucleus.store.schema.table.MemberColumnMapping
getMemberColumnMappingForMember
(org.datanucleus.metadata.AbstractMemberMetaData mmd) Set
<org.datanucleus.store.schema.table.MemberColumnMapping> getName()
int
Accessor for the Schema Name.getSQLCreateStatements
(Properties props) Accessor for the SQL create statements.Accessor for the SQL drop statements.getSurrogateColumn
(org.datanucleus.store.schema.table.SurrogateColumnType colType) getSurrogateMapping
(org.datanucleus.store.schema.table.SurrogateColumnType colType, boolean allowSuperclasses) Accessor for the mapping for the specified surrogate type.org.datanucleus.metadata.VersionMetaData
Accessor for the Version MetaData.boolean
hasColumn
(DatastoreIdentifier identifier) Checks if there is a column for the identifierprotected boolean
hasColumnName
(DatastoreIdentifier colName) Utility to return if a column of this name exists.final int
hashCode()
boolean
Accessor for whether the table has been initialised.boolean
Accessor for whether the table has been modified since initialisation.boolean
Accessor for whether the primary key of the table is initialised.boolean
Accessor for whether the table is validated.void
postInitialize
(org.datanucleus.ClassLoaderResolver clr) Post-initialize; for things that must be set after all classes have been initialized.void
preInitialize
(org.datanucleus.ClassLoaderResolver clr) Pre-initialize method; for things that must be initialized right after construction.protected boolean
Determine whether our table exists in the datastore (without modifying datastore).final 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
getIdMapping, getMemberMapping, initialize, validate
-
Field Details
-
TABLE_STATE_NEW
protected static final short TABLE_STATE_NEWTable object has just been created.- See Also:
-
TABLE_STATE_PK_INITIALIZED
protected static final short TABLE_STATE_PK_INITIALIZEDTable object is created and PK initialised.- See Also:
-
TABLE_STATE_INITIALIZED
protected static final short TABLE_STATE_INITIALIZEDTable object has been initialised.- See Also:
-
TABLE_STATE_INITIALIZED_MODIFIED
protected static final short TABLE_STATE_INITIALIZED_MODIFIEDTable object has been initialized but has had structural modifications since.- See Also:
-
TABLE_STATE_VALIDATED
protected static final short TABLE_STATE_VALIDATEDTable object has been validated.- See Also:
-
storeMgr
Manager for this table. -
dba
Database Adapter being used. -
identifier
Identifier name for the table. Includes the catalog/schema internally (if defined by the user). -
state
protected short stateState of the table -
columns
Columns for this table. -
columnsByIdentifier
Index to the columns, keyed by name identifier. TODO Key this by the column name, not its identifier. -
fullyQualifiedName
Fully qualified name of this table. -
hashCode
private final int hashCodecompute hashCode in advance to improve performance -
existsInDatastore
Cache what we learned in a call to exists()
-
-
Constructor Details
-
AbstractTable
Constructor taking the table name and the RDBMSManager managing this table.- Parameters:
identifier
- Name of the tablestoreMgr
- The RDBMS Manager
-
-
Method Details
-
isInitialized
public boolean isInitialized()Description copied from interface:Table
Accessor for whether the table has been initialised.- Specified by:
isInitialized
in interfaceTable
- Returns:
- Whether it is initialised.
-
preInitialize
public void preInitialize(org.datanucleus.ClassLoaderResolver clr) Description copied from interface:Table
Pre-initialize method; for things that must be initialized right after construction.- Specified by:
preInitialize
in interfaceTable
- Parameters:
clr
- the ClassLoaderResolver
-
postInitialize
public void postInitialize(org.datanucleus.ClassLoaderResolver clr) Description copied from interface:Table
Post-initialize; for things that must be set after all classes have been initialized.- Specified by:
postInitialize
in interfaceTable
- Parameters:
clr
- the ClassLoaderResolver
-
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()Description copied from interface:Table
Accessor for whether the table is validated.- Specified by:
isValidated
in interfaceTable
- Returns:
- Whether it is validated.
-
isInitializedModified
public boolean isInitializedModified()Accessor for whether the table has been modified since initialisation.- Specified by:
isInitializedModified
in interfaceTable
- Returns:
- Whether it is modified since initialisation.
-
getStoreManager
- Specified by:
getStoreManager
in interfaceTable
- Specified by:
getStoreManager
in interfaceorg.datanucleus.store.schema.table.Table
-
getName
- Specified by:
getName
in interfaceorg.datanucleus.store.schema.table.Table
-
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 interfaceorg.datanucleus.store.schema.table.Table
- Returns:
- Catalog Name
-
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 interfaceorg.datanucleus.store.schema.table.Table
- Returns:
- Schema Name
-
getIdentifier
Accessor for the SQL identifier (the table name).- Specified by:
getIdentifier
in interfaceTable
- Returns:
- The name
-
getClassMetaData
public org.datanucleus.metadata.AbstractClassMetaData getClassMetaData()- Specified by:
getClassMetaData
in interfaceorg.datanucleus.store.schema.table.Table
-
getNumberOfColumns
public int getNumberOfColumns()- Specified by:
getNumberOfColumns
in interfaceorg.datanucleus.store.schema.table.Table
-
getColumns
- Specified by:
getColumns
in interfaceorg.datanucleus.store.schema.table.Table
-
getColumnForPosition
public org.datanucleus.store.schema.table.Column getColumnForPosition(int pos) - Specified by:
getColumnForPosition
in interfaceorg.datanucleus.store.schema.table.Table
-
getSurrogateColumn
- Specified by:
getSurrogateColumn
in interfaceorg.datanucleus.store.schema.table.Table
-
getColumnForName
- Specified by:
getColumnForName
in interfaceorg.datanucleus.store.schema.table.Table
-
getMemberColumnMappingForMember
public org.datanucleus.store.schema.table.MemberColumnMapping getMemberColumnMappingForMember(org.datanucleus.metadata.AbstractMemberMetaData mmd) - Specified by:
getMemberColumnMappingForMember
in interfaceorg.datanucleus.store.schema.table.Table
-
getMemberColumnMappingForEmbeddedMember
public org.datanucleus.store.schema.table.MemberColumnMapping getMemberColumnMappingForEmbeddedMember(List<org.datanucleus.metadata.AbstractMemberMetaData> mmds) - Specified by:
getMemberColumnMappingForEmbeddedMember
in interfaceorg.datanucleus.store.schema.table.Table
-
getMemberColumnMappings
- Specified by:
getMemberColumnMappings
in interfaceorg.datanucleus.store.schema.table.Table
-
getSurrogateMapping
public JavaTypeMapping getSurrogateMapping(org.datanucleus.store.schema.table.SurrogateColumnType colType, boolean allowSuperclasses) Description copied from interface:Table
Accessor for the mapping for the specified surrogate type.- Specified by:
getSurrogateMapping
in interfaceTable
- Parameters:
colType
- Column type for the surrogateallowSuperclasses
- Whether to allow searching superclasses when not specified in this table.- Returns:
- The mapping
-
getVersionMetaData
public org.datanucleus.metadata.VersionMetaData getVersionMetaData()Description copied from interface:Table
Accessor for the Version MetaData.- Specified by:
getVersionMetaData
in interfaceTable
- Returns:
- Returns the Version MetaData.
-
getDiscriminatorMetaData
public org.datanucleus.metadata.DiscriminatorMetaData getDiscriminatorMetaData()Description copied from interface:Table
Accessor for Discriminator MetaData.- Specified by:
getDiscriminatorMetaData
in interfaceTable
- Returns:
- Returns the Discriminator MetaData.
-
addColumn
public Column addColumn(String storedJavaType, DatastoreIdentifier name, JavaTypeMapping mapping, org.datanucleus.metadata.ColumnMetaData 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 :-- The 2 columns are for same named fields in the class or its subclasses with the subclass(es) using "superclass-table" inheritance strategy. One of the columns has to come from a subclass - cant have both from the same class.
- Specified by:
addColumn
in interfaceTable
- Parameters:
storedJavaType
- the java type of the columnname
- the SQL identifier for the column to be addedmapping
- the mapping for the column to be addedcolmd
- ColumnMetaData for the column to be added to the table- Returns:
- the new Column
- Throws:
DuplicateColumnException
- if a column already exists with same name and not a supported situation.
-
hasColumn
Description copied from interface:Table
Checks if there is a column for the identifier -
getColumn
Description copied from interface:Table
Accessor for the column with the specified identifier. Returns null if has no column of this name. -
create
Description copied from interface:Table
Method to create the table in the datastore representation.- Specified by:
create
in interfaceTable
- Parameters:
conn
- The connection to use- Returns:
- true if the table was created
- Throws:
SQLException
- Thrown if an error occurs creating the table.
-
drop
Description copied from interface:Table
Method to drop the table from the datastore representation.- Specified by:
drop
in interfaceTable
- Parameters:
conn
- The connection to use- Throws:
SQLException
- Thrown if an error occurs
-
exists
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 interfaceTable
- Parameters:
conn
- The JDBC Connectionauto_create
- Whether to auto create the table if not existing- Returns:
- Whether the table was added
- Throws:
SQLException
- Thrown when an error occurs in the JDBC calls
-
equals
-
hashCode
public final int hashCode() -
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. -
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
Utility method to add a column to the internal representation- Parameters:
col
- The column
-
hasColumnName
Utility to return if a column of this name exists.- Parameters:
colName
- The column name- Returns:
- Whether the column of this name exists
-
getSQLCreateStatements
Accessor for the SQL create statements.- Parameters:
props
- Properties controlling the table creation- Returns:
- The SQL Create statements
-
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
Method to perform the required SQL statements.- Parameters:
stmts
- A List of statementsconn
- The Connection to the datastore- Throws:
SQLException
- Any exception thrown by the statements
-
executeDdlStatement
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 onstmtText
- The actual SQL statement text- Throws:
SQLException
- Thrown if an error occurs
-
tableExistsInDatastore
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:
SQLException
- Thrown if an error occurs
-