Search in sources :

Example 26 with StandardException

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

the class EmbedResultSet method getObject.

/**
 * <p>Get the value of a column in the current row as a Java object.
 *
 * <p>This method will return the value of the given column as a
 * Java object.  The type of the Java object will be the default
 * Java Object type corresponding to the column's SQL type,
 * following the mapping specified in the JDBC spec.
 *
 * <p>This method may also be used to read datatabase specific abstract
 * data types.
 *
 * JDBC 2.0
 *
 * New behavior for getObject().
 * The behavior of method getObject() is extended to materialize
 * data of SQL user-defined types.  When the column @columnIndex is
 * a structured or distinct value, the behavior of this method is as
 * if it were a call to: getObject(columnIndex,
 * this.getStatement().getConnection().getTypeMap()).
 *
 * @param columnIndex the first column is 1, the second is 2, ...
 * @return A java.lang.Object holding the column value.
 * @exception SQLException thrown on failure.
 */
public final Object getObject(int columnIndex) throws SQLException {
    checkIfClosed("getObject");
    // need special handling for some types.
    int colType = getColumnType(columnIndex);
    switch(colType) {
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            // handles maxfield size correctly
            return getString(columnIndex);
        case Types.CLOB:
            return getClob(columnIndex);
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            // handles maxfield size correctly
            return getBytes(columnIndex);
        case Types.BLOB:
            return getBlob(columnIndex);
        default:
            break;
    }
    try {
        DataValueDescriptor dvd = getColumn(columnIndex);
        if (wasNull = dvd.isNull())
            return null;
        return dvd.getObject();
    } catch (StandardException t) {
        throw noStateChangeException(t);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 27 with StandardException

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

the class EmbedResultSet method getBytes.

/**
 * Get the value of a column in the current row as a Java byte array.
 * The bytes represent the raw values returned by the driver.
 *
 * @param columnIndex the first column is 1, the second is 2, ...
 * @return the column value; if the value is SQL NULL, the result is null
 * @exception SQLException thrown on failure.
 */
public final byte[] getBytes(int columnIndex) throws SQLException {
    checkIfClosed("getBytes");
    int columnType = getColumnType(columnIndex);
    if (columnType == Types.BLOB) {
        checkLOBMultiCall(columnIndex);
    // If the above didn't fail, this is the first getter invocation,
    // or only getBytes has been invoked previously. The special
    // treatment of this getter is allowed for backwards compatibility.
    }
    try {
        DataValueDescriptor dvd = getColumn(columnIndex);
        if (wasNull = dvd.isNull())
            return null;
        byte[] value = dvd.getBytes();
        // check for the max field size limit
        if (maxFieldSize > 0 && isMaxFieldSizeType(columnType)) {
            if (value.length > maxFieldSize) {
                byte[] limited_value = new byte[maxFieldSize];
                System.arraycopy(value, 0, limited_value, 0, maxFieldSize);
                value = limited_value;
            }
        }
        return value;
    } catch (StandardException t) {
        throw noStateChangeException(t);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 28 with StandardException

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

the class DatabaseContextImpl method cleanupOnError.

public void cleanupOnError(Throwable t) {
    if (!(t instanceof StandardException))
        return;
    StandardException se = (StandardException) t;
    // going away.
    if (se.getSeverity() < ExceptionSeverity.SESSION_SEVERITY)
        return;
    popMe();
    if (se.getSeverity() >= ExceptionSeverity.DATABASE_SEVERITY) {
        // DERBY-5108: Shut down the istat daemon thread before shutting
        // down the various modules belonging to the database. An active
        // istat daemon thread at the time of shutdown may result in
        // containers being reopened after the container cache has been
        // shut down. On certain platforms, this results in database
        // files that can't be deleted until the VM exits.
        DataDictionary dd = db.getDataDictionary();
        // dd is null if the db is an active slave db (replication)
        if (dd != null) {
            dd.disableIndexStatsRefresher();
        }
    }
    if (se.getSeverity() == ExceptionSeverity.DATABASE_SEVERITY) {
        getContextService().notifyAllActiveThreads(this);
        // This may be called multiple times, but is short-circuited
        // in the monitor.
        getMonitor().shutdown(db);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary)

Example 29 with StandardException

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

the class SlaveDatabase method handleShutdown.

/**
 * Used to shutdown this database.
 *
 * If an error occurs as part of the database boot process, we
 * hand the exception that caused boot to fail to the client
 * thread. The client thread will in turn shut down this database.
 *
 * If an error occurs at a later stage than during boot, we shut
 * down the database by setting up a connection with the shutdown
 * attribute. The internal connection is required because database
 * shutdown requires EmbedConnection to do cleanup.
 *
 * @param shutdownCause the reason why the database needs to be
 * shutdown
 */
private void handleShutdown(StandardException shutdownCause) {
    if (inBoot) {
        bootException = shutdownCause;
        return;
    }
    try {
        shutdownInitiated = true;
        String conStr = "jdbc:derby:" + dbname + ";" + Attribute.REPLICATION_INTERNAL_SHUTDOWN_SLAVE + "=true";
        InternalDriver driver = InternalDriver.activeDriver();
        if (driver != null) {
            driver.connect(conStr, (Properties) null, 0);
        }
    } catch (Exception e) {
    // Todo: report error to derby.log if exception is not
    // SQLState.SHUTDOWN_DATABASE
    }
}
Also used : InternalDriver(org.apache.derby.iapi.jdbc.InternalDriver) StandardException(org.apache.derby.shared.common.error.StandardException) PrivilegedActionException(java.security.PrivilegedActionException) SQLException(java.sql.SQLException)

Example 30 with StandardException

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

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