Search in sources :

Example 1 with NoStreamInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier in project hale by halestudio.

the class MsSQLServer14Test method readInstances.

/**
 * Reads instances from from a MsAccess database file with the provided
 * schema.
 *
 * @param sourceSchema the schema of the source database
 * @return the read instances
 * @throws Exception any exception thrown by {@link JDBCInstanceReader}
 */
private InstanceCollection readInstances(Schema sourceSchema) throws Exception {
    JDBCInstanceReader instanceReader = new JDBCInstanceReader();
    JDBCURI = new MsSqlURIBuilder().createJdbcUri(HOST, DATABASE);
    instanceReader.setSource(new NoStreamInputSupplier(JDBCURI));
    instanceReader.setSourceSchema(sourceSchema);
    instanceReader.setParameter(JDBCInstanceReader.PARAM_USER, Value.of(USER_NAME));
    instanceReader.setParameter(JDBCInstanceReader.PARAM_PASSWORD, Value.of(PASSWORD));
    // Test instances
    IOReport report = instanceReader.execute(new LogProgressIndicator());
    assertTrue("Data import was not successfull.", report.isSuccess());
    return instanceReader.getInstances();
}
Also used : MsSqlURIBuilder(eu.esdihumboldt.hale.io.jdbc.mssql.MsSqlURIBuilder) JDBCInstanceReader(eu.esdihumboldt.hale.io.jdbc.JDBCInstanceReader) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator) NoStreamInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier)

Example 2 with NoStreamInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier 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)

Example 3 with NoStreamInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier in project hale by halestudio.

the class AbstractDBTest method readSchema.

/**
 * Load the database schema.
 *
 * @return the schema
 * @throws Exception if reading the schema fails
 */
protected Schema readSchema() throws Exception {
    JDBCSchemaReader schemaReader = new JDBCSchemaReader();
    schemaReader.setSource(new NoStreamInputSupplier(jdbcUri));
    schemaReader.setParameter(JDBCSchemaReader.PARAM_USER, Value.of(dbi.getUser()));
    schemaReader.setParameter(JDBCSchemaReader.PARAM_PASSWORD, Value.of(dbi.getPassword()));
    // This is set for setting inclusion rule for reading schema
    if (dbi.getDatabase().equalsIgnoreCase("ORCL")) {
        schemaReader.setParameter(JDBCSchemaReader.SCHEMAS, Value.of(dbi.getUser().toUpperCase()));
    }
    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) JDBCSchemaReader(eu.esdihumboldt.hale.io.jdbc.JDBCSchemaReader) NoStreamInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier)

Example 4 with NoStreamInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier in project hale by halestudio.

the class AbstractDBTest method readInstances.

/**
 * Read instances from the database.
 *
 * @param schema the source schema
 * @return the database instances
 *
 * @throws Exception if reading the instances fails
 */
protected InstanceCollection readInstances(Schema schema) throws Exception {
    JDBCInstanceReader reader = new JDBCInstanceReader();
    reader.setSource(new NoStreamInputSupplier(jdbcUri));
    reader.setParameter(JDBCInstanceWriter.PARAM_USER, Value.of(dbi.getUser()));
    reader.setParameter(JDBCInstanceWriter.PARAM_PASSWORD, Value.of(dbi.getPassword()));
    DefaultSchemaSpace sourceSchema = new DefaultSchemaSpace();
    sourceSchema.addSchema(schema);
    reader.setSourceSchema(sourceSchema);
    IOReport report = reader.execute(null);
    assertTrue(report.isSuccess());
    assertTrue(report.getErrors().isEmpty());
    return reader.getInstances();
}
Also used : JDBCInstanceReader(eu.esdihumboldt.hale.io.jdbc.JDBCInstanceReader) DefaultSchemaSpace(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) NoStreamInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier)

Example 5 with NoStreamInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier in project hale by halestudio.

the class MsSQLServer14Test method readSchema.

/**
 * Reads a schema from a MS SQL database.
 *
 * @return the schema
 * @throws Exception any exception thrown by {@link JDBCSchemaReader}
 */
private Schema readSchema() throws Exception {
    JDBCSchemaReader schemaReader = new JDBCSchemaReader();
    JDBCURI = new MsSqlURIBuilder().createJdbcUri(HOST, DATABASE);
    schemaReader.setSource(new NoStreamInputSupplier(JDBCURI));
    schemaReader.setParameter(JDBCSchemaReader.PARAM_USER, Value.of(USER_NAME));
    schemaReader.setParameter(JDBCSchemaReader.PARAM_PASSWORD, Value.of(PASSWORD));
    // This is set for setting inclusion rule for reading schema
    schemaReader.setParameter(JDBCSchemaReader.SCHEMAS, Value.of(SCHEMA));
    IOReport report = schemaReader.execute(new LogProgressIndicator());
    assertTrue(report.isSuccess());
    assertTrue(report.getErrors().isEmpty());
    Schema schema = schemaReader.getSchema();
    assertNotNull(schema);
    return schema;
}
Also used : MsSqlURIBuilder(eu.esdihumboldt.hale.io.jdbc.mssql.MsSqlURIBuilder) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator) JDBCSchemaReader(eu.esdihumboldt.hale.io.jdbc.JDBCSchemaReader) NoStreamInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier)

Aggregations

IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)7 NoStreamInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier)7 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)4 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)4 MsSqlURIBuilder (eu.esdihumboldt.hale.io.jdbc.mssql.MsSqlURIBuilder)4 JDBCInstanceReader (eu.esdihumboldt.hale.io.jdbc.JDBCInstanceReader)3 JDBCSchemaReader (eu.esdihumboldt.hale.io.jdbc.JDBCSchemaReader)3 DefaultSchemaSpace (eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace)1 SQLSchemaReader (eu.esdihumboldt.hale.io.jdbc.SQLSchemaReader)1