use of catdata.fql.decl.InstOps in project fql by CategoricalData.
the class JDBCBridge method run.
public static Triple<Map<String, Set<Map<Object, Object>>>, String, List<Throwable>> run(FQLProgram prog) {
Map<String, Set<Map<Object, Object>>> ret = new HashMap<>();
List<Throwable> exns = new LinkedList<>();
InstOps ops = new InstOps(prog);
PSMInterp interp = new PSMInterp();
Connection Conn;
Statement Stmt = null;
List<PSM> sqls = new LinkedList<>();
try {
switch(DefunctGlobalOptions.debug.fql.sqlKind) {
case H2:
Class.forName("org.h2.Driver");
Conn = DriverManager.getConnection("jdbc:h2:mem:");
Stmt = Conn.createStatement();
Stmt.execute("SET @GUID = 0");
break;
case JDBC:
Class.forName(DefunctGlobalOptions.debug.fql.jdbcClass);
Conn = DriverManager.getConnection(DefunctGlobalOptions.debug.fql.jdbcUrl);
Stmt = Conn.createStatement();
String[] prel = DefunctGlobalOptions.debug.fql.prelude.split(";");
for (String s : prel) {
Stmt.execute(s);
}
break;
case NATIVE:
break;
default:
throw new RuntimeException();
}
for (String k : prog.order) {
InstExp v1 = prog.insts.get(k);
TransExp v2 = prog.transforms.get(k);
try {
if (v1 != null) {
sqls.addAll(maybeExecInstance(ops, prog, Stmt, k, v1, interp, ret));
} else if (v2 != null) {
sqls.addAll(maybeExecTransform(ops, prog, Stmt, k, v2, interp, ret));
}
} catch (Throwable re) {
String thing = (v1 == null) ? "transform" : "instance";
re.printStackTrace();
LineException exn = new LineException(re.getLocalizedMessage(), k, thing);
if (DefunctGlobalOptions.debug.fql.continue_on_error) {
exns.add(exn);
} else {
if (DefunctGlobalOptions.debug.fql.sqlKind == SQLKIND.JDBC) {
String[] prel0 = DefunctGlobalOptions.debug.fql.afterlude.split(";");
for (String s : prel0) {
if (!s.trim().isEmpty()) {
if (Stmt == null) {
throw new RuntimeException("Anomaly: please report");
}
Stmt.execute(s);
}
}
}
throw exn;
}
}
}
List<PSM> drops = Driver.computeDrops(prog);
if (DefunctGlobalOptions.debug.fql.sqlKind == SQLKIND.JDBC) {
for (PSM dr : drops) {
if (Stmt == null) {
throw new RuntimeException("Anomaly: please report");
}
Stmt.execute(dr.toPSM());
}
String[] prel0 = DefunctGlobalOptions.debug.fql.afterlude.split(";");
for (String s : prel0) {
if (!s.trim().isEmpty()) {
if (Stmt == null) {
throw new RuntimeException("Anomaly: please report");
}
Stmt.execute(s);
}
}
}
String str;
try {
str = DefunctGlobalOptions.debug.fql.prelude + "\n\n" + PSMGen.prettyPrint(sqls) + "\n\n" + (drops.isEmpty() ? "" : PSMGen.prettyPrint(drops) + "\n\n") + DefunctGlobalOptions.debug.fql.afterlude + "\n\n";
} catch (RuntimeException re) {
str = re.getLocalizedMessage();
}
return new Triple<>(ret, str, exns);
} catch (Exception exception) {
if (exception instanceof LineException) {
throw ((LineException) exception);
}
exception.printStackTrace();
throw new RuntimeException(exception.getLocalizedMessage());
}
}
Aggregations