use of catdata.sql.SqlInstance in project fql by CategoricalData.
the class InstExpJdbcAll method eval.
@Override
public Instance<Ty, En, Sym, Fk, Att, Gen, Null<?>, Gen, Null<?>> eval(AqlEnv env) {
String toGet = jdbcString;
String driver = clazz;
AqlOptions op = new AqlOptions(options, null, env.defaults);
if (clazz.trim().isEmpty()) {
driver = (String) op.getOrDefault(AqlOption.jdbc_default_class);
Util.checkClass(driver);
}
if (jdbcString.trim().isEmpty()) {
toGet = (String) op.getOrDefault(AqlOption.jdbc_default_string);
}
try (Connection conn = DriverManager.getConnection(toGet)) {
SqlSchema sch = new SqlSchema(conn.getMetaData());
boolean noDistinct = (Boolean) op.getOrDefault(AqlOption.jdbc_no_distinct_unsafe);
boolean schemaOnly = (Boolean) op.getOrDefault(AqlOption.schema_only);
boolean nullOnErr = (Boolean) op.getOrDefault(AqlOption.import_null_on_err_unsafe);
if (!schemaOnly) {
SqlInstance inst = new SqlInstance(sch, conn, nullOnErr, noDistinct);
return toInstance(env, inst, sch);
}
return toInstance(env, null, sch);
} catch (SQLException exn) {
exn.printStackTrace();
throw new RuntimeException("JDBC exception: " + exn.getMessage());
}
}
Aggregations