Search in sources :

Example 96 with TransactionController

use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.

the class SystemProcedures method SYSCS_SET_XPLAIN_SCHEMA.

/**
 * This procedure sets the current xplain schema.
 * If the schema is not set, runtime statistics are captured as a
 * textual stream printout. If it is set, statisitcs information is
 * stored in that schema in user tables.
 * @param schemaName May be an empty string.
 * @throws SQLException
 */
public static void SYSCS_SET_XPLAIN_SCHEMA(String schemaName) throws SQLException, StandardException {
    try {
        // make sure that application code doesn't bypass security checks
        // by calling this public entry point
        SecurityUtil.authorize(Securable.SET_XPLAIN_SCHEMA);
    } catch (StandardException se) {
        throw PublicAPI.wrapStandardException(se);
    }
    LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
    TransactionController tc = lcc.getTransactionExecute();
    if (schemaName == null || schemaName.trim().length() == 0) {
        lcc.setXplainSchema(null);
        return;
    }
    boolean statsSave = lcc.getRunTimeStatisticsMode();
    lcc.setRunTimeStatisticsMode(false);
    createXplainSchema(schemaName);
    createXplainTable(lcc, schemaName, new XPLAINStatementDescriptor());
    createXplainTable(lcc, schemaName, new XPLAINStatementTimingsDescriptor());
    createXplainTable(lcc, schemaName, new XPLAINResultSetDescriptor());
    createXplainTable(lcc, schemaName, new XPLAINResultSetTimingsDescriptor());
    createXplainTable(lcc, schemaName, new XPLAINScanPropsDescriptor());
    createXplainTable(lcc, schemaName, new XPLAINSortPropsDescriptor());
    lcc.setRunTimeStatisticsMode(statsSave);
    lcc.setXplainSchema(schemaName);
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) XPLAINSortPropsDescriptor(org.apache.derby.impl.sql.catalog.XPLAINSortPropsDescriptor) XPLAINStatementDescriptor(org.apache.derby.impl.sql.catalog.XPLAINStatementDescriptor) XPLAINResultSetDescriptor(org.apache.derby.impl.sql.catalog.XPLAINResultSetDescriptor) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) XPLAINScanPropsDescriptor(org.apache.derby.impl.sql.catalog.XPLAINScanPropsDescriptor) XPLAINStatementTimingsDescriptor(org.apache.derby.impl.sql.catalog.XPLAINStatementTimingsDescriptor) TransactionController(org.apache.derby.iapi.store.access.TransactionController) XPLAINResultSetTimingsDescriptor(org.apache.derby.impl.sql.catalog.XPLAINResultSetTimingsDescriptor)

Example 97 with TransactionController

use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.

the class SystemProcedures method SYSCS_CREATE_USER.

/**
 * Create a new user.
 */
public static void SYSCS_CREATE_USER(String userName, String password) throws SQLException {
    userName = normalizeUserName(userName);
    LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
    TransactionController tc = lcc.getTransactionExecute();
    // can add them
    try {
        // make sure that application code doesn't bypass security checks
        // by calling this public entry point
        SecurityUtil.authorize(Securable.CREATE_USER);
        DataDictionary dd = lcc.getDataDictionary();
        String dbo = dd.getAuthorizationDatabaseOwner();
        if (!dbo.equals(userName)) {
            if (dd.getUser(dbo) == null) {
                throw StandardException.newException(SQLState.DBO_FIRST);
            }
        } else // we are trying to create credentials for the DBO
        {
            String currentUser = lcc.getStatementContext().getSQLSessionContext().getCurrentUser();
            if (!dbo.equals(currentUser)) {
                throw StandardException.newException(SQLState.DBO_ONLY);
            }
        }
    } catch (StandardException se) {
        throw PublicAPI.wrapStandardException(se);
    }
    addUser(userName, password, tc);
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) TransactionController(org.apache.derby.iapi.store.access.TransactionController) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary)

Example 98 with TransactionController

use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.

the class StatementNode method lockTableForCompilation.

/* We need to get some kind of table lock (IX here) at the beginning of
	 * compilation of DMLModStatementNode and DDLStatementNode, to prevent the
	 * interference of insert/update/delete/DDL compilation and DDL execution,
	 * see beetle 3976, 4343, and $WS/language/SolutionsToConcurrencyIssues.txt
	 */
protected TableDescriptor lockTableForCompilation(TableDescriptor td) throws StandardException {
    DataDictionary dd = getDataDictionary();
    /* we need to lock only if the data dictionary is in DDL cache mode
		 */
    if (dd.getCacheMode() == DataDictionary.DDL_MODE) {
        ConglomerateController heapCC;
        TransactionController tc = getLanguageConnectionContext().getTransactionCompile();
        heapCC = tc.openConglomerate(td.getHeapConglomerateId(), false, TransactionController.OPENMODE_FORUPDATE | TransactionController.OPENMODE_FOR_LOCK_ONLY, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
        heapCC.close();
        /*
			** Need to get TableDescriptor again after getting the lock, in
			** case for example, a concurrent add column thread commits
			** while we are binding.
			*/
        String tableName = td.getName();
        td = getTableDescriptor(td.getName(), getSchemaDescriptor(td.getSchemaName()));
        if (td == null) {
            throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tableName);
        }
    }
    return td;
}
Also used : ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 99 with TransactionController

use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.

the class SequenceUpdater method updateCurrentValueOnDisk.

// /////////////////////////////////////////////////////////////////////////////////
// 
// DISK WRITING MINIONS
// 
// /////////////////////////////////////////////////////////////////////////////////
/**
 * <p>
 * Update the value on disk. Does its work in a subtransaction of the user's
 * execution transaction. If that fails, raises a TOO MUCH CONTENTION exception.
 * </p>
 *
 * @return Returns true if the value was successfully updated, false if we lost a race with another session.
 */
public synchronized boolean updateCurrentValueOnDisk(Long oldValue, Long newValue) throws StandardException {
    LanguageConnectionContext lcc = getLCC();
    // 
    if (lcc == null) {
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(oldValue == null, "We should be flushing unused sequence values here.");
        }
        ContextService csf = getContextService();
        ContextManager cm = csf.getCurrentContextManager();
        AccessFactory af = _dd.af;
        TransactionController dummyTransaction = af.getTransaction(cm);
        boolean retval = updateCurrentValueOnDisk(dummyTransaction, oldValue, newValue, false);
        dummyTransaction.commit();
        dummyTransaction.destroy();
        return retval;
    }
    TransactionController executionTransaction = lcc.getTransactionExecute();
    TransactionController nestedTransaction = executionTransaction.startNestedUserTransaction(false, true);
    if (nestedTransaction != null) {
        boolean retval = false;
        boolean escalateToParentTransaction = false;
        try {
            retval = updateCurrentValueOnDisk(nestedTransaction, oldValue, newValue, false);
        } catch (StandardException se) {
            if (!se.isLockTimeout()) {
                if (se.isSelfDeadlock()) {
                    // We're blocked by a lock held by our parent transaction.
                    // Escalate into the parent transaction now. See DERBY-6554.
                    escalateToParentTransaction = true;
                } else {
                    Monitor.logThrowable(se);
                    throw se;
                }
            }
        } finally {
            // DERBY-5494, if this commit does not flush log then an
            // unorderly shutdown could lose the update.  Do not use
            // commitNoSync(), and store needs to flush user nested update
            // transaction commits by default.
            nestedTransaction.commit();
            nestedTransaction.destroy();
            if (escalateToParentTransaction) {
                retval = updateCurrentValueOnDisk(executionTransaction, oldValue, newValue, false);
            }
            return retval;
        }
    }
    throw tooMuchContentionException();
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) ContextService(org.apache.derby.iapi.services.context.ContextService) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) ContextManager(org.apache.derby.iapi.services.context.ContextManager) TransactionController(org.apache.derby.iapi.store.access.TransactionController) AccessFactory(org.apache.derby.iapi.store.access.AccessFactory)

Example 100 with TransactionController

use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.

the class IndexRowToBaseRowResultSet method openCore.

// 
// ResultSet interface (leftover from NoPutResultSet)
// 
/**
 * open this ResultSet.
 *
 * @exception StandardException thrown if cursor finished.
 */
public void openCore() throws StandardException {
    boolean lockingRequired = false;
    TransactionController tc;
    // is access to open controlled and ensured valid.
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(!isOpen, "IndexRowToBaseRowResultSet already open");
    }
    beginTime = getCurrentTimeMillis();
    source.openCore();
    /* Get a ConglomerateController for the base conglomerate 
		 * NOTE: We only need to acquire locks on the data pages when
		 * going through the index when we are at READ COMMITTED and
		 * the source is a BulkTableScan or HashScan.  (The underlying
		 * row will not be guaranteed to be locked.)
		 */
    if (source.requiresRelocking()) {
        lockingRequired = true;
    }
    tc = activation.getTransactionController();
    int openMode;
    int isolationLevel;
    if (forUpdate) {
        openMode = TransactionController.OPENMODE_FORUPDATE;
    } else {
        openMode = 0;
    }
    isolationLevel = source.getScanIsolationLevel();
    if (!lockingRequired) {
        // flag indicates that lock has already been acquired by access to
        // the secondary index, and need not be gotten again in the base
        // table.
        openMode |= TransactionController.OPENMODE_SECONDARY_LOCKED;
    }
    /* Try to get the ConglomerateController from the activation
		 * first, for the case that we are part of an update or delete.
		 * If so, then the RowChangerImpl did the correct locking.
		 * If not there, then we go off and open it ourself.
		 */
    if (forUpdate) {
        baseCC = activation.getHeapConglomerateController();
    }
    if (baseCC == null) {
        baseCC = tc.openCompiledConglomerate(activation.getResultSetHoldability(), openMode, // consistent with FromBaseTable's updateTargetLockMode
        TransactionController.MODE_RECORD, isolationLevel, scoci, dcoci);
        closeBaseCCHere = true;
    }
    isOpen = true;
    numOpens++;
    openTime += getElapsedMillis(beginTime);
}
Also used : TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Aggregations

TransactionController (org.apache.derby.iapi.store.access.TransactionController)124 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)47 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)40 StandardException (org.apache.derby.shared.common.error.StandardException)26 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)23 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 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)13 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)12 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)12 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)12 Properties (java.util.Properties)11 AccessFactory (org.apache.derby.iapi.store.access.AccessFactory)11 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)11 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)10 XATransactionController (org.apache.derby.iapi.store.access.XATransactionController)9 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)8 ReferencedKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor)8 ScanController (org.apache.derby.iapi.store.access.ScanController)8