public interface ExtendedConnection
extends java.sql.Connection
Connection in order to provide further functionality
to assist in writing vendor-independent database accessing code. This
additional functionality is provided by an implementation of
DBAccessProvider.| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MAX_IN_OPERATOR_PARAMETER_COUNT
the default value for
getMaxInOperatorParameterCount() |
static int |
DEFAULT_MAX_PARAMETER_COUNT
the default value for
getMaxParameterCount() |
static int |
DEFAULT_MAX_STATEMENT_LENGTH
the default value for
getMaxStatementLength() |
| Modifier and Type | Method and Description |
|---|---|
void |
addColumn(java.lang.String tableName,
java.lang.String columnName,
java.lang.String correspondingDbType)
Adds an additional column to the designated table of the designated type.
|
boolean |
columnExists(java.lang.String columnName,
java.lang.String tableName)
Returns whether the column with the provided name exists in the provided
table.
|
java.lang.String |
createRecursionTable(java.lang.String[] selectAttributes,
java.lang.String[] rootAttributes,
java.lang.String tableName,
java.lang.String startCondition,
ParentToChildConnection[] parentToChildConnections)
Like
createRecursionTable(String[], String, String, ParentToChildConnection[], int)
but without a maximum depth. |
java.lang.String |
createRecursionTable(java.lang.String[] selectAttributes,
java.lang.String tableName,
java.lang.String startCondition,
ParentToChildConnection[] parentToChildConnections,
int maxDepth)
Creates a (temporary) table or view containing tuples that match a
recursive/hierarchical SQL-query which is based on the specified
parameters.
|
void |
createSequence(java.lang.String sequenceName,
long start,
long increment)
Creates a new sequence in the database.
|
void |
deregisterIterator()
Deregisters an iterator for this
ExtendedConnection which
allows this connection to be reclaimed again in case it is not used any
more. |
void |
dropAllRecursionTables()
All tables that have been created via
createRecursionTable(String[],
String, String, String[], int) are dropped. |
void |
dropColumn(java.lang.String tableName,
java.lang.String columnName)
Drops the specified column from the table which corresponds to an
ALTER TABLE DROP COLUMN statement. |
void |
dropRecursionTable(java.lang.String tableName)
The specified table that has been created via
createRecursionTable(String[], String, String, String[], int)
is dropped. |
void |
dropSchemaVersion(java.lang.String serviceName) |
void |
dropSequence(java.lang.String sequenceName)
Drop the sequence with the given name.
|
java.lang.String |
formatValue(java.lang.Object value,
int typeCode)
Formats the given value to a string that can be used in SQL statements and
queries.
|
java.lang.String |
getAddForeignKey(de.aristaflow.adept2.base.dbaccess.model.ForeignKey fk,
boolean quoteIdentifiers)
Gets an SQL string for
ALTER TABLE which adds the designated
foreign key. |
java.util.Collection<java.lang.String> |
getAllTableNames()
Returns a collection of the names of all existing tables in the database.
|
java.lang.String[] |
getColumnNames(java.lang.String tableName)
Gets all column names of a specific table.
|
int |
getColumnType(java.lang.String columnName,
java.lang.String tableName)
Gets the type of a specific column as
java.sql.Types. |
java.lang.String |
getCorrespondingDBType(int jdbcTypeCode)
Converts the given JDBC type code and given size constraints into a vendor
specific SQL type.
|
java.lang.String |
getCorrespondingDBType(int jdbcTypeCode,
int size)
Converts the given JDBC type code and given size constraints into a vendor
specific SQL type.
|
java.lang.String |
getCorrespondingDBType(int jdbcTypeCode,
int size,
int scale)
Converts the given JDBC type code and given size constraints into a vendor
specific SQL type.
|
java.sql.Timestamp |
getCurrentTime()
Gets the current time (as timestamp) from the underlying DBMS in UTC timezone.
|
DatabaseName |
getDatabaseName()
Gets the name of the underlying database.
|
java.lang.String |
getDropForeignKeyConstraintKeyword()
To drop a foreign key constraint from table columns, there are two syntaxes
available.
|
java.lang.String |
getEXCEPTKeyword()
Gets the keyword that is interpreted as EXCEPT by the underlying
database-management-system.
|
int |
getMaxInOperatorParameterCount()
Return the maximum number of parameters within the IN-operator.
|
int |
getMaxParameterCount()
Returns the maximum number of parameters in prepared statements.
|
int |
getMaxStatementLength()
Returns the maximum length for SQL statements.
|
int |
getSchemaVersion(java.lang.String serviceName)
Returns the version number associated with the current database structure
of the given service name.
|
java.lang.String |
getStringComparison(java.lang.String tableName,
java.lang.String columnName,
java.lang.String tableAlias,
int type,
int length,
boolean equal)
Gets a string to be used in a WHERE-clause for comparing the designated
column with another string.
|
java.lang.String |
getTimeDifference(java.lang.String column,
long seconds)
Gets the string representing the timestamp value (to be calculated within the DBMS) based on
the designated column having the designated difference (in seconds).
|
boolean |
isForeignKeyViolation(java.sql.SQLException ex)
Returns true if the given exception was caused by a FOREIGN KEY constraint.
|
boolean |
isLockTimeout(java.sql.SQLException ex)
Gets whether the designated exception indicates a lock timeout, e. g. while
waiting for a
table lock. |
boolean |
isSyntaxError(java.sql.SQLException ex)
Gets whether the designated exception indicates syntax error.
|
boolean |
isTableMissing(java.sql.SQLException ex)
Returns true if the given exception was caused by a missing table.
|
boolean |
isUniqueViolation(java.sql.SQLException ex)
Returns true if the given exception was caused by a UNIQUE constraint.
|
void |
lockTable(java.lang.String tableName,
long timeout)
Locks the designated table exclusively until the end of the corresponding
transaction.
|
long |
nextID(java.lang.String sequenceName)
Returns the next ID from the sequence with the given name.
|
void |
registerIterator()
Registers an iterator for this
ExtendedConnection which
prevents this connection from being reclaimed in case it is pooled. |
void |
renameColumn(java.lang.String tableName,
java.lang.String oldColumnName,
java.lang.String newColumnName)
Renames the designated column from the table which corresponds to an
ALTER TABLE RENAME COLUMN statement. |
void |
renameTable(java.lang.String oldName,
java.lang.String newName)
Renames the designated table using the designated new name.
|
boolean |
sequenceExists(java.lang.String sequenceName)
Returns whether a sequence with the given name exists.
|
void |
setDefaultLockTimeout()
Sets the default value for the lock timeout for this connection.
|
long |
setLockTimeout(long timeout)
Sets the lock timeout for the current transaction in this connection to the
designated timeout (in milliseconds) and returns the current lock timeout.
|
void |
setSchemaVersion(java.lang.String serviceName,
int version)
Sets the version number associated with the current database structure of
the given service name.
|
boolean |
supportsIntersect()
Gets whether the underlying DBMS supports intersect.
|
boolean |
tableExists(java.lang.String tableName)
Returns whether the table (or the view) with the provided name exists in
the database.
|
java.lang.String |
toUpperCase(java.lang.String s)
Gets the designated string converted to upper case as suggested by the underlying
database-management system.
|
void |
updateColumnsNullable(java.lang.String tableName,
boolean nullable,
java.lang.String... columns)
Sets the designated columns of the designated table nullable (not
nullable).
|
void |
updateColumnType(java.lang.String tableName,
java.lang.String columnName,
java.lang.String correspondingDbType)
Sets the type of the designated column of the designated table to the
provided one.
|
java.lang.String |
useLockTimeout(java.lang.String query,
long timeout)
Appends the designated lock timeout in milliseconds to the designated query
(DDL and DML are not supported!).
|
abort, clearWarnings, close, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getHoldability, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, isClosed, isReadOnly, isValid, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMapstatic final int DEFAULT_MAX_STATEMENT_LENGTH
getMaxStatementLength()static final int DEFAULT_MAX_PARAMETER_COUNT
getMaxParameterCount()static final int DEFAULT_MAX_IN_OPERATOR_PARAMETER_COUNT
getMaxInOperatorParameterCount()DatabaseName getDatabaseName()
java.lang.String getEXCEPTKeyword()
java.lang.String toUpperCase(java.lang.String s)
Locale.ENGLISH will be
used. s - The string which to convert to upper case.boolean supportsIntersect()
java.lang.String getStringComparison(java.lang.String tableName,
java.lang.String columnName,
java.lang.String tableAlias,
int type,
int length,
boolean equal)
? with the real content of the string. getColumnType(String, String) to determine it once and reuse it.
Depending on the data type, the comparison is determined. For instance,
most DBMS do not allow to compare CLOB.
Do not rely on the data type specified when creating the designated column!
For instance long character columns may be CLOB instead of the
data type provided when creating the column.
Make sure that the provided string to compare is never null!
While null in the designated column will be handled
appropriately, providing a null string will usually not work.
tableName - The name of the table which contains the column.columnName - The name of column which to compare.tableAlias - The table alias to be used as prefix of the column in the
statement. Do not provide the separating . as this
will be added appropriately by the method. If null is
provided, the column name will have no prefix.type - The JDBC data type of the designated column. Use
getColumnType(String, String) for determining it.length - The length of the string. When reusing the prepared statement
for several strings, use the longest one. This allows the
underlying database to cast to VARCHAR for comparing.equal - Whether to compare the strings for whether they are equal (or
whether they are not).java.lang.String getTimeDifference(java.lang.String column,
long seconds)
CURRENT_TIMESTAMP. CURRENT_TIMESTAMP to compare with that column.column - The (fully-qualified) name of the column which contains the time/date/timestamp.
This may also be a pseudo-column.seconds - The difference in seconds (!!) which to add or remove from the time in the
designated column.java.lang.String getDropForeignKeyConstraintKeyword()
ALTER TABLE <tableName> DROP <b>CONSTRAINT</b> <constraintName>ALTER TABLE <tableName> DROP <b>FOREIGN KEY</b> <constraintName>CONSTRAINT or FOREIGN KEY, whichever is
appropriate for the DBMSjava.lang.String getAddForeignKey(de.aristaflow.adept2.base.dbaccess.model.ForeignKey fk,
boolean quoteIdentifiers)
throws java.sql.SQLException
ALTER TABLE which adds the designated
foreign key.fk - The definition of the foreign key to be added.quoteIdentifiers - Whether identifiers should be quoted.ALTER TABLE statement for
adding the designated foreign key.java.sql.SQLException - If there are problems retrieving the required meta
data or the foreign key cannot be created, an
SQLException will be thrown.java.lang.String getCorrespondingDBType(int jdbcTypeCode)
A call to this method is equivalent to
getCorrespondingDBType(jdbcTypeCode, -1, -1). See
getCorrespondingDBType(int, int, int).
jdbcTypeCode - the JDBC type code that should be mapped to a vendor
specific SQL type stringjava.lang.String getCorrespondingDBType(int jdbcTypeCode,
int size)
A call to this method is equivalent to
getCorrespondingDBType(jdbcTypeCode, size, -1). See
getCorrespondingDBType(int, int, int).
jdbcTypeCode - the JDBC type code that should be mapped to a vendor
specific SQL type stringsize - the desired size of the type (i.e. length for string and binary
types, precision for number types or fractional seconds for time
types); use negative value to indicate that size is not usedjava.lang.String getCorrespondingDBType(int jdbcTypeCode,
int size,
int scale)
Please be aware that binary or character types may be mapped to their LOB
variants if the specified size doesn't allow the smaller types. This might
however lead to problems when setting or getting the values in the regular
way. E.g. ResultSet.getString(int) might not always work for CLOBs
or only up to a certain size.
Character types will be translated to Unicode-capable data types if available. Generally, the following types are supported. Implementations are allowed to also support the remaining JDBC types but the requirements for those aren't very clear. E.g. are size and scale enough for them as parameters? Negative values for size and scale indicate that they are not specified.
TODO: Add support for size in CLOB and BLOB?
jdbcTypeCode - the JDBC type code that should be mapped to a vendor
specific SQL type stringsize - the desired size of the type (i.e. length for string and binary
types, precision for number types or fractional seconds for time
types); use negative value to indicate that size is not usedscale - only used for some number types and determines the precision
after the decimal point; use negative value to indicate that scale
is not usednull if the type is not supportedjava.lang.IllegalArgumentException - if the combination of JDBC type code, size
and scale is illegal, e.g. if scale or size is set for
Types.INTEGERjava.lang.String formatValue(java.lang.Object value,
int typeCode)
Types) determines
the target type. The main intention for this method is to be an alternative
where it is not easily possible to use PreparedStatements,
e.g. in highly dynamic and complex queries.
Please be aware that string escaping may not have been implemented in a
100% safe way due to lacking specifications for each database. So for
strings it's much safer to use
PreparedStatements to
prevent any kind of SQL injection.
This method may throw a runtime exception if object type of the value and type code don't fit together. However it does NOT guarantee to do so, which may result in improperly formatted or even illegal values.
For all date-related types (i.e. DATE, TIME and TIMESTAMP) not only
Date is allowed, but also Date,
Time and Timestamp.
A null value will result in the string "null".
Booleans are properly formatted to 1 or 0 if the target
type is Types.BIT.
value - the value to formattypeCode - the JDBC type code of the target typeboolean tableExists(java.lang.String tableName)
throws java.sql.SQLException
tableName - The name of the table (or the view) to look for.true if the table exists in the database, otherwise
false.java.sql.SQLException - If a database access error occurs, a
SQLException will be thrown.void renameTable(java.lang.String oldName,
java.lang.String newName)
throws java.sql.SQLException
oldName - The name of the table which to rename.newName - The new name of the table.java.sql.SQLException - If a database access error occurs, the specified table
name is invalid, a SQLException will be thrown.java.util.Collection<java.lang.String> getAllTableNames()
throws java.sql.SQLException
java.sql.SQLException - If a database access error occurs, a
SQLException will be thrown.boolean columnExists(java.lang.String columnName,
java.lang.String tableName)
throws java.sql.SQLException
columnName - The name of the column to look for.tableName - The name of the table in which to look for the column.true if the column exists in the table, otherwise
false.java.sql.SQLException - If a database access error occurs or the specified
table name is invalid, a SQLException will be
thrown.void addColumn(java.lang.String tableName,
java.lang.String columnName,
java.lang.String correspondingDbType)
throws java.sql.SQLException
getCorrespondingDBType(int) or one of the overloaded methods
to determine the database-specific type of the column. update the
column afterwards.tableName - The name of the table to which to add a new column.columnName - The name of column which to add.correspondingDbType - The string representation of the desired type of
the column. Use the string returned by
getCorrespondingDBType(int) (or the overloaded methods).java.sql.SQLException - If a database access error occurs, the specified table
name or column name is invalid, a SQLException
will be thrown.void updateColumnType(java.lang.String tableName,
java.lang.String columnName,
java.lang.String correspondingDbType)
throws java.sql.SQLException
getCorrespondingDBType(int) or one of the
overloaded methods to determine the database-specific type of the column.
Note that not all DBMS support shortening the type of a column, for instance Derby. This requires creating a new column, copying the data, dropping the old column and renaming the new one. Do not forget to handle indexes and key columns appropriately if required.
tableName - The table containing the column to change the data type.columnName - The name of the column to change the data type.correspondingDbType - The string representation of the desired type of
the column. Use the string returned by
getCorrespondingDBType(int) (or the overloaded methods).java.sql.SQLException - If a database access error occurs, the specified table
name or column name is invalid, a SQLException
will be thrown.void updateColumnsNullable(java.lang.String tableName,
boolean nullable,
java.lang.String... columns)
throws java.sql.SQLException
SQLException.tableName - The table containing the columns to change the
nullable-state.nullable - Whether the columns should allow null values or not.columns - The names of the columns to change the nullable-state.java.sql.SQLException - If there are problems checking the metadata or
changing the nullable-state, an SQLException will be
thrown.void renameColumn(java.lang.String tableName,
java.lang.String oldColumnName,
java.lang.String newColumnName)
throws java.sql.SQLException
ALTER TABLE RENAME COLUMN statement.tableName - The name of the table to which to rename a column.oldColumnName - The old name of column which to rename.newColumnName - The new name of the column.java.sql.SQLException - If a database access error occurs, the specified table
name or column name is invalid, a SQLException
will be thrown.void dropColumn(java.lang.String tableName,
java.lang.String columnName)
throws java.sql.SQLException
ALTER TABLE DROP COLUMN statement.
Do not try to drop columns that are referenced in any (primary key, foreign key, unique, ...) constraints. This may have unpredictable results or even fail (in a data-destroying way).
tableName - The name of the table of which the column type is of
interest.columnName - The name of column of which the type is of interest.java.sql.SQLException - If a database access error occurs, the specified table
name or column name is invalid, a SQLException
will be thrown.java.lang.String[] getColumnNames(java.lang.String tableName)
throws java.sql.SQLException
tableName - The name of the table of which the column names are of
interest.java.sql.SQLException - If a database access error occurs or the specified
table name is invalid, a SQLException will be
thrown.int getColumnType(java.lang.String columnName,
java.lang.String tableName)
throws java.sql.SQLException
java.sql.Types.tableName - The name of the table of which the column type is of
interest.columnName - The name of column of which the type is of interest.java.sql.Types.java.sql.SQLException - If a database access error occurs or the specified
table name or column name is invalid, a SQLException
will be thrown.Typesint getMaxStatementLength()
int getMaxParameterCount()
int getMaxInOperatorParameterCount()
boolean isTableMissing(java.sql.SQLException ex)
ex - the exception to be testedboolean isUniqueViolation(java.sql.SQLException ex)
ex - the exception to be testedboolean isForeignKeyViolation(java.sql.SQLException ex)
ex - the exception to be testedboolean isLockTimeout(java.sql.SQLException ex)
table lock.ex - The exception to be testedboolean isSyntaxError(java.sql.SQLException ex)
ex - The exception to be testedjava.sql.Timestamp getCurrentTime()
throws java.sql.SQLException
java.sql.SQLException - If there are problems retrieving the current time, an
SQLException will be thrown.void createSequence(java.lang.String sequenceName,
long start,
long increment)
throws java.sql.SQLException
sequenceName - the name of the sequence to be createdstart - the initial value of the sequence, i.e. the first value that
will be returned by nextID(String); may be negativeincrement - the value by which to increment the ID after a call to
nextID(String); may be negativejava.sql.SQLException - if a database access error occursvoid dropSequence(java.lang.String sequenceName)
throws java.sql.SQLException
sequenceName - the name of the sequence to be droppedjava.sql.SQLException - if a database access error occurs or the specified
sequence doesn't existboolean sequenceExists(java.lang.String sequenceName)
throws java.sql.SQLException
sequenceName - the sequence to be testedjava.sql.SQLException - if a database access error occurslong nextID(java.lang.String sequenceName)
throws java.sql.SQLException
sequenceName - the sequence from which to return the next IDjava.sql.SQLException - if a database access error occursvoid lockTable(java.lang.String tableName,
long timeout)
throws java.sql.SQLException,
java.util.concurrent.TimeoutException
This connection needs to have auto-commit disabled. The table lock is held until the end of the transaction! So be sure to not hold any other locks and usually use a separate transaction for locking the table unless modifying the very same table.
tableName - The name of the table which to lock. This table has to
exist.timeout - The wait time in milliseconds. Use 0 to not wait at all
(just try to lock) or a negative value to wait forever.java.sql.SQLException - If there are problems locking the designated table, an
SQLException will be thrown.java.util.concurrent.TimeoutException - If the designated timeout elapsed before the lock
can be acquired, a TimeoutException will be thrown.java.lang.String useLockTimeout(java.lang.String query,
long timeout)
throws java.sql.SQLException
NOWAIT as
well as waiting forever.
Note that not all DBMS support a lock timeout for each query separately.
These will return the designated query unchanged. In this case you need to
set the lock timeout for the transaction temporarily using
setLockTimeout(long).
DBMS not supporting a lock timeout will also return the designated query unchanged.
query - The query which should use a specific lock timeout.timeout - The lock timeout in milliseconds. Use 0 to not wait at all,
use -1 to wait forever.java.sql.SQLException - If there are problems appending the lock timeout, e.g.
when accessing the meta data of the designated connection, an
SQLException will be thrown.long setLockTimeout(long timeout)
throws java.sql.SQLException
finally.
Note that not all DBMS support a lock timeout for a transaction but require
the lock timeout for each query separately. So you need to
setLockTimeout(long) as well as
useLockTimeout(String, long).
Note that not all DBMS support a dynamic lock timeout. These will throw an
UnsupportedOperationException.
timeout - The lock timeout in milliseconds. Use 0 to not wait at all,
use -1 to wait forever.java.sql.SQLException - If there are problems setting the lock timeout, an
SQLException will be thrown.void setDefaultLockTimeout()
throws java.sql.SQLException
java.sql.SQLException - If there are problems setting the lock timeout, an
SQLException will be thrown.int getSchemaVersion(java.lang.String serviceName)
throws java.sql.SQLException
serviceName - the service name (e.g. the simple name of the main interface)java.sql.SQLExceptionvoid setSchemaVersion(java.lang.String serviceName,
int version)
throws java.sql.SQLException
serviceName - the service name (e.g. the simple name of the main interface)version - the new versionjava.sql.SQLExceptionvoid dropSchemaVersion(java.lang.String serviceName)
throws java.sql.SQLException
java.sql.SQLExceptionjava.lang.String createRecursionTable(java.lang.String[] selectAttributes,
java.lang.String tableName,
java.lang.String startCondition,
ParentToChildConnection[] parentToChildConnections,
int maxDepth)
throws java.sql.SQLException
Therefore not all features are supported. The main restriction are the SELECT-attributes. They are always from the current recursion step which means a tuple always contains only values from the child tables. There are no tuples containing (joined) parent and child attributes. Further aggregation is not supported. This can be achieved by grouping all resulting tuples by their level.
Following are examples for translations of the method parameters to DB2- and Oracle-syntax. in DB2:
CREATE TABLE return AS
WITH RecRel(Depth, selectAttributes[]) AS
(SELECT 1, selectAttributes[]
FROM tableName
WHERE startCondition
UNION ALL
SELECT Parent.Depth + 1, Child.selectAttributes[]
FROM RecRel AS Parent, tableName AS Child
WHERE Parent.parentToChildConnection[0].getParentAttribute()
parentToChildConnection[0].getOperator()
Child.parentToChildConnection[0].getChildAttribute()
AND Parent.parentToChildConnection[1].getParentAttribute()
parentToChildConnection[1].getOperator()
Child.parentToChildConnection[1].getChildAttribute()
AND ...
AND Parent.Depth < maxDepth
)
SELECT *
FROM RecRel
in Oracle:
CREATE TABLE return AS
SELECT Depth, selectAttributes[]
FROM tableName
START WITH startCondition
CONNECT BY PRIOR parentToChildConnection[0]
AND PRIOR parentToChildConnection[1]
AND ...
AND Depth <= maxDepth
selectAttributes - Array of the names of the columns to be in the
created recursion table. The names have to be valid column names
of the specified table.tableName - The name of the table which contains the hierarchical
data. If the hierarchical data spans several tables, a new
temporary table will have to be created by joining these tables.
Thus the name of the temporary table is to be used as parameter.startCondition - A string forming a valid WHERE-condition which
specifies the conditions which have to hold for the top-level
tuples respectively the tuples for the start of the recursion. The
string may be any valid WHERE-condition, even complex ones, as
long as it is understood by all database-management-systems. The
names have to be valid column names of the specified table.parentToChildConnections - An array consisting of
ParentToChildConnections that specify WHERE-conditions for joining
the hierarchical data. The individual ParentToChildConnections are
logically linked via AND. These can only contain columns that are
part of the selectAttributes.maxDepth - The maximum depth of the recursion/hierarchical level which
is needed. The recursions will stop when this depth is reached
even if not all tuples are reached.java.sql.SQLException - If a database access error occurs or the specified
attributes, the table name or the conditions are invalid, a
SQLException will be thrown.java.lang.String createRecursionTable(java.lang.String[] selectAttributes,
java.lang.String[] rootAttributes,
java.lang.String tableName,
java.lang.String startCondition,
ParentToChildConnection[] parentToChildConnections)
throws java.sql.SQLException
createRecursionTable(String[], String, String, ParentToChildConnection[], int)
but without a maximum depth. Here the recursion stops as soon as there are
no more tuples in a recursion step.
Following are examples for translations of the method parameters to DB2- and Oracle-syntax. in DB2:
CREATE TABLE return AS
WITH RecRel(Depth, selectAttributes[]) AS
(SELECT 1, selectAttributes[]
FROM tableName
WHERE startCondition
UNION ALL
SELECT Parent.Depth + 1, Parent.rootAttributes[], Child.selectAttributes[]
FROM RecRel AS Parent, tableName AS Child
WHERE Parent.parentToChildConnection[0].getParentAttribute()
parentToChildConnection[0].getOperator()
Child.parentToChildConnection[0].getChildAttribute()
AND Parent.parentToChildConnection[1].getParentAttribute()
parentToChildConnection[1].getOperator()
Child.parentToChildConnection[1].getChildAttribute()
AND ...
)
SELECT *
FROM RecRel
in Oracle:
CREATE TABLE return AS
SELECT Depth, CONNECT_BY_ROOT rootAttributes[], (additional) selectAttributes[]
FROM tableName
START WITH startCondition
CONNECT BY PRIOR parentToChildConnection[0]
AND PRIOR parentToChildConnection[1]
AND ...
selectAttributes - Array of the names of the columns to be in the
created recursion table. The names have to be valid column names
of the specified table.rootAttributes - Array of the names of columns of the root table, that
is, these values will be constant in each recursion step and
therefore stem from recursion initialisation. This is a subset of
the selectAttributes. If this is null,
each tuple from a recursion step will have new attributes.tableName - The name of the table which contains the hierarchical
data. If the hierarchical data spans several tables, a new
temporary table will have to be created by joining these tables.
Thus the name of the temporary table is to be used as parameter.startCondition - A string forming a valid WHERE-condition which
specifies the conditions which have to hold for the top-level
tuples respectively the tuples for the start of the recursion. The
string may be any valid WHERE-condition, even complex ones, as
long as it is understood by all database-management-systems. The
names have to be valid column names of the specified table.parentToChildConnections - An array consisting of
ParentToChildConnections that specify WHERE-conditions for joining
the hierarchical data. The individual ParentToChildConnections are
logically linked via AND. These can only contain columns that are
part of the selectAttributes.java.sql.SQLException - If a database access error occurs or the specified
attributes, the table name or the conditions are invalid, a
SQLException will be thrown.void dropAllRecursionTables()
throws java.sql.SQLException
createRecursionTable(String[],
String, String, String[], int) are dropped. This needs to be done to
clean up the database. The corresponding table names are stored internally
and need not be provided.java.sql.SQLException - If a database access error occurs, a
SQLException will be thrown.createRecursionTable(String[], String[], String, String,
ParentToChildConnection[])void dropRecursionTable(java.lang.String tableName)
throws java.sql.SQLException
createRecursionTable(String[], String, String, String[], int)
is dropped. This needs to be done to clean up the database. If the provided
table has not been created by
createRecursionTable(String[], String, String,
String[], int),
the call will be ignored. If the table has been created by
createRecursionTable(String[], String, String, String[], int)
but does not exists in the database any more, a DBException
will be raised.
Implementors of this method have to take care not to drop the table again
in dropAllRecursionTables().
tableName - The name of the created temporary table. If it has not
been created by
createRecursionTable(String[], String, String,
String[], int),
the call will be ignored. If the table does otherwise not exist in
the database, a DBException will be raised.java.sql.SQLException - If a database access error occurs, a
SQLException will be thrown, especially if the
provided table does not exist.dropAllRecursionTables(),
createRecursionTable(String[], String, String,
ParentToChildConnection[], int)void registerIterator()
ExtendedConnection which
prevents this connection from being reclaimed in case it is pooled. A
pooled connection must not be reclaimed while an iterator is active.void deregisterIterator()
ExtendedConnection which
allows this connection to be reclaimed again in case it is not used any
more.