public abstract class TempTableHelper
extends java.lang.Object
sqlTempTableCreate(com.goldencode.p2j.persist.Database, java.lang.Class<?>)
- gets a dialect-specific SQL statement
to create a particular temp table.
sqlTempTableDrop(com.goldencode.p2j.persist.Database, java.lang.Class<?>)
- gets a dialect-specific SQL statement
to drop a particular temp table.
sqlTempTableIndexCreate(com.goldencode.p2j.persist.Database, java.lang.Class<?>)
- gets a list of dialect-specific
SQL statements to create indexes for a particular temp table.
sqlTempTableIndexDrop(com.goldencode.p2j.persist.Database, java.lang.Class<?>)
- gets a list of dialect-specific
SQL statements to drop indexes for a particular temp table.
Modifier and Type | Class and Description |
---|---|
private static class |
TempTableHelper.TableMapping
Implementation of Hibernate's internal
Mapping interface,
required when generating dialect-specific, SQL create temp table
statements. |
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.Class<?>,TempTableHelper> |
cache
Map of DMO interfaces to helper objects
|
private static int |
CREATE_PREFIX_LEN
Length of "create table" prefix in SQL create table statements
|
protected Database |
database
The used database
|
private TempTableHelper.TableMapping |
defaultTableMapping
Object used by Hibernate for create table and index statements
|
private java.lang.Class<?> |
dmoIface
DMO interface which provides the public API to the temp table
|
private static java.util.logging.Logger |
LOG
Logger
|
protected java.lang.String |
schema
Name of table schema
|
private java.util.List<java.lang.String> |
sqlCreateIndexes
Dialect-specific SQL statement(s) to create temp table index(es)
|
private java.util.List<java.lang.String> |
sqlCreateTables
Dialect-specific SQL statement(s) to create temp table(s)
|
private java.util.List<java.lang.String> |
sqlDropIndexes
Dialect-specific SQL statement(s) to drop temp table index(es)
|
private java.util.List<java.lang.String> |
sqlDropTables
Dialect-specific SQL statement(s) to drop temp table(s)
|
(package private) static java.lang.String |
UNIQUE_SUFFIX_KEY
Key which will be replaced by a unique suffix in certain DDL
|
Constructor and Description |
---|
TempTableHelper(P2JDialect dialect,
java.lang.Class<?> dmoIface,
Database database)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private java.lang.String |
generateComputedColumnsSQLCreate(org.hibernate.mapping.Table table,
P2JDialect dialect)
Generate the DDL necessary to create a local, temporary table with
computed columns which right trim whitespace and optionally uppercase
text columns.
|
protected java.lang.String |
generateSQLCreateIndex(P2JDialect dialect,
P2JIndex index,
org.hibernate.mapping.Table table,
boolean mpid,
boolean overridePK)
Generate the dialect-specific SQL statement used to create an index
for the temp table.
|
private java.util.List<java.lang.String> |
generateSQLCreateIndexList(P2JDialect dialect,
java.lang.Class<?> dmoIface,
org.hibernate.mapping.Table primary,
java.util.List<org.hibernate.mapping.Table> secondaries)
Populate the list of dialect-specific SQL statements used to create
any indexes required by the temp table(s).
|
protected java.util.List<java.lang.String> |
generateSQLCreateIndexList(P2JDialect dialect,
java.lang.Class<?> dmoIface,
org.hibernate.mapping.Table primary,
java.util.List<org.hibernate.mapping.Table> secondaries,
java.util.Iterator<P2JIndex> iter)
Populate the list of dialect-specific SQL statements used to create
any indexes required by the temp table(s).
|
private java.lang.String |
generateSQLCreateTable(org.hibernate.mapping.Table table,
P2JDialect dialect)
Generate the dialect-specific SQL statement used to create a primary
or secondary temp table.
|
private java.util.List<java.lang.String> |
generateSQLCreateTableList(P2JDialect dialect,
org.hibernate.mapping.Table primary,
java.util.List<org.hibernate.mapping.Table> secondaries)
Populate the list of dialect-specific SQL statements used to create
the required temp table(s).
|
protected java.lang.String |
generateSQLDropIndex(P2JDialect dialect,
java.lang.String name)
Generate the dialect-specific SQL statement used to drop an index for
the temp table.
|
private java.util.List<java.lang.String> |
generateSQLDropIndexList(P2JDialect dialect,
java.lang.Class<?> dmoIface,
org.hibernate.mapping.Table primary,
java.util.List<org.hibernate.mapping.Table> secondaries)
Populate the list of dialect-specific SQL statements used to drop
any indexes required by the temp table(s).
|
protected java.util.List<java.lang.String> |
generateSQLDropIndexList(P2JDialect dialect,
java.lang.Class<?> dmoIface,
org.hibernate.mapping.Table primary,
java.util.List<org.hibernate.mapping.Table> secondaries,
java.util.Iterator<P2JIndex> iter)
Populate the list of dialect-specific SQL statements used to drop
any indexes required by the temp table(s).
|
private java.lang.String |
generateSQLDropTable(org.hibernate.mapping.Table table,
P2JDialect dialect)
Generate the dialect-specific SQL statement used to drop a temp
table.
|
protected java.util.List<java.lang.String> |
generateSQLDropTableList(P2JDialect dialect,
org.hibernate.mapping.Table primary,
java.util.List<org.hibernate.mapping.Table> secondaries)
Populate the list of dialect-specific SQL statements used to drop
the specified temp table(s).
|
private java.lang.String |
generateStandardSQLCreate(org.hibernate.mapping.Table table,
P2JDialect dialect)
Generate the DDL necessary to create a standard temp table (without
computed columns).
|
(package private) static TempTableHelper |
get(Database database,
java.lang.Class<?> dmoIface)
Factory method for obtaining a helper.
|
protected abstract java.lang.String |
getAdditionalIndexSuffix()
Abstract method which will return the an additional index suffix (to
make the index unique across sessions), if needed.
|
(package private) static java.util.Map<java.lang.String,P2JIndexComponent> |
getComputedCols(Database database,
java.lang.Class<?> dmoIface)
Get the computed cols for a certain table.
|
protected abstract java.util.Map<java.lang.String,P2JIndexComponent> |
getComputedCols(java.lang.String schema,
java.lang.Class<?> dmoIface)
Abstract method which will return the computed columns for the required
DMO.
|
protected abstract java.lang.String |
getCreateTableStatement()
Abstract method which will return the needed create table string:
"create local temporary table" or "create temporary table".
|
protected abstract java.util.Iterator<P2JIndex> |
getIndexes(java.lang.String schema,
java.lang.Class<?> dmoIface)
Abstract method which will return the indexes associated with a certain
DMO.
|
(package private) static java.lang.String |
getTableName(Database database,
java.lang.Class<?> dmoIface)
Get the backing temp table name associated with the given DMO
interface, primarily for debugging and error reporting purposes.
|
protected abstract boolean |
isNotNullAllowed()
Indicate whether non-nullable columns are permitted.
|
static java.util.Iterator<java.lang.String> |
sqlTempTableCreate(Database database,
java.lang.Class<?> dmoIface)
Return the SQL statement text used to create a temporary table for the
given DMO class, using the specified database dialect.
|
static java.util.Iterator<java.lang.String> |
sqlTempTableDrop(Database database,
java.lang.Class<?> dmoIface)
Return the SQL statement text used to drop a temporary table for the
given DMO class, using the specified database dialect.
|
static java.util.Iterator<java.lang.String> |
sqlTempTableIndexCreate(Database database,
java.lang.Class<?> dmoIface)
Return a list of SQL statements used to create the indexes for a
temporary table for the given DMO class, using the specified database
dialect.
|
static java.util.Iterator<java.lang.String> |
sqlTempTableIndexDrop(Database database,
java.lang.Class<?> dmoIface)
Return a list of SQL statements used to drop the indexes for a
temporary table for the given DMO class, using the specified database
dialect.
|
private static final java.util.logging.Logger LOG
static final java.lang.String UNIQUE_SUFFIX_KEY
private static final int CREATE_PREFIX_LEN
private static final java.util.Map<java.lang.Class<?>,TempTableHelper> cache
protected final java.lang.String schema
protected final Database database
private final TempTableHelper.TableMapping defaultTableMapping
private final java.util.List<java.lang.String> sqlCreateTables
private final java.util.List<java.lang.String> sqlDropTables
private final java.util.List<java.lang.String> sqlCreateIndexes
private final java.util.List<java.lang.String> sqlDropIndexes
private final java.lang.Class<?> dmoIface
TempTableHelper(P2JDialect dialect, java.lang.Class<?> dmoIface, Database database)
dialect
- Hibernate database dialect helper.dmoIface
- DMO interface which provides the public API to the temp
table.database
- The database for which we generate the sql's.public static java.util.Iterator<java.lang.String> sqlTempTableCreate(Database database, java.lang.Class<?> dmoIface)
database
- The dmoIface
's backing database.dmoIface
- DMO interface which represents the temp table.java.lang.RuntimeException
- if any error occurs generating the SQL statement. This will
generally indicate a configuration problem, rather than a
condition which should be handled by application code.public static java.util.Iterator<java.lang.String> sqlTempTableDrop(Database database, java.lang.Class<?> dmoIface)
database
- The dmoIface
's backing database.dmoIface
- DMO interface which represents the temp table.public static java.util.Iterator<java.lang.String> sqlTempTableIndexCreate(Database database, java.lang.Class<?> dmoIface)
database
- The dmoIface
's backing database.dmoIface
- DMO interface which represents the temp table.java.lang.RuntimeException
- if any error occurs generating the SQL statements. This will
generally indicate a configuration problem, rather than a
condition which should be handled by application code.public static java.util.Iterator<java.lang.String> sqlTempTableIndexDrop(Database database, java.lang.Class<?> dmoIface)
database
- The dmoIface
's backing database.dmoIface
- DMO interface which represents the temp table.java.lang.RuntimeException
- if any error occurs generating the SQL statements. This will
generally indicate a configuration problem, rather than a
condition which should be handled by application code.static java.lang.String getTableName(Database database, java.lang.Class<?> dmoIface)
database
- The dmoIface
's backing database.dmoIface
- DMO interface for which a table name is needed.static java.util.Map<java.lang.String,P2JIndexComponent> getComputedCols(Database database, java.lang.Class<?> dmoIface)
database
- The dmoIface
's backing database.dmoIface
- DMO interface for which a table name is needed.static TempTableHelper get(Database database, java.lang.Class<?> dmoIface)
If the associated database is the database
, an instance of class LocalTempTableHelper
will be
returned. Else, an instance of class DirtyTempTableHelper
will
be returned.
database
- The dmoIface
's backing database.dmoIface
- DMO interface which provides the public API to the temp
table.protected abstract java.lang.String getCreateTableStatement()
protected abstract java.lang.String getAdditionalIndexSuffix()
protected abstract java.util.Map<java.lang.String,P2JIndexComponent> getComputedCols(java.lang.String schema, java.lang.Class<?> dmoIface)
schema
- The schema used for this DMO.dmoIface
- The DMO for which to retrieve the computed columns.protected abstract java.util.Iterator<P2JIndex> getIndexes(java.lang.String schema, java.lang.Class<?> dmoIface)
schema
- The schema used for this DMO.dmoIface
- The DMO for which to retrieve the indexes.protected abstract boolean isNotNullAllowed()
true
if non-nullable columns are permitted, else false
.protected java.util.List<java.lang.String> generateSQLCreateIndexList(P2JDialect dialect, java.lang.Class<?> dmoIface, org.hibernate.mapping.Table primary, java.util.List<org.hibernate.mapping.Table> secondaries, java.util.Iterator<P2JIndex> iter)
dialect
- Hibernate database dialect helper.dmoIface
- DMO interface which provides the public API to the temp
table.primary
- Hibernate database table configuration for primary temp
table.secondaries
- Optional list of Hibernate database table configurations
for secondary temp tables. These are the tables which
support temp table fields with extents, if any. May be
null
if no such tables exist.iter
- The iterator for the collection which contains the needed
indexes.protected java.lang.String generateSQLCreateIndex(P2JDialect dialect, P2JIndex index, org.hibernate.mapping.Table table, boolean mpid, boolean overridePK)
dialect
- Hibernate database dialect helper.index
- P2J index descriptor.table
- Hibernate database table helper.mpid
- true
to make multiplex ID the leading index
component; false
to omit it. The multiplex ID
column will not be indexed if the schema
is not the
DatabaseManager.TEMP_TABLE_SCHEMA
.overridePK
- If true
, do not add primary key column to a
non-unique index; if false
, add primary key
column to a non-unique index.protected java.util.List<java.lang.String> generateSQLDropIndexList(P2JDialect dialect, java.lang.Class<?> dmoIface, org.hibernate.mapping.Table primary, java.util.List<org.hibernate.mapping.Table> secondaries, java.util.Iterator<P2JIndex> iter)
dialect
- Hibernate database dialect helper.dmoIface
- DMO interface which provides the public API to the temp
table.primary
- Hibernate database table configuration for primary temp
table.secondaries
- Optional list of Hibernate database table configurations
for secondary temp tables. These are the tables which
support temp table fields with extents, if any. May be
null
if no such tables exist.iter
- The iterator for the collection which contains the needed
indexes.protected java.lang.String generateSQLDropIndex(P2JDialect dialect, java.lang.String name)
dialect
- Hibernate database dialect helper.name
- Index base name.protected java.util.List<java.lang.String> generateSQLDropTableList(P2JDialect dialect, org.hibernate.mapping.Table primary, java.util.List<org.hibernate.mapping.Table> secondaries)
dialect
- Hibernate database dialect helper.primary
- Hibernate database table configuration for primary temp
table.secondaries
- Optional list of Hibernate database table configurations
for secondary temp tables. These are the tables which
support temp table fields with extents, if any. May be
null
if no such tables exist.private java.util.List<java.lang.String> generateSQLCreateTableList(P2JDialect dialect, org.hibernate.mapping.Table primary, java.util.List<org.hibernate.mapping.Table> secondaries)
dialect
- Hibernate database dialect helper.primary
- Hibernate database table configuration for primary temp
table.secondaries
- Optional list of Hibernate database table configurations
for secondary temp tables. These are the tables which
support temp table fields with extents, if any. May be
null
if no such tables exist.private java.lang.String generateSQLCreateTable(org.hibernate.mapping.Table table, P2JDialect dialect)
table
- Hibernate database table helper.dialect
- Hibernate database dialect helper.java.lang.RuntimeException
- if there is any error generating the SQL statement.private java.lang.String generateComputedColumnsSQLCreate(org.hibernate.mapping.Table table, P2JDialect dialect)
table
- Hibernate table definition.dialect
- P2J database dialect.private java.lang.String generateStandardSQLCreate(org.hibernate.mapping.Table table, P2JDialect dialect)
table
- Hibernate table definition.dialect
- P2J database dialect.private java.util.List<java.lang.String> generateSQLCreateIndexList(P2JDialect dialect, java.lang.Class<?> dmoIface, org.hibernate.mapping.Table primary, java.util.List<org.hibernate.mapping.Table> secondaries)
dialect
- Hibernate database dialect helper.dmoIface
- DMO interface which provides the public API to the temp
table.primary
- Hibernate database table configuration for primary temp
table.secondaries
- Optional list of Hibernate database table configurations
for secondary temp tables. These are the tables which
support temp table fields with extents, if any. May be
null
if no such tables exist.private java.lang.String generateSQLDropTable(org.hibernate.mapping.Table table, P2JDialect dialect)
table
- Hibernate database table helper.dialect
- Hibernate database dialect helper.java.lang.RuntimeException
- if there is any error generating the SQL statement.private java.util.List<java.lang.String> generateSQLDropIndexList(P2JDialect dialect, java.lang.Class<?> dmoIface, org.hibernate.mapping.Table primary, java.util.List<org.hibernate.mapping.Table> secondaries)
dialect
- Hibernate database dialect helper.dmoIface
- DMO interface which provides the public API to the temp
table.primary
- Hibernate database table configuration for primary temp
table.secondaries
- Optional list of Hibernate database table configurations
for secondary temp tables. These are the tables which
support temp table fields with extents, if any. May be
null
if no such tables exist.