Search in sources :

Example 1 with PutBatch

use of com.palantir.atlasdb.keyvalue.jdbc.impl.PutBatch in project atlasdb by palantir.

the class JdbcKeyValueService method putBatch.

private void putBatch(DSLContext ctx, TableReference tableRef, PutBatch batch, boolean allowReinserts) {
    InsertValuesStep4<Record, byte[], byte[], Long, byte[]> query = ctx.insertInto(table(tableName(tableRef)), field(ROW_NAME, byte[].class), field(COL_NAME, byte[].class), field(TIMESTAMP, Long.class), field(VALUE, byte[].class));
    query = batch.addValuesForInsert(query);
    try {
        query.execute();
    } catch (DataAccessException e) {
        if (allowReinserts) {
            Result<? extends Record> records = ctx.select(A_ROW_NAME, A_COL_NAME, A_TIMESTAMP, A_VALUE).from(atlasTable(tableRef).as(ATLAS_TABLE)).where(row(A_ROW_NAME, A_COL_NAME, A_TIMESTAMP).in(batch.getRowsForSelect())).fetch();
            if (records.isEmpty()) {
                throw e;
            }
            PutBatch nextBatch = batch.getNextBatch(records);
            if (nextBatch != null) {
                putBatch(ctx, tableRef, nextBatch, allowReinserts);
                return;
            }
        }
        throw new KeyAlreadyExistsException("Conflict on table " + tableRef, e);
    }
}
Also used : PutBatch(com.palantir.atlasdb.keyvalue.jdbc.impl.PutBatch) MultiTimestampPutBatch(com.palantir.atlasdb.keyvalue.jdbc.impl.MultiTimestampPutBatch) SingleTimestampPutBatch(com.palantir.atlasdb.keyvalue.jdbc.impl.SingleTimestampPutBatch) Record(org.jooq.Record) DataAccessException(org.jooq.exception.DataAccessException) KeyAlreadyExistsException(com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException) Result(org.jooq.Result) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult)

Aggregations

KeyAlreadyExistsException (com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException)1 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)1 MultiTimestampPutBatch (com.palantir.atlasdb.keyvalue.jdbc.impl.MultiTimestampPutBatch)1 PutBatch (com.palantir.atlasdb.keyvalue.jdbc.impl.PutBatch)1 SingleTimestampPutBatch (com.palantir.atlasdb.keyvalue.jdbc.impl.SingleTimestampPutBatch)1 Record (org.jooq.Record)1 Result (org.jooq.Result)1 DataAccessException (org.jooq.exception.DataAccessException)1