use of org.voltdb.utils.LineReaderAdapter in project voltdb by VoltDB.
the class DDLCompiler method loadSchemaWithFiltering.
public void loadSchemaWithFiltering(Reader reader, final Database db, final DdlProceduresToLoad whichProcs, SQLParser.FileInfo fileInfo) throws VoltCompiler.VoltCompilerException {
final LineReaderAdapter lineReader = new LineReaderAdapter(reader);
DDLParserCallback callback = new DDLParserCallback() {
@Override
public void statement(String statement, int lineNum) throws VoltCompiler.VoltCompilerException {
try {
if (statement == null || statement.trim().isEmpty()) {
return;
}
doExecuteStatement(statement.trim() + ";", lineNum);
} catch (Exception e) {
throw m_compiler.new VoltCompilerException(e);
}
}
@Override
public void batch(String batch, int batchEndLineNumber) throws VoltCompiler.VoltCompilerException {
try {
String[] parts = batch.split(";");
int currLine = batchEndLineNumber - parts.length;
for (String s : parts) {
if (!s.trim().isEmpty()) {
doExecuteStatement(s.trim() + ";", currLine++);
}
}
} catch (Exception e) {
throw m_compiler.new VoltCompilerException(e);
}
}
private void doExecuteStatement(String statement, int lineNum) throws VoltCompiler.VoltCompilerException {
// Filter out any statements that we don't want to deal with
if (statement.toUpperCase().startsWith("LOAD")) {
return;
}
DDLStatement stmt = new DDLStatement(statement, lineNum);
processVoltDBStatements(db, whichProcs, stmt);
}
};
try {
SQLCommand.executeScriptFromReader(fileInfo, lineReader, callback);
} catch (Exception e) {
throw m_compiler.new VoltCompilerException(e);
} finally {
// NEEDSWORK (ENG-12255): This really should be done outside the loop, by the caller. The exception propagation, at this point, is pretty messy, and
// changing it would be a pretty big effort that's really not relevant to this ticket. Fix this sometime.
lineReader.close();
}
// process extra classes
m_tracker.addExtraClasses(m_classMatcher.getMatchedClassList());
// possibly save some memory
m_classMatcher.clear();
}
Aggregations