Class LogicalStatementEntity
- All Implemented Interfaces:
AutoCloseable, Statement, Wrapper
- Direct Known Subclasses:
LogicalPreparedStatement
Note that getPhysPs() and getPhysCs() takes care of checking if
the logical statement has been closed. The physical statement will take care
of validating itself.
Beside from the above, special treatment of logical entities happens on close. This is the point where cache interaction takes place, and also where the appropriate methods are called on the physical statement to perform the necessary clean up for later reuse.
A note regarding the thread safety of this class, is that access to
physicalPs and physicalCs is guarded by the instance of this
class, but it is assumed that operation on/within the physical statement is
synchronized in the physical statement itself .
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final JDBCStatementCacheCache for physical statements.private final booleanTells if we're holding a callable statement or not.private StatementCacheInteractorThe owner of this logical entity.private CallableStatementAssociated physical callable statement, if any.private PreparedStatementAssociated physical prepared statement.private final StatementKeyThe key for the associated statement.Fields inherited from interface Statement
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLogicalStatementEntity(PreparedStatement physicalPs, StatementKey stmtKey, StatementCacheInteractor cacheInteractor) Create a logical entity for aPreparedStatement. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the logical statement.void/////////////////////////////////////////////////////////////////long[]/////////////////////////////////////////////////////////////////longexecuteLargeUpdate(String sql) longexecuteLargeUpdate(String sql, int autoGeneratedKeys) longexecuteLargeUpdate(String sql, int[] columnIndexes) longexecuteLargeUpdate(String sql, String[] columnNames) longlong(package private) CallableStatementReturns the associated physical callable statement.(package private) PreparedStatementReturns the associated physical prepared statement.private StatementReturns the associated physical statement.boolean(package private) booleanTells if the logical entity is closed.booleanisWrapperFor(Class<?> iface) Check whether this instance wraps an object that implements the interface specified byiface.voidsetLargeMaxRows(long maxRows) <T> TReturns an instance of the specified interface if this instance is a wrapper for the interface.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Statement
addBatch, cancel, clearBatch, clearWarnings, enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, execute, execute, execute, execute, executeBatch, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, isClosed, isPoolable, isSimpleIdentifier, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeout
-
Field Details
-
hasCallableStmt
private final boolean hasCallableStmtTells if we're holding a callable statement or not.Used for sanity checking.
-
physicalPs
Associated physical prepared statement.If this is
null, the logical entity is closed. -
physicalCs
Associated physical callable statement, if any.This is a convenience reference, to avoid having to cast on every invocation of
getPhysCs()if the logical entity represents a callable statement. -
owner
The owner of this logical entity. -
stmtKey
The key for the associated statement. -
cache
Cache for physical statements.
-
-
Constructor Details
-
LogicalStatementEntity
protected LogicalStatementEntity(PreparedStatement physicalPs, StatementKey stmtKey, StatementCacheInteractor cacheInteractor) Create a logical entity for aPreparedStatement.- Parameters:
physicalPs- a physicalPreparedStatementstmtKey- cache key for the physical statementcacheInteractor- creating statement cache interactor- Throws:
IllegalArgumentException- ifcacheisnull
-
-
Method Details
-
getPhysPs
Returns the associated physical prepared statement.- Returns:
- A prepared statement.
- Throws:
SQLException- if the logical statement has been closed
-
getPhysCs
Returns the associated physical callable statement.- Returns:
- A callable statement.
- Throws:
SQLException- if the logical statement has been closed
-
getPhysStmt
Returns the associated physical statement.- Returns:
- A statement.
- Throws:
SQLException- if the logical statement has been closed
-
close
Close the logical statement.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceStatement- Throws:
SQLException- if closing the statement fails
-
isLogicalEntityClosed
boolean isLogicalEntityClosed()Tells if the logical entity is closed.If this method is used to avoid the possibility of raising an exception because the logical statement has been closed and then invoke a method on the physical statement, one must synchronize on this instance in the calling code.
- Returns:
trueif closed,falseif open.
-
isWrapperFor
Check whether this instance wraps an object that implements the interface specified byiface.- Specified by:
isWrapperForin interfaceWrapper- Parameters:
iface- a class defining an interface- Returns:
trueif this instance implementsiface, orfalseotherwise- Throws:
SQLException- if an error occurs while determining if this instance implementsiface
-
unwrap
Returns an instance of the specified interface if this instance is a wrapper for the interface.- Specified by:
unwrapin interfaceWrapper- Parameters:
iface- a class defining an interface- Returns:
- an object that implements the interface
- Throws:
SQLException- if no object is found that implements the interface
-
closeOnCompletion
/////////////////////////////////////////////////////////////////- Specified by:
closeOnCompletionin interfaceStatement- Throws:
SQLException
-
isCloseOnCompletion
- Specified by:
isCloseOnCompletionin interfaceStatement- Throws:
SQLException
-
executeLargeBatch
/////////////////////////////////////////////////////////////////- Specified by:
executeLargeBatchin interfaceStatement- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdatein interfaceStatement- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdatein interfaceStatement- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdatein interfaceStatement- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdatein interfaceStatement- Throws:
SQLException
-
getLargeUpdateCount
- Specified by:
getLargeUpdateCountin interfaceStatement- Throws:
SQLException
-
getLargeMaxRows
- Specified by:
getLargeMaxRowsin interfaceStatement- Throws:
SQLException
-
setLargeMaxRows
- Specified by:
setLargeMaxRowsin interfaceStatement- Throws:
SQLException
-