Class StatementFacade
- All Implemented Interfaces:
InvocationHandler
The handles this facade hands out implement only the standard JDBC interfaces, as do the proxies of the interceptors
that wrap statements beneath it, so the driver's own statement and result set classes are never visible to the
application through a cast. Every result set a pooled statement hands back, and every result set that one of those
handles hands back in turn, reaches the application as one of these handles, whatever the method that returned it was
called: a cursor that arrives as a plain object - a REF cursor OUT-parameter read through
CallableStatement.getObject(int), or the nested cursor a ResultSet.getObject(int)
column value hands out - is sealed to the borrow like the ones the standard result set methods return. The
Wrapper methods are delegated to the driver, and unwrap is the supported way to reach
driver-specific methods through every layer. An unwrapped driver object, however, is a driver object rather than a
pooled handle: retiring these handles at the end of the borrow does not retire what was already unwrapped, and only
tracking the statements with StatementFinalizer (or the application
closing them) keeps the statements underneath from outliving the borrow - unless an interceptor recycles them for the
next borrow, as a statement cache does.
The rule that decides what is sealed is a type rule, and its boundary is the type. A value a handle hands back
that is not itself a result set is passed through as it came (what a statement handle reports as its connection
is the pool's own handle, not the driver's), and a cursor that rides inside such a value reaches the application
over that same unsealed path: the Array read for an ARRAY column or an ARRAY OUT-parameter
hands out its cursors through Array.getResultSet(), a Struct through its
attributes, and the deprecated Ref a getRef call hands back is itself the
driver's object; the Blob, Clob and SQLXML locators are the
same shape without a cursor in them. None of that is sealed to the borrow, just as what unwrap()
hands back is not: this facade seals the result sets a pooled statement hands out and the result sets those
handles hand out in turn, not cursors that arrive inside values of another type - the REF cursor OUT-parameter
and the nested cursor named above are themselves result sets, which is why they are sealed and these composites
are not. Whether a driver object kept past the borrow still reads, and over what session, is the driver's affair;
no handle of this facade retires it.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classProxy for a ResultSet.protected classProxy for a SQL statement used to measure query execute time. -
Field Summary
Fields inherited from class AbstractCreateStatementInterceptor
constructors, CREATE_STATEMENT, CREATE_STATEMENT_IDX, EXECUTE, EXECUTE_BATCH, EXECUTE_LARGE_BATCH, EXECUTE_LARGE_UPDATE, EXECUTE_QUERY, EXECUTE_TYPES, EXECUTE_UPDATE, GET_GENERATED_KEYS, GET_RESULTSET, GET_STATEMENT, PREPARE_CALL, PREPARE_CALL_IDX, PREPARE_STATEMENT, PREPARE_STATEMENT_IDX, RESULTSET_IDX, STATEMENT_TYPE_COUNT, STATEMENT_TYPESModifier and TypeFieldDescriptionprotected static final Constructor<?>[]the constructors that are used to create statement proxies.protected static final Stringprotected static final intprotected static final Stringprotected static final Stringprotected static final Stringprotected static final StringStatement.executeLargeUpdate(String)and its overloads, andPreparedStatement.executeLargeUpdate()protected static final Stringprotected static final String[]Array of execute type method namesprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final intprotected static final Stringprotected static final intprotected static final intprotected static final intCount of statement types inAbstractCreateStatementInterceptor.STATEMENT_TYPESprotected static final String[]Array of statement type method namesFields inherited from class JdbcInterceptor
ABORT_VAL, CLOSE_VAL, EQUALS_VAL, GETCONNECTION_VAL, HASHCODE_VAL, ISCLOSED_VAL, ISVALID_VAL, ISWRAPPERFOR_VAL, properties, TOSTRING_VAL, UNWRAP_VALModifier and TypeFieldDescriptionstatic final StringConnection.abort(java.util.concurrent.Executor)method namestatic final StringConnection.close()method namestatic final Stringstatic final StringPooledConnection.getConnection()method namestatic final Stringstatic final StringConnection.isClosed()method namestatic final StringConnection.isValid(int)method namestatic final StringWrapper.isWrapperFor(Class)method nameprotected Map<String, PoolProperties.InterceptorProperty> Properties for this interceptor.static final StringObject.toString()method namestatic final StringWrapper.unwrap(Class)method name -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedStatementFacade(JdbcInterceptor interceptor) Constructs a StatementFacade. -
Method Summary
Modifier and TypeMethodDescriptionvoidMarks the borrow as ended, which closes every statement and result set handle this facade handed out.createStatement(Object proxy, Method method, Object[] args, Object statement, long time) Creates a statement interceptor to monitor query response timesMethods inherited from class AbstractCreateStatementInterceptor
getConstructor, invoke, isExecute, isStatement, process, resetModifier and TypeMethodDescriptionprotected Constructor<?> getConstructor(int idx, Class<?> clazz) Creates a constructor for a proxy class, if one doesn't already exist.Gets invoked each time an operation onConnectionis invoked.protected booleanReturns true if the method that is being invoked matches one of the execute types.protected booleanisStatement(Method method, boolean process) Returns true if the method that is being invoked matches one of the statement types.protected booleanReturns true if the method that is being invoked matches one of the method names passed invoidreset(ConnectionPool parent, PooledConnection con) no-op for this interceptor. no state is stored.Methods inherited from class JdbcInterceptor
compare, compare, disconnected, getNext, getProperties, isUseEquals, poolClosed, poolStarted, setNext, setProperties, setUseEqualsModifier and TypeMethodDescriptionbooleanCompares a method name (String) to a method (Method)JdbcInterceptor.compare(String,String)Uses reference comparison unless the useEquals property is set to truebooleanPerforms a string comparison, using references unless the useEquals property is set to true.voiddisconnected(ConnectionPool parent, PooledConnection con, boolean finalizing) Called whenConnection.close()is called on the underlying connection.getNext()Returns the next interceptor in the chainReturns the properties configured for this interceptorbooleanTrue if the compare method uses the Object.equals(Object) method, false if comparison is done on a reference level.voidpoolClosed(ConnectionPool pool) This method is invoked by a connection pool when the pool is closed.voidpoolStarted(ConnectionPool pool) This method is invoked by a connection pool when the pool is first started up, usually when the first connection is requested.voidsetNext(JdbcInterceptor next) configures the next interceptor in the chainvoidsetProperties(Map<String, PoolProperties.InterceptorProperty> properties) Called during the creation of an interceptor The properties can be set during the configuration of an interceptor Override this method to perform type casts between string values and object propertiesvoidsetUseEquals(boolean useEquals) Set to true if string comparisons (for theJdbcInterceptor.compare(String, Method)andJdbcInterceptor.compare(String, String)methods) should use the Object.equals(Object) method The default is false
-
Constructor Details
-
StatementFacade
Constructs a StatementFacade.- Parameters:
interceptor- the next interceptor in the chain
-
-
Method Details
-
closeInvoked
public void closeInvoked()Marks the borrow as ended, which closes every statement and result set handle this facade handed out. Called before the connection is handed back, so a handle cannot outlive the borrow and end up driving the session of the next borrower. A borrow that is abandoned instead never runs this method, but the pool destroys an abandoned session rather than lending it again, so those handles only fail at the driver.- Specified by:
closeInvokedin classAbstractCreateStatementInterceptor
-
createStatement
public Object createStatement(Object proxy, Method method, Object[] args, Object statement, long time) Creates a statement interceptor to monitor query response times- Specified by:
createStatementin classAbstractCreateStatementInterceptor- Parameters:
proxy- the actual proxy objectmethod- the method that was called. It will be one of the methods defined inAbstractCreateStatementInterceptor.STATEMENT_TYPESargs- the arguments to the methodstatement- the statement that the underlying connection createdtime- Elapsed time- Returns:
- a
Statementobject
-