Package org.apache.derby.impl.jdbc
Class EmbedConnectionContext
- java.lang.Object
-
- org.apache.derby.iapi.services.context.ContextImpl
-
- org.apache.derby.impl.jdbc.EmbedConnectionContext
-
- All Implemented Interfaces:
ConnectionContext
,Context
class EmbedConnectionContext extends ContextImpl implements ConnectionContext
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ref.SoftReference<EmbedConnection>
connRef
We hold a soft reference to the connection so that when the application releases its reference to the Connection without closing it, its finalize method will be called, which will then close the connection.-
Fields inherited from interface org.apache.derby.iapi.jdbc.ConnectionContext
CONTEXT_ID
-
-
Constructor Summary
Constructors Constructor Description EmbedConnectionContext(ContextManager cm, EmbedConnection conn)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanupOnError(java.lang.Throwable error)
Contexts will be passed errors that are caught by the outer system when they are serious enough to require corrective action.java.sql.Connection
getNestedConnection(boolean internal)
Get a connection equivalent to the calljava.sql.ResultSet
getResultSet(ResultSet executionResultSet)
Get a jdbc ResultSet based on the execution ResultSet.private LanguageConnectionContext
privilegedGetLCC(EmbedConnection conn)
Private, privileged lookup of the lcc..boolean
processInaccessibleDynamicResult(java.sql.ResultSet resultSet)
Process a ResultSet from a procedure to be a dynamic result, but one that will be closed due to it being inaccessible.-
Methods inherited from class org.apache.derby.iapi.services.context.ContextImpl
appendErrorInfo, getContextManager, getIdName, isLastHandler, popMe, pushMe
-
-
-
-
Field Detail
-
connRef
private java.lang.ref.SoftReference<EmbedConnection> connRef
We hold a soft reference to the connection so that when the application releases its reference to the Connection without closing it, its finalize method will be called, which will then close the connection. If a direct reference is used here, such a Connection will never be closed or garbage collected as modules hold onto the ContextManager and thus there would be a direct reference through this object.
-
-
Constructor Detail
-
EmbedConnectionContext
EmbedConnectionContext(ContextManager cm, EmbedConnection conn)
-
-
Method Detail
-
cleanupOnError
public void cleanupOnError(java.lang.Throwable error)
Description copied from interface:Context
Contexts will be passed errors that are caught by the outer system when they are serious enough to require corrective action. They will be told what the error is, so that they can react appropriately. Most of the time, the contexts will react by either doing nothing or by removing themselves from the context manager. If there are no other references to the context, removing itself from the manager equates to freeing it.
On an exception that is session severity or greater the Context must push itself off the stack. This is to ensure that after a session has been closed there are no Contexts on the stack that potentially hold references to objects, thus delaying their garbage collection.Contexts must release all their resources before removing themselves from their context manager.
The context manager will "unwind" the contexts during cleanup in the reverse order they were placed on its global stack.
If error is an instance of StandardException then an implementation of this method may throw a new exception if and only if the new exception is an instance of StandardException that is more severe than the original error or the new exception is a not an instance of StandardException (e.g java.lang.NullPointerException).
- Specified by:
cleanupOnError
in interfaceContext
-
getNestedConnection
public java.sql.Connection getNestedConnection(boolean internal) throws java.sql.SQLException
Get a connection equivalent to the callDriverManager.getConnection("jdbc:default:connection");
- Specified by:
getNestedConnection
in interfaceConnectionContext
- Throws:
java.sql.SQLException
- Parent connection has been closed.
-
getResultSet
public java.sql.ResultSet getResultSet(ResultSet executionResultSet) throws java.sql.SQLException
Get a jdbc ResultSet based on the execution ResultSet.- Specified by:
getResultSet
in interfaceConnectionContext
- Parameters:
executionResultSet
- a result set as gotten from execution- Throws:
java.sql.SQLException
- on error
-
processInaccessibleDynamicResult
public boolean processInaccessibleDynamicResult(java.sql.ResultSet resultSet)
Process a ResultSet from a procedure to be a dynamic result, but one that will be closed due to it being inaccessible. We cannot simply close the ResultSet as it the nested connection that created it might be closed, leading to its close method being a no-op. This performs all the conversion (linking the ResultSet to a valid connection) required but does not close the ResultSet.- Specified by:
processInaccessibleDynamicResult
in interfaceConnectionContext
- Parameters:
resultSet
- ResultSet to process.- Returns:
- True if this ResultSet was created by this connection and the result set is open. False otherwise.
- See Also:
EmbedStatement.processDynamicResult(EmbedConnection, java.sql.ResultSet, EmbedStatement)
-
privilegedGetLCC
private LanguageConnectionContext privilegedGetLCC(EmbedConnection conn)
Private, privileged lookup of the lcc..
-
-