Search in sources :

Example 76 with StandardException

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

the class BaseActivation method checkStatementValidity.

public final void checkStatementValidity() throws StandardException {
    if (preStmt == null || preStmt.upToDate(gc))
        return;
    StandardException se = StandardException.newException(SQLState.LANG_STATEMENT_NEEDS_RECOMPILE);
    se.setReport(StandardException.REPORT_NEVER);
    throw se;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException)

Example 77 with StandardException

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

the class CallStatementResultSet method close.

/**
 * Need to explicitly close any dynamic result sets.
 * <BR>
 * If the dynamic results are not accessible then they
 * need to be destroyed (ie. closed) according the the
 * SQL Standard.
 * <BR>
 * An execution of a CALL statement through JDBC makes the
 * dynamic results accessible, in this case the closing
 * of the dynamic result sets is handled by the JDBC
 * statement object (EmbedStatement) that executed the CALL.
 * We cannot unify the closing of dynamic result sets to
 * this close, as in accessible case it is called during
 * the Statement.execute call, thus it would close the
 * dynamic results before the application has a change
 * to use them.
 *
 * <BR>
 * With an execution of a CALL
 * statement as a trigger's action statement the dynamic
 * result sets are not accessible. In this case this close
 * method is called after the execution of the trigger's
 * action statement.
 * <BR>
 * <BR>
 * Section 4.27.5 of the TECHNICAL CORRIGENDUM 1 to the SQL 2003
 * Standard details what happens to dynamic result sets in detail,
 * the SQL 2003 foundation document is missing these details.
 */
public void close() throws StandardException {
    close(false);
    ResultSet[][] dynamicResults = getActivation().getDynamicResults();
    if (dynamicResults != null) {
        // Need to ensure all the result sets opened by this
        // CALL statement for this connection are closed.
        // If any close() results in an exception we need to keep going,
        // save any exceptions and then throw them once we are complete.
        StandardException errorOnClose = null;
        ConnectionContext jdbcContext = null;
        for (int i = 0; i < dynamicResults.length; i++) {
            ResultSet[] param = dynamicResults[i];
            ResultSet drs = param[0];
            // or if the dynamic results were processed by JDBC (EmbedStatement).
            if (drs == null)
                continue;
            if (jdbcContext == null)
                jdbcContext = (ConnectionContext) lcc.getContextManager().getContext(ConnectionContext.CONTEXT_ID);
            try {
                // Is this a valid, open dynamic result set for this connection?
                if (!jdbcContext.processInaccessibleDynamicResult(drs)) {
                    // If not just ignore it, not Derby's problem.
                    continue;
                }
                drs.close();
            } catch (SQLException e) {
                // Just report the first error
                if (errorOnClose == null) {
                    StandardException se = StandardException.plainWrapException(e);
                    errorOnClose = se;
                }
            } finally {
                // Remove any reference to the ResultSet to allow
                // it and any associated resources to be garbage collected.
                param[0] = null;
            }
        }
        if (errorOnClose != null)
            throw errorOnClose;
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ConnectionContext(org.apache.derby.iapi.jdbc.ConnectionContext) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext)

Example 78 with StandardException

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

the class XMLOptTrace method getOptimizableName.

/**
 * Get the name of an optimizable
 */
private TableName getOptimizableName(Optimizable optimizable) {
    try {
        if (isBaseTable(optimizable)) {
            ProjectRestrictNode prn = (ProjectRestrictNode) optimizable;
            TableDescriptor td = ((FromBaseTable) prn.getChildResult()).getTableDescriptor();
            return makeTableName(td.getSchemaName(), td.getName(), _cm);
        } else if (OptimizerImpl.isTableFunction(optimizable)) {
            ProjectRestrictNode prn = (ProjectRestrictNode) optimizable;
            AliasDescriptor ad = ((StaticMethodCallNode) ((FromVTI) prn.getChildResult()).getMethodCall()).ad;
            return makeTableName(ad.getSchemaName(), ad.getName(), _cm);
        } else if (isFromTable(optimizable)) {
            TableName retval = ((FromTable) ((ProjectRestrictNode) optimizable).getChildResult()).getTableName();
            if (retval != null) {
                return retval;
            }
        }
    } catch (StandardException e) {
    // Technically, an exception could occur here if the table name
    // was not previously bound and if an error occured while binding it.
    // But the optimizable should have been bound long before optimization,
    // so this should not be a problem.
    }
    String nodeClass = optimizable.getClass().getName();
    String unqualifiedName = nodeClass.substring(nodeClass.lastIndexOf(".") + 1);
    return makeTableName(null, unqualifiedName, _cm);
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 79 with StandardException

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

the class ReferencedKeyRIChecker method postCheck.

/**
 * Check that we have at least one more row in the referenced
 * table table containing a key than the number of projected deletes of that
 * key. Only used when the referenced constraint id deferred and with
 * RESTRICT mode
 *
 * @throws StandardException Standard error policy
 */
public void postCheck() throws StandardException {
    if (!fkInfo.refConstraintIsDeferrable) {
        return;
    }
    int indexOfFirstRestrict = -1;
    for (int i = 0; i < fkInfo.fkConglomNumbers.length; i++) {
        if (fkInfo.raRules[i] == StatementType.RA_RESTRICT) {
            indexOfFirstRestrict = i;
            break;
        }
    }
    if (indexOfFirstRestrict == -1) {
        return;
    }
    if (deletedKeys != null) {
        final Enumeration<?> e = deletedKeys.elements();
        while (e.hasMoreElements()) {
            final DataValueDescriptor[] row = (DataValueDescriptor[]) e.nextElement();
            final DataValueDescriptor[] key = new DataValueDescriptor[row.length - 1];
            System.arraycopy(row, 0, key, 0, key.length);
            // The number of times this key is to be deleted,
            // we need at least one more if for Fk constraint to hold.
            final long requiredCount = row[row.length - 1].getLong() + 1;
            if (!isDuplicated(key, requiredCount)) {
                int[] oneBasedIdentityMap = new int[numColumns];
                for (int i = 0; i < numColumns; i++) {
                    // Column numbers are numbered from 1 and
                    // call to RowUtil.toString below expects that
                    // convention.
                    oneBasedIdentityMap[i] = i + 1;
                }
                StandardException se = StandardException.newException(SQLState.LANG_FK_VIOLATION, fkInfo.fkConstraintNames[indexOfFirstRestrict], fkInfo.tableName, StatementUtil.typeName(fkInfo.stmtType), RowUtil.toString(row, oneBasedIdentityMap));
                throw se;
            }
        }
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 80 with StandardException

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

the class DDLConstantAction method executeCAPreferSubTrans.

private static void executeCAPreferSubTrans(CreateSchemaConstantAction csca, TransactionController tc, Activation activation) throws StandardException {
    TransactionController useTc;
    TransactionController nestedTc = null;
    try {
        nestedTc = tc.startNestedUserTransaction(false, true);
        useTc = nestedTc;
    } catch (StandardException e) {
        if (SanityManager.DEBUG) {
            SanityManager.THROWASSERT("Unexpected: not able to start nested transaction " + "to auto-create schema", e);
        }
        useTc = tc;
    }
    // once in the outer transaction.
    while (true) {
        try {
            csca.executeConstantAction(activation, useTc);
        } catch (StandardException se) {
            if (se.isLockTimeout()) {
                if (!se.getMessageId().equals(SQLState.LOCK_TIMEOUT_LOG)) {
                    if (useTc == nestedTc) {
                        // clean up after use of nested transaction,
                        // then try again in outer transaction
                        useTc = tc;
                        nestedTc.destroy();
                        continue;
                    }
                }
            } else if (se.getMessageId().equals(SQLState.LANG_OBJECT_ALREADY_EXISTS)) {
                // probably created it after we checked for it
                break;
            }
            // transaction; we had better pass that on
            if (useTc == nestedTc) {
                nestedTc.destroy();
            }
            throw se;
        }
        break;
    }
    // Clean up if we did this in a nested transaction.
    if (useTc == nestedTc) {
        nestedTc.commit();
        nestedTc.destroy();
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

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