* transaction rollback.
*/
public static void runScript(Database database, String logFilename) {
IntKeyHashMap sessionMap = new IntKeyHashMap();
Session current = null;
int currentId = 0;
database.setReferentialIntegrity(false);
ScriptReaderBase scr = null;
String statement;
int statementType;
Statement dummy = new StatementDML(StatementTypes.UPDATE_CURSOR,
StatementTypes.X_SQL_DATA_CHANGE,
null);
try {
StopWatch sw = new StopWatch();
Crypto crypto = database.logger.getCrypto();
if (crypto == null) {
scr = new ScriptReaderText(database, logFilename);
} else {
scr = new ScriptReaderDecode(database, logFilename, crypto,
true);
}
while (scr.readLoggedStatement(current)) {
int sessionId = scr.getSessionNumber();
if (current == null || currentId != sessionId) {
currentId = sessionId;
current = (Session) sessionMap.get(currentId);
if (current == null) {
current =
database.getSessionManager().newSession(database,
database.getUserManager().getSysUser(), false,
true, null, 0);
sessionMap.put(currentId, current);
}
}
if (current.isClosed()) {
sessionMap.remove(currentId);
continue;
}
Result result = null;
statementType = scr.getStatementType();
switch (statementType) {
case ScriptReaderBase.ANY_STATEMENT :
statement = scr.getLoggedStatement();
result = current.executeDirectStatement(statement,
ResultProperties.defaultPropsValue);
if (result != null && result.isError()) {
if (result.getException() != null) {
throw result.getException();
}
throw Error.error(result);
}
break;
case ScriptReaderBase.COMMIT_STATEMENT :
current.commit(false);
break;
case ScriptReaderBase.INSERT_STATEMENT : {
current.sessionContext.currentStatement = dummy;
current.beginAction(dummy);
Object[] data = scr.getData();
scr.getCurrentTable().insertNoCheckFromLog(current,
data);
current.endAction(Result.updateOneResult);
break;
}
case ScriptReaderBase.DELETE_STATEMENT : {
current.sessionContext.currentStatement = dummy;
current.beginAction(dummy);
Object[] data = scr.getData();
scr.getCurrentTable().deleteNoCheckFromLog(current,
data);
current.endAction(Result.updateOneResult);
break;
}
case ScriptReaderBase.SET_SCHEMA_STATEMENT : {
HsqlName name =
database.schemaManager.findSchemaHsqlName(
scr.getCurrentSchema());
current.setCurrentSchemaHsqlName(name);
break;
}
case ScriptReaderBase.SESSION_ID : {
break;
}
}
if (current.isClosed()) {
sessionMap.remove(currentId);
}
}
} catch (Throwable e) {