@Override public String toString() { final ToStringHelper toString = Objects.toStringHelper(this.getClass()); toString.add("Version", row.getVersion()) .add("UUID", getUUID()); for (final Map.Entry<String, ByteBuffer> entry : getRecords().entrySet()) { toString.add("Record", format("%s: %s", entry.getKey(), entry.getValue())); } return toString.toString(); } }
/** * Build delete list for the data and indices belonging to the row * * @param tableId * @param row * @return The list of delete mutations */ public List<Delete> delete(long tableId, final Row row) { List<Delete> deletes = deleteIndices(tableId, row); deletes.add(new Delete(new DataRowKey(tableId, row.getUUID()).encode())); return deletes; }
/** * Build put list for a row insert with specified indices * * @param tableId * @param row * @param indices * @return The list of put mutations */ public List<Put> insert(long tableId, final Row row, final Collection<IndexSchema> indices) { checkNotNull(row); // tableId, indices checked by called methods final byte[] serializedRow = row.serialize(); final UUID uuid = row.getUUID(); final ImmutableList.Builder<Put> puts = ImmutableList.builder(); puts.add(emptyQualifierPut(new DataRowKey(tableId, uuid), serializedRow)); puts.addAll(insertIndices(tableId, row, indices)); return puts.build(); }
private void doToIndices(long tableId, final Row row, final Collection<IndexSchema> indices, final IndexAction action) { for (IndexSchema index : indices) { long indexId = store.getIndexId(tableId, index.getIndexName()); TableSchema schema = store.getSchema(tableId); IndexRowKeyBuilder builder = IndexRowKeyBuilder .newBuilder(tableId, indexId) .withUUID(row.getUUID()) .withRow(row, index.getIndexName(), schema); action.execute(builder); } }
public void updateRow(byte[] oldRowBytes, byte[] rowBytes) { checkTableOpen(); checkNotNull(rowBytes); Row updatedRow = Row.deserialize(rowBytes); TableSchema schema = store.getSchema(tableName); Row oldRow = Row.deserialize(oldRowBytes); oldRow.setUUID(updatedRow.getUUID()); ImmutableList<IndexSchema> changedIndices = Util.getChangedIndices(schema.getIndices(), oldRow.getRecords(), updatedRow.getRecords()); table.updateRow(oldRow, updatedRow, changedIndices); if (schema.hasUniqueIndices()) { table.flush(); } }