Search in sources :

Example 1 with SqlInstance

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());
    }
}
Also used : SqlInstance(catdata.sql.SqlInstance) SqlSchema(catdata.sql.SqlSchema) SQLException(java.sql.SQLException) Connection(java.sql.Connection) AqlOptions(catdata.aql.AqlOptions)

Aggregations

AqlOptions (catdata.aql.AqlOptions)1 SqlInstance (catdata.sql.SqlInstance)1 SqlSchema (catdata.sql.SqlSchema)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1