Search in sources :

Example 1 with SQLSchemaReader

use of eu.esdihumboldt.hale.io.jdbc.SQLSchemaReader in project hale by halestudio.

the class AbstractDBTest method readSchema.

/**
 * Load the database schema for a SQL statement.
 *
 * @param sql the SQL query
 * @param typeName the type name for the query
 *
 * @return the schema
 * @throws Exception if reading the schema fails
 */
protected Schema readSchema(String sql, String typeName) throws Exception {
    SQLSchemaReader schemaReader = new SQLSchemaReader();
    schemaReader.setSource(new NoStreamInputSupplier(jdbcUri));
    schemaReader.setParameter(JDBCSchemaReader.PARAM_USER, Value.of(dbi.getUser()));
    schemaReader.setParameter(JDBCSchemaReader.PARAM_PASSWORD, Value.of(dbi.getPassword()));
    schemaReader.setParameter(SQLSchemaReader.PARAM_SQL, Value.of(sql));
    schemaReader.setParameter(SQLSchemaReader.PARAM_TYPE_NAME, Value.of(typeName));
    IOReport report = schemaReader.execute(null);
    assertTrue(report.isSuccess());
    assertTrue(report.getErrors().isEmpty());
    Schema schema = schemaReader.getSchema();
    assertNotNull(schema);
    return schema;
}
Also used : Schema(eu.esdihumboldt.hale.common.schema.model.Schema) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) SQLSchemaReader(eu.esdihumboldt.hale.io.jdbc.SQLSchemaReader) NoStreamInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier)

Aggregations

IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)1 NoStreamInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier)1 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)1 SQLSchemaReader (eu.esdihumboldt.hale.io.jdbc.SQLSchemaReader)1