Search in sources :

Example 26 with LanguageConnectionContext

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
    }
}
Also used : SQLException(java.sql.SQLException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext)

Example 27 with LanguageConnectionContext

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;
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) ExecutionFactory(org.apache.derby.iapi.sql.execute.ExecutionFactory) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 28 with LanguageConnectionContext

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);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) SQLException(java.sql.SQLException) TransactionController(org.apache.derby.iapi.store.access.TransactionController) XATransactionController(org.apache.derby.iapi.store.access.XATransactionController)

Example 29 with LanguageConnectionContext

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);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) ShutdownException(org.apache.derby.shared.common.error.ShutdownException)

Example 30 with LanguageConnectionContext

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;
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) CacheFactory(org.apache.derby.iapi.services.cache.CacheFactory) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Aggregations

LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)126 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)57 TransactionController (org.apache.derby.iapi.store.access.TransactionController)47 StandardException (org.apache.derby.shared.common.error.StandardException)36 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)20 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)20 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)20 UUID (org.apache.derby.catalog.UUID)14 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)13 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)11 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)10 StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)7 ReferencedKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor)7 RoleGrantDescriptor (org.apache.derby.iapi.sql.dictionary.RoleGrantDescriptor)7 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)6 SQLException (java.sql.SQLException)5 Iterator (java.util.Iterator)5 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)5 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)5 ArrayList (java.util.ArrayList)4