Class LogicalStatementEntity
- java.lang.Object
-
- org.apache.derby.client.am.LogicalStatementEntity
-
- All Implemented Interfaces:
java.lang.AutoCloseable,java.sql.Statement,java.sql.Wrapper
- Direct Known Subclasses:
LogicalPreparedStatement
abstract class LogicalStatementEntity extends java.lang.Object implements java.sql.StatementCommon class interacting with the JDBC statement cache for logical prepared statements and logical callable statements.Note that
getPhysPs()andgetPhysCs()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
physicalPsandphysicalCsis 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
Fields Modifier and Type Field Description private JDBCStatementCachecacheCache for physical statements.private booleanhasCallableStmtTells if we're holding a callable statement or not.private StatementCacheInteractorownerThe owner of this logical entity.private java.sql.CallableStatementphysicalCsAssociated physical callable statement, if any.private java.sql.PreparedStatementphysicalPsAssociated physical prepared statement.private StatementKeystmtKeyThe key for the associated statement.
-
Constructor Summary
Constructors Modifier Constructor Description protectedLogicalStatementEntity(java.sql.PreparedStatement physicalPs, StatementKey stmtKey, StatementCacheInteractor cacheInteractor)Create a logical entity for aPreparedStatement.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the logical statement.voidcloseOnCompletion()long[]executeLargeBatch()longexecuteLargeUpdate(java.lang.String sql)longexecuteLargeUpdate(java.lang.String sql, int autoGeneratedKeys)longexecuteLargeUpdate(java.lang.String sql, int[] columnIndexes)longexecuteLargeUpdate(java.lang.String sql, java.lang.String[] columnNames)longgetLargeMaxRows()longgetLargeUpdateCount()(package private) java.sql.CallableStatementgetPhysCs()Returns the associated physical callable statement.(package private) java.sql.PreparedStatementgetPhysPs()Returns the associated physical prepared statement.private java.sql.StatementgetPhysStmt()Returns the associated physical statement.booleanisCloseOnCompletion()(package private) booleanisLogicalEntityClosed()Tells if the logical entity is closed.booleanisWrapperFor(java.lang.Class<?> iface)Check whether this instance wraps an object that implements the interface specified byiface.voidsetLargeMaxRows(long maxRows)<T> Tunwrap(java.lang.Class<T> iface)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 Detail
-
hasCallableStmt
private final boolean hasCallableStmt
Tells if we're holding a callable statement or not.Used for sanity checking.
-
physicalPs
private java.sql.PreparedStatement physicalPs
Associated physical prepared statement.If this is
null, the logical entity is closed.
-
physicalCs
private java.sql.CallableStatement 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
private StatementCacheInteractor owner
The owner of this logical entity.
-
stmtKey
private final StatementKey stmtKey
The key for the associated statement.
-
cache
private final JDBCStatementCache cache
Cache for physical statements.
-
-
Constructor Detail
-
LogicalStatementEntity
protected LogicalStatementEntity(java.sql.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:
java.lang.IllegalArgumentException- ifcacheisnull
-
-
Method Detail
-
getPhysPs
java.sql.PreparedStatement getPhysPs() throws java.sql.SQLExceptionReturns the associated physical prepared statement.- Returns:
- A prepared statement.
- Throws:
java.sql.SQLException- if the logical statement has been closed
-
getPhysCs
java.sql.CallableStatement getPhysCs() throws java.sql.SQLExceptionReturns the associated physical callable statement.- Returns:
- A callable statement.
- Throws:
java.sql.SQLException- if the logical statement has been closed
-
getPhysStmt
private java.sql.Statement getPhysStmt() throws java.sql.SQLExceptionReturns the associated physical statement.- Returns:
- A statement.
- Throws:
java.sql.SQLException- if the logical statement has been closed
-
close
public void close() throws java.sql.SQLExceptionClose the logical statement.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.sql.Statement- Throws:
java.sql.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
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLExceptionCheck whether this instance wraps an object that implements the interface specified byiface.- Specified by:
isWrapperForin interfacejava.sql.Wrapper- Parameters:
iface- a class defining an interface- Returns:
trueif this instance implementsiface, orfalseotherwise- Throws:
java.sql.SQLException- if an error occurs while determining if this instance implementsiface
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLExceptionReturns an instance of the specified interface if this instance is a wrapper for the interface.- Specified by:
unwrapin interfacejava.sql.Wrapper- Parameters:
iface- a class defining an interface- Returns:
- an object that implements the interface
- Throws:
java.sql.SQLException- if no object is found that implements the interface
-
closeOnCompletion
public void closeOnCompletion() throws java.sql.SQLException- Specified by:
closeOnCompletionin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
isCloseOnCompletion
public boolean isCloseOnCompletion() throws java.sql.SQLException- Specified by:
isCloseOnCompletionin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
executeLargeBatch
public long[] executeLargeBatch() throws java.sql.SQLException- Specified by:
executeLargeBatchin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
executeLargeUpdate
public long executeLargeUpdate(java.lang.String sql) throws java.sql.SQLException- Specified by:
executeLargeUpdatein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
executeLargeUpdate
public long executeLargeUpdate(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException- Specified by:
executeLargeUpdatein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
executeLargeUpdate
public long executeLargeUpdate(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException- Specified by:
executeLargeUpdatein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
executeLargeUpdate
public long executeLargeUpdate(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException- Specified by:
executeLargeUpdatein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getLargeUpdateCount
public long getLargeUpdateCount() throws java.sql.SQLException- Specified by:
getLargeUpdateCountin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getLargeMaxRows
public long getLargeMaxRows() throws java.sql.SQLException- Specified by:
getLargeMaxRowsin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
setLargeMaxRows
public void setLargeMaxRows(long maxRows) throws java.sql.SQLException- Specified by:
setLargeMaxRowsin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
-