Search in sources :

Example 36 with StandardException

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

the class Util method javaException.

public static SQLException javaException(Throwable t) {
    String name, msg;
    msg = t.getMessage();
    if (msg == null)
        msg = "";
    name = t.getClass().getName();
    SQLException next = null;
    Throwable cause = t.getCause();
    if (cause != null) {
        if (cause instanceof SQLException) {
            next = (SQLException) cause;
        } else if (cause instanceof StandardException) {
            next = generateCsSQLException((StandardException) cause);
        } else {
            next = javaException(cause);
        }
    }
    SQLException result = seeNextException(SQLState.JAVA_EXCEPTION, next, t, name, msg);
    if (result.getErrorCode() >= logSeverityLevel) {
        logSQLException(result);
    }
    return result;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) SQLException(java.sql.SQLException)

Example 37 with StandardException

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

the class XML method XMLQuery.

/**
 * Evaluate the XML query expression contained within the received
 * util object against this XML value and store the results into
 * the received XMLDataValue "result" param (assuming "result" is
 * non-null; else create a new XMLDataValue).
 *
 * @param sqlxUtil Contains SQL/XML objects and util methods that
 *  facilitate execution of XML-related operations
 * @param result The result of a previous call to this method; null
 *  if not called yet.
 * @return An XMLDataValue whose content corresponds to the serialized
 *  version of the results from evaluation of the query expression.
 *  Note: this XMLDataValue may not be storable into Derby XML
 *  columns.
 * @exception StandardException thrown on error
 */
public XMLDataValue XMLQuery(SqlXmlUtil sqlxUtil, XMLDataValue result) throws StandardException {
    if (this.isNull()) {
        // per SQL/XML[2006] 6.17:GR.1.a.ii.1.
        if (result == null)
            result = (XMLDataValue) getNewNull();
        else
            result.setToNull();
        return result;
    }
    try {
        // Return an XML data value whose contents are the
        // serialized version of the query results.
        int[] xType = new int[1];
        List itemRefs = sqlxUtil.evalXQExpression(this, true, xType);
        if (result == null)
            result = new XML();
        String strResult = sqlxUtil.serializeToString(itemRefs, result);
        result.setValue(new SQLChar(strResult));
        // Now that we've set the result value, make sure
        // to indicate what kind of XML value we have.
        result.setXType(xType[0]);
        // And finally we return the query result as an XML value.
        return result;
    } catch (StandardException se) {
        // Just re-throw it.
        throw se;
    } catch (Throwable xe) {
        /* Failed somewhere during evaluation of the XML query expression;
         * turn error into a StandardException and throw it.  Note: we
         * catch "Throwable" here to catch as many Xalan-produced errors
         * as possible in order to minimize the chance of an uncaught Xalan
         * error (such as a NullPointerException) causing Derby to fail in
         * a more serious way.  In particular, an uncaught Java exception
         * like NPE can result in Derby throwing "ERROR 40XT0: An internal
         * error was identified by RawStore module" for all statements on
         * the connection after the failure--which we clearly don't want.  
         * If we catch the error and wrap it, though, the statement will
         * fail but Derby will continue to run as normal. 
         */
        throw StandardException.newException(SQLState.LANG_XML_QUERY_ERROR, xe, "XMLQUERY", xe.getMessage());
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) List(java.util.List)

Example 38 with StandardException

use of org.apache.derby.shared.common.error.StandardException 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 39 with StandardException

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

the class EmbedCallableStatement method getBoolean.

/**
 * @see CallableStatement#getBoolean
 * @exception SQLException NoOutputParameters thrown.
 */
public boolean getBoolean(int parameterIndex) throws SQLException {
    checkStatus();
    try {
        DataValueDescriptor param = getParms().getParameterForGet(parameterIndex - 1);
        boolean v = param.getBoolean();
        wasNull = (!v) && param.isNull();
        return v;
    } catch (StandardException e) {
        throw EmbedResultSet.noStateChangeException(e);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 40 with StandardException

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

the class EmbedCallableStatement method getShort.

/**
 * @see CallableStatement#getShort
 * @exception SQLException NoOutputParameters thrown.
 */
public short getShort(int parameterIndex) throws SQLException {
    checkStatus();
    try {
        DataValueDescriptor param = getParms().getParameterForGet(parameterIndex - 1);
        short s = param.getShort();
        wasNull = (s == 0) && param.isNull();
        return s;
    } catch (StandardException e) {
        throw EmbedResultSet.noStateChangeException(e);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

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