/** * Set the auto increment value of the table to the max of value and the * current value. * * @param value */ public void setAutoIncrement(long value) { checkTableOpen(); store.setAutoInc(tableName, value); }
public void incrementRowCount(long amount) { checkTableOpen(); store.incrementRowCount(tableName, amount); }
public void truncateRowCount() { checkTableOpen(); store.truncateRowCount(tableName); }
public void truncateAutoIncrement() { checkTableOpen(); store.truncateAutoInc(tableName); }
public long getRowCount() { checkTableOpen(); return store.getRowCount(tableName); }
public void deleteRow(byte[] rowBytes) { checkTableOpen(); Row row = Row.deserialize(rowBytes); table.deleteRow(row); }
public long getAutoIncrement() { checkTableOpen(); if (!Verify.hasAutoIncrementColumn(store.getSchema(tableName))) { throw new IllegalArgumentException(format("Table %s does not" + " contain an auto increment column.", tableName)); } return store.getAutoInc(tableName); }
/** * Delete all rows in the table. */ public void deleteAllRows() { checkTableOpen(); store.truncateRowCount(tableName); table.deleteAllRows(); }
/** * Delete all rows in the table, and reset the auto increment value. */ public void truncateTable() { checkTableOpen(); deleteAllRows(); store.truncateAutoInc(tableName); }
public void startTableScan() { checkTableOpen(); if (currentScanner != null) { endScan(); } currentScanner = table.tableScan(); }
public byte[] getRow(byte[] uuid) { checkTableOpen(); checkNotNull(uuid, "Get row cannot have a null UUID."); return table.getRow(Util.bytesToUUID(uuid)).serialize(); }
/** * Increment the auto increment value of the table by amount, and return the * next auto increment value. The next value will be the current value, * not the incremented value (equivalently, the incremented value - amount). * * @param amount * @return The specified amount subtracted from the incremented value */ public long incrementAutoIncrement(long amount) { checkTableOpen(); if (!Verify.hasAutoIncrementColumn(store.getSchema(tableName))) { throw new IllegalArgumentException(format("Table %s does not contain an auto increment column.", tableName)); } long current = store.incrementAutoInc(getTableName(), amount); long next = current - amount; return next; }
/** * Add the provided index information to the table. The table must be open * before this operation can be performed. * * @param indexName The name of the index to add, not null or empty * @param serializedSchema The byte representation of the {@link IndexSchema} for this index, not null */ public void addIndex(String indexName, byte[] serializedSchema) { Verify.isNotNullOrEmpty(indexName, "The index name is invalid"); checkNotNull(serializedSchema, "Schema cannot be null"); checkTableOpen(); IndexSchema schema = IndexSchema.deserialize(serializedSchema, indexName); checkArgument(!schema.getIsUnique(), "Honeycomb does not support adding unique indices without a table rebuild."); store.addIndex(tableName, schema); table.insertTableIndex(schema); table.flush(); }
/** * Drop the index specified by the index name from the table. The table must be open * before this operation can be performed. * * @param indexName The name of the index to add, not null or empty */ public void dropIndex(String indexName) { Verify.isNotNullOrEmpty(indexName, "The index name is invalid"); checkTableOpen(); TableSchema tableSchema = store.getSchema(tableName); IndexSchema indexSchema = tableSchema.getIndexSchema(indexName); table.deleteTableIndex(indexSchema); store.dropIndex(tableName, indexName); }
/** * 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(); } }
public void startIndexScan(byte[] indexKeys) { checkTableOpen(); if (currentScanner != null) { endScan();
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(); } }