|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lapetus_ltd._2009.xml.types.XLptsDBStatementType
com.lapetus_ltd.api.db.control.TLptsStatement
public class TLptsStatement
Class Description : This is the statement class that implements the java.sql.Statement interface.
Field Summary |
---|
Fields inherited from class com.lapetus_ltd._2009.xml.types.XLptsDBStatementType |
---|
charset, columnListItem, connectionId, createRootItem, criteriaType, executable, id, sqlDatabaseFormat, sqlStatementExtension, sqlStatementModified, sqlStatementUnformatted, sqlStatementUser, sqlStringFormat, tableListItem, tableTypesView, title, typeOfStatement, upInsDelListItem, version, visible, xResultSetConcurrency, xResultSetType |
Fields inherited from interface java.sql.Statement |
---|
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO |
Constructor Summary | |
---|---|
TLptsStatement(TLptsConnection connection,
XLptsDBStatementType statementType)
This Constructor create a new Statement by setting only the connection and loading all the fields from another Statement. |
|
TLptsStatement(TLptsConnection connection,
XLptsDBTypeOfStatementType typeOfStatement)
Creates a new Statement by setting the connection and the type of the statement. |
Method Summary | ||
---|---|---|
void |
addBatch(java.lang.String sql)
Javadoc taken from Statement interface : Adds the given SQL command to the current list of commmands for this Statement object. |
|
void |
addPrimaryRelationship(int localColumnIndex,
int[] foreignColumnIndexes,
java.lang.String operation)
Adds a primary relationship of the current statement with the primary statement. |
|
void |
cancel()
Javadoc taken from Statement interface : Cancels this Statement object if both the DBMS and
driver support aborting an SQL statement. |
|
void |
clearBatch()
Javadoc taken from Statement interface : Empties this Statement object's current list of
SQL commands. |
|
void |
clearWarnings()
Javadoc taken from Statement interface : Clears all the warnings reported on this Statement
object. |
|
void |
close()
Javadoc taken from Statement interface : Releases this Statement object's database
and JDBC resources immediately instead of waiting for
this to happen when it is automatically closed. |
|
boolean |
closeWE()
Close current statement. |
|
boolean |
equals(java.lang.Object obj)
Compares the objects by their ID. |
|
boolean |
execute(java.lang.String sql)
Javadoc taken from Statement interface : Executes the given SQL statement, which may return multiple results. |
|
boolean |
execute(java.lang.String sql,
int autoGeneratedKeys)
Javadoc taken from Statement interface : Executes the given SQL statement, which may return multiple results, and signals the driver that any auto-generated keys should be made available for retrieval. |
|
boolean |
execute(java.lang.String sql,
int[] columnIndexes)
Javadoc taken from Statement interface : Executes the given SQL statement, which may return multiple results, and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval. |
|
boolean |
execute(java.lang.String sql,
java.lang.String[] columnNames)
Javadoc taken from Statement interface : Executes the given SQL statement, which may return multiple results, and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval. |
|
int[] |
executeBatch()
Javadoc taken from Statement interface : Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. |
|
java.sql.ResultSet |
executeQuery()
Executes the query of the selected statement. |
|
java.sql.ResultSet |
executeQuery(java.lang.String sql)
Javadoc taken from Statement interface : Executes the given SQL statement, which returns a single ResultSet object. |
|
int |
executeUpdate()
Executes an Update on a PreparedStatement. |
|
int |
executeUpdate(java.lang.String sql)
Javadoc taken from Statement interface : Executes the given SQL statement, which may be an INSERT ,
UPDATE , or DELETE statement or an
SQL statement that returns nothing, such as an SQL DDL statement. |
|
int |
executeUpdate(java.lang.String sql,
int autoGeneratedKeys)
Javadoc taken from Statement interface : Executes the given SQL statement and signals the driver with the given flag about whether the auto-generated keys produced by this Statement object
should be made available for retrieval. |
|
int |
executeUpdate(java.lang.String sql,
int[] columnIndexes)
Javadoc taken from Statement interface : Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval. |
|
int |
executeUpdate(java.lang.String sql,
java.lang.String[] columnNames)
Javadoc taken from Statement interface : Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval. |
|
TLptsStatement |
findTopPrimaryStatement()
Gets the top primary statement (level 1). |
|
java.util.List<java.lang.Integer> |
geSelectedColumnSqlTypeList()
Gets a list of SQL types for the currently selected columns of this statement. |
|
XLptsDBStatementColumnType |
getColumnItemById(java.lang.String id)
Gets a column by it's ID. |
|
XLptsDBStatementColumnType |
getColumnItemByName(java.lang.String tableName,
java.lang.String columnName)
Gets a column by it's name and table name. |
|
java.util.List<XLptsDBStatementColumnType> |
getColumnItemsForTable(java.lang.String tableName)
Gets a list with all the columns for a table. |
|
java.util.List<XLptsDBStatementColumnType> |
getColumnListItem()
Gets a copy of the actual list of all columns from current datasource. |
|
java.sql.Connection |
getConnection()
Javadoc taken from Statement interface : Retrieves the Connection object (TLptsConnection)
that produced this Statement object. |
|
java.sql.Connection |
getConnectionWE()
Retrieves the Connection object (TLptsConnection)
that produced this Statement object. |
|
int |
getFetchDirection()
Javadoc taken from Statement interface : Retrieves the direction for fetching rows from database tables that is the default for result sets generated from this Statement object. |
|
int |
getFetchSize()
Javadoc taken from Statement interface : Retrieves the number of result set rows that is the default fetch size for ResultSet objects
generated from this Statement object. |
|
java.sql.ResultSet |
getGeneratedKeys()
Javadoc taken from Statement interface : Retrieves any auto-generated keys created as a result of executing this Statement object. |
|
int |
getMaxFieldSize()
Javadoc taken from Statement interface : Retrieves the maximum number of bytes that can be returned for character and binary column values in a ResultSet
object produced by this Statement object. |
|
int |
getMaxRows()
Javadoc taken from Statement interface : Retrieves the maximum number of rows that a ResultSet object produced by this
Statement object can contain. |
|
boolean |
getMoreResults()
Javadoc taken from Statement interface : Moves to this Statement object's next result, returns
true if it is a ResultSet object, and
implicitly closes any current ResultSet
object(s) obtained with the method getResultSet . |
|
boolean |
getMoreResults(int current)
Javadoc taken from Statement interface : Moves to this Statement object's next result, deals with
any current ResultSet object(s) according to the instructions
specified by the given flag, and returns
true if the next result is a ResultSet object. |
|
int |
getQueryTimeout()
Javadoc taken from Statement interface : Retrieves the number of seconds the driver will wait for a Statement object to execute. |
|
java.sql.ResultSet |
getResultSet()
Javadoc taken from Statement interface : Retrieves the current result as a ResultSet object. |
|
int |
getResultSetConcurrency()
Javadoc taken from Statement interface : Retrieves the result set concurrency for ResultSet objects
generated by this Statement object. |
|
int |
getResultSetHoldability()
Javadoc taken from Statement interface : Retrieves the result set holdability for ResultSet objects
generated by this Statement object. |
|
int |
getResultSetType()
Javadoc taken from Statement interface : Retrieves the result set type for ResultSet objects
generated by this Statement object. |
|
TLptsRowSet |
getRowSet()
Gets the RowSet for this statement after execution. |
|
XLptsDBStatementColumnType |
getSelectedColumnItemByIndex(int index)
Gets the selected column by it's INDEX. |
|
java.util.List<XLptsDBStatementColumnType> |
getSelectedColumnList()
This function returns the columns that are currently selected for this statement. |
|
java.util.List<java.lang.String> |
getSelectedColumnNameList()
Gets a list of names for the currently selected columns of this statement. |
|
java.lang.String |
getSqlStatementExtension()
This is an override of the XLptsDBStatementType getSqlStatementExtension. |
|
java.lang.String |
getSqlStatementFormatted()
Gets the formatted SQL String for the current statement after setting statement parameters. |
|
int |
getSqlType(int sqlColumnIndex)
Gets the SQL Type for the selected column index. |
|
XLptsDBSqlStringFormatType |
getStandardSqlFormat(XLptsDBSqlDatabaseFormat type)
Gets the SQL String formats for the standard types, like MS SQL, MySql, Postgres and ODBC. |
|
XLptsDBStatementTableType |
getTableItemById(java.lang.String tableId)
Gets a specific table by it's id. |
|
XLptsDBStatementTableType |
getTableItemByName(java.lang.String tableName)
Gets a table by name. |
|
java.util.List<XLptsDBStatementTableType> |
getTableListItem()
Gets a copy of the actual table list for this statement. |
|
int |
getUpdateCount()
Javadoc taken from Statement interface : Retrieves the current result as an update count; if the result is a ResultSet object or there are no more results, -1
is returned. |
|
java.util.List<XLptsDBUpInsDelType> |
getUpInsDelListItem()
Gets a copy of the list of items to be used for update/insert/delete processing on this statement. |
|
java.sql.SQLWarning |
getWarnings()
Javadoc taken from Statement interface : Retrieves the first warning reported by calls on this Statement object. |
|
boolean |
hasDynamicSubStatement()
Tells us if the current statement has a dynamic sub-statement (ie is a primary statement). |
|
boolean |
hasPrimaryStatement()
Tells us if this statement has a primary statement (ie if it is dynamic). |
|
void |
initTablesAndColumns(int tableTypes)
Loads the specified types of tables, and their columns, into the current statement. |
|
void |
interruptExecution()
Interrupts current statement execution. |
|
boolean |
isClosed()
Javadoc taken from Statement interface : Retrieves whether this Statement object has been closed. |
|
boolean |
isInterrupted()
Tells us if the statement execution was interrupted. |
|
boolean |
isPoolable()
Javadoc taken from Statement interface : Returns a value indicating whether the Statement
is poolable or not. |
|
boolean |
isWrapperFor(java.lang.Class<?> iface)
Javadoc taken from Statement interface : Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does. |
|
void |
resetAllTablesAndColumns()
Deselects all tables and columns for the current statement. |
|
void |
setCursorName(java.lang.String name)
Javadoc taken from Statement interface : Sets the SQL cursor name to the given String , which
will be used by subsequent Statement object
execute methods. |
|
void |
setEscapeProcessing(boolean enable)
Javadoc taken from Statement interface : Sets escape processing on or off. |
|
void |
setFetchDirection(int direction)
Javadoc taken from Statement interface : Gives the driver a hint as to the direction in which rows will be processed in ResultSet
objects created using this Statement object. |
|
void |
setFetchSize(int rows)
Javadoc taken from Statement interface : Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for ResultSet objects genrated by this Statement . |
|
void |
setMaxFieldSize(int max)
Javadoc taken from Statement interface : Sets the limit for the maximum number of bytes that can be returned for character and binary column values in a ResultSet
object produced by this Statement object. |
|
void |
setMaxRows(int max)
Javadoc taken from Statement interface : Sets the limit for the maximum number of rows that any ResultSet object generated by this Statement
object can contain to the given number. |
|
void |
setObject(int i,
java.lang.Object obj,
int sqlType)
Sets an object for substitution at runtime (replaces the ? |
|
void |
setPoolable(boolean poolable)
Javadoc taken from Statement interface : Requests that a Statement be pooled or not pooled. |
|
void |
setPrimaryStatement(java.lang.String primaryStatementId,
boolean isSubstituteValueIntoSQLString)
Sets the primary statement for the current statement. |
|
void |
setQueryTimeout(int seconds)
Javadoc taken from Statement interface : Sets the number of seconds the driver will wait for a Statement object to execute to the given number of seconds. |
|
void |
setSelectOnAllColumns(java.lang.String tableName,
boolean isSelect)
Sets all the columns for a specific table to be SELECTED or NOT in the SQL statement. |
|
void |
setSqlDatabaseFormat(XLptsDBSqlDatabaseFormat value)
Sets the quotation format for current statement. |
|
void |
setSqlStatementExtension(java.lang.String value)
This is an override of the XLptsDBStatementType setSqlStatementExtension. |
|
void |
setSqlStatementUser(java.lang.String value)
This is an override of XLptsDBStatementType.setSqlStatementUser(String) . |
|
void |
setTitle(java.lang.String value)
Overrides of function from XLptsDBStatementType : Sets the title of the statement. |
|
|
unwrap(java.lang.Class<T> iface)
Javadoc taken from Statement interface : Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy. |
|
void |
zaCLI(XLptsDBStatementColumnType sct)
Obfuscated as it is not required by the application interface. |
|
void |
zaTLI(XLptsDBStatementTableType stt)
Obfuscated as it is not required by the application interface. |
|
void |
zaUIDLI(XLptsDBUpInsDelType uidt)
Obfuscated as it is not required by the application interface. |
|
void |
zcUIDLI()
Obfuscated as it is not required by the application interface. |
|
int |
zgCI(XLptsDBStatementColumnType column)
Obfuscated as it is not required by the application interface. |
|
java.util.List<com.lapetus_ltd.api.db.control.TLptsStatement.SetObjectClass> |
zgOL()
Obfuscated. |
|
java.lang.String |
zgSSS()
Obfuscated as it is not required by the application interface. |
|
boolean |
ziSS()
Obfuscated as it is not required by the application interface. |
|
boolean |
zpPR()
Obfuscated as it is not required by the application interface. |
|
void |
zrc(XLptsDBStatementColumnType sct)
Obfuscated as it is not required by the application interface. |
|
void |
zrI()
Obfuscated as it is not required by the application interface. |
|
void |
zrTLI(XLptsDBStatementTableType stt)
Obfuscated as it is not required by the application interface. |
|
void |
zrUIDLI(XLptsDBUpInsDelType uidt)
Obfuscated as it is not required by the application interface. |
|
void |
zsOL()
Obfuscated. |
|
void |
zsR(TLptsRowSet rowSet)
Obfuscated as it is not required by the application interface. |
|
void |
zsS(java.sql.Statement statement)
Obfuscated as it is not required by the application interface. |
|
void |
zsSS(boolean setSub)
Obfuscated as it is not required by the application interface. |
|
void |
zsSSS(java.lang.String sql)
Obfuscated as it is not required by the application interface. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TLptsStatement(TLptsConnection connection, XLptsDBStatementType statementType)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : No
Notes :
Example :
TLptsConnection connection; TLptsStatement statement; ... //load project from XML files XLptsDBStatementType statementType //statement loaded from project statement = new TLptsStatement(connection,statementType);
connection
- is the statement's connectionstatementType
- is the statement to load values frompublic TLptsStatement(TLptsConnection connection, XLptsDBTypeOfStatementType typeOfStatement)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : No
Notes : Types of statement are: SELECT, CREATE, UPDATE, INSERT, DELETE
Example :
// lets create a simple statement with one table and all columns selected. TLptsStatement statement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); // set the table and columns for selecting XLptsDBStatementTableType table = statement.getTableItemByName(tableName); table.setSelected(true); statement.setSelectOnAllColumns(tableName, true); statement.getCriteriaType().setType(XLptsDBCriteriaType.NONE); statement.setTitle(tableName); System.out.println("SQL Statement " + statement.getTitle() + ": " + statement.getSqlStatementFormatted()); TLptsFactoryStatement.createNewStatement(connection,statement); // then catch with the factory statement listener OR TLptsFactoryRowSet.executeSelectStatement(statement); // then catch with the factory rowset listener ------------ OR A SIMPLE CASE WITH THE NORMAL RESULTSET PROCESSING ---------------- TLptsStatement statement = new TLptsStatement(lptsConnection, XLptsDBTypeOfStatementType.SELECT); XLptsDBStatementTableType table = statement.getTableItemByName(TABLE_NAME); if (table == null) return ; table.setSelected(true); statement.setSelectOnAllColumns(table.getTableName(), true); statement.setSqlDatabaseFormat(XLptsDBSqlDatabaseFormat.DEFAULT_MYSQL); statement.getCriteriaType().setType(XLptsDBCriteriaType.NONE); statement.setTitle("NAME"); try { PreparedStatement stmt = lptsConnection.prepareStatement(statement.getSqlStatementFormatted()); ResultSet rs = stmt.executeQuery(statement.getSqlStatementFormatted()); while (rs.next()) { if (rs.getString(COLUMN_1)!=null) if (rs.getString(COLUMN_2)!=null) if (rs.getString(COLUMN_3)!=null) processData(rs.getString(COLUMN_1),rs.getString(COLUMN_2),rs.getString(COLUMN_3)) ; } } catch (Exception e) { // react }
connection
- is the statement's connectiontypeOfStatement
- is the type of new statementMethod Detail |
---|
public void addBatch(java.lang.String sql) throws java.sql.SQLException
Statement
object. The commands in this list can be
executed as a batch by calling the method executeBatch
.
addBatch
in interface java.sql.Statement
sql
- typically this is a SQL INSERT
or
UPDATE
statement
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
or the
driver does not support batch updatesexecuteBatch()
,
DatabaseMetaData.supportsBatchUpdates()
public void addPrimaryRelationship(int localColumnIndex, int[] foreignColumnIndexes, java.lang.String operation)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
This function is always accompanied by setPrimaryStatement(java.lang.String, boolean)
.
THE PRIMARY STATEMENT NEEDS TO BE SET BEFORE WE CALL THIS FUNCTION.
Together these functions specify a link or relationship between two statements.
The statement that calls these functions is the dynamic statement, which means that it is executed with every row
of the primary statement, taking the values specified from the primary statement's current row and substituting
them into the current statement and then execute the resultset.
In the example below we have 3 statements, namely Customers, Accounts and transactions. Customer is the top primary
and feeds data to account. For every account of the current customer, data is fed to the transactions so that we have
a 3 level dynamic statement relationship. There is no limit to the number of levels we can declare and execute.
This brings about one or many rowsets per customer for accounts, and one or many rowsets per account for transactions.
So in the end there is a tree or rowsets built, with the customer statement as the top level.
Each row comes down to the application with identification as to its statement, rowset and own id. The application can
then easily map the rows to a hierarchy structure (as shown in TLptsRowEvent.getRowObjectList()
).
Example :
...
// first we create the customer, account and transaction statements. Then we dynamically link them.
// once they are linked, dbJAPI will process the hole structure and provide each record, one at a time, to the application
// through the listener, with reference to its position in the structure. The application can then process the records as
// required, with the correct structure. (like the data view window does TLptsViewDataDialog
)
TLptsStatement customerStatement, transStatement, itemStatement;
////////////////////////////////// CUSTOMER ////////////////////////////////////
// contains all the tables and columns of the connection. We need to select some or input a SQL string manually
customerStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT);
customerStatement.setTitle("CUSTOMERS");
// the quotations are for ODBC
customerStatement.setSqlDatabaseFormat(XLptsDBSqlDatabaseFormat.DEFAULT_MYSQL);
XLptsDBStatementTableType table = customerStatement.getTableItemByName("CUSTOMERS");
table.setSelected(true); // selecting one table only, with all its columns
customerStatement.setSelectOnAllColumns(table.getTableName(), true);
// make sure this is not processed as we are waiting for the dynamic statements below to be created.
customerStatement.setExecutable(false);
TLptsFactoryStatement.createNewStatement(connection, customerStatement);
////////////////////////////////// ACCOUNT ////////////////////////////////////
accountStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT);
accountStatement.setTitle("TRANSACTIONS");
accountStatement.setSqlDatabaseFormat(XLptsDBSqlDatabaseFormat.DEFAULT_MYSQL);
table = accountStatement.getTableItemByName("TRANSACTIONS");
table.setSelected(true); // selecting one table only, with all its columns
accountStatement.setSelectOnAllColumns(table.getTableName(), true); // select all the columns and the select statement SQL string will be created automatically.
// relate this statement to the customer statement (this means that 'customer' will feed the data to this statement for every record of 'customer' to regenerate this statement every time)
accountStatement.setPrimaryStatement(customerStatement.getId(),false); // false means that we do not want static string substitution (uses the setObject of Statement)
accountStatement.addPrimaryRelationship(2,new int[] {1}, TLptsFactoryStatement.OPERATION_EQUAL); // column 2 in this statement is related to column 1 in customer
// certain operations allow for many indexes (like IN and BETWEEN)
// make sure this is not processed as we are waiting for the dynamic statement below to be created.
accountStatement.setExecutable(false);
TLptsFactoryStatement.createNewStatement(connection, accountStatement);
////////////////////////////////// TRANSACTION ////////////////////////////////////
transStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT);
transStatement.setTitle("TRANSACTIONS");
transStatement.setSqlDatabaseFormat(XLptsDBSqlDatabaseFormat.DEFAULT_MYSQL);
table = transStatement.getTableItemByName("TRANSACTIONS");
table.setSelected(true); // selecting one table only, with all its columns
transStatement.setSelectOnAllColumns(table.getTableName(), true); // select all the columns and the select statement SQL string will be created automatically.
// relate this statement to the account statement (this means that 'account' will feed the data to this statement for every record of 'account' to regenerate this statement every time)
transStatement.setPrimaryStatement(accountStatement.getId(),false); // false means that we do not want static string substitution (false uses the setObject of Statement)
transStatement.addPrimaryRelationship(2,new int[] {1}, TLptsFactoryStatement.OPERATION_EQUAL); // column 2 in this statement is related to column 1 in account
// certain operations allow for many indexes (like IN and BETWEEN)
// this statement can be processed now that all the statements are ready and created. This will execute the others dynamically
transStatement.setExecutable(false);
TLptsFactoryStatement.createNewStatement(connection, transStatement);
...
localColumnIndex
- The index of the column in the current statement (1 based) to link to the other statement with the operation below.foreignColumnIndexes
- The index (1 based) of the column in the primary statement to link to this statement's column at localColumnIndex.operation
- This is the operation that in put into the where clause for these columns. This is then processed by the SQL processor of the
data source so that the resultset can be formed.public void cancel() throws java.sql.SQLException
Statement
object if both the DBMS and
driver support aborting an SQL statement.
This method can be used by one thread to cancel a statement that
is being executed by another thread.
cancel
in interface java.sql.Statement
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
java.sql.SQLFeatureNotSupportedException
- if the JDBC driver does not support
this methodpublic void clearBatch() throws java.sql.SQLException
Statement
object's current list of
SQL commands.
clearBatch
in interface java.sql.Statement
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
or the
driver does not support batch updatesaddBatch(java.lang.String)
,
DatabaseMetaData.supportsBatchUpdates()
public void clearWarnings() throws java.sql.SQLException
Statement
object. After a call to this method,
the method getWarnings
will return
null
until a new warning is reported for this
Statement
object.
clearWarnings
in interface java.sql.Statement
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
public void close() throws java.sql.SQLException
Statement
object's database
and JDBC resources immediately instead of waiting for
this to happen when it is automatically closed.
It is generally good practice to release resources as soon as
you are finished with them to avoid tying up database
resources.
Calling the method close
on a Statement
object that is already closed has no effect.
Note:When a Statement
object is
closed, its current ResultSet
object, if one exists, is
also closed.
close
in interface java.sql.Statement
java.sql.SQLException
- if a database access error occurspublic boolean closeWE()
Close current statement.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : No
Notes :
Example :
private class RowSetListener implements ILptsFactoryRowSetListener { public void rowEvent(TLptsRowEvent rowEvent) { if(rowEvent.getEventType()==TLptsRowEvent.EVENT_TYPE.EXECUTION_INTERRUPTED) { if(rowEvent.getStatement().isInterrupted()) { if(rowEvent.getStatement().close()) System.out.println("Process Complete, statement close successfully"); else System.out.println("Process Complete, statement did not close"); } } else { if(rowEvent.getStatement().getId().equals(statementId)) if(rowEvent.getCurrentRowNo()> desiredNumberOfProcessedRows) rowEvent.getStatement().interruptExecution(); } } public boolean processNewRowSetRows(TLptsRowSetEvent rowSetEvent) { return true; } }
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- An object of type TLptsStatement.
public boolean execute(java.lang.String sql) throws java.sql.SQLException
execute
method executes an SQL statement and indicates the
form of the first result. You must then use the methods
getResultSet
or getUpdateCount
to retrieve the result, and getMoreResults
to
move to any subsequent result(s).
execute
in interface java.sql.Statement
sql
- any SQL statement
true
if the first result is a ResultSet
object; false
if it is an update count or there are
no results
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
getResultSet()
,
getUpdateCount()
,
getMoreResults()
public boolean execute(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
INSERT
statement, or an SQL statement able to return
auto-generated keys (the list of such statements is vendor-specific).
In some (uncommon) situations, a single SQL statement may return
multiple result sets and/or update counts. Normally you can ignore
this unless you are (1) executing a stored procedure that you know may
return multiple results or (2) you are dynamically executing an
unknown SQL string.
The execute
method executes an SQL statement and indicates the
form of the first result. You must then use the methods
getResultSet
or getUpdateCount
to retrieve the result, and getMoreResults
to
move to any subsequent result(s).
execute
in interface java.sql.Statement
sql
- any SQL statementautoGeneratedKeys
- a constant indicating whether auto-generated
keys should be made available for retrieval using the method
getGeneratedKeys
; one of the following constants:
Statement.RETURN_GENERATED_KEYS
or
Statement.NO_GENERATED_KEYS
true
if the first result is a ResultSet
object; false
if it is an update count or there are
no results
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
or the second
parameter supplied to this method is not
Statement.RETURN_GENERATED_KEYS
or
Statement.NO_GENERATED_KEYS
.
java.sql.SQLFeatureNotSupportedException
- if the JDBC driver does not support
this method with a constant of Statement.RETURN_GENERATED_KEYSgetResultSet()
,
getUpdateCount()
,
getMoreResults()
,
getGeneratedKeys()
public boolean execute(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
INSERT
statement, or an SQL statement able to return
auto-generated keys (the list of such statements is vendor-specific).
Under some (uncommon) situations, a single SQL statement may return
multiple result sets and/or update counts. Normally you can ignore
this unless you are (1) executing a stored procedure that you know may
return multiple results or (2) you are dynamically executing an
unknown SQL string.
The execute
method executes an SQL statement and indicates the
form of the first result. You must then use the methods
getResultSet
or getUpdateCount
to retrieve the result, and getMoreResults
to
move to any subsequent result(s).
execute
in interface java.sql.Statement
sql
- any SQL statementcolumnIndexes
- an array of the indexes of the columns in the
inserted row that should be made available for retrieval by a
call to the method getGeneratedKeys
true
if the first result is a ResultSet
object; false
if it is an update count or there
are no results
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
or the
elements in the int
array passed to this method
are not valid column indexes
java.sql.SQLFeatureNotSupportedException
- if the JDBC driver does not support this methodgetResultSet()
,
getUpdateCount()
,
getMoreResults()
public boolean execute(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
INSERT
statement, or an SQL statement able to return
auto-generated keys (the list of such statements is vendor-specific).
In some (uncommon) situations, a single SQL statement may return
multiple result sets and/or update counts. Normally you can ignore
this unless you are (1) executing a stored procedure that you know may
return multiple results or (2) you are dynamically executing an
unknown SQL string.
The execute
method executes an SQL statement and indicates the
form of the first result. You must then use the methods
getResultSet
or getUpdateCount
to retrieve the result, and getMoreResults
to
move to any subsequent result(s).
execute
in interface java.sql.Statement
sql
- any SQL statementcolumnNames
- an array of the names of the columns in the inserted
row that should be made available for retrieval by a call to the
method getGeneratedKeys
true
if the next result is a ResultSet
object; false
if it is an update count or there
are no more results
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
or the
elements of the String
array passed to this
method are not valid column names
java.sql.SQLFeatureNotSupportedException
- if the JDBC driver does not support this methodgetResultSet()
,
getUpdateCount()
,
getMoreResults()
,
getGeneratedKeys()
public int[] executeBatch() throws java.sql.SQLException
int
elements of the array that is returned are ordered
to correspond to the commands in the batch, which are ordered
according to the order in which they were added to the batch.
The elements in the array returned by the method executeBatch
may be one of the following:
SUCCESS_NO_INFO
-- indicates that the command was
processed successfully but that the number of rows affected is
unknown
If one of the commands in a batch update fails to execute properly,
this method throws a BatchUpdateException
, and a JDBC
driver may or may not continue to process the remaining commands in
the batch. However, the driver's behavior must be consistent with a
particular DBMS, either always continuing to process commands or never
continuing to process commands. If the driver continues processing
after a failure, the array returned by the method
BatchUpdateException.getUpdateCounts
will contain as many elements as there are commands in the batch, and
at least one of the elements will be the following:
EXECUTE_FAILED
-- indicates that the command failed
to execute successfully and occurs only if a driver continues to
process commands after a command fails
BatchUpdateException
obejct has been thrown.
executeBatch
in interface java.sql.Statement
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
or the
driver does not support batch statements. Throws BatchUpdateException
(a subclass of SQLException
) if one of the commands sent to the
database fails to execute properly or attempts to return a result set.addBatch(java.lang.String)
,
DatabaseMetaData.supportsBatchUpdates()
public java.sql.ResultSet executeQuery()
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes. An error is logged in TLptsLogger
, when NULL is returned.
Notes :
This is done automatically by TLptsFactoryRowSet when executing a statement TLptsFactoryRowSet.executeSelectStatement(com.lapetus_ltd.api.db.control.TLptsStatement, int, int, boolean)
.
Example :
private void selectDataStatements(TLptsConnection connection, String columnName) { TLptsStatement statement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); // set the table and columns for selecting statement.setSqlStatementUser("SELECT * FROM [testTable] WHERE [testTable].[Occupation] <> N'Software Developer'"); // the statement is modified by hand and will not be generated from the selected tables and columns. statement.setSqlStatementModified(true); statement.setTitle(columnName); processData(statement.executeQuery()); } private void processData(ResultSet rs) { ... while (rs.next) ... }
public java.sql.ResultSet executeQuery(java.lang.String sql) throws java.sql.SQLException
ResultSet
object.
executeQuery
in interface java.sql.Statement
sql
- an SQL statement to be sent to the database, typically a
static SQL SELECT
statement
ResultSet
object that contains the data produced
by the given query; never null
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
or the given
SQL statement produces anything other than a single
ResultSet
objectpublic int executeUpdate()
Thread Safe : Yes
Spawns its own Thread : No, but it is executed within a worker thread if called by TLptsFactoryRowSet
May Return NULL : N/A
Notes :
This is executed by TLptsFactoryRowSet.executeDynamicDelete(com.lapetus_ltd.api.db.control.TLptsStatement)
,
TLptsFactoryRowSet.executeDynamicInsert(com.lapetus_ltd.api.db.control.TLptsStatement)
,
TLptsFactoryRowSet.executeDynamicUpdate(com.lapetus_ltd.api.db.control.TLptsStatement)
.
This should also be called for CREATE statements after their creation TLptsFactoryStatement.createNewStatement(com.lapetus_ltd.api.db.control.TLptsConnection, com.lapetus_ltd._2009.xml.types.XLptsDBStatementType)
, as in the example.
Example :
private class CreateStatementListener implements ILptsFactoryStatementListener { ... public void newStatementCreated(TLptsConnection connection, TLptsStatement statement) { if(statement.getTypeOfStatement()==XLptsDBTypeOfStatementType.CREATE) { if (!TLptsFactoryStatement.initiatePrepareStatement(statement)) return; statement.executeUpdate(); } } ... }
TLptsLogger
will have a log in case of error.public int executeUpdate(java.lang.String sql) throws java.sql.SQLException
INSERT
,
UPDATE
, or DELETE
statement or an
SQL statement that returns nothing, such as an SQL DDL statement.
executeUpdate
in interface java.sql.Statement
sql
- an SQL Data Manipulation Language (DML) statement, such as INSERT
, UPDATE
or
DELETE
; or an SQL statement that returns nothing,
such as a DDL statement.
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
or the given
SQL statement produces a ResultSet
objectpublic int executeUpdate(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
Statement
object
should be made available for retrieval. The driver will ignore the
flag if the SQL statement
is not an INSERT
statement, or an SQL statement able to return
auto-generated keys (the list of such statements is vendor-specific).
executeUpdate
in interface java.sql.Statement
sql
- an SQL Data Manipulation Language (DML) statement, such as INSERT
, UPDATE
or
DELETE
; or an SQL statement that returns nothing,
such as a DDL statement.autoGeneratedKeys
- a flag indicating whether auto-generated keys
should be made available for retrieval;
one of the following constants:
Statement.RETURN_GENERATED_KEYS
Statement.NO_GENERATED_KEYS
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
, the given
SQL statement returns a ResultSet
object, or
the given constant is not one of those allowed
java.sql.SQLFeatureNotSupportedException
- if the JDBC driver does not support
this method with a constant of Statement.RETURN_GENERATED_KEYSpublic int executeUpdate(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
INSERT
statement, or an SQL statement able to return
auto-generated keys (the list of such statements is vendor-specific).
executeUpdate
in interface java.sql.Statement
sql
- an SQL Data Manipulation Language (DML) statement, such as INSERT
, UPDATE
or
DELETE
; or an SQL statement that returns nothing,
such as a DDL statement.columnIndexes
- an array of column indexes indicating the columns
that should be returned from the inserted row
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
, the SQL
statement returns a ResultSet
object, or the
second argument supplied to this method is not an int
array
whose elements are valid column indexes
java.sql.SQLFeatureNotSupportedException
- if the JDBC driver does not support this methodpublic int executeUpdate(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
INSERT
statement, or an SQL statement able to return
auto-generated keys (the list of such statements is vendor-specific).
executeUpdate
in interface java.sql.Statement
sql
- an SQL Data Manipulation Language (DML) statement, such as INSERT
, UPDATE
or
DELETE
; or an SQL statement that returns nothing,
such as a DDL statement.columnNames
- an array of the names of the columns that should be
returned from the inserted row
INSERT
, UPDATE
,
or DELETE
statements, or 0 for SQL statements
that return nothing
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
, the SQL
statement returns a ResultSet
object, or the
second argument supplied to this method is not a String
array
whose elements are valid column names
java.sql.SQLFeatureNotSupportedException
- if the JDBC driver does not support this methodpublic TLptsStatement findTopPrimaryStatement()
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : No, but it could return it's own ID if it is the top statement or the only statement.
Notes :
Example :
private class RowSetListener implements ILptsFactoryRowSetListener { private MaptreeMap = Collections.synchronizedMap(new LinkedHashMap ()); public boolean processNewRowSetRows(TLptsRowSetEvent rowSetEvent) { System.out.println("The ID of the top primary to this statement is : " + rowEvent.getStatement().findTopPrimaryStatement().getId()); return false; // tell dbJAPI not to process the rowset } public void rowEvent(final TLptsRowEvent rowEvent) { // nothing to do here } }
public java.util.List<java.lang.Integer> geSelectedColumnSqlTypeList()
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Never, an empty list in the worst case.
Notes :
Example :
// print out the column names with their SQL types below System.out.println("Column Names : "); for (Listname : getSelectedColumnNameList()) System.out.print("\t" + name); System.out.println("SQL Types : "); for (List sqlType : geSelectedColumnSqlTypeList()) System.out.print("\t" + sqlType);
public XLptsDBStatementColumnType getColumnItemById(java.lang.String id)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes
Notes :
Example :
TLptsStatement statement; String columnId; ... XLptsDBStatementColumnType column = statement.getColumnItemById(columnId); ...
id
- is the unique id of the desired column
public XLptsDBStatementColumnType getColumnItemByName(java.lang.String tableName, java.lang.String columnName)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes
Notes :
Example :
// Here are the selected columns // ------------------------------------------------------- // |table1.column1 | table1.column2 | table4.column3 | ... // ------------------------------------------------------- TLptsStatement statement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); statement.getColumnItemByName("table1","column1").setSelected(true); statement.getColumnItemByName("table1","column2").setSelected(true); statement.getColumnItemByName("table1","column3").setSelected(true); ... System.out.println(deleteStatement.getSelectedColumnItemByIndex(1).getTableName() + "." + deleteStatement.getSelectedColumnItemByIndex(1).getColumnName()); System.out.println(deleteStatement.getSelectedColumnItemByIndex(2).getTableName() + "." + deleteStatement.getSelectedColumnItemByIndex(2).getColumnName()); System.out.println(deleteStatement.getSelectedColumnItemByIndex(3).getTableName() + "." + deleteStatement.getSelectedColumnItemByIndex(3).getColumnName()); Result: table1.column1 table1.column2 table4.column3
tableName
- is the name of the table for our columncolumnName
- is the name of the column
public java.util.List<XLptsDBStatementColumnType> getColumnItemsForTable(java.lang.String tableName)
Gets a list with all the columns for a table.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Never, an empty list in the worst case.
Notes :
Example :
private void selectDataStatements(TLptsConnection connection, String tableName, String columnName) { TLptsStatement statement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); // set the table and columns for selecting XLptsDBStatementTableType table = statement.getTableItemByName(tableName); table.setSelected(true); // just one column is selected to be output to the rowset. for(XLptsDBStatementColumnType column : statement.getColumnItemsForTable(table.getTableName())) if(column.getColumnName().equalsIgnoreCase(columnName)) column.setSelected(true); statement.getCriteriaType().setType(XLptsDBCriteriaType.NONE); statement.setTitle(columnName); System.out.println("SQL Statement " + statement.getTitle() + ": " + statement.getSqlStatementFormatted()); TLptsFactoryStatement.createNewStatement(connection,statement); }
tableName
- The table to get the colums for.
public java.util.List<XLptsDBStatementColumnType> getColumnListItem()
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Never, an empty list in the worst case.
Notes : This is a list of all table, not just the selected on for the current statement.
Example :
TLptsStatement statement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); ... System.out.println("This is a list of all column in the data source :"); for(XLptsDBStatementColumnType column : statement.getColumnListItem()) System.out.println("Name=" + column.getColumnName + ", Selected="+(column.isSelected()?"Yes":"No") + ", SQL type="+column.getSqlType());
getColumnListItem
in class XLptsDBStatementType
public java.sql.Connection getConnection() throws java.sql.SQLException
Connection
object (TLptsConnection)
that produced this Statement
object.
This connection is actually of type TLptsConnection.
getConnection
in interface java.sql.Statement
java.sql.SQLException
public java.sql.Connection getConnectionWE()
Retrieves the Connection
object (TLptsConnection)
that produced this Statement
object.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes : This connection is actually of type TLptsConnection.
Example :
private class RowSetListener implements ILptsFactoryRowSetListener { public void rowEvent(TLptsRowEvent rowEvent) { } public boolean processNewRowSetRows(TLptsRowSetEvent rowSetEvent) { if(rowSetEvent.getEventType()==TLptsRowSetEvent.EVENT_TYPE.INSERT_COMPLETE) { System.out.println("Statement "+ rowSetEvent.getStatement().getTitle()+" " + ((TLptsConnection) rowSetEvent.getStatement().getConnectionWE()).getTitle()+ " insert execution complete..."); System.out.println(rowSetEvent.getRows()+" rows inserted, " + rowSetEvent.getObjects() + " objects inserted"); if(rowSetEvent.getRowSetsNotFinished().isEmpty()) System.out.println("All row sets has finished"); else for(String rowSet : rowSetEvent.getRowSetsNotFinished()) System.out.println(rowSet + " did not finished"); } if(rowSetEvent.getEventType()==TLptsRowSetEvent.EVENT_TYPE.ERROR_OCCURRED) System.out.println("The insert was not successful. We need to check the output from the logger for more information."); // we tell the rowset factory not to process the rows and send them to us via the rowEvent. return false; } }
public int getFetchDirection() throws java.sql.SQLException
Statement
object.
If this Statement
object has not set
a fetch direction by calling the method setFetchDirection
,
the return value is implementation-specific.
getFetchDirection
in interface java.sql.Statement
Statement
object
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
setFetchDirection(int)
public int getFetchSize() throws java.sql.SQLException
ResultSet
objects
generated from this Statement
object.
If this Statement
object has not set
a fetch size by calling the method setFetchSize
,
the return value is implementation-specific.
getFetchSize
in interface java.sql.Statement
Statement
object
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
setFetchSize(int)
public java.sql.ResultSet getGeneratedKeys() throws java.sql.SQLException
Statement
object. If this Statement
object did
not generate any keys, an empty ResultSet
object is returned.
Note:If the columns which represent the auto-generated keys were not specified, the JDBC driver implementation will determine the columns which best represent the auto-generated keys.
getGeneratedKeys
in interface java.sql.Statement
ResultSet
object containing the auto-generated key(s)
generated by the execution of this Statement
object
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
java.sql.SQLFeatureNotSupportedException
- if the JDBC driver does not support this methodpublic int getMaxFieldSize() throws java.sql.SQLException
ResultSet
object produced by this Statement
object.
This limit applies only to BINARY
, VARBINARY
,
LONGVARBINARY
, CHAR
, VARCHAR
,
NCHAR
, NVARCHAR
, LONGNVARCHAR
and LONGVARCHAR
columns. If the limit is exceeded, the
excess data is silently discarded.
getMaxFieldSize
in interface java.sql.Statement
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
setMaxFieldSize(int)
public int getMaxRows() throws java.sql.SQLException
ResultSet
object produced by this
Statement
object can contain. If this limit is exceeded,
the excess rows are silently dropped.
getMaxRows
in interface java.sql.Statement
ResultSet
object produced by this Statement
object;
zero means there is no limit
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
setMaxRows(int)
public boolean getMoreResults() throws java.sql.SQLException
Statement
object's next result, returns
true
if it is a ResultSet
object, and
implicitly closes any current ResultSet
object(s) obtained with the method getResultSet
.
There are no more results when the following is true:
// stmt is a Statement object ((stmt.getMoreResults() == false) && (stmt.getUpdateCount() == -1))
getMoreResults
in interface java.sql.Statement
true
if the next result is a ResultSet
object; false
if it is an update count or there are
no more results
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
execute(java.lang.String)
public boolean getMoreResults(int current) throws java.sql.SQLException
Statement
object's next result, deals with
any current ResultSet
object(s) according to the instructions
specified by the given flag, and returns
true
if the next result is a ResultSet
object.
There are no more results when the following is true:
// stmt is a Statement object ((stmt.getMoreResults(current) == false) && (stmt.getUpdateCount() == -1))
getMoreResults
in interface java.sql.Statement
current
- one of the following Statement
constants indicating what should happen to current
ResultSet
objects obtained using the method
getResultSet
:
Statement.CLOSE_CURRENT_RESULT
,
Statement.KEEP_CURRENT_RESULT
, or
Statement.CLOSE_ALL_RESULTS
true
if the next result is a ResultSet
object; false
if it is an update count or there are no
more results
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
or the argument
supplied is not one of the following:
Statement.CLOSE_CURRENT_RESULT
,
Statement.KEEP_CURRENT_RESULT
or
Statement.CLOSE_ALL_RESULTS
java.sql.SQLFeatureNotSupportedException
- if
DatabaseMetaData.supportsMultipleOpenResults
returns
false
and either
Statement.KEEP_CURRENT_RESULT
or
Statement.CLOSE_ALL_RESULTS
are supplied as
the argument.execute(java.lang.String)
public int getQueryTimeout() throws java.sql.SQLException
Statement
object to execute.
If the limit is exceeded, a
SQLException
is thrown.
getQueryTimeout
in interface java.sql.Statement
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
setQueryTimeout(int)
public java.sql.ResultSet getResultSet() throws java.sql.SQLException
ResultSet
object.
This method should be called only once per result.
getResultSet
in interface java.sql.Statement
ResultSet
object or
null
if the result is an update count or there are no more results
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
execute(java.lang.String)
public int getResultSetConcurrency() throws java.sql.SQLException
ResultSet
objects
generated by this Statement
object.
getResultSetConcurrency
in interface java.sql.Statement
ResultSet.CONCUR_READ_ONLY
or
ResultSet.CONCUR_UPDATABLE
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
public int getResultSetHoldability() throws java.sql.SQLException
ResultSet
objects
generated by this Statement
object.
getResultSetHoldability
in interface java.sql.Statement
ResultSet.HOLD_CURSORS_OVER_COMMIT
or
ResultSet.CLOSE_CURSORS_AT_COMMIT
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
public int getResultSetType() throws java.sql.SQLException
ResultSet
objects
generated by this Statement
object.
getResultSetType
in interface java.sql.Statement
ResultSet.TYPE_FORWARD_ONLY
,
ResultSet.TYPE_SCROLL_INSENSITIVE
, or
ResultSet.TYPE_SCROLL_SENSITIVE
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
public TLptsRowSet getRowSet()
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes
Notes :
With the current structure of dbJAPI this function has no real use.
The reason being that the system takes care of the rowset processing internally, so applications can just listen to the results on ILptsFactoryRowSetListener
.
Example :
... TLptsStatement statement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); statement.zsR(new TLptsRowSet(statement,statement.executeQuery())); ... //Later in the code we want to process the execute statement processData(statement.getRowSet()); ...
public XLptsDBStatementColumnType getSelectedColumnItemByIndex(int index)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes
Notes :
Example :
// Here are the selected columns // ------------------------------------------------------- // |table1.column1 | table1.column2 | table4.column3 | ... // ------------------------------------------------------- TLptsStatement statement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); statement.getColumnItemByName("table1","column1").setSelected(true); statement.getColumnItemByName("table1","column2").setSelected(true); statement.getColumnItemByName("table1","column3").setSelected(true); ... System.out.println(deleteStatement.getSelectedColumnItemByIndex(1).getTableName() + "." + deleteStatement.getSelectedColumnItemByIndex(1).getColumnName()); System.out.println(deleteStatement.getSelectedColumnItemByIndex(2).getTableName() + "." + deleteStatement.getSelectedColumnItemByIndex(2).getColumnName()); System.out.println(deleteStatement.getSelectedColumnItemByIndex(3).getTableName() + "." + deleteStatement.getSelectedColumnItemByIndex(3).getColumnName()); Result: table1.column1 table1.column2 table4.column3
index
- of the selected column (1 based)
public java.util.List<XLptsDBStatementColumnType> getSelectedColumnList()
This function returns the columns that are currently selected for this statement.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Never, an empty list in the worst case.
Notes : This is a subset of all columns in the datasource and depicts the statement columns to be processed.
Example :
TLptsStatement statement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); ... System.out.println("This is a list of all Selected column in the data source :"); for(XLptsDBStatementColumnType column : statement.getColumnListItem()) System.out.println("Name=" + column.getColumnName + ", SQL type="+column.getSqlType());
public java.util.List<java.lang.String> getSelectedColumnNameList()
Gets a list of names for the currently selected columns of this statement.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Never, an empty list in the worst case.
Notes : This may return columns from multiple tables, as per the selected tables and columns.
Example :
// print out the column names with their SQL types below System.out.println("Column Names : "); for (Listname : getSelectedColumnNameList()) System.out.print("\t" + name); System.out.println("SQL Types : "); for (List sqlType : geSelectedColumnSqlTypeList()) System.out.print("\t" + sqlType);
public java.lang.String getSqlStatementExtension()
setSqlStatementUser(java.lang.String)
& XLptsDBStatementType.setSqlStatementModified(boolean)
.
getSqlStatementExtension
in class XLptsDBStatementType
public java.lang.String getSqlStatementFormatted()
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : No, worst case is an empty string.
Notes :
This function checks the value of XLptsDBStatementType.isSqlStatementModified()
, which indicates if a user SQL is to be used
for SQL processing or if the selected tables and columns are to be used to automatically generate the string.
If isSqlStatementModified is true, then the user string is returned without modification.
Otherwise the selected tables and columns, along with the criteria parameters XLptsDBStatementType.getCriteriaType()
,
setPrimaryStatement(java.lang.String, boolean)
and addPrimaryRelationship(int, int[], java.lang.String)
.
Example :
{ ... selectDataStatements(mySqlConnection, "customers", "idcustomers"); } ... private void selectDataStatements(TLptsConnection connection, String tableName, String columnName) { TLptsStatement statement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); statement. XLptsDBStatementTableType table = statement.getTableItemByName(tableName); table.setSelected(true); //statement.setSelectOnAllColumns(table.getTable(),true); statement.getColumnItemByName(tableName,columnName).setSelected(true); statement.getCriteriaType().setType(XLptsDBCriteriaType.NONE); statement.setTitle(columnName); TLptsFactoryStatement.createNewStatement(connection,statement); } Result: "SQL Statement idcustomers: SELECT `customers`.`idcustomers` FROM `customers`"
public int getSqlType(int sqlColumnIndex)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
Example :
... int sqlType = statement.getSqlType(1); // first sql type of the selected columns ...
sqlColumnIndex
- the selected column index (1 based)
public XLptsDBSqlStringFormatType getStandardSqlFormat(XLptsDBSqlDatabaseFormat type)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
Example :
statement.setSqlStringFormat(getStandardSqlFormat(XLptsDBSqlDatabaseFormat.DEFAULT_MYSQL));
public XLptsDBStatementTableType getTableItemById(java.lang.String tableId)
Gets a specific table by it's id.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
Example :
... // this is a bit foolish, but it helps with the understanding XLptsDBStatementTableType tableType = getTableItemByName(tableName); // now get the same table, but with the id XLptsDBStatementTableType sameTableType = getTableItemById(tableType.getId());
tableId
- the table id
public XLptsDBStatementTableType getTableItemByName(java.lang.String tableName)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
Example :
... customerStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); customerStatement.setTitle("CUSTOMERS"); // the quotations are for MySQL customerStatement.setSqlDatabaseFormat(XLptsDBSqlDatabaseFormat.DEFAULT_MYSQL); XLptsDBStatementTableType table = customerStatement.getTableItemByName("CUSTOMERS"); table.setSelected(true); // selecting one table only, with all its columns customerStatement.setSelectOnAllColumns(table.getTableName(), true); // dbJAPI automatically formats the SQL statement string so that it is ready for creation and execution. TLptsFactoryStatement.createNewStatement(connection, customerStatement); ...
tableName
- The name of the table.
public java.util.List<XLptsDBStatementTableType> getTableListItem()
Gets a copy of the actual table list for this statement.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Never, an empty list in the worst case.
Notes : This list contains all tables of all types.
Example :
... ListselectedTables = new LinkedList (); for(XLptsDBStatementTableType table : statement.getTableListItem()) if(table.isSelected()) selectedTables.add(table); ...
getTableListItem
in class XLptsDBStatementType
public int getUpdateCount() throws java.sql.SQLException
ResultSet
object or there are no more results, -1
is returned. This method should be called only once per result.
getUpdateCount
in interface java.sql.Statement
ResultSet
object or there are no more results
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
execute(java.lang.String)
public java.util.List<XLptsDBUpInsDelType> getUpInsDelListItem()
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Never, an empty list in the worst case.
Notes :
Example :
for(XLptsDBUpInsDelType uidt : statement.getUpInsDelListItem()) if(uidt.getSourceType().equals(XLptsDBUpInsDelSourceType.LPTS_STATEMENT)) for(TLptsStatement stmt : TLptsFactoryStatement.getStatementList()) if(uidt.getSourceString().equals(stmt.getTitle())) System.out.println("Found the statement to be used as a source to this statement.");
getUpInsDelListItem
in class XLptsDBStatementType
public java.sql.SQLWarning getWarnings() throws java.sql.SQLException
Statement
object.
Subsequent Statement
object warnings will be chained to this
SQLWarning
object.
The warning chain is automatically cleared each time
a statement is (re)executed. This method may not be called on a closed
Statement
object; doing so will cause an SQLException
to be thrown.
Note: If you are processing a ResultSet
object, any
warnings associated with reads on that ResultSet
object
will be chained on it rather than on the Statement
object that produced it.
getWarnings
in interface java.sql.Statement
SQLWarning
object or null
if there are no warnings
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
public boolean hasDynamicSubStatement()
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : No
Notes :
A statement can be both dynamic and primary if it is in the middle of a multi-level relationship.
Example :
public class ProcessData implements ILptsFactoryRowSetListener
{
public boolean processNewRowSetRows(TLptsRowSetEvent rowSetEvent)
{
if (rowSetEvent.getEventType() == TLptsRowSetEvent.EVENT_TYPE.NEW_SELECT_RESULTSET)
{
System.out.println("New rowset is available.");
if (!rowSetEvent.getStatement().hasPrimaryStatement() && !rowSetEvent.getStatement().hasDynamicSubStatement())
{
// this is not a primary set and it does not have a primary (is not dynamic)
while (rowSetEvent.getRowSet().nextWE())
{
// process the row in here
}
return false; // TLptsFactoryRowSet should not process this rowset.
}
}
if (rowSetEvent.getPrimaryStatementId() != null)
System.out.println("The primary statement for this rowset is " + rowSetEvent.getPrimaryStatementId());
return true; // This is part of a dynamic primary relationship. Let TLptsFactoryRowSet process the rows and send the the rowEvents below.
}
public void rowEvent(TLptsRowEvent rowEvent)
{
// Here were have the row events. See TLptsRowEvent
for more details.
}
}
public boolean hasPrimaryStatement()
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
A statement can be both dynamic and primary if it is in the middle of a multi-level relationship.
Example :
public class ProcessData implements ILptsFactoryRowSetListener
{
public boolean processNewRowSetRows(TLptsRowSetEvent rowSetEvent)
{
if (rowSetEvent.getEventType() == TLptsRowSetEvent.EVENT_TYPE.NEW_SELECT_RESULTSET)
{
System.out.println("New rowset is available.");
if (!rowSetEvent.getStatement().hasPrimaryStatement() && !rowSetEvent.getStatement().hasDynamicSubStatement())
{
// this is not a primary set and it does not have a primary (is not dynamic)
while (rowSetEvent.getRowSet().nextWE())
{
// process the row in here
}
return false; // TLptsFactoryRowSet should not process this rowset.
}
}
if (rowSetEvent.getPrimaryStatementId() != null)
System.out.println("The primary statement for this rowset is " + rowSetEvent.getPrimaryStatementId());
return true; // This is part of a dynamic primary relationship. Let TLptsFactoryRowSet process the rows and send the the rowEvents below.
}
public void rowEvent(TLptsRowEvent rowEvent)
{
// Here were have the row events. See TLptsRowEvent
for more details.
}
}
public void initTablesAndColumns(int tableTypes)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
Use this to change the types of tables loaded into the statement.
Different types are loaded depending on the driver type.
Use 'if ((getTableTypesView() & TLptsFactoryStatement.TABLE_TYPE_USER)!=0)' to see if a type is loaded.
WARNING: On some databases there may be thousands of tables, and tens of thousands of columns. This may take a while in some cases.
If the tables are cached (have been initialised before) in the connection, then loading is quick.
Use TLptsConnection.clearCachedTablesAndColumns()
to clear the cache if the tables have changed.
Example :
TLptsStatement statement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); if ((statement.getTableTypesView()&TLptsFactoryStatement.TABLE_TYPE_SYSTEM)!=0) initTablesAndColumns(statement.getTableTypesView()|TLptsFactoryStatement.TABLE_TYPE_SYSTEM);
tableTypes
- valid types are ORed combinations of the following:
TLptsFactortStatement.TABLE_TYPE_USER
TLptsFactortStatement.TABLE_TYPE_VIEW
TLptsFactortStatement.TABLE_TYPE_SYSTEM
TLptsFactortStatement.TABLE_TYPE_OTHER
TLptsFactortStatement.TABLE_TYPE_TEMPpublic void interruptExecution()
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
Example :
... private class RowSetListener implements ILptsFactoryRowSetListener { public void rowEvent(TLptsRowEvent rowEvent) { if(rowEvent.getEventType()==TLptsRowEvent.EVENT_TYPE.EXECUTION_INTERRUPTED) { System.out.println("Processing was interrupted on this Statement!"); // interruptExecution was called externally } } public boolean processNewRowSetRows(TLptsRowSetEvent rowSetEvent) { return true; } }
public boolean isClosed() throws java.sql.SQLException
Statement
object has been closed. A Statement
is closed if the
method close has been called on it, or if it is automatically closed.
isClosed
in interface java.sql.Statement
Statement
object is closed; false if it is still open
java.sql.SQLException
- if a database access error occurspublic boolean isInterrupted()
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
Example :
... private String statementId; private int desiredNumberOfProcessedRows; ... private class RowSetListener implements ILptsFactoryRowSetListener { public void rowEvent(TLptsRowEvent rowEvent) { if(rowEvent.getStatement().isInterrupted()) return; // throw it away! ... } public boolean processNewRowSetRows(TLptsRowSetEvent rowSetEvent) { return true; } }
public boolean isPoolable() throws java.sql.SQLException
Statement
is poolable or not.
isPoolable
in interface java.sql.Statement
true
if the Statement
is poolable; false
otherwise
java.sql.SQLException
- if this method is called on a closed
Statement
setPoolable(boolean)
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
isWrapperFor
on the wrapped
object. If this does not implement the interface and is not a wrapper, return false.
This method should be implemented as a low-cost operation compared to unwrap
so that
callers can use this method to avoid expensive unwrap
calls that may fail. If this method
returns true then calling unwrap
with the same argument should succeed.
isWrapperFor
in interface java.sql.Wrapper
iface
- a Class defining an interface.
java.sql.SQLException
- if an error occurs while determining whether this is a wrapper
for an object with the given interface.public void resetAllTablesAndColumns()
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
Example :
//Create statement, select multiple columns, process etc.. ... // This sets the tables and column of this data source to DESELECTED. // That means that no columns or tables will appear in the select SQL statement. statement.resetAllTablesAndColumns(); ...
public void setCursorName(java.lang.String name) throws java.sql.SQLException
String
, which
will be used by subsequent Statement
object
execute
methods. This name can then be
used in SQL positioned update or delete statements to identify the
current row in the ResultSet
object generated by this
statement. If the database does not support positioned update/delete,
this method is a noop. To insure that a cursor has the proper isolation
level to support updates, the cursor's SELECT
statement
should have the form SELECT FOR UPDATE
. If
FOR UPDATE
is not present, positioned updates may fail.
Note: By definition, the execution of positioned updates and
deletes must be done by a different Statement
object than
the one that generated the ResultSet
object being used for
positioning. Also, cursor names must be unique within a connection.
setCursorName
in interface java.sql.Statement
name
- the new cursor name, which must be unique within
a connection
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
java.sql.SQLFeatureNotSupportedException
- if the JDBC driver does not support this methodpublic void setEscapeProcessing(boolean enable) throws java.sql.SQLException
PreparedStatements
objects will have no effect.
setEscapeProcessing
in interface java.sql.Statement
enable
- true
to enable escape processing;
false
to disable it
java.sql.SQLException
- if a database access error occurs or
this method is called on a closed Statement
public void setFetchDirection(int direction) throws java.sql.SQLException
ResultSet
objects created using this Statement
object. The
default value is ResultSet.FETCH_FORWARD
.
Note that this method sets the default fetch direction for
result sets generated by this Statement
object.
Each result set has its own methods for getting and setting
its own fetch direction.
setFetchDirection
in interface java.sql.Statement
direction
- the initial direction for processing rows
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
or the given direction
is not one of ResultSet.FETCH_FORWARD
,
ResultSet.FETCH_REVERSE
, or ResultSet.FETCH_UNKNOWN
getFetchDirection()
public void setFetchSize(int rows) throws java.sql.SQLException
ResultSet
objects genrated by this Statement
.
If the value specified is zero, then the hint is ignored.
The default value is zero.
setFetchSize
in interface java.sql.Statement
rows
- the number of rows to fetch
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
or the
condition rows >= 0
is not satisfied.getFetchSize()
public void setMaxFieldSize(int max) throws java.sql.SQLException
ResultSet
object produced by this Statement
object.
This limit applies
only to BINARY
, VARBINARY
,
LONGVARBINARY
, CHAR
, VARCHAR
,
NCHAR
, NVARCHAR
, LONGNVARCHAR
and
LONGVARCHAR
fields. If the limit is exceeded, the excess data
is silently discarded. For maximum portability, use values
greater than 256.
setMaxFieldSize
in interface java.sql.Statement
max
- the new column size limit in bytes; zero means there is no limit
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
or the condition max >= 0 is not satisfiedgetMaxFieldSize()
public void setMaxRows(int max) throws java.sql.SQLException
ResultSet
object generated by this Statement
object can contain to the given number.
If the limit is exceeded, the excess
rows are silently dropped.
setMaxRows
in interface java.sql.Statement
max
- the new max rows limit; zero means there is no limit
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
or the condition max >= 0 is not satisfiedgetMaxRows()
public void setObject(int i, java.lang.Object obj, int sqlType)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : No
Notes :
This function is normally used at runtime for substituting dynamic objects into the SQL string, so that
they are used for processing the statement.
This version of setObject also allows for the setting of objects during instantiation of the TLptsStatement object.
This is done so that charsets can be supported through objects. Extended characters in SQL strings do not normally
function, so they need to added to the string through the setObject mechanism.
Obviously this can only be used with setSqlStatementUser as shown below.
In dynamic resultset processing, this mechanism is still in affect, but care needs to be taken with the indexing.
Example :
// Sql code : "SELECT customer.* FROM customer WHERE customer.name = ?" ... TLptsStatement statement = new TLptsStatement(connection, XLptsDBTypeOfStatementType.SELECT); statement.setSqlStatementUser("SELECT [testTable].[ID] FROM [testTable] WHERE [testTable].[Occupation] <> ?"); statement.setSqlStatementModified(true); statement.setObject(1,"ΟΙΚΙΑΚΑ", Types.NVARCHAR); statement.setTitle(columnName); TLptsFactoryStatement.createNewStatement(connection, statement); ...
i
- is the index to substitute the questionmark in the prepare statement. 1 based, not 0.obj
- is the object to be set in the place of the questionmark.sqlType
- The SQL type of the objectpublic void setPoolable(boolean poolable) throws java.sql.SQLException
Statement
be pooled or not pooled. The value
specified is a hint to the statement pool implementation indicating
whether the applicaiton wants the statement to be pooled. It is up to
the statement pool manager as to whether the hint is used.
The poolable value of a statement is applicable to both internal
statement caches implemented by the driver and external statement caches
implemented by application servers and other applications.
By default, a Statement
is not poolable when created, and
a PreparedStatement
and CallableStatement
are poolable when created.
setPoolable
in interface java.sql.Statement
poolable
- requests that the statement be pooled if true and
that the statement not be pooled if false
java.sql.SQLException
- if this method is called on a closed
Statement
public void setPrimaryStatement(java.lang.String primaryStatementId, boolean isSubstituteValueIntoSQLString)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
This function is always accompanied by addPrimaryRelationship(int, int[], java.lang.String)
.
Together these functions specify a link or relationship between two statements.
The statement that calls these functions is the dynamic statement, which means that it is executed with every row
of the primary statement, taking the values specified from the primary statement's current row and substituting
them into the current statement and then execute the resultset.
In the example below we have 3 statements, namely Customers, Account and transactions. Customer is the top primary
and feeds data to account. For every account of the current customer, data is fed to the transactions so that we have
a 3 level dynamic statement relationship. There is no limit to the number of levels we can declare and execute.
This brings about one or many rowsets per customer for accounts, and one or many rowsets per account for transactions.
So in the end there is a tree or rowsets built, with the customer statement as the top level.
Each row comes down to the application with identification as to its statement, rowset and own id. The application can
then easily map the rows to a hierarchy structure (as shown in TLptsRowEvent.getRowObjectList()
).
Example :
...
// first we create the customer, account and transaction statements. Then we dynamically link them.
// once they are linked, dbJAPI will process the hole structure and provide each record, one at a time, to the application
// through the listener, with reference to its position in the structure. The application can then process the records as
// required, with the correct structure. (like the data view window does TLptsViewDataDialog
)
TLptsStatement customerStatement, transStatement, itemStatement;
////////////////////////////////// CUSTOMER ////////////////////////////////////
// contains all the tables and columns of the connection. We need to select some or input a SQL string manually
customerStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT);
customerStatement.setTitle("CUSTOMERS");
// the quotations are for ODBC
customerStatement.setSqlDatabaseFormat(XLptsDBSqlDatabaseFormat.DEFAULT_MYSQL);
XLptsDBStatementTableType table = customerStatement.getTableItemByName("CUSTOMERS");
table.setSelected(true); // selecting one table only, with all its columns
customerStatement.setSelectOnAllColumns(table.getTableName(), true);
// make sure this is not processed as we are waiting for the dynamic statements below to be created.
customerStatement.setExecutable(false);
TLptsFactoryStatement.createNewStatement(connection, customerStatement);
////////////////////////////////// ACCOUNT ////////////////////////////////////
accountStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT);
accountStatement.setTitle("TRANSACTIONS");
accountStatement.setSqlDatabaseFormat(XLptsDBSqlDatabaseFormat.DEFAULT_MYSQL);
table = accountStatement.getTableItemByName("TRANSACTIONS");
table.setSelected(true); // selecting one table only, with all its columns
accountStatement.setSelectOnAllColumns(table.getTableName(), true); // select all the columns and the select statement SQL string will be created automatically.
// relate this statement to the customer statement (this means that 'customer' will feed the data to this statement for every record of 'customer' to regenerate this statement every time)
accountStatement.setPrimaryStatement(customerStatement.getId(),false); // false means that we do not want static string substitution (uses the setObject of Statement)
accountStatement.addPrimaryRelationship(2,new int[] {1}, TLptsFactoryStatement.OPERATION_EQUAL); // column 2 in this statement is related to column 1 in customer
// certain operations allow for many indexes (like IN and BETWEEN)
// make sure this is not processed as we are waiting for the dynamic statement below to be created.
accountStatement.setExecutable(false);
TLptsFactoryStatement.createNewStatement(connection, accountStatement);
////////////////////////////////// TRANSACTION ////////////////////////////////////
transStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT);
transStatement.setTitle("TRANSACTIONS");
transStatement.setSqlDatabaseFormat(XLptsDBSqlDatabaseFormat.DEFAULT_MYSQL);
table = transStatement.getTableItemByName("TRANSACTIONS");
table.setSelected(true); // selecting one table only, with all its columns
transStatement.setSelectOnAllColumns(table.getTableName(), true); // select all the columns and the select statement SQL string will be created automatically.
// relate this statement to the account statement (this means that 'account' will feed the data to this statement for every record of 'account' to regenerate this statement every time)
transStatement.setPrimaryStatement(accountStatement.getId(),false); // false means that we do not want static string substitution (false uses the setObject of Statement)
transStatement.addPrimaryRelationship(2,new int[] {1}, TLptsFactoryStatement.OPERATION_EQUAL); // column 2 in this statement is related to column 1 in account
// certain operations allow for many indexes (like IN and BETWEEN)
// this statement can be processed now that all the statements are ready and created. This will execute the others dynamically
transStatement.setExecutable(false);
TLptsFactoryStatement.createNewStatement(connection, transStatement);
...
primaryStatementId
- This is the id of the statement that is the primary to this dynamicisSubstituteValueIntoSQLString
- is true if we want to substitute '?' with the appropriate string in the SQL statementpublic void setQueryTimeout(int seconds) throws java.sql.SQLException
Statement
object to execute to the given number of seconds.
If the limit is exceeded, an SQLException
is thrown. A JDBC
driver must apply this limit to the execute
,
executeQuery
and executeUpdate
methods. JDBC driver
implementations may also apply this limit to ResultSet
methods
(consult your driver vendor documentation for details).
setQueryTimeout
in interface java.sql.Statement
seconds
- the new query timeout limit in seconds; zero means
there is no limit
java.sql.SQLException
- if a database access error occurs,
this method is called on a closed Statement
or the condition seconds >= 0 is not satisfiedgetQueryTimeout()
public void setSelectOnAllColumns(java.lang.String tableName, boolean isSelect)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
Example :
customerStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); customerStatement.setTitle("CUSTOMERS"); // the quotations are for MySQL customerStatement.setSqlDatabaseFormat(XLptsDBSqlDatabaseFormat.DEFAULT_MYSQL); XLptsDBStatementTableType table = customerStatement.getTableItemByName("CUSTOMERS"); table.setSelected(true); // selecting one table only, with all its columns customerStatement.setSelectOnAllColumns(table.getTableName(), true); // dbJAPI automatically formats the SQL statement string so that it is ready for creation and execution. TLptsFactoryStatement.createNewStatement(connection, customerStatement); ...
tableName
- the name of the specific tableisSelect
- set true to set the columns selected or false to unselectpublic void setSqlDatabaseFormat(XLptsDBSqlDatabaseFormat value)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : No
Notes :
Example :
TLptsStatement customerStatement; ////////////////////////////////// CUSTOMER //////////////////////////////////// // contains all the tables and columns of the connection. We need to select some or input a SQL string manually customerStatement = new TLptsStatement(connection,XLptsDBTypeOfStatementType.SELECT); customerStatement.setTitle("CUSTOMERS"); // the quotations are for ODBC customerStatement.setSqlDatabaseFormat(XLptsDBSqlDatabaseFormat.DEFAULT_MYSQL); XLptsDBStatementTableType table = customerStatement.getTableItemByName("CUSTOMERS"); table.setSelected(true); // selecting one table only, with all its columns customerStatement.setSelectOnAllColumns(table.getTableName(), true); // make sure this is not processed as we are waiting for the dynamic statements below to be created. customerStatement.setExecutable(false); TLptsFactoryStatement.createNewStatement(connection, customerStatement);
setSqlDatabaseFormat
in class XLptsDBStatementType
value
- One of the following: ORACLE_NO_QUOTATION,
DEFAULT_ODBC,
DEFAULT_MS_SQL,
DEFAULT_POSTGRES,
DEFAULT_MYSQLpublic void setSqlStatementExtension(java.lang.String value)
setSqlStatementUser(java.lang.String)
& XLptsDBStatementType.setSqlStatementModified(boolean)
.
setSqlStatementExtension
in class XLptsDBStatementType
value
- The String to go on the end of the generated string. Normally contains and ORDER BY or SORT clause, which could not be generated.public void setSqlStatementUser(java.lang.String value)
XLptsDBStatementType.setSqlStatementUser(String)
.
setSqlStatementUser
in class XLptsDBStatementType
value
- The new user SQL statement.public void setTitle(java.lang.String value)
setTitle
in class XLptsDBStatementType
value
- The desired title of the statement.public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
unwrap
recursively on the wrapped object
or a proxy for that result. If the receiver is not a
wrapper and does not implement the interface, then an SQLException
is thrown.
unwrap
in interface java.sql.Wrapper
iface
- A Class defining an interface that the result must implement.
java.sql.SQLException
- If no object found that implements the interfacepublic void zaCLI(XLptsDBStatementColumnType sct)
public void zaTLI(XLptsDBStatementTableType stt)
public void zaUIDLI(XLptsDBUpInsDelType uidt)
public void zcUIDLI()
public int zgCI(XLptsDBStatementColumnType column)
public java.util.List<com.lapetus_ltd.api.db.control.TLptsStatement.SetObjectClass> zgOL()
public java.lang.String zgSSS()
public boolean ziSS()
public boolean zpPR()
public void zrc(XLptsDBStatementColumnType sct)
public void zrI()
public void zrTLI(XLptsDBStatementTableType stt)
public void zrUIDLI(XLptsDBUpInsDelType uidt)
public void zsOL()
public void zsR(TLptsRowSet rowSet)
public void zsS(java.sql.Statement statement)
public void zsSS(boolean setSub)
public void zsSSS(java.lang.String sql)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |