*/
public static void runScript(Database database, String logFilename,
int logType) throws HsqlException {
IntKeyHashMap sessionMap = new IntKeyHashMap();
Session sysSession = database.getSessionManager().getSysSession();
Session current = sysSession;
int currentId = 0;
database.setReferentialIntegrity(false);
ScriptReaderBase scr = null;
try {
StopWatch sw = new StopWatch();
scr = ScriptReaderBase.newScriptReader(database, logFilename,
logType);
while (scr.readLoggedStatement(current)) {
int sessionId = scr.getSessionNumber();
if (currentId != sessionId) {
currentId = sessionId;
current = (Session) sessionMap.get(currentId);
if (current == null) {
current =
database.getSessionManager().newSession(database,
sysSession.getUser(), false, true);
sessionMap.put(currentId, current);
}
}
if (current.isClosed()) {
sessionMap.remove(currentId);
continue;
}
Result result = null;
switch (scr.getStatementType()) {
case ScriptReaderBase.ANY_STATEMENT :
result = current.sqlExecuteDirectNoPreChecks(
scr.getLoggedStatement());
if (result != null && result.isError()) {
if (result.getException() != null) {
throw result.getException();
}
throw Trace.error(result);
}
break;
case ScriptReaderBase.SEQUENCE_STATEMENT :
scr.getCurrentSequence().reset(
scr.getSequenceValue());
break;
case ScriptReaderBase.COMMIT_STATEMENT :
current.commit();
break;
case ScriptReaderBase.INSERT_STATEMENT : {
Object[] data = scr.getData();
scr.getCurrentTable().insertNoCheckFromLog(current,
data);
break;
}
case ScriptReaderBase.DELETE_STATEMENT : {
Object[] data = scr.getData();
scr.getCurrentTable().deleteNoCheckFromLog(current,
data);
break;
}
case ScriptReaderBase.SCHEMA_STATEMENT : {
current.setSchema(scr.getCurrentSchema());
}
}
if (current.isClosed()) {
sessionMap.remove(currentId);
}
}
} catch (Throwable e) {
String message;