@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(); } }
/** * Set the values of the index row based on a sql row. If an index column is * missing from the sql row it is replaced with an explicit null. (This * method is intended for insert) * * @param row SQL row * @param indexName Columns in the index * @param tableSchema Table schema * @return The current builder instance */ public IndexRowKeyBuilder withRow(Row row, String indexName, TableSchema tableSchema) { checkNotNull(row, "row must not be null."); Map<String, ByteBuffer> recordCopy = Maps.newHashMap(row.getRecords()); for (String column : tableSchema.getIndexSchema(indexName).getColumns()) { if (!recordCopy.containsKey(column)) { recordCopy.put(column, null); } } this.fields = recordCopy; this.indexName = indexName; this.tableSchema = tableSchema; return this; }
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(); } }
/** * Insert row into table. * * @param rowBytes Serialized row to be written */ public void insertRow(byte[] rowBytes) { checkTableOpen(); checkNotNull(rowBytes); TableSchema schema = store.getSchema(tableName); Row row = Row.deserialize(rowBytes); row.setRandomUUID(); String auto_inc_col = schema.getAutoIncrementColumn(); if (auto_inc_col != null) { ByteBuffer bb = row.getRecords().get(auto_inc_col); if (bb != null) { long auto_inc = bb.getLong(); long next_auto_inc = auto_inc + 1; if (auto_inc > next_auto_inc) { // The autoincrement will wrap around. MySQL says don't wrap. next_auto_inc = auto_inc; } bb.rewind(); store.setAutoInc(tableName, next_auto_inc); } } table.insertRow(row); if (schema.hasUniqueIndices()) { table.flush(); } }
IndexSchema indexSchema = schema.getIndexSchema(indexName); QueryKey key = new QueryKey(indexName, QueryType.EXACT_KEY, row.getRecords()); Scanner scanner = t.indexScanExact(key); boolean isNullInRecord = !row.getRecords().containsKey(column); if (isNullInRecord) { return false;
@Override public QueryKey next() { return new QueryKey(indices.next(), queryTypes.next(), rows.next().getRecords()); } }