Search in sources :

Example 1 with JDBCInstanceWriter

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

the class AbstractDBTest method writeInstances.

/**
 * Write instances to the database.
 *
 * @param instances the collection of instances
 * @param schema the target schema
 * @throws Exception if writing the instances fails
 */
protected void writeInstances(InstanceCollection instances, Schema schema) throws Exception {
    JDBCInstanceWriter writer = new JDBCInstanceWriter();
    writer.setTarget(new NoStreamOutputSupplier(jdbcUri));
    writer.setParameter(JDBCInstanceWriter.PARAM_USER, Value.of(dbi.getUser()));
    writer.setParameter(JDBCInstanceWriter.PARAM_PASSWORD, Value.of(dbi.getPassword()));
    writer.setInstances(instances);
    DefaultSchemaSpace targetSchema = new DefaultSchemaSpace();
    targetSchema.addSchema(schema);
    writer.setTargetSchema(targetSchema);
    IOReport report = writer.execute(null);
    assertTrue(report.isSuccess());
    assertTrue(report.getErrors().isEmpty());
}
Also used : DefaultSchemaSpace(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) NoStreamOutputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.NoStreamOutputSupplier) JDBCInstanceWriter(eu.esdihumboldt.hale.io.jdbc.JDBCInstanceWriter)

Aggregations

IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)1 NoStreamOutputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.NoStreamOutputSupplier)1 DefaultSchemaSpace (eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace)1 JDBCInstanceWriter (eu.esdihumboldt.hale.io.jdbc.JDBCInstanceWriter)1