|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectmondrian.rolap.SqlStatement
public class SqlStatement
SqlStatement contains a SQL statement and associated resources throughout its lifetime.
The goal of SqlStatement is to make tracing, error-handling and
resource-management easier. None of the methods throws a SQLException;
if an error occurs in one of the methods, the method wraps the exception
in a RuntimeException describing the high-level operation, logs
that the operation failed, and throws that RuntimeException.
If methods succeed, the method generates lifecycle logging such as the elapsed time and number of rows fetched.
There are a few obligations on the caller. The caller must:
handle(Throwable) method if one of the contained
objects (say the ResultSet) gives an error;
close() method if all operations complete
successfully.
rowCount field each time a row is fetched.
The close() method is idempotent. You are welcome to call it
more than once.
SqlStatement is not thread-safe.
| Nested Class Summary | |
|---|---|
static interface |
SqlStatement.Accessor
|
static class |
SqlStatement.MyDelegatingInvocationHandler
Reflectively implements the ResultSet interface by routing method
calls to the result set inside a SqlStatement. |
static class |
SqlStatement.StatementLocus
|
static class |
SqlStatement.Type
The approximate JDBC type of a column. |
| Field Summary | |
|---|---|
int |
rowCount
|
| Constructor Summary | |
|---|---|
SqlStatement(DataSource dataSource,
String sql,
List<SqlStatement.Type> types,
int maxRows,
int firstRowOrdinal,
Locus locus,
int resultSetType,
int resultSetConcurrency)
Creates a SqlStatement. |
|
| Method Summary | |
|---|---|
void |
close()
Closes all resources (statement, result set) held by this SqlStatement. |
void |
execute()
Executes the current statement, and handles any SQLException. |
List<SqlStatement.Accessor> |
getAccessors()
|
ResultSet |
getResultSet()
|
ResultSet |
getWrappedResultSet()
Returns the result set in a proxy which automatically closes this SqlStatement (and hence also the statement and result set) when the result set is closed. |
static SqlStatement.Type |
guessType(SqlStatement.Type suggestedType,
ResultSetMetaData metaData,
int i)
Chooses the most appropriate type for accessing the values of a column in a result set. |
List<SqlStatement.Type> |
guessTypes()
|
RuntimeException |
handle(Throwable e)
Handles an exception thrown from the ResultSet, implicitly calls close(), and returns an exception which includes the full
stack, including a description of the high-level operation. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public int rowCount
| Constructor Detail |
|---|
public SqlStatement(DataSource dataSource,
String sql,
List<SqlStatement.Type> types,
int maxRows,
int firstRowOrdinal,
Locus locus,
int resultSetType,
int resultSetConcurrency)
dataSource - Data sourcesql - SQLtypes - Suggested types of columns, or null;
if present, must have one element for each SQL column;
each not-null entry overrides deduced JDBC type of the columnmaxRows - Maximum rows; <= 0 means no maximumfirstRowOrdinal - Ordinal of first row to skip to; <= 0 do not skiplocus - Execution context of this statementresultSetType - Result set typeresultSetConcurrency - Result set concurrency| Method Detail |
|---|
public void execute()
public void close()
If any of them fails, wraps them in a
RuntimeException describing the high-level operation which
this statement was performing. No further error-handling is required
to produce a descriptive stack trace, unless you want to absorb the
error.
public ResultSet getResultSet()
public RuntimeException handle(Throwable e)
close(), and returns an exception which includes the full
stack, including a description of the high-level operation.
e - Exception
public static SqlStatement.Type guessType(SqlStatement.Type suggestedType,
ResultSetMetaData metaData,
int i)
throws SQLException
NOTE: It is possible that this method is driver-dependent. If this is
the case, move it to Dialect.
suggestedType - Type suggested by Level.internalType attributemetaData - Result set metadatai - Column ordinal (0-based)
SQLException - on error
public List<SqlStatement.Type> guessTypes()
throws SQLException
SQLException
public List<SqlStatement.Accessor> getAccessors()
throws SQLException
SQLExceptionpublic ResultSet getWrappedResultSet()
This helps to prevent connection leaks. The caller still has to remember to call ResultSet.close(), of course.
|
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||