Search in sources :

Example 71 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class CompilerContextImpl method closeStoreCostControllers.

/**
 */
private void closeStoreCostControllers() {
    Iterator<StoreCostController> it = storeCostControllers.values().iterator();
    while (it.hasNext()) {
        StoreCostController scc = it.next();
        try {
            scc.close();
        } catch (StandardException se) {
        }
    }
    storeCostControllers.clear();
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) StoreCostController(org.apache.derby.iapi.store.access.StoreCostController)

Example 72 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class GenericLanguageConnectionContext method dropAllDeclaredGlobalTempTables.

/**
 * Drop all the declared global temporary tables associated with this
 * connection. This gets called when a getConnection() is done on a
 * PooledConnection. This will ensure all the temporary tables declared on
 * earlier connection handle associated with this physical database
 * connection are dropped before a new connection handle is issued on that
 * same physical database connection.
 */
private void dropAllDeclaredGlobalTempTables() throws StandardException {
    if (allDeclaredGlobalTempTables == null)
        return;
    DependencyManager dm = getDataDictionary().getDependencyManager();
    StandardException topLevelStandardException = null;
    // temporary tables and throw them as one chained exception at the end.
    for (int i = 0; i < allDeclaredGlobalTempTables.size(); i++) {
        try {
            TempTableInfo tempTableInfo = allDeclaredGlobalTempTables.get(i);
            TableDescriptor td = tempTableInfo.getTableDescriptor();
            // the following 2 lines of code has been copied from
            // DropTableConstantAction. If there are any changes made there
            // in future, we should check if they need to be made here too.
            dm.invalidateFor(td, DependencyManager.DROP_TABLE, this);
            tran.dropConglomerate(td.getHeapConglomerateId());
        } catch (StandardException e) {
            if (topLevelStandardException == null) {
                // always keep the first exception unchanged
                topLevelStandardException = e;
            } else {
                try {
                    // Try to create a chain of exceptions. If successful,
                    // the current exception is the top-level exception,
                    // and the previous exception the cause of it.
                    e.initCause(topLevelStandardException);
                    topLevelStandardException = e;
                } catch (IllegalStateException ise) {
                // initCause() has already been called on e. We don't
                // expect this to happen, but if it happens, just skip
                // the current exception from the chain. This is safe
                // since we always keep the first exception.
                }
            }
        }
    }
    allDeclaredGlobalTempTables = null;
    try {
        internalCommit(true);
    } catch (StandardException e) {
        // do the same chaining as above
        if (topLevelStandardException == null) {
            topLevelStandardException = e;
        } else {
            try {
                e.initCause(topLevelStandardException);
                topLevelStandardException = e;
            } catch (IllegalStateException ise) {
            /* ignore */
            }
        }
    }
    if (topLevelStandardException != null)
        throw topLevelStandardException;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 73 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class GenericLanguageConnectionContext method cleanupOnError.

// 
// Context interface
// 
/**
 *        If worse than a transaction error, everything goes; we
 *        rely on other contexts to kill the context manager
 *        for this session.
 *        <p>
 *        If a transaction error, act like we saw a rollback.
 *        <p>
 *        If more severe or a java error, the outer cleanup
 *        will shutdown the connection, so we don't have to clean up.
 *        <p>
 *        REMIND: connection should throw out all contexts and start
 *        over when the connection is closed... perhaps by throwing
 *        out the context manager?
 *        <p>
 *        REVISIT: If statement error, should we do anything?
 *        <P>
 *        Since the access manager's own context takes care of its own
 *        resources on errors, there is nothing that this context has
 *        to do with the transaction controller.
 *
 *        @exception StandardException thrown on error. REVISIT: don't want
 *        cleanupOnError's to throw exceptions.
 */
public void cleanupOnError(Throwable error) throws StandardException {
    /*
        ** If it isn't a StandardException, then assume
        ** session severity. It is probably an unexpected
        ** java error somewhere in the language.
        ** Store layer treats JVM error as session severity, 
        ** hence to be consistent and to avoid getting rawstore
        ** protocol violation errors, we treat java errors here
        ** to be of session severity.
        */
    int severity = (error instanceof StandardException) ? ((StandardException) error).getSeverity() : ExceptionSeverity.SESSION_SEVERITY;
    if (statementContexts[0] != null) {
        statementContexts[0].clearInUse();
        // and no hanging refrences in the ContextManager.
        if (severity >= ExceptionSeverity.SESSION_SEVERITY)
            statementContexts[0].popMe();
    }
    if (statementContexts[1] != null) {
        statementContexts[1].clearInUse();
    }
    // cursors.
    if (severity >= ExceptionSeverity.SESSION_SEVERITY) {
        for (int i = acts.size() - 1; i >= 0; i--) {
            // the end of the array
            if (i >= acts.size())
                continue;
            Activation a = acts.get(i);
            a.reset();
            a.close();
        }
        popMe();
        InterruptStatus.saveInfoFromLcc(this);
    } else /*
        ** We have some global state that we need
        ** to clean up no matter what.  Be sure
        ** to do so.
        */
    if (severity >= ExceptionSeverity.TRANSACTION_SEVERITY) {
        internalRollback();
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) Activation(org.apache.derby.iapi.sql.Activation) CursorActivation(org.apache.derby.iapi.sql.execute.CursorActivation)

Example 74 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class StatementNode method generate.

/**
 * Do code generation for this statement.
 *
 * @param byteCode	the generated byte code for this statement.
 *			if non-null, then the byte code is saved
 *			here.
 *
 * @return		A GeneratedClass for this statement
 *
 * @exception StandardException		Thrown on error
 */
public GeneratedClass generate(ByteArray byteCode) throws StandardException {
    // start the new activation class.
    // it starts with the Execute method
    // and the appropriate superclass (based on
    // statement type, from inspecting the queryTree).
    int nodeChoice = activationKind();
    /* RESOLVE: Activation hierarchy was way too complicated
		 * and added no value.  Simple thing to do was to simply
		 * leave calling code alone and to handle here and to
		 * eliminate unnecessary classes.
		 */
    String superClass;
    switch(nodeChoice) {
        case NEED_CURSOR_ACTIVATION:
            superClass = ClassName.CursorActivation;
            break;
        case NEED_DDL_ACTIVATION:
            return getClassFactory().loadGeneratedClass("org.apache.derby.impl.sql.execute.ConstantActionActivation", null);
        case NEED_NOTHING_ACTIVATION:
        case NEED_ROW_ACTIVATION:
        case NEED_PARAM_ACTIVATION:
            superClass = ClassName.BaseActivation;
            break;
        default:
            throw StandardException.newException(SQLState.LANG_UNAVAILABLE_ACTIVATION_NEED, String.valueOf(nodeChoice));
    }
    ActivationClassBuilder generatingClass = new ActivationClassBuilder(superClass, getCompilerContext());
    // Create the method that generates the ResultSet tree used when
    // executing this statement. Implements the abstract method
    // BaseActivation.createResultSet().
    MethodBuilder mbWorker = generatingClass.getClassBuilder().newMethodBuilder(Modifier.PROTECTED, ClassName.ResultSet, "createResultSet");
    mbWorker.addThrownException(ClassName.StandardException);
    // Generate the complete ResultSet tree for this statement.
    // This step may add statements into the execute method
    // for per-execution actions.
    generate(generatingClass, mbWorker);
    mbWorker.methodReturn();
    mbWorker.complete();
    // wrap up the activation class definition
    // generate on the tree gave us back the newExpr
    // for getting a result set on the tree.
    // we put it in a return statement and stuff
    // it in the execute method of the activation.
    // The generated statement is the expression:
    // the activation class builder takes care of constructing it
    // for us, given the resultSetExpr to use.
    // return (this.resultSet = #resultSetExpr);
    generatingClass.finishExecuteMethod();
    // wrap up the constructor by putting a return at the end of it
    generatingClass.finishConstructor();
    try {
        // cook the completed class into a real class
        // and stuff it into activationClass
        GeneratedClass activationClass = generatingClass.getGeneratedClass(byteCode);
        return activationClass;
    } catch (StandardException e) {
        String msgId = e.getMessageId();
        if (SQLState.GENERATED_CLASS_LIMIT_EXCEEDED.equals(msgId) || SQLState.GENERATED_CLASS_LINKAGE_ERROR.equals(msgId)) {
            throw StandardException.newException(SQLState.LANG_QUERY_TOO_COMPLEX, e);
        }
        throw e;
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) GeneratedClass(org.apache.derby.iapi.services.loader.GeneratedClass) MethodBuilder(org.apache.derby.iapi.services.compiler.MethodBuilder)

Example 75 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class UnaryComparisonOperatorNode method getOperand.

/**
 * @see RelationalOperator#getOperand
 */
public ValueNode getOperand(ColumnReference cRef, int refSetSize, boolean otherSide) {
    if (otherSide)
        // there is no "other" side for Unary, so just return null.
        return null;
    ColumnReference cr;
    if (operand instanceof ColumnReference) {
        /*
			** The operand is a column reference.
			** Is it the correct column?
			*/
        JBitSet cRefTables = new JBitSet(refSetSize);
        JBitSet crTables = new JBitSet(refSetSize);
        BaseTableNumbersVisitor btnVis = new BaseTableNumbersVisitor(crTables);
        cr = (ColumnReference) operand;
        try {
            cr.accept(btnVis);
            btnVis.setTableMap(cRefTables);
            cRef.accept(btnVis);
        } catch (StandardException se) {
            if (SanityManager.DEBUG) {
                SanityManager.THROWASSERT("Failed when trying to " + "find base table number for column reference check:", se);
            }
        }
        crTables.and(cRefTables);
        if (crTables.getFirstSetBit() != -1) {
            /*
				** The table is correct, how about the column position?
				*/
            if (cr.getSource().getColumnPosition() == cRef.getColumnNumber()) {
                /* We've found the correct column - return it. */
                return operand;
            }
        }
    }
    /* Not the column we're looking for */
    return null;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) JBitSet(org.apache.derby.iapi.util.JBitSet)

Aggregations

StandardException (org.apache.derby.shared.common.error.StandardException)276 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)43 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)37 IOException (java.io.IOException)32 Properties (java.util.Properties)29 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)27 TransactionController (org.apache.derby.iapi.store.access.TransactionController)26 ContextManager (org.apache.derby.iapi.services.context.ContextManager)22 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)20 SQLException (java.sql.SQLException)17 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)17 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)16 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)12 RowLocation (org.apache.derby.iapi.types.RowLocation)11 SQLLongint (org.apache.derby.iapi.types.SQLLongint)11 StorageFile (org.apache.derby.io.StorageFile)10 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)9 ScanController (org.apache.derby.iapi.store.access.ScanController)9 File (java.io.File)8 LogInstant (org.apache.derby.iapi.store.raw.log.LogInstant)8