Search in sources :

Example 6 with JdbcEntryData

use of org.apache.gobblin.converter.jdbc.JdbcEntryData in project incubator-gobblin by apache.

the class TeradataBufferedInserter method insertBatch.

@Override
protected boolean insertBatch(PreparedStatement pstmt) throws SQLException {
    for (JdbcEntryData pendingEntry : TeradataBufferedInserter.this.pendingInserts) {
        int i = 1;
        for (JdbcEntryDatum datum : pendingEntry) {
            Object value = datum.getVal();
            if (value != null) {
                pstmt.setObject(i, value);
            } else {
                // Column type is needed for null value insertion
                pstmt.setNull(i, columnPosSqlTypes.get(i));
            }
            i++;
        }
        pstmt.addBatch();
        pstmt.clearParameters();
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Executing SQL " + pstmt);
    }
    int[] execStatus = pstmt.executeBatch();
    // Check status explicitly if driver continues batch insertion upon failure
    for (int status : execStatus) {
        if (status == Statement.EXECUTE_FAILED) {
            throw new BatchUpdateException("Batch insert failed.", execStatus);
        }
    }
    return true;
}
Also used : JdbcEntryDatum(org.apache.gobblin.converter.jdbc.JdbcEntryDatum) JdbcEntryData(org.apache.gobblin.converter.jdbc.JdbcEntryData) BatchUpdateException(java.sql.BatchUpdateException)

Aggregations

JdbcEntryData (org.apache.gobblin.converter.jdbc.JdbcEntryData)6 PreparedStatement (java.sql.PreparedStatement)3 State (org.apache.gobblin.configuration.State)3 JdbcEntryDatum (org.apache.gobblin.converter.jdbc.JdbcEntryDatum)3 JdbcBufferedInserter (org.apache.gobblin.writer.commands.JdbcBufferedInserter)2 MockParameterMetaData (com.mockrunner.mock.jdbc.MockParameterMetaData)1 BatchUpdateException (java.sql.BatchUpdateException)1 ArrayList (java.util.ArrayList)1 MySqlBufferedInserter (org.apache.gobblin.writer.commands.MySqlBufferedInserter)1