Search in sources :

Example 1 with JdbcEntryDatum

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

the class JdbcBufferedInserterTestBase method createJdbcEntry.

private JdbcEntryData createJdbcEntry(Collection<String> colNames, int colSize) {
    List<JdbcEntryDatum> datumList = new ArrayList<>();
    for (String colName : colNames) {
        JdbcEntryDatum datum = new JdbcEntryDatum(colName, RandomStringUtils.randomAlphabetic(colSize));
        datumList.add(datum);
    }
    return new JdbcEntryData(datumList);
}
Also used : ArrayList(java.util.ArrayList) JdbcEntryDatum(org.apache.gobblin.converter.jdbc.JdbcEntryDatum) JdbcEntryData(org.apache.gobblin.converter.jdbc.JdbcEntryData)

Example 2 with JdbcEntryDatum

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

the class GenericJdbcBufferedInserter method insert.

@Override
public void insert(String databaseName, String table, JdbcEntryData jdbcEntryData) throws SQLException {
    if (this.insertPstmtForFixedBatch == null) {
        for (JdbcEntryDatum datum : jdbcEntryData) {
            this.columnNames.add(datum.getColumnName());
        }
        initializeBatch(databaseName, table);
    }
    int i = 0;
    for (JdbcEntryDatum datum : jdbcEntryData) {
        this.insertPstmtForFixedBatch.setObject(++i, datum.getVal());
    }
    this.insertPstmtForFixedBatch.addBatch();
    this.currBatchSize++;
    if (this.currBatchSize >= this.batchSize) {
        executeBatchInsert(this.insertPstmtForFixedBatch);
    }
}
Also used : JdbcEntryDatum(org.apache.gobblin.converter.jdbc.JdbcEntryDatum)

Example 3 with JdbcEntryDatum

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

the class MySqlBufferedInserter method insertBatch.

@Override
protected boolean insertBatch(PreparedStatement pstmt) throws SQLException {
    int i = 0;
    pstmt.clearParameters();
    for (JdbcEntryData pendingEntry : MySqlBufferedInserter.this.pendingInserts) {
        for (JdbcEntryDatum datum : pendingEntry) {
            pstmt.setObject(++i, datum.getVal());
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Executing SQL " + pstmt);
    }
    return pstmt.execute();
}
Also used : JdbcEntryDatum(org.apache.gobblin.converter.jdbc.JdbcEntryDatum) JdbcEntryData(org.apache.gobblin.converter.jdbc.JdbcEntryData)

Example 4 with JdbcEntryDatum

use of org.apache.gobblin.converter.jdbc.JdbcEntryDatum 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

JdbcEntryDatum (org.apache.gobblin.converter.jdbc.JdbcEntryDatum)4 JdbcEntryData (org.apache.gobblin.converter.jdbc.JdbcEntryData)3 BatchUpdateException (java.sql.BatchUpdateException)1 ArrayList (java.util.ArrayList)1