Search in sources :

Example 16 with HsqlException

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

the class DataFileCache method defrag.

/**
     *  Writes out all the rows to a new file without fragmentation.
     */
public void defrag() {
    if (cacheReadonly) {
        return;
    }
    if (fileFreePosition == INITIAL_FREE_POS) {
        return;
    }
    database.logger.appLog.logContext(SimpleLog.LOG_NORMAL, "start");
    try {
        boolean wasNio = dataFile.wasNio();
        cache.saveAll();
        DataFileDefrag dfd = new DataFileDefrag(database, this, fileName);
        dfd.process();
        close(false);
        deleteFile(wasNio);
        renameDataFile(wasNio);
        backupFile();
        database.getProperties().setProperty(HsqlDatabaseProperties.hsqldb_cache_version, HsqlDatabaseProperties.THIS_CACHE_VERSION);
        database.getProperties().save();
        cache.clear();
        cache = new Cache(this);
        open(cacheReadonly);
        dfd.updateTableIndexRoots();
        dfd.updateTransactionRowIDs();
    } catch (Throwable e) {
        database.logger.appLog.logContext(e, null);
        if (e instanceof HsqlException) {
            throw (HsqlException) e;
        } else {
            throw new HsqlException(e, Error.getMessage(ErrorCode.GENERAL_IO_ERROR), ErrorCode.GENERAL_IO_ERROR);
        }
    }
    database.logger.appLog.logContext(SimpleLog.LOG_NORMAL, "end");
}
Also used : HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 17 with HsqlException

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

the class BlobInputStream method read.

public int read() throws IOException {
    if (currentPosition >= availableLength) {
        return -1;
    }
    if (buffer == null || currentPosition >= bufferOffset + buffer.length) {
        try {
            checkClosed();
            readIntoBuffer();
        } catch (HsqlException e) {
            throw new IOException(e.getMessage());
        }
    }
    int val = buffer[(int) (currentPosition - bufferOffset)] & 0xff;
    currentPosition++;
    return val;
}
Also used : IOException(java.io.IOException) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 18 with HsqlException

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

the class ScriptReaderText method readDDL.

protected void readDDL(Session session) throws IOException {
    for (; readLoggedStatement(session); ) {
        Statement cs = null;
        Result result = null;
        if (rowIn.getStatementType() == INSERT_STATEMENT) {
            isInsert = true;
            break;
        }
        try {
            cs = session.compileStatement(statement);
            result = session.executeCompiledStatement(cs, ValuePool.emptyObjectArray);
            if (cs.getType() == StatementTypes.CREATE_SCHEMA) {
                HsqlName name = cs.getSchemaName();
                session.setSchema(name.name);
            }
        } catch (HsqlException e) {
            result = Result.newErrorResult(e);
        }
        if (result.isError()) {
            // handle grants on math and library routines in old versions
            if (cs == null) {
            } else {
                if (cs.getType() == StatementTypes.GRANT) {
                    continue;
                }
            }
        //
        }
        if (result.isError()) {
            db.logger.appLog.logContext(SimpleLog.LOG_ERROR, result.getMainString());
            throw Error.error(ErrorCode.ERROR_IN_SCRIPT_FILE, ErrorCode.M_DatabaseScriptReader_readDDL, new Object[] { new Integer(lineCount), result.getMainString() });
        }
    }
}
Also used : Statement(org.hsqldb_voltpatches.Statement) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) HsqlException(org.hsqldb_voltpatches.HsqlException) Result(org.hsqldb_voltpatches.result.Result)

Example 19 with HsqlException

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

the class JDBCCallableStatement method getColumnInType.

/**
     * Checks if the parameter of the given index has been successfully
     * registered as an OUT parameter. <p>
     *
     * @param parameterIndex to check
     * @throws SQLException if not registered
     */
/*
    private void checkIsRegisteredParameterIndex(int parameterIndex)
    throws SQLException {

        int    type;
        String msg;

        checkClosed();

        type = outRegistrationMap.get(parameterIndex, Integer.MIN_VALUE);

        if (type == Integer.MIN_VALUE) {
            msg = "Parameter not registered: " + parameterIndex; //NOI18N

            throw Util.sqlException(ErrorCode.INVALID_JDBC_ARGUMENT, msg);
        }
    }
*/
/**
     * Internal value converter. Similar to its counterpart in JDBCResultSet <p>
     *
     * All trivially successful getXXX methods eventually go through this
     * method, converting if neccessary from the source type to the
     * requested type.  <p>
     *
     * Conversion to the JDBC representation, if different, is handled by the
     * calling methods.
     *
     * @param columnIndex of the column value for which to perform the
     *                 conversion
     * @param targetType the org.hsqldb_voltpatches.types.Type object for targetType
     * @return an Object of the requested targetType, representing the value of the
     *       specified column
     * @throws SQLException when there is no rowData, the column index is
     *    invalid, or the conversion cannot be performed
     */
private Object getColumnInType(int columnIndex, Type targetType) throws SQLException {
    Type sourceType;
    Object value;
    sourceType = parameterTypes[--columnIndex];
    value = parameterValues[columnIndex];
    if (trackNull(value)) {
        return null;
    }
    if (sourceType.typeCode != targetType.typeCode) {
        try {
            value = targetType.convertToTypeJDBC(session, value, sourceType);
        } catch (HsqlException e) {
            String stringValue = (value instanceof Number || value instanceof String || value instanceof java.util.Date) ? value.toString() : "instance of " + value.getClass().getName();
            String msg = "from SQL type " + sourceType.getNameString() + " to " + targetType.getJDBCClassName() + ", value: " + stringValue;
            HsqlException err = Error.error(ErrorCode.X_42561, msg);
            throw Util.sqlException(err, e);
        }
    }
    return value;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) SchemaObject(org.hsqldb_voltpatches.SchemaObject) HsqlException(org.hsqldb_voltpatches.HsqlException) Date(java.sql.Date)

Example 20 with HsqlException

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

the class TextCache method findNextUsedLinePos.

// fredt - new method
/**
     * Searches from file pointer, pos, and finds the beginning of the first
     * line that contains any non-space character. Increments the row counter
     * when a blank line is skipped.
     *
     * If none found return -1
     */
int findNextUsedLinePos(int pos) {
    try {
        int firstPos = pos;
        int currentPos = pos;
        boolean wasCR = false;
        dataFile.seek(pos);
        while (true) {
            int c = dataFile.read();
            currentPos++;
            switch(c) {
                case CR_CHAR:
                    wasCR = true;
                    break;
                case LF_CHAR:
                    wasCR = false;
                    ((RowInputText) rowIn).skippedLine();
                    firstPos = currentPos;
                    break;
                case ' ':
                    if (wasCR) {
                        wasCR = false;
                        ((RowInputText) rowIn).skippedLine();
                    }
                    break;
                case -1:
                    return -1;
                default:
                    return firstPos;
            }
        }
    } catch (IOException e) {
        throw new HsqlException(e.getMessage(), "", 0);
    }
}
Also used : RowInputText(org.hsqldb_voltpatches.rowio.RowInputText) IOException(java.io.IOException) 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