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 JDBCStatementCache
Cache for physical statements.private final boolean
Tells if we're holding a callable statement or not.private StatementCacheInteractor
The owner of this logical entity.private CallableStatement
Associated physical callable statement, if any.private PreparedStatement
Associated physical prepared statement.private final StatementKey
The key for the associated statement.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
ConstructorsModifierConstructorDescriptionprotected
LogicalStatementEntity
(PreparedStatement physicalPs, StatementKey stmtKey, StatementCacheInteractor cacheInteractor) Create a logical entity for aPreparedStatement
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close the logical statement.void
long[]
long
executeLargeUpdate
(String sql) long
executeLargeUpdate
(String sql, int autoGeneratedKeys) long
executeLargeUpdate
(String sql, int[] columnIndexes) long
executeLargeUpdate
(String sql, String[] columnNames) long
long
(package private) CallableStatement
Returns the associated physical callable statement.(package private) PreparedStatement
Returns the associated physical prepared statement.private Statement
Returns the associated physical statement.boolean
(package private) boolean
Tells if the logical entity is closed.boolean
isWrapperFor
(Class<?> iface) Check whether this instance wraps an object that implements the interface specified byiface
.void
setLargeMaxRows
(long maxRows) <T> T
Returns an instance of the specified interface if this instance is a wrapper for the interface.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.sql.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 physicalPreparedStatement
stmtKey
- cache key for the physical statementcacheInteractor
- creating statement cache interactor- Throws:
IllegalArgumentException
- ifcache
isnull
-
-
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:
close
in interfaceAutoCloseable
- Specified by:
close
in 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:
true
if closed,false
if open.
-
isWrapperFor
Check whether this instance wraps an object that implements the interface specified byiface
.- Specified by:
isWrapperFor
in interfaceWrapper
- Parameters:
iface
- a class defining an interface- Returns:
true
if this instance implementsiface
, orfalse
otherwise- 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:
unwrap
in 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:
closeOnCompletion
in interfaceStatement
- Throws:
SQLException
-
isCloseOnCompletion
- Specified by:
isCloseOnCompletion
in interfaceStatement
- Throws:
SQLException
-
executeLargeBatch
- Specified by:
executeLargeBatch
in interfaceStatement
- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdate
in interfaceStatement
- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdate
in interfaceStatement
- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdate
in interfaceStatement
- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdate
in interfaceStatement
- Throws:
SQLException
-
getLargeUpdateCount
- Specified by:
getLargeUpdateCount
in interfaceStatement
- Throws:
SQLException
-
getLargeMaxRows
- Specified by:
getLargeMaxRows
in interfaceStatement
- Throws:
SQLException
-
setLargeMaxRows
- Specified by:
setLargeMaxRows
in interfaceStatement
- Throws:
SQLException
-