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);
}
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);
}
}
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();
}
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;
}
Aggregations