Search in sources :

Example 36 with HsqlException

use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.

the class DataFileCache method getFromFile.

private CachedObject getFromFile(int pos, PersistentStore store, boolean keep) {
    CachedObject object = null;
    boolean outOfMemory = false;
    writeLock.lock();
    try {
        for (int j = 0; j < 5; j++) {
            outOfMemory = false;
            try {
                RowInputInterface rowInput = readObject(pos);
                if (rowInput == null) {
                    return null;
                }
                object = store.get(rowInput);
                break;
            } catch (OutOfMemoryError err) {
                cache.cleanUp();
                outOfMemory = true;
                database.logger.appLog.logContext(err, null);
            }
        }
        if (outOfMemory) {
            throw Error.error(ErrorCode.OUT_OF_MEMORY);
        }
        // for text tables with empty rows at the beginning,
        // pos may move forward in readObject
        pos = object.getPos();
        cache.put(pos, object);
        if (keep) {
            object.keepInMemory(true);
        }
        store.set(object);
        return object;
    } catch (HsqlException e) {
        database.logger.appLog.logContext(e, fileName + " get pos: " + pos);
        throw e;
    } finally {
        writeLock.unlock();
    }
}
Also used : RowInputInterface(org.hsqldb_voltpatches.rowio.RowInputInterface) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 37 with HsqlException

use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.

the class DataFileCache method saveRowNoLock.

public void saveRowNoLock(CachedObject row) {
    try {
        setFileModified();
        rowOut.reset();
        row.write(rowOut);
        dataFile.seek((long) row.getPos() * cacheFileScale);
        dataFile.write(rowOut.getOutputStream().getBuffer(), 0, rowOut.getOutputStream().size());
    } catch (IOException e) {
        throw new HsqlException(e.getMessage(), "", 0);
    }
}
Also used : IOException(java.io.IOException) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 38 with HsqlException

use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.

the class LobManager method setBytesIS.

private Result setBytesIS(Session session, long lobID, InputStream inputStream, long length) {
    int blockLimit = (int) (length / lobBlockSize);
    int byteLimitOffset = (int) (length % lobBlockSize);
    if (byteLimitOffset == 0) {
        byteLimitOffset = lobBlockSize;
    } else {
        blockLimit++;
    }
    createBlockAddresses(session, lobID, 0, blockLimit);
    int[][] blockAddresses = getBlockAddresses(session, lobID, 0, blockLimit);
    byte[] dataBytes = new byte[lobBlockSize];
    for (int i = 0; i < blockAddresses.length; i++) {
        for (int j = 0; j < blockAddresses[i][1]; j++) {
            int localLength = lobBlockSize;
            if (i == blockAddresses.length - 1 && j == blockAddresses[i][1] - 1) {
                localLength = byteLimitOffset;
                // todo -- use block op
                for (int k = localLength; k < lobBlockSize; k++) {
                    dataBytes[k] = 0;
                }
            }
            try {
                int count = 0;
                while (localLength > 0) {
                    int read = inputStream.read(dataBytes, count, localLength);
                    if (read == -1) {
                        return Result.newErrorResult(new EOFException());
                    }
                    localLength -= read;
                    count += read;
                }
            // read more
            } catch (IOException e) {
                // deallocate
                return Result.newErrorResult(e);
            }
            try {
                lobStore.setBlockBytes(dataBytes, blockAddresses[i][0] + j, 1);
            } catch (HsqlException e) {
                return Result.newErrorResult(e);
            }
        }
    }
    return ResultLob.newLobSetResponse(lobID, 0);
}
Also used : EOFException(java.io.EOFException) IOException(java.io.IOException) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 39 with HsqlException

use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.

the class JDBCPreparedStatement method setParameter.

/**
     * The internal parameter value setter always converts the parameter to
     * the Java type required for data transmission.
     *
     * @param i parameter index
     * @param o object
     * @throws SQLException if either argument is not acceptable.
     */
void setParameter(int i, Object o) throws SQLException {
    checkSetParameterIndex(i, false);
    i--;
    if (o == null) {
        parameterValues[i] = null;
        return;
    }
    Type outType = parameterTypes[i];
    switch(outType.typeCode) {
        case Types.OTHER:
            try {
                if (o instanceof Serializable) {
                    o = new JavaObjectData((Serializable) o);
                    break;
                }
            } catch (HsqlException e) {
                Util.throwError(e);
            }
            Util.throwError(Error.error(ErrorCode.X_42565));
            break;
        case Types.SQL_BIT:
        case Types.SQL_BIT_VARYING:
            if (o instanceof Boolean) {
                if (outType.precision == 1) {
                    byte[] bytes = ((Boolean) o).booleanValue() ? new byte[] { -0x80 } : new byte[] { 0 };
                    o = new BinaryData(bytes, 1);
                    break;
                }
                Util.throwError(Error.error(ErrorCode.X_42565));
            }
            try {
                if (o instanceof byte[]) {
                    o = outType.convertToDefaultType(connection.sessionProxy, o);
                    break;
                }
                if (o instanceof String) {
                    o = outType.convertToDefaultType(connection.sessionProxy, o);
                    break;
                }
            } catch (HsqlException e) {
                Util.throwError(e);
            }
            Util.throwError(Error.error(ErrorCode.X_42565));
        // $FALL-THROUGH$
        case Types.SQL_BINARY:
        case Types.SQL_VARBINARY:
            if (o instanceof byte[]) {
                o = new BinaryData((byte[]) o, !connection.isNetConn);
                break;
            }
            try {
                if (o instanceof String) {
                    o = outType.convertToDefaultType(connection.sessionProxy, o);
                    break;
                }
            } catch (HsqlException e) {
                Util.throwError(e);
            }
            Util.throwError(Error.error(ErrorCode.X_42565));
            break;
        case Types.SQL_BLOB:
            setBlobParameter(i + 1, o);
            return;
        case Types.SQL_CLOB:
            setClobParameter(i + 1, o);
            return;
        case Types.SQL_DATE:
        case Types.SQL_TIME_WITH_TIME_ZONE:
        case Types.SQL_TIMESTAMP_WITH_TIME_ZONE:
        case Types.SQL_TIME:
        case Types.SQL_TIMESTAMP:
            {
                try {
                    if (o instanceof String) {
                        o = outType.convertToType(connection.sessionProxy, o, Type.SQL_VARCHAR);
                        break;
                    }
                    o = outType.convertJavaToSQL(connection.sessionProxy, o);
                    break;
                } catch (HsqlException e) {
                    Util.throwError(e);
                }
            }
        // $FALL-THROUGH$
        case Types.TINYINT:
        case Types.SQL_SMALLINT:
        case Types.SQL_INTEGER:
        case Types.SQL_BIGINT:
        case Types.SQL_REAL:
        case Types.SQL_FLOAT:
        case Types.SQL_DOUBLE:
        case Types.SQL_NUMERIC:
        case Types.SQL_DECIMAL:
            try {
                if (o instanceof String) {
                    o = outType.convertToType(connection.sessionProxy, o, Type.SQL_VARCHAR);
                    break;
                }
                o = outType.convertToDefaultType(connection.sessionProxy, o);
                break;
            } catch (HsqlException e) {
                Util.throwError(e);
            }
        // $FALL-THROUGH$
        default:
            try {
                o = outType.convertToDefaultType(connection.sessionProxy, o);
                break;
            } catch (HsqlException e) {
                Util.throwError(e);
            }
    }
    parameterValues[i] = o;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) Serializable(java.io.Serializable) JavaObjectData(org.hsqldb_voltpatches.types.JavaObjectData) BinaryData(org.hsqldb_voltpatches.types.BinaryData) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 40 with HsqlException

use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.

the class JDBCConnection method prepareCall.

/**
     * <!-- start generic documentation -->
     *
     * Creates a <code>CallableStatement</code> object for calling
     * database stored procedures.
     * The <code>CallableStatement</code> object provides
     * methods for setting up its IN and OUT parameters, and
     * methods for executing the call to a stored procedure.
     *
     * <P><B>Note:</B> This method is optimized for handling stored
     * procedure call statements. Some drivers may send the call
     * statement to the database when the method <code>prepareCall</code>
     * is done; others
     * may wait until the <code>CallableStatement</code> object
     * is executed. This has no
     * direct effect on users; however, it does affect which method
     * throws certain SQLExceptions.
     * <P>
     * Result sets created using the returned <code>CallableStatement</code>
     * object will by default be type <code>TYPE_FORWARD_ONLY</code>
     * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
     * The holdability of the created result sets can be determined by
     * calling {@link #getHoldability}.
     *
     * <!-- end generic documentation -->
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * Starting with 1.7.2, the support for and behaviour of
     * CallableStatement has changed.  Please read the introductory section
     * of the documentation for org.hsqldb_voltpatches.jdbc.JDBCCallableStatement.
     *
     * </div> <!-- end release-specific documentation -->
     *
     * @param sql an SQL statement that may contain one or more '?'
     * parameter placeholders. (JDBC4 clarification:) Typically this statement is specified using JDBC
     * call escape syntax.
     * @return a new default <code>CallableStatement</code> object containing the
     * pre-compiled SQL statement
     * @exception SQLException if a database access error occurs
     * (JDBC4 clarification:)
     * or this method is called on a closed connection
     * @see #prepareCall(String,int,int)
     */
public synchronized CallableStatement prepareCall(String sql) throws SQLException {
    CallableStatement stmt;
    checkClosed();
    try {
        stmt = new JDBCCallableStatement(this, sql, JDBCResultSet.TYPE_FORWARD_ONLY, JDBCResultSet.CONCUR_READ_ONLY, rsHoldability);
        return stmt;
    } catch (HsqlException e) {
        throw Util.sqlException(e);
    }
}
Also used : CallableStatement(java.sql.CallableStatement) HsqlException(org.hsqldb_voltpatches.HsqlException)

Aggregations

HsqlException (org.hsqldb_voltpatches.HsqlException)46 SchemaObject (org.hsqldb_voltpatches.SchemaObject)19 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)17 Constraint (org.hsqldb_voltpatches.Constraint)16 Table (org.hsqldb_voltpatches.Table)16 Iterator (org.hsqldb_voltpatches.lib.Iterator)16 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)16 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)16 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)16 TextTable (org.hsqldb_voltpatches.TextTable)14 IOException (java.io.IOException)10 Routine (org.hsqldb_voltpatches.Routine)5 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)5 TriggerDef (org.hsqldb_voltpatches.TriggerDef)4 Grantee (org.hsqldb_voltpatches.rights.Grantee)4 Right (org.hsqldb_voltpatches.rights.Right)4 Type (org.hsqldb_voltpatches.types.Type)4 Row (org.hsqldb_voltpatches.Row)3 Result (org.hsqldb_voltpatches.result.Result)3 BatchUpdateException (java.sql.BatchUpdateException)2