Interface ISqlWorker
- All Superinterfaces:
AutoCloseable
This interface will usually provide functions for 99% of all tasks related to db operations.
Many of the functions in this interface in addition to sql query string also take Object array
of parameters and object array of macros. The parameters array contain input parameters
for query or stored procedure. The actualy values are normal Java objects like String, Integer, Long,
Boolean, etc. When parameter is NULL, then special constants of ISqlWorker
interface should be
used in place, which is guaranteed to work on any JDBC driver. It is also safe to just use Java null (depending on driver)
Here is an example of query strings that might be used:
- UPDATE {0} SET {1} = ? - Having 2 macros and one input parameter
- SELECT * FROM tblTest WHERE idThing = ? and idType = ? - Having 2 input parameters only
- spListObjectTypes - call to stored procedure. Please note that when calling stored procedure you need to pass only stored procedure name. The actual sql statement will be compiled automatically depending on type of stored procedure, its parameters, type of the server: MS SQL or Oracle. Those calling stored procedures with output parameters also need array of output parameter types.
All ResultSet
resultset objects returned are automatically closed by SqlWorker on
release()
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
Null class that defines type information for null object -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Object
Identifies NULL Booleanstatic final Object
Identifies NULL Bytestatic final Object
Identifies NULL Charstatic final Object
Identifies NULL Integerstatic final Object
Identifies NULL Longstatic final Object
Identifies default NULL - will assume VARCHAR typestatic final Object
Identifies NULL Numeric (all floats)static final int
Supported database server typesstatic final int
static final String
static final int
static final String
static final int
static final String
static final int
static final String
static final int
static final String
static final int
static final String
static final int
static final String
static final int
static final String
static final int
static final String
static final int
static final String
static final Object
Identifies NULL Shortstatic final Object
Identifies NULL VARCHAR type -
Method Summary
Modifier and TypeMethodDescriptionvoid
Begins transaction for encapsulated connection and increments current transaction countvoid
close()
void
Commits currently active transaction for encapsulated connection.Execute sql formatted with parameters and macros that return ResultSet.default int[]
executeBatchUpdate
(String sql, List<Object[]> paramList, Object[] macros) Execute batch updatedefault int[]
executeBatchUpdate
(String sql, List<Object[]> paramList, Object[] macros, boolean handleError) Execute batch updatevoid
executeBlobUpdate
(String tablename, String fieldname, byte[] blobvalue, String keyfield, Object keyvalue) Executes update for Clob type of field.void
executeClobUpdate
(String tablename, String fieldname, String clobvalue, String keyfield, Object keyvalue) Executes update for Clob type of field.executeQuery
(String sql) Execute sql that return ResultSetexecuteQuery
(String sql, Object[] parameters, Object[] macros) Execute sql formatted with parameters and macros that return ResultSetexecuteQuery
(String sql, Object[] parameters, Object[] macros, int resultsettype, int resultsetconcur) Execute sql formatted with parameters and macros that return ResultSetexecuteQuery
(String sql, Object[] parameters, Object[] macros, int resultsettype, int resultsetconcur, int fetchSize) Execute sql formatted with parameters and macros that return ResultSetObject[]
executeQueryProcOut
(String strProc, Object[] parameters, int[] outParamTypes) Execute stored procedure that returns output parametersexecuteQueryProcResult
(String strProc, Object[] parameters) Execute stored procedure or package that returns result setexecuteQueryProcResult
(String strProc, Object[] parameters, boolean assumePackageName) Executes stored procedure by name, returning result set Important Oracle comment: Procedure that returns Cursor (aka ResultSet) must be declared within package and when called package name should be specified if assumePackageName = false, if assumePackageName = true, the package name is assumed equals to stored proc name.Object[]
executeQueryProcResultOut
(String strProc, Object[] parameters, int[] outParamTypes) Deprecated.doesn't work in SQLint
executeUpdate
(String sql) Execute sql that doesn't return ResultSet or update statementsint
executeUpdate
(String sql, Object[] parameters, Object[] macros) Execute statement that does not return result set or an update statementint
executeUpdate
(String sql, Object[] parameters, Object[] macros, boolean requestIdentity) Execute statement that does not return result set or an update statementint
executeUpdate
(String sql, Object[] parameters, Object[] macros, boolean requestIdentity, boolean handleError) Execute statement that does not return result set or an update statementint
executeUpdateProc
(String strProc, Object[] parameters) Execute stored procedure that doesn't return anything.int
Returns a bitset from object translates based on DBint
getBitsetFromResult
(ResultSet rs, int index) Returns a bitset from a resultset entry in given DB of worker.getBitsetObject
(int bitset) Returns a Java Object that translates a int value into the appropriate object type depending on the DB system the worker is usingint
Returns server storage type for bit set value.byte[]
Returnes binary array for ResultSet column.Returnes String value for ResultSet clob column.Returns encapsulated sql connectionReturns current database runtime, may be null if there is no runtime associatedint
Returns last inserted identityint
Returns server typevoid
init
(IConnectionInfo connInfo) Initializes SQL worker connection.boolean
If there is an active transactionboolean
isDeadlockCode
(int code) Deprecated.UseisDeadlockError(SQLException)
insteadboolean
Determines if SQLException reports deadlock errorvoid
release()
Deprecated.- since 10.3, useAutoCloseable
void
Rollbacks currently active transaction for encapsulated connection.void
setDatabaseRuntime
(IDatabaseRuntime databaseRuntime) Sets database runtime for this sql worker instancevoid
setExternalTran
(boolean isExternal) Sets transaction flag
-
Field Details
-
VARCHAR_NULL
Identifies NULL VARCHAR type -
INTEGER_NULL
Identifies NULL Integer -
LONG_NULL
Identifies NULL Long -
SHORT_NULL
Identifies NULL Short -
BYTE_NULL
Identifies NULL Byte -
BOOLEAN_NULL
Identifies NULL Boolean -
CHAR_NULL
Identifies NULL Char -
NUMERIC_NULL
Identifies NULL Numeric (all floats) -
NULL
Identifies default NULL - will assume VARCHAR type -
SERVERTYPE_ANY
static final int SERVERTYPE_ANYSupported database server types- See Also:
-
SERVERTYPE_MSSQL
static final int SERVERTYPE_MSSQL- See Also:
-
SERVERTYPE_ORACLE
static final int SERVERTYPE_ORACLE- See Also:
-
SERVERTYPE_ODBC
static final int SERVERTYPE_ODBC- See Also:
-
SERVERTYPE_DB2
static final int SERVERTYPE_DB2- See Also:
-
SERVERTYPE_INFORMIX
static final int SERVERTYPE_INFORMIX- See Also:
-
SERVERTYPE_SYBASE
static final int SERVERTYPE_SYBASE- See Also:
-
SERVERTYPE_CUSTOM
static final int SERVERTYPE_CUSTOM- See Also:
-
SERVERTYPE_MYSQL
static final int SERVERTYPE_MYSQL- See Also:
-
SERVERTYPE_DERBY
static final int SERVERTYPE_DERBY- See Also:
-
SERVERTYPE_POSTGRESQL
static final int SERVERTYPE_POSTGRESQL- See Also:
-
SERVERTYPE_MSSQL_STR
- See Also:
-
SERVERTYPE_ORACLE_STR
- See Also:
-
SERVERTYPE_MYSQL_STR
- See Also:
-
SERVERTYPE_ODBC_STR
- See Also:
-
SERVERTYPE_DB2_STR
- See Also:
-
SERVERTYPE_INFORMIX_STR
- See Also:
-
SERVERTYPE_SYBASE_STR
- See Also:
-
SERVERTYPE_CUSTOM_STR
- See Also:
-
SERVERTYPE_DERBY_STR
- See Also:
-
SERVERTYPE_POSTGRESQL_STR
- See Also:
-
-
Method Details
-
init
Initializes SQL worker connection.- Parameters:
connInfo
- to initialize SQL worker for- Throws:
SQLException
-
release
Deprecated.- since 10.3, useAutoCloseable
Releases all resources aquired by SqlWorker, including database connection, result sets, prepares statements Will be executed once number of release() calls is equal to number of reinit() calls -
beginTran
Begins transaction for encapsulated connection and increments current transaction count- Throws:
SQLException
-
commitTran
Commits currently active transaction for encapsulated connection. Commit is only executed if current transaction count == 1. Does nothing if there is no currently active transaction e.g. transaction count == 0- Throws:
SQLException
-
rollbackTran
Rollbacks currently active transaction for encapsulated connection. Does nothing if there is no currently active transaction e.g. transaction count == 0- Throws:
SQLException
-
setExternalTran
void setExternalTran(boolean isExternal) Sets transaction flag -
isActiveTran
boolean isActiveTran()If there is an active transaction- Returns:
-
getConnection
Connection getConnection()Returns encapsulated sql connection- Returns:
- Connection object
-
getServerType
int getServerType()Returns server type- Returns:
- either
SERVERTYPE_MSSQL
or {@link @ISqlWorker#SERVERTYPE_ORACLE} server type
-
getBlob
Returnes binary array for ResultSet column. Must be a Blob or compatible type to work properly- Parameters:
rs
- is source ResultSet that contains blob type columncolumn
- is column number for blob field- Returns:
- null if empty or field is not a Blob object
- Throws:
SQLException
-
getClob
Returnes String value for ResultSet clob column. Must be a Clob or compatible type to work properly.- Parameters:
rs
- is source ResultSet that contains clob type columncolumn
- is column number for clob field- Returns:
- value of Clob column or null if empty or field is not a Clob object
- Throws:
SQLException
-
executeUpdate
Execute sql that doesn't return ResultSet or update statements- Parameters:
sql
- is sql statement to be executed- Returns:
- number of updated records
- Throws:
SQLException
ServerBusyException
DeadlockException
-
executeUpdate
int executeUpdate(String sql, Object[] parameters, Object[] macros) throws SQLException, ServerBusyException, DeadlockException Execute statement that does not return result set or an update statement- Parameters:
sql
- statement to be executedparameters
- is an Object array of input parameters for query. May be nullmacros
- is an Object array of macros to be used to format original query text. May be null- Returns:
- number of updated records
- Throws:
SQLException
ServerBusyException
DeadlockException
-
executeBatchUpdate
default int[] executeBatchUpdate(String sql, List<Object[]> paramList, Object[] macros) throws SQLException, ServerBusyException, DeadlockException Execute batch update- Parameters:
sql
- - statement to be executedparamList
- - is an Object array of input parameters for query. May be nullmacros
- - is an Object array of macros to be used to format original query text. May be null- Returns:
- number of updated records
- Throws:
SQLException
ServerBusyException
DeadlockException
-
executeBatchUpdate
default int[] executeBatchUpdate(String sql, List<Object[]> paramList, Object[] macros, boolean handleError) throws SQLException, ServerBusyException, DeadlockException Execute batch update- Parameters:
sql
- - statement to be executedparamList
- - is an Object array of input parameters for query. May be nullmacros
- - is an Object array of macros to be used to format original query text. May be nullhandleError
- - whether an exception should be handled, provided it occurs during execution- Returns:
- number of updated records
- Throws:
SQLException
ServerBusyException
DeadlockException
-
executeUpdate
int executeUpdate(String sql, Object[] parameters, Object[] macros, boolean requestIdentity) throws SQLException, ServerBusyException, DeadlockException Execute statement that does not return result set or an update statement- Parameters:
sql
- statement to be executedparameters
- is an Object array of input parameters for query. May be nullmacros
- is an Object array of macros to be used to format original query text. May be nullrequestIdentity
- whether to request inserted identity value from the driver. If requested the last returned identity could be obtained usinggetLastInsertedIdentity()
function- Returns:
- number of updated records
- Throws:
SQLException
ServerBusyException
DeadlockException
-
executeUpdate
int executeUpdate(String sql, Object[] parameters, Object[] macros, boolean requestIdentity, boolean handleError) throws SQLException, ServerBusyException, DeadlockException Execute statement that does not return result set or an update statement- Parameters:
sql
- statement to be executedparameters
- is an Object array of input parameters for query. May be nullmacros
- is an Object array of macros to be used to format original query text. May be nullrequestIdentity
- whether to request inserted identity value from the driver. If requested the last returned identity could be obtained usinggetLastInsertedIdentity()
function- Returns:
- number of updated records
- Throws:
SQLException
ServerBusyException
DeadlockException
-
executeQuery
ResultSet executeQuery(String sql, Object[] parameters, Object[] macros) throws SQLException, ServerBusyException, DeadlockException Execute sql formatted with parameters and macros that return ResultSet- Parameters:
sql
- sql query to be executedparameters
- is an Object array of input parameters for query. May be nullmacros
- is an Object array of macros to be used to format original query text. May be null- Throws:
SQLException
ServerBusyException
DeadlockException
-
executeQuery
Execute sql that return ResultSet- Parameters:
sql
- sql query to be executed- Returns:
- ResultSet produced from sql query
- Throws:
SQLException
ServerBusyException
DeadlockException
-
execute
ResultSet execute(String sql, Object[] parameters, Object[] macros) throws SQLException, ServerBusyException, DeadlockException Execute sql formatted with parameters and macros that return ResultSet. Wraps Statement.execute method- Parameters:
sql
- sql query to be executedparameters
- is an Object array of input parameters for query. May be nullmacros
- is an Object array of macros to be used to format original query text. May be null- Returns:
- produced ResultSet
- Throws:
SQLException
ServerBusyException
DeadlockException
-
executeQuery
ResultSet executeQuery(String sql, Object[] parameters, Object[] macros, int resultsettype, int resultsetconcur) throws SQLException, ServerBusyException, DeadlockException Execute sql formatted with parameters and macros that return ResultSet- Parameters:
sql
- sql query to be executedparameters
- is an Object array of input parameters for query. May be nullmacros
- is an Object array of macros to be used to format original query text. May be nullresultsettype
- see JDBC docs for details on thisresultsetconcur
- see JDBC docs for details on this- Returns:
- produced ResultSet
- Throws:
SQLException
ServerBusyException
DeadlockException
-
executeQuery
ResultSet executeQuery(String sql, Object[] parameters, Object[] macros, int resultsettype, int resultsetconcur, int fetchSize) throws SQLException, ServerBusyException, DeadlockException Execute sql formatted with parameters and macros that return ResultSet- Parameters:
sql
- sql query to be executedparameters
- is an Object array of input parameters for query. May be nullmacros
- is an Object array of macros to be used to format original query text. May be nullresultsettype
- see JDBC docs for details on thisresultsetconcur
- see JDBC docs for details on thisfetchSize
- desired fetch size- Returns:
- produced ResultSet
- Throws:
SQLException
ServerBusyException
DeadlockException
-
executeQueryProcResult
ResultSet executeQueryProcResult(String strProc, Object[] parameters) throws SQLException, ServerBusyException, DeadlockException Execute stored procedure or package that returns result set- Parameters:
strProc
- name of the stored procedure to executeparameters
- is an Object array of input parameters for query. May be null- Throws:
SQLException
ServerBusyException
DeadlockException
-
executeQueryProcResult
ResultSet executeQueryProcResult(String strProc, Object[] parameters, boolean assumePackageName) throws SQLException, ServerBusyException, DeadlockException Executes stored procedure by name, returning result set Important Oracle comment: Procedure that returns Cursor (aka ResultSet) must be declared within package and when called package name should be specified if assumePackageName = false, if assumePackageName = true, the package name is assumed equals to stored proc name. This flag is not used when database server is MS Sql Server -
executeQueryProcResultOut
@Deprecated Object[] executeQueryProcResultOut(String strProc, Object[] parameters, int[] outParamTypes) throws SQLException, ServerBusyException, DeadlockException Deprecated.doesn't work in SQLExecutes stored procedure by name, returning output params and result set Returns ResultSet and 0's element in the output Object[] array, all other output params returned starting from index 1 -
executeQueryProcOut
Object[] executeQueryProcOut(String strProc, Object[] parameters, int[] outParamTypes) throws SQLException, ServerBusyException, DeadlockException Execute stored procedure that returns output parameters- Parameters:
strProc
- name of the stored procedure to executeparameters
- is an Object array of input parameters for query. May be nulloutParamTypes
- array of output parameter types. See @Types interface for list of JDBC types- Throws:
SQLException
ServerBusyException
DeadlockException
-
executeUpdateProc
int executeUpdateProc(String strProc, Object[] parameters) throws SQLException, ServerBusyException, DeadlockException Execute stored procedure that doesn't return anything. Usually that could be update stored proc.- Parameters:
strProc
- name of the stored procedure to executeparameters
- is an Object array of input parameters for query. May be null- Returns:
- number of affected records.
- Throws:
SQLException
ServerBusyException
DeadlockException
-
executeClobUpdate
void executeClobUpdate(String tablename, String fieldname, String clobvalue, String keyfield, Object keyvalue) throws SQLException, ServerBusyException, DeadlockException Executes update for Clob type of field. Updates existing record, or creates new record if doesn't exists. This routine may be used for both MS SQL and Oracle databases- Parameters:
tablename
- - table name with clob compatible field. For MS SQL Clob maps to text/ntext data typesfieldname
- - name of the clob fieldclobvalue
- - value to writekeyfield
- of key field for the tablename. Usually this is PKkeyvalue
- for the key field- Throws:
SQLException
ServerBusyException
DeadlockException
-
executeBlobUpdate
void executeBlobUpdate(String tablename, String fieldname, byte[] blobvalue, String keyfield, Object keyvalue) throws SQLException, ServerBusyException, DeadlockException Executes update for Clob type of field. Updates existing record, or creates new record if doesn't exists. This routine may be used for both MS SQL and Oracle databases- Parameters:
tablename
- - table name with clob compatible field. For MS SQL Blob maps to image data typefieldname
- - name of the clob fieldblobvalue
- - value to write to the blob fieldkeyfield
- of key field for the tablename. Usually this is PKkeyvalue
- for the key field- Throws:
SQLException
ServerBusyException
DeadlockException
-
isDeadlockCode
Deprecated.UseisDeadlockError(SQLException)
insteadChecks if error code is a deadlock code- Parameters:
code
- error code- Returns:
- true if code corresponds to a deadlock situation depending on DB
-
isDeadlockError
Determines if SQLException reports deadlock error- Parameters:
e
-- Returns:
-
getBitsetObject
Returns a Java Object that translates a int value into the appropriate object type depending on the DB system the worker is using- Parameters:
bitset
- 32-bit set- Returns:
- correct object
-
getBitsetFromResult
Returns a bitset from a resultset entry in given DB of worker. uses current row, caller must call index in order.- Parameters:
rs
- current setindex
- field index- Returns:
- 32-bit bitset
- Throws:
SQLException
- if EOF or bad index
-
getBitsetFromObject
Returns a bitset from object translates based on DB- Parameters:
o
- Integer in SQL, String in Oracle
-
getBitsetOutputType
int getBitsetOutputType()Returns server storage type for bit set value. Those areTypes.VARCHAR
for Oracle andTypes.INTEGER
for SQL Server- Returns:
-
getDatabaseRuntime
IDatabaseRuntime getDatabaseRuntime()Returns current database runtime, may be null if there is no runtime associated -
getLastInsertedIdentity
int getLastInsertedIdentity()Returns last inserted identity -
setDatabaseRuntime
Sets database runtime for this sql worker instance -
close
void close()- Specified by:
close
in interfaceAutoCloseable
-