use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class EmbedResultSet method close.
/**
* In some cases, it is desirable to immediately release a
* ResultSet's database and JDBC resources instead of waiting for
* this to happen when it is automatically closed; the close
* method provides this immediate release.
*
* <P><B>Note:</B> A ResultSet is automatically closed by the
* Statement that generated it when that Statement is closed,
* re-executed, or is used to retrieve the next result from a
* sequence of multiple results. A ResultSet is also automatically
* closed when it is garbage collected.
* @exception SQLException thrown on failure.
*/
public void close() throws SQLException {
/* if this result is already closed, don't try to close again
* we may have closed it earlier because of an error and trying
* to close again will cause a different problem if the connection
* has been closed as in XA error handling
*/
if (isClosed)
return;
// closing currentStream does not depend on the
closeCurrentStream();
// both in the same sync block.
synchronized (getConnectionSynchronization()) {
try {
// make sure there's context
setupContextStack();
} catch (SQLException se) {
// just give up and return
return;
}
try {
LanguageConnectionContext lcc = getLanguageConnectionContext(getEmbedConnection());
try {
theResults.close();
if (this.singleUseActivation != null) {
this.singleUseActivation.close();
this.singleUseActivation = null;
}
InterruptStatus.restoreIntrFlagIfSeen(lcc);
} catch (Throwable t) {
throw handleException(t);
}
//
if (forMetaData) {
if (lcc.getActivationCount() > 1) {
// we do not want to commit here as there seems to be other
// statements/resultSets currently opened for this connection.
} else if (owningStmt != null)
// allow the satement to commit if required.
owningStmt.resultSetClosing(this);
} else if (owningStmt != null) {
// allow the satement to commit if required.
owningStmt.resultSetClosing(this);
}
} finally {
markClosed();
restoreContextStack();
}
// the idea is to release resources, so:
currentRow = null;
// we hang on to theResults and messenger
// in case more calls come in on this resultSet
}
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class BasicDatabase method setupConnection.
public LanguageConnectionContext setupConnection(ContextManager cm, String user, String drdaID, String dbname) throws StandardException {
TransactionController tc = getConnectionTransaction(cm);
cm.setLocaleFinder(this);
pushDbContext(cm);
// push a database shutdown context
// we also need to push a language connection context.
LanguageConnectionContext lctx = lcf.newLanguageConnectionContext(cm, tc, lf, this, user, drdaID, dbname);
// push the context that defines our class factory
pushClassFactoryContext(cm, lcf.getClassFactory());
// we also need to push an execution context.
ExecutionFactory ef = lcf.getExecutionFactory();
ef.newExecutionContext(cm);
//
// Initialize our language connection context. Note: This is
// a bit of a hack. Unfortunately, we can't initialize this
// when we push it. We first must push a few more contexts.
lctx.initialize();
// Need to commit this to release locks gotten in initialize.
// Commit it but make sure transaction not have any updates.
lctx.internalCommitNoSync(TransactionController.RELEASE_LOCKS | TransactionController.READONLY_TRANSACTION_INITIALIZATION);
return lctx;
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class EmbedXAResource method getDefaultXATransactionTimeout.
/**
* Returns the default value for the transaction timeout in milliseconds
* setted up by the system properties.
*/
private long getDefaultXATransactionTimeout() throws XAException {
try {
LanguageConnectionContext lcc = getLanguageConnectionContext(con);
TransactionController tc = lcc.getTransactionExecute();
long timeoutMillis = 1000 * (long) PropertyUtil.getServiceInt(tc, Property.PROP_XA_TRANSACTION_TIMEOUT, 0, Integer.MAX_VALUE, Property.DEFAULT_XA_TRANSACTION_TIMEOUT);
return timeoutMillis;
} catch (SQLException sqle) {
throw wrapInXAException(sqle);
} catch (StandardException se) {
throw wrapInXAException(se);
}
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class InterruptStatus method setInterrupted.
/**
* Make a note that this thread saw an interrupt. Thread's intr
* status flag is presumably off already, but we reset it here
* also. Use lcc if available, else thread local variable.
*/
public static void setInterrupted() {
LanguageConnectionContext lcc = null;
try {
lcc = (LanguageConnectionContext) getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
} catch (ShutdownException e) {
// Ignore. Can happen when: a) background thread (RawStoreDaemon)
// is performing checkpointing and b) a user thread starts shutdown
// and interrupts the background thread. During recovery of the
// container we get here. DERBY-4920.
}
Thread.interrupted();
StandardException e = StandardException.newException(SQLState.CONN_INTERRUPT);
if (lcc != null) {
lcc.setInterruptedException(e);
} else {
exception.set(e);
}
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class DataDictionaryImpl method getPermissionsCache.
private CacheManager getPermissionsCache() throws StandardException {
if (permissionsCache == null) {
CacheFactory cf = (CacheFactory) startSystemModule(org.apache.derby.shared.common.reference.Module.CacheFactory);
LanguageConnectionContext lcc = getLCC();
TransactionController tc = lcc.getTransactionExecute();
permissionsCacheSize = PropertyUtil.getServiceInt(tc, Property.LANG_PERMISSIONS_CACHE_SIZE, 40, /* min value */
Integer.MAX_VALUE, permissionsCacheSize);
permissionsCache = cf.newCacheManager(this, "PermissionsCache", permissionsCacheSize, permissionsCacheSize);
}
return permissionsCache;
}
Aggregations