sqlg2
Class GBase

java.lang.Object
  extended by sqlg2.GBase

public class GBase
extends java.lang.Object

Base class for all classes which are processed by preprocessor. Wraps access to JDBC methods allowing preprocessor to intercept them and extract required information. This class itself is not thread-safe, so it cannot be used by more than one thread at a time. Use wrappers generated by preprocessor to access business methods.


Field Summary
static java.lang.String[] ALL_KEYS
          Use it for autoKeys parameter of prepareStatementKey(String[], String) to retrieve all generated columns.
 
Constructor Summary
GBase(LocalWrapperBase lwb)
          Constructor.
 
Method Summary
 java.lang.Object[] callStoredBlock(java.lang.String block, java.lang.Object... in)
          Executes PL/SQL block.
 java.lang.Object[] callStoredProc(java.lang.String name, boolean block, java.lang.Object... in)
          Executes stored procedure or PL/SQL block (depending of block parameter).
 java.lang.Object[] callStoredProc(java.lang.String name, java.lang.Object... in)
          Calls stored procedure.
 void close(java.sql.ResultSet rs, java.sql.Statement st)
          Closes result set and statement.
 void close(java.sql.Statement st)
          Closes statement.
 void closeStatements()
          Closes all open statements (usually this method is called by wrappers automatically).
<T extends MappedType>
java.util.List<T>
columnOf(java.lang.Class<T> cls, java.sql.PreparedStatement stmt)
          Executes select query returning single column of T.
 double[] columnOfDouble(java.sql.PreparedStatement stmt)
          Executes select query returning single column of double.
 int[] columnOfInt(java.sql.PreparedStatement stmt)
          Executes select query returning single column of int.
 long[] columnOfLong(java.sql.PreparedStatement stmt)
          Executes select query returning single column of long.
 java.lang.Object[] columnOfObject(java.sql.PreparedStatement stmt)
          Executes select query returning single column of Object.
 java.lang.String[] columnOfString(java.sql.PreparedStatement stmt)
          Executes select query returning single column of String.
static QueryPiece createQueryPiece(QueryPiece query)
          This is for preprocessor-generated QueryPieces (see Query).
static QueryPiece createQueryPiece(java.lang.String sql)
          Creates piece of SQL query consisting only of text.
static QueryPiece createQueryPiece(java.lang.String sql, java.lang.Object[] params, java.lang.Class<?>[] paramTypes)
          This is for preprocessor-generated QueryPieces (see Query).
static QueryPiece createQueryPiece(java.lang.String sql, java.lang.Object[] params, java.lang.String stmtId)
          This is for preprocessor-generated QueryPieces (see Query).
 java.sql.Statement createStatement()
          Creates Statement.
 void endCall(java.sql.CallableStatement stmt)
          Closes CallableStatement.
 void executeCall(java.sql.CallableStatement stmt)
          Executes stored procedure or PL/SQL block.
 java.lang.Object[] executeCall(QueryPiece query)
          Executes PL/SQL block constructed from pieces.
 java.lang.Object[] executeCall(java.lang.String sql, java.lang.Object... params)
          Executes CallableStatement.
 java.lang.Object[] executeCall(java.lang.String sql, java.lang.Object[] params, java.lang.Class<?>[] paramTypes)
          This is for preprocessor-generated CallableStatements.
 java.lang.Object[] executeCall(java.lang.String sql, java.lang.Object[] params, java.lang.String stmtId)
          This is for preprocessor-generated CallableStatements.
 void executeSql(java.lang.String sql)
          Executes SQL statement.
 int executeUpdate(java.sql.PreparedStatement stmt)
          Executes update/delete/insert SQL statement.
 int executeUpdate(java.sql.PreparedStatement stmt, boolean reuse)
          Same as executeUpdate(java.sql.PreparedStatement) but closes statement when reuse=false.
static java.math.BigDecimal getBigDecimal(java.sql.CallableStatement stmt, int i)
          Returns OUT parameter of stored procedure with index i (from 1) as BigDecimal.
static byte[] getBytes(java.sql.CallableStatement stmt, int i)
          Returns OUT parameter of stored procedure with index i (from 1) as byte[].
static java.sql.Date getDate(java.sql.CallableStatement stmt, int i)
          Returns OUT parameter of stored procedure with index i (from 1) as Date.
static java.lang.Double getDouble(java.sql.CallableStatement stmt, int i)
          Returns OUT parameter of stored procedure with index i (from 1) as Double.
 java.lang.Number[] getGeneratedKeys(java.sql.PreparedStatement stmt)
          Returns array of auto-generated keys for insert/update statement.
static java.lang.Integer getInt(java.sql.CallableStatement stmt, int i)
          Returns OUT parameter of stored procedure with index i (from 1) as Integer.
<T extends LIDBCommon>
T
getInterface(java.lang.Class<T> iface)
          Returns data access interface generated by preprocessor.
protected  java.sql.Connection getJdbcConnection()
          Access to raw JDBC connection.
static java.lang.Long getLong(java.sql.CallableStatement stmt, int i)
          Returns OUT parameter of stored procedure with index i (from 1) as Long.
 long getNextId(java.lang.String sequence)
          Returns next number in sequence.
static java.lang.Object getObject(java.sql.CallableStatement stmt, int i)
          Returns OUT parameter of stored procedure with index i (from 1) as Object.
static java.lang.String getString(java.sql.CallableStatement stmt, int i)
          Returns OUT parameter of stored procedure with index i (from 1) as String.
static java.sql.Time getTime(java.sql.CallableStatement stmt, int i)
          Returns OUT parameter of stored procedure with index i (from 1) as Time.
static java.sql.Timestamp getTimestamp(java.sql.CallableStatement stmt, int i)
          Returns OUT parameter of stored procedure with index i (from 1) as Timestamp.
static boolean isTesting()
          Returns true if method is called at preprocessing time (false at application run time).
<T> T
metaRowQuery(java.sql.PreparedStatement stmt, java.lang.Class<T> cls)
          Returns result set metadata as RowType object.
<T> java.util.List<T>
multiRowQuery(java.sql.PreparedStatement stmt, java.lang.Class<T> cls)
          Executes select query returning multiple (zero or more) rows.
<T> T
newRow(java.lang.Class<T> cls)
          Create row instance by row type class; class should have EditableRowType annotation.
<T> T
optionalRowQuery(java.sql.PreparedStatement stmt, java.lang.Class<T> cls)
          Same as singleRowQuery(java.sql.PreparedStatement, Class) but returns null when no rows found.
<T extends MappedType>
T
optionalRowQueryReturning(java.lang.Class<T> cls, java.sql.PreparedStatement stmt)
          Same as singleRowQueryReturning(Class, java.sql.PreparedStatement) but returns null when no rows found.
 java.math.BigDecimal optionalRowQueryReturningBigDecimal(java.sql.PreparedStatement stmt)
          Same as singleRowQueryReturningBigDecimal(java.sql.PreparedStatement) but returns null when no rows found.
 byte[] optionalRowQueryReturningBlob(java.sql.PreparedStatement stmt)
          Same as singleRowQueryReturningBlob(java.sql.PreparedStatement) but returns null when no rows found.
 byte[] optionalRowQueryReturningBytes(java.sql.PreparedStatement stmt)
          Same as singleRowQueryReturningBytes(java.sql.PreparedStatement) but returns null when no rows found.
 java.lang.String optionalRowQueryReturningClob(java.sql.PreparedStatement stmt)
          Same as singleRowQueryReturningClob(java.sql.PreparedStatement) but returns null when no rows found.
 java.sql.Date optionalRowQueryReturningDate(java.sql.PreparedStatement stmt)
          Same as singleRowQueryReturningDate(java.sql.PreparedStatement) but returns null when no rows found.
 java.lang.Double optionalRowQueryReturningDouble(java.sql.PreparedStatement stmt)
          Same as singleRowQueryReturningDouble(java.sql.PreparedStatement) but returns null when no rows found.
 java.lang.Integer optionalRowQueryReturningInt(java.sql.PreparedStatement stmt)
          Same as singleRowQueryReturningInt(java.sql.PreparedStatement) but returns null when no rows found.
 java.lang.Long optionalRowQueryReturningLong(java.sql.PreparedStatement stmt)
          Same as singleRowQueryReturningLong(java.sql.PreparedStatement) but returns null when no rows found.
 java.lang.Object optionalRowQueryReturningObject(java.sql.PreparedStatement stmt)
          Same as singleRowQueryReturningObject(java.sql.PreparedStatement) but returns null when no rows found.
 java.lang.String optionalRowQueryReturningString(java.sql.PreparedStatement stmt)
          Same as singleRowQueryReturningString(java.sql.PreparedStatement) but returns null when no rows found.
 java.sql.Time optionalRowQueryReturningTime(java.sql.PreparedStatement stmt)
          Same as singleRowQueryReturningTime(java.sql.PreparedStatement) but returns null when no rows found.
 java.sql.Timestamp optionalRowQueryReturningTimestamp(java.sql.PreparedStatement stmt)
          Same as singleRowQueryReturningTimestamp(java.sql.PreparedStatement) but returns null when no rows found.
 OutParameter out(java.lang.Object param)
          This is for preprocessor-generated CallableStatements.
static
<T> TypedList<T>
outResultSet(java.lang.Class<T> cls)
          Creates OUT parameter for cursor parameters.
 java.sql.CallableStatement prepareCall(java.lang.String sql)
          Creates CallableStatement for stored procedure (or PL/SQL block) call.
 java.sql.PreparedStatement prepareStatement(QueryPiece query)
          Creates PreparedStatement for further execution.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
          Creates PreparedStatement for further execution.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.Object... params)
          Creates PreparedStatement for further execution.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.Object[] params, java.lang.Class<?>[] paramTypes)
          This is for preprocessor-generated PreparedStatements (see Prepare).
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.Object[] params, java.lang.String stmtId)
          This is for preprocessor-generated PreparedStatements (see Prepare).
 java.sql.PreparedStatement prepareStatementKey(java.lang.String[] autoKeys, QueryPiece query)
          Creates PreparedStatement with auto-generated keys for further execution.
 java.sql.PreparedStatement prepareStatementKey(java.lang.String[] autoKeys, java.lang.String sql)
          Creates PreparedStatement with auto-generated keys for further execution.
 java.sql.PreparedStatement prepareStatementKey(java.lang.String[] autoKeys, java.lang.String sql, java.lang.Object... params)
          Creates PreparedStatement with auto-generated keys for further execution.
 java.sql.PreparedStatement prepareStatementKey(java.lang.String[] autoKeys, java.lang.String sql, java.lang.Object[] params, java.lang.Class<?>[] paramTypes)
          This is for preprocessor-generated PreparedStatements with auto-generated keys (see PrepareKey).
 java.sql.PreparedStatement prepareStatementKey(java.lang.String[] autoKeys, java.lang.String sql, java.lang.Object[] params, java.lang.String stmtId)
          This is for preprocessor-generated PreparedStatements with auto-generated keys (see PrepareKey).
 void setBlob(java.sql.PreparedStatement stmt, byte[] data)
          Writes bytes to BLOB.
 void setClob(java.sql.PreparedStatement stmt, java.lang.String text)
          Writes text to CLOB.
 void setParameter(java.sql.PreparedStatement st, int index, java.lang.Object param)
           
 void setParameter(java.sql.PreparedStatement st, int index, java.lang.Object param, java.lang.Class<?> cls)
           
 void setParameters(java.sql.PreparedStatement st, java.lang.Object... in)
          Binds prepared statement parameters to specific values.
<T> T
singleRowQuery(java.sql.PreparedStatement stmt, java.lang.Class<T> cls)
          Executes select query, which should return one row (more or less than one rows raises runtime exception).
<T extends MappedType>
T
singleRowQueryReturning(java.lang.Class<T> cls, java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 java.math.BigDecimal singleRowQueryReturningBigDecimal(java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 byte[] singleRowQueryReturningBlob(java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 byte[] singleRowQueryReturningBytes(java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 java.lang.String singleRowQueryReturningClob(java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 java.sql.Date singleRowQueryReturningDate(java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 double singleRowQueryReturningDouble(java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 java.lang.Double singleRowQueryReturningDOUBLE(java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 int singleRowQueryReturningInt(java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 java.lang.Integer singleRowQueryReturningINT(java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 long singleRowQueryReturningLong(java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 java.lang.Long singleRowQueryReturningLONG(java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 java.lang.Object singleRowQueryReturningObject(java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 java.lang.String singleRowQueryReturningString(java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 java.sql.Time singleRowQueryReturningTime(java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 java.sql.Timestamp singleRowQueryReturningTimestamp(java.sql.PreparedStatement stmt)
          Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception).
 void traceSql(boolean ok)
          SQL tracing.
 void traceSql(boolean ok, long t0)
          SQL tracing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALL_KEYS

public static final java.lang.String[] ALL_KEYS
Use it for autoKeys parameter of prepareStatementKey(String[], String) to retrieve all generated columns.

See Also:
PrepareKey.value()
Constructor Detail

GBase

public GBase(LocalWrapperBase lwb)
Constructor. Usually it is called by generated wrappers.

Parameters:
lwb - wrapper for this object
Method Detail

isTesting

public static boolean isTesting()
Returns true if method is called at preprocessing time (false at application run time).


getJdbcConnection

protected final java.sql.Connection getJdbcConnection()
                                               throws java.sql.SQLException
Access to raw JDBC connection. Can be used only at application run time, not at preprocess time, so check isTesting() before calling this method.

Throws:
java.sql.SQLException

traceSql

public final void traceSql(boolean ok)
SQL tracing. Usually called by generated wrappers.

Parameters:
ok - false if SQL caused an error

traceSql

public final void traceSql(boolean ok,
                           long t0)
SQL tracing. Usually called by generated wrappers.

Parameters:
ok - false if SQL caused an error
t0 - business method start time (as in System.currentTimeMillis()

executeSql

public final void executeSql(java.lang.String sql)
                      throws java.sql.SQLException
Executes SQL statement.

Warning: usually you should call this method only at application run time, not at preprocess time, because it can alter DB state (for example, when you execute DROP TABLE statement). Since preprocessor executes business method code and it is undesirable for preprocessor to alter DB state, calls to this method should be guarded by check of isTesting():

 if (isTesting()) {
     executeSql("DROP TABLE BOBBY");
 }
 

Parameters:
sql - SQL statement to execute
Throws:
java.sql.SQLException

createStatement

public final java.sql.Statement createStatement()
                                         throws java.sql.SQLException
Creates Statement.

Warning: usually you should call this method only at application run time, not at preprocess time, because it can alter DB state (for example, when you execute DROP TABLE statement). Since preprocessor executes business method code and it is undesirable for preprocessor to alter DB state, calls to this method should be guarded by check of isTesting():

 if (isTesting()) {
     Statement st = createStatement();
     st.execute("DROP TABLE BOBBY");
 }
 

Throws:
java.sql.SQLException

createQueryPiece

public static QueryPiece createQueryPiece(java.lang.String sql)
Creates piece of SQL query consisting only of text.

Parameters:
sql - SQL text

createQueryPiece

public static QueryPiece createQueryPiece(QueryPiece query)
This is for preprocessor-generated QueryPieces (see Query).


createQueryPiece

public static QueryPiece createQueryPiece(java.lang.String sql,
                                          java.lang.Object[] params,
                                          java.lang.Class<?>[] paramTypes)
This is for preprocessor-generated QueryPieces (see Query).


createQueryPiece

public static QueryPiece createQueryPiece(java.lang.String sql,
                                          java.lang.Object[] params,
                                          java.lang.String stmtId)
This is for preprocessor-generated QueryPieces (see Query).


prepareStatement

public final java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                                  throws java.sql.SQLException
Creates PreparedStatement for further execution. Statement should be executed by executeUpdate(java.sql.PreparedStatement) or by some select method.

It is more convenient to use Prepare annotation to generate such queries than to use this method manually.

Throws:
java.sql.SQLException

prepareStatementKey

public final java.sql.PreparedStatement prepareStatementKey(java.lang.String[] autoKeys,
                                                            java.lang.String sql)
                                                     throws java.sql.SQLException
Creates PreparedStatement with auto-generated keys for further execution. Statement should be executed by executeUpdate(java.sql.PreparedStatement, boolean) and generated keys extracted with getGeneratedKeys(java.sql.PreparedStatement).

It is more convenient to use PrepareKey annotation to generate such queries than to use this method manually.

Parameters:
autoKeys - array of column names which are auto-generated. Note that upper/lower case may be significant (depends on DB).
Throws:
java.sql.SQLException

prepareStatement

public final java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                         java.lang.Object[] params,
                                                         java.lang.Class<?>[] paramTypes)
                                                  throws java.sql.SQLException
This is for preprocessor-generated PreparedStatements (see Prepare). Creates PreparedStatement for further execution.

Throws:
java.sql.SQLException

prepareStatementKey

public final java.sql.PreparedStatement prepareStatementKey(java.lang.String[] autoKeys,
                                                            java.lang.String sql,
                                                            java.lang.Object[] params,
                                                            java.lang.Class<?>[] paramTypes)
                                                     throws java.sql.SQLException
This is for preprocessor-generated PreparedStatements with auto-generated keys (see PrepareKey). Creates PreparedStatement for further execution.

Throws:
java.sql.SQLException

prepareStatement

public final java.sql.PreparedStatement prepareStatement(QueryPiece query)
                                                  throws java.sql.SQLException
Creates PreparedStatement for further execution. Statement should be executed by executeUpdate(java.sql.PreparedStatement) or by some select method.

Throws:
java.sql.SQLException

prepareStatementKey

public final java.sql.PreparedStatement prepareStatementKey(java.lang.String[] autoKeys,
                                                            QueryPiece query)
                                                     throws java.sql.SQLException
Creates PreparedStatement with auto-generated keys for further execution. Statement should be executed by executeUpdate(java.sql.PreparedStatement, boolean) and generated keys extracted with getGeneratedKeys(java.sql.PreparedStatement).

Parameters:
autoKeys - array of column names which are auto-generated. Note that upper/lower case may be significant (depends on DB).
Throws:
java.sql.SQLException

prepareStatement

public final java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                         java.lang.Object[] params,
                                                         java.lang.String stmtId)
                                                  throws java.sql.SQLException
This is for preprocessor-generated PreparedStatements (see Prepare). Creates PreparedStatement for further execution.

Throws:
java.sql.SQLException

prepareStatementKey

public final java.sql.PreparedStatement prepareStatementKey(java.lang.String[] autoKeys,
                                                            java.lang.String sql,
                                                            java.lang.Object[] params,
                                                            java.lang.String stmtId)
                                                     throws java.sql.SQLException
This is for preprocessor-generated PreparedStatements with auto-generated keys (see PrepareKey). Creates PreparedStatement for further execution.

Throws:
java.sql.SQLException

prepareStatement

public final java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                         java.lang.Object... params)
                                                  throws java.sql.SQLException
Creates PreparedStatement for further execution. Statement shoud be executed by executeUpdate(java.sql.PreparedStatement) or by some select method.

It is more convenient to use Prepare annotation to generate such queries than to use this method manually.

Parameters:
params - parameters for PreparedStatement.setXXX
Throws:
java.sql.SQLException

prepareStatementKey

public final java.sql.PreparedStatement prepareStatementKey(java.lang.String[] autoKeys,
                                                            java.lang.String sql,
                                                            java.lang.Object... params)
                                                     throws java.sql.SQLException
Creates PreparedStatement with auto-generated keys for further execution. Statement should be executed by executeUpdate(java.sql.PreparedStatement, boolean) and generated keys extracted with getGeneratedKeys(java.sql.PreparedStatement).

It is more convenient to use PrepareKey annotation to generate such queries than to use this method manually.

Parameters:
autoKeys - array of column names which are auto-generated. Note that upper/lower case may be significant (depends on DB).
params - parameters for PreparedStatement.setXXX
Throws:
java.sql.SQLException

prepareCall

public final java.sql.CallableStatement prepareCall(java.lang.String sql)
                                             throws java.sql.SQLException
Creates CallableStatement for stored procedure (or PL/SQL block) call.

Parameters:
sql - stored procedure to call. Syntax is the same as for Connection.prepareCall(String):
  • { call proc_name(params) } or { ? = func_name(params) }
  • begin ... end;
Throws:
java.sql.SQLException

out

public final OutParameter out(java.lang.Object param)
This is for preprocessor-generated CallableStatements. Creates OUT parameter for stored procedure call.

Parameters:
param - Shoud be an array with at least one element to store output value

outResultSet

public static <T> TypedList<T> outResultSet(java.lang.Class<T> cls)
Creates OUT parameter for cursor parameters.

Parameters:
cls - row type class to be returned from cursor

executeCall

public final java.lang.Object[] executeCall(QueryPiece query)
                                     throws java.sql.SQLException
Executes PL/SQL block constructed from pieces.

Parameters:
query - query text and parameter values
Returns:
array of all OUT parameter values
Throws:
java.sql.SQLException

executeCall

public final java.lang.Object[] executeCall(java.lang.String sql,
                                            java.lang.Object[] params,
                                            java.lang.Class<?>[] paramTypes)
                                     throws java.sql.SQLException
This is for preprocessor-generated CallableStatements. Calls stored procedure and returns its OUT parameter values.

Throws:
java.sql.SQLException

executeCall

public final java.lang.Object[] executeCall(java.lang.String sql,
                                            java.lang.Object[] params,
                                            java.lang.String stmtId)
                                     throws java.sql.SQLException
This is for preprocessor-generated CallableStatements. Calls stored procedure and returns its OUT parameter values.

Throws:
java.sql.SQLException

executeCall

public final java.lang.Object[] executeCall(java.lang.String sql,
                                            java.lang.Object... params)
                                     throws java.sql.SQLException
Executes CallableStatement.

Parameters:
params - parameters for CallableStatement.setXXX. Can contain OutParameter.
Returns:
array of all OUT parameter values
Throws:
java.sql.SQLException

newRow

public final <T> T newRow(java.lang.Class<T> cls)
Create row instance by row type class; class should have EditableRowType annotation. Returns null

executeUpdate

public final int executeUpdate(java.sql.PreparedStatement stmt)
                        throws java.sql.SQLException
Executes update/delete/insert SQL statement. This method should always be used instead of PreparedStatement.executeUpdate() because the latter can modify database state at preprocess phase.

This method does not close statement, so it can be called multiple times. You don't have to close statement manually if it was created with prepareStatement(String) or the like, because all statements created with GBase methods are closed automatically after business method exit.

Parameters:
stmt - SQL statement
Returns:
number of modified database rows
Throws:
java.sql.SQLException

executeUpdate

public final int executeUpdate(java.sql.PreparedStatement stmt,
                               boolean reuse)
                        throws java.sql.SQLException
Same as executeUpdate(java.sql.PreparedStatement) but closes statement when reuse=false.

Parameters:
stmt - SQL statement
reuse - false if close statement after execution
Returns:
number of modified database rows
Throws:
java.sql.SQLException

getGeneratedKeys

public final java.lang.Number[] getGeneratedKeys(java.sql.PreparedStatement stmt)
                                          throws java.sql.SQLException
Returns array of auto-generated keys for insert/update statement. List of auto-generated columns is provided by prepareStatementKey(String[], sqlg2.db.QueryPiece) autoKeys parameter or by PrepareKey annotation value. Number of elements in array equals to the number of auto-generated columns.

Throws:
java.sql.SQLException

executeCall

public final void executeCall(java.sql.CallableStatement stmt)
                       throws java.sql.SQLException
Executes stored procedure or PL/SQL block. Does not close statement, you can explicitly call endCall(java.sql.CallableStatement) to close it. You can retrieve OUT parameters with getXXX(CallableStatement, int) methods after call to this method.

Throws:
java.sql.SQLException

endCall

public final void endCall(java.sql.CallableStatement stmt)
Closes CallableStatement.


getInt

public static java.lang.Integer getInt(java.sql.CallableStatement stmt,
                                       int i)
                                throws java.sql.SQLException
Returns OUT parameter of stored procedure with index i (from 1) as Integer.

Throws:
java.sql.SQLException

getLong

public static java.lang.Long getLong(java.sql.CallableStatement stmt,
                                     int i)
                              throws java.sql.SQLException
Returns OUT parameter of stored procedure with index i (from 1) as Long.

Throws:
java.sql.SQLException

getDouble

public static java.lang.Double getDouble(java.sql.CallableStatement stmt,
                                         int i)
                                  throws java.sql.SQLException
Returns OUT parameter of stored procedure with index i (from 1) as Double.

Throws:
java.sql.SQLException

getString

public static java.lang.String getString(java.sql.CallableStatement stmt,
                                         int i)
                                  throws java.sql.SQLException
Returns OUT parameter of stored procedure with index i (from 1) as String.

Throws:
java.sql.SQLException

getBytes

public static byte[] getBytes(java.sql.CallableStatement stmt,
                              int i)
                       throws java.sql.SQLException
Returns OUT parameter of stored procedure with index i (from 1) as byte[].

Throws:
java.sql.SQLException

getBigDecimal

public static java.math.BigDecimal getBigDecimal(java.sql.CallableStatement stmt,
                                                 int i)
                                          throws java.sql.SQLException
Returns OUT parameter of stored procedure with index i (from 1) as BigDecimal.

Throws:
java.sql.SQLException

getDate

public static java.sql.Date getDate(java.sql.CallableStatement stmt,
                                    int i)
                             throws java.sql.SQLException
Returns OUT parameter of stored procedure with index i (from 1) as Date.

Throws:
java.sql.SQLException

getTime

public static java.sql.Time getTime(java.sql.CallableStatement stmt,
                                    int i)
                             throws java.sql.SQLException
Returns OUT parameter of stored procedure with index i (from 1) as Time.

Throws:
java.sql.SQLException

getTimestamp

public static java.sql.Timestamp getTimestamp(java.sql.CallableStatement stmt,
                                              int i)
                                       throws java.sql.SQLException
Returns OUT parameter of stored procedure with index i (from 1) as Timestamp.

Throws:
java.sql.SQLException

getObject

public static java.lang.Object getObject(java.sql.CallableStatement stmt,
                                         int i)
                                  throws java.sql.SQLException
Returns OUT parameter of stored procedure with index i (from 1) as Object.

Throws:
java.sql.SQLException

singleRowQueryReturningInt

public final int singleRowQueryReturningInt(java.sql.PreparedStatement stmt)
                                     throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Result is returned as a single int. Closes statement after execution.

Throws:
java.sql.SQLException

singleRowQueryReturningLong

public final long singleRowQueryReturningLong(java.sql.PreparedStatement stmt)
                                       throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Result is returned as a single long. Closes statement after execution.

Throws:
java.sql.SQLException

singleRowQueryReturningDouble

public final double singleRowQueryReturningDouble(java.sql.PreparedStatement stmt)
                                           throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Result is returned as a single double. Closes statement after execution.

Throws:
java.sql.SQLException

singleRowQueryReturningINT

public final java.lang.Integer singleRowQueryReturningINT(java.sql.PreparedStatement stmt)
                                                   throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Result is returned as a single Integer. Closes statement after execution.

Throws:
java.sql.SQLException

singleRowQueryReturningLONG

public final java.lang.Long singleRowQueryReturningLONG(java.sql.PreparedStatement stmt)
                                                 throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Result is returned as a single Long. Closes statement after execution.

Throws:
java.sql.SQLException

singleRowQueryReturningDOUBLE

public final java.lang.Double singleRowQueryReturningDOUBLE(java.sql.PreparedStatement stmt)
                                                     throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Result is returned as a single Double. Closes statement after execution.

Throws:
java.sql.SQLException

singleRowQueryReturningString

public final java.lang.String singleRowQueryReturningString(java.sql.PreparedStatement stmt)
                                                     throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Result is returned as a single String. Closes statement after execution.

Throws:
java.sql.SQLException

singleRowQueryReturningBytes

public final byte[] singleRowQueryReturningBytes(java.sql.PreparedStatement stmt)
                                          throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Result is returned as a single byte[]. Closes statement after execution.

Throws:
java.sql.SQLException

singleRowQueryReturningBigDecimal

public final java.math.BigDecimal singleRowQueryReturningBigDecimal(java.sql.PreparedStatement stmt)
                                                             throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Result is returned as a single BigDecimal. Closes statement after execution.

Throws:
java.sql.SQLException

singleRowQueryReturningDate

public final java.sql.Date singleRowQueryReturningDate(java.sql.PreparedStatement stmt)
                                                throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Result is returned as a single Date. Closes statement after execution.

Throws:
java.sql.SQLException

singleRowQueryReturningTime

public final java.sql.Time singleRowQueryReturningTime(java.sql.PreparedStatement stmt)
                                                throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Result is returned as a single Time. Closes statement after execution.

Throws:
java.sql.SQLException

singleRowQueryReturningTimestamp

public final java.sql.Timestamp singleRowQueryReturningTimestamp(java.sql.PreparedStatement stmt)
                                                          throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Result is returned as a single Timestamp. Closes statement after execution.

Throws:
java.sql.SQLException

singleRowQueryReturningObject

public final java.lang.Object singleRowQueryReturningObject(java.sql.PreparedStatement stmt)
                                                     throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Result is returned as a single Object. Closes statement after execution.

Throws:
java.sql.SQLException

singleRowQueryReturningClob

public final java.lang.String singleRowQueryReturningClob(java.sql.PreparedStatement stmt)
                                                   throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Result is returned as a single String. Closes statement after execution.

Throws:
java.sql.SQLException

singleRowQueryReturningBlob

public final byte[] singleRowQueryReturningBlob(java.sql.PreparedStatement stmt)
                                         throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Result is returned as a single byte[]. Closes statement after execution.

Throws:
java.sql.SQLException

singleRowQueryReturning

public final <T extends MappedType> T singleRowQueryReturning(java.lang.Class<T> cls,
                                                              java.sql.PreparedStatement stmt)
                                                   throws java.sql.SQLException
Executes select query, which should return one row and one column (more or less than one rows raises runtime exception, more or less than one column raises preprocess-time exception). Closes statement after execution.

Parameters:
cls - class with user-defined mapping
Throws:
java.sql.SQLException

optionalRowQueryReturningInt

public final java.lang.Integer optionalRowQueryReturningInt(java.sql.PreparedStatement stmt)
                                                     throws java.sql.SQLException
Same as singleRowQueryReturningInt(java.sql.PreparedStatement) but returns null when no rows found. Closes statement after execution.

Throws:
java.sql.SQLException

optionalRowQueryReturningLong

public final java.lang.Long optionalRowQueryReturningLong(java.sql.PreparedStatement stmt)
                                                   throws java.sql.SQLException
Same as singleRowQueryReturningLong(java.sql.PreparedStatement) but returns null when no rows found. Closes statement after execution.

Throws:
java.sql.SQLException

optionalRowQueryReturningDouble

public final java.lang.Double optionalRowQueryReturningDouble(java.sql.PreparedStatement stmt)
                                                       throws java.sql.SQLException
Same as singleRowQueryReturningDouble(java.sql.PreparedStatement) but returns null when no rows found. Closes statement after execution.

Throws:
java.sql.SQLException

optionalRowQueryReturningString

public final java.lang.String optionalRowQueryReturningString(java.sql.PreparedStatement stmt)
                                                       throws java.sql.SQLException
Same as singleRowQueryReturningString(java.sql.PreparedStatement) but returns null when no rows found. Closes statement after execution.

Throws:
java.sql.SQLException

optionalRowQueryReturningBytes

public final byte[] optionalRowQueryReturningBytes(java.sql.PreparedStatement stmt)
                                            throws java.sql.SQLException
Same as singleRowQueryReturningBytes(java.sql.PreparedStatement) but returns null when no rows found. Closes statement after execution.

Throws:
java.sql.SQLException

optionalRowQueryReturningBigDecimal

public final java.math.BigDecimal optionalRowQueryReturningBigDecimal(java.sql.PreparedStatement stmt)
                                                               throws java.sql.SQLException
Same as singleRowQueryReturningBigDecimal(java.sql.PreparedStatement) but returns null when no rows found. Closes statement after execution.

Throws:
java.sql.SQLException

optionalRowQueryReturningDate

public final java.sql.Date optionalRowQueryReturningDate(java.sql.PreparedStatement stmt)
                                                  throws java.sql.SQLException
Same as singleRowQueryReturningDate(java.sql.PreparedStatement) but returns null when no rows found. Closes statement after execution.

Throws:
java.sql.SQLException

optionalRowQueryReturningTime

public final java.sql.Time optionalRowQueryReturningTime(java.sql.PreparedStatement stmt)
                                                  throws java.sql.SQLException
Same as singleRowQueryReturningTime(java.sql.PreparedStatement) but returns null when no rows found. Closes statement after execution.

Throws:
java.sql.SQLException

optionalRowQueryReturningTimestamp

public final java.sql.Timestamp optionalRowQueryReturningTimestamp(java.sql.PreparedStatement stmt)
                                                            throws java.sql.SQLException
Same as singleRowQueryReturningTimestamp(java.sql.PreparedStatement) but returns null when no rows found. Closes statement after execution.

Throws:
java.sql.SQLException

optionalRowQueryReturningClob

public final java.lang.String optionalRowQueryReturningClob(java.sql.PreparedStatement stmt)
                                                     throws java.sql.SQLException
Same as singleRowQueryReturningClob(java.sql.PreparedStatement) but returns null when no rows found. Closes statement after execution.

Throws:
java.sql.SQLException

optionalRowQueryReturningBlob

public final byte[] optionalRowQueryReturningBlob(java.sql.PreparedStatement stmt)
                                           throws java.sql.SQLException
Same as singleRowQueryReturningBlob(java.sql.PreparedStatement) but returns null when no rows found. Closes statement after execution.

Throws:
java.sql.SQLException

optionalRowQueryReturningObject

public final java.lang.Object optionalRowQueryReturningObject(java.sql.PreparedStatement stmt)
                                                       throws java.sql.SQLException
Same as singleRowQueryReturningObject(java.sql.PreparedStatement) but returns null when no rows found. Closes statement after execution.

Throws:
java.sql.SQLException

optionalRowQueryReturning

public final <T extends MappedType> T optionalRowQueryReturning(java.lang.Class<T> cls,
                                                                java.sql.PreparedStatement stmt)
                                                     throws java.sql.SQLException
Same as singleRowQueryReturning(Class, java.sql.PreparedStatement) but returns null when no rows found. Closes statement after execution.

Parameters:
cls - class with user-defined mapping
Throws:
java.sql.SQLException

columnOfInt

public final int[] columnOfInt(java.sql.PreparedStatement stmt)
                        throws java.sql.SQLException
Executes select query returning single column of int. Closes statement after execution.

Throws:
java.sql.SQLException

columnOfLong

public final long[] columnOfLong(java.sql.PreparedStatement stmt)
                          throws java.sql.SQLException
Executes select query returning single column of long. Closes statement after execution.

Throws:
java.sql.SQLException

columnOfDouble

public final double[] columnOfDouble(java.sql.PreparedStatement stmt)
                              throws java.sql.SQLException
Executes select query returning single column of double. Closes statement after execution.

Throws:
java.sql.SQLException

columnOfString

public final java.lang.String[] columnOfString(java.sql.PreparedStatement stmt)
                                        throws java.sql.SQLException
Executes select query returning single column of String. Closes statement after execution.

Throws:
java.sql.SQLException

columnOfObject

public final java.lang.Object[] columnOfObject(java.sql.PreparedStatement stmt)
                                        throws java.sql.SQLException
Executes select query returning single column of Object. Closes statement after execution.

Throws:
java.sql.SQLException

columnOf

public final <T extends MappedType> java.util.List<T> columnOf(java.lang.Class<T> cls,
                                                               java.sql.PreparedStatement stmt)
                                                    throws java.sql.SQLException
Executes select query returning single column of T. Closes statement after execution.

Parameters:
cls - class with user-defined mapping
Throws:
java.sql.SQLException

singleRowQuery

public final <T> T singleRowQuery(java.sql.PreparedStatement stmt,
                                  java.lang.Class<T> cls)
                       throws java.sql.SQLException
Executes select query, which should return one row (more or less than one rows raises runtime exception). Result is returned as an object which class implementation is generated by preprocessor. Closes statement after execution.

Parameters:
stmt - SQL statement
cls - row type class or interface generated by preprocessor (see RowType).
Throws:
java.sql.SQLException

optionalRowQuery

public final <T> T optionalRowQuery(java.sql.PreparedStatement stmt,
                                    java.lang.Class<T> cls)
                         throws java.sql.SQLException
Same as singleRowQuery(java.sql.PreparedStatement, Class) but returns null when no rows found. Closes statement after execution.

Throws:
java.sql.SQLException

multiRowQuery

public final <T> java.util.List<T> multiRowQuery(java.sql.PreparedStatement stmt,
                                                 java.lang.Class<T> cls)
                                      throws java.sql.SQLException
Executes select query returning multiple (zero or more) rows. Result is returned as a list of objects which class implementation is generated by preprocessor. Closes statement after execution.

Parameters:
stmt - SQL statement
cls - row type class or interface generated by preprocessor (see RowType).
Throws:
java.sql.SQLException

metaRowQuery

public final <T> T metaRowQuery(java.sql.PreparedStatement stmt,
                                java.lang.Class<T> cls)
                     throws java.sql.SQLException
Returns result set metadata as RowType object. Columns of RowType contain:
  • For integer types (byte, short, int, long) field contains column's max length
  • For character types (String) field contains string of max length (containing only '\0' chars)
  • For RAW types (byte[]) field contains byte array of max length (containing only zero bytes)
  • For other types field contains 0/null/false.

Throws:
java.sql.SQLException

close

public final void close(java.sql.Statement st)
Closes statement.


close

public final void close(java.sql.ResultSet rs,
                        java.sql.Statement st)
Closes result set and statement.


closeStatements

public final void closeStatements()
Closes all open statements (usually this method is called by wrappers automatically).


setClob

public final void setClob(java.sql.PreparedStatement stmt,
                          java.lang.String text)
                   throws java.sql.SQLException
Writes text to CLOB. Statement should contain SELECT … FOR UPDATE SQL statement. This method does NOT write EMPTY_CLOB before writing data, so you should do it yourself if required. Closes statement after execution.

Parameters:
stmt - SELECT … FOR UPDATE SQL statement
text - text to write
Throws:
java.sql.SQLException

setBlob

public final void setBlob(java.sql.PreparedStatement stmt,
                          byte[] data)
                   throws java.sql.SQLException
Writes bytes to BLOB. Statement should contain SELECT … FOR UPDATE SQL statement. This method does NOT write EMPTY_BLOB before writing data, so you should do it yourself if required. Closes statement after execution.

Parameters:
stmt - SELECT … FOR UPDATE SQL statement
data - bytes to write
Throws:
java.sql.SQLException

getNextId

public final long getNextId(java.lang.String sequence)
                     throws java.sql.SQLException
Returns next number in sequence.

Parameters:
sequence - sequence name
Throws:
java.sql.SQLException

setParameters

public final void setParameters(java.sql.PreparedStatement st,
                                java.lang.Object... in)
                         throws java.sql.SQLException
Binds prepared statement parameters to specific values. Allowed object types: Byte, Short, Integer, Long, Float, Double, String, StringBuilder, Boolean, Character, Date, byte[], MappedType. Effect is the same as for setParameter(st, 1, in[0]); ... setParameter(st, n, in[n - 1]);

Parameters:
st - SQL statement
in - parameter values
Throws:
java.sql.SQLException

setParameter

public final void setParameter(java.sql.PreparedStatement st,
                               int index,
                               java.lang.Object param,
                               java.lang.Class<?> cls)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

setParameter

public final void setParameter(java.sql.PreparedStatement st,
                               int index,
                               java.lang.Object param)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

callStoredProc

public final java.lang.Object[] callStoredProc(java.lang.String name,
                                               java.lang.Object... in)
                                        throws java.sql.SQLException
Calls stored procedure. Input parameters are set just like in setParameters(java.sql.PreparedStatement, Object...).

Parameters:
name - Stored procedure name. SQL statement is generated by procedure name and parameters count as { call proc_name(in) }.
in - input/output parameters array (see setParameters(java.sql.PreparedStatement, Object...)). Can contain objects of type OutParameter.
Returns:
output parameters values, not null. Table of correspondence of type codes to Java classes:
TINYINTByte
SMALLINTShort
INTEGERInteger
BIGINTLong
FLOATFloat
REAL, DOUBLEDouble
DECIMAL, NUMERICBigDecimal
CHAR, VARCHARString
BINARY, VARBINARYbyte[]
DATEDate
TIMETime
TIMESTAMPTimestamp
CLOBString
BLOBbyte[]
OTHERObject
Throws:
java.sql.SQLException

callStoredBlock

public final java.lang.Object[] callStoredBlock(java.lang.String block,
                                                java.lang.Object... in)
                                         throws java.sql.SQLException
Executes PL/SQL block. Other parameters see callStoredProc(String, Object...).

Parameters:
block - PL/SQL block text
Throws:
java.sql.SQLException

callStoredProc

public final java.lang.Object[] callStoredProc(java.lang.String name,
                                               boolean block,
                                               java.lang.Object... in)
                                        throws java.sql.SQLException
Executes stored procedure or PL/SQL block (depending of block parameter). If block == true then callStoredBlock(String, Object...) is executed, else if block == false then callStoredProc(String, Object...) is executed.

Throws:
java.sql.SQLException

getInterface

public final <T extends LIDBCommon> T getInterface(java.lang.Class<T> iface)
Returns data access interface generated by preprocessor. Data access class should be marked with SQLG annotation having attribute SQLG.inline() = true.

Parameters:
iface - interface class
Returns:
data access interface implementation object working in current transaction