Search in sources :

Example 1 with PalantirSqlConnection

use of com.palantir.nexus.db.sql.PalantirSqlConnection in project atlasdb by palantir.

the class UpdateExecutor method update.

public void update(Cell cell, long ts, byte[] oldValue, byte[] newValue) {
    Object[] args = new Object[] { cell.getRowName(), cell.getColumnName(), ts, newValue, cell.getRowName(), cell.getColumnName(), ts, oldValue };
    String prefixedTableName = prefixedTableNames.get(tableRef, conns);
    String sqlString = "/* UPDATE (" + prefixedTableName + ") */" + " UPDATE " + prefixedTableName + "" + " SET row_name = ?, col_name = ?, ts = ?, val = ?" + " WHERE row_name = ?" + " AND col_name = ?" + " AND ts = ?" + " AND val = ?";
    PalantirSqlConnection connection = (PalantirSqlConnection) conns.get();
    while (true) {
        int updated = connection.updateCountRowsUnregisteredQuery(sqlString, args);
        if (updated != 0) {
            return;
        }
        List<byte[]> currentValue = getCurrentValue(connection, cell, ts, prefixedTableName);
        byte[] onlyValue = Iterables.getOnlyElement(currentValue, null);
        if (!Arrays.equals(onlyValue, oldValue)) {
            throw new CheckAndSetException(cell, tableRef, oldValue, currentValue);
        }
    }
}
Also used : PalantirSqlConnection(com.palantir.nexus.db.sql.PalantirSqlConnection) CheckAndSetException(com.palantir.atlasdb.keyvalue.api.CheckAndSetException)

Aggregations

CheckAndSetException (com.palantir.atlasdb.keyvalue.api.CheckAndSetException)1 PalantirSqlConnection (com.palantir.nexus.db.sql.PalantirSqlConnection)1