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");
}
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;
}
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() });
}
}
}
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;
}
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);
}
}
Aggregations