use of com.nearinfinity.honeycomb.mysql.schema.TableSchema in project honeycomb by altamiracorp.
the class VerifyTest method testIsValidTableSchemaValidSchema.
@Test
public void testIsValidTableSchemaValidSchema() {
final List<ColumnSchema> columns = ImmutableList.<ColumnSchema>of(ColumnSchema.builder(COLUMN_B, ColumnType.LONG).setIsAutoIncrement(true).build());
Verify.isValidTableSchema(new TableSchema(columns, ImmutableList.<IndexSchema>of()));
}
use of com.nearinfinity.honeycomb.mysql.schema.TableSchema in project honeycomb by altamiracorp.
the class VerifyTest method testHasAutoIncrementColumn.
@Test
public void testHasAutoIncrementColumn() {
final List<ColumnSchema> columns = ImmutableList.<ColumnSchema>of(ColumnSchema.builder(COLUMN_B, ColumnType.LONG).setIsAutoIncrement(true).build());
final TableSchema tableSchema = new TableSchema(columns, ImmutableList.<IndexSchema>of());
Verify.hasAutoIncrementColumn(tableSchema);
}
use of com.nearinfinity.honeycomb.mysql.schema.TableSchema in project honeycomb by altamiracorp.
the class HandlerProxy method createTable.
/**
* Create a table with the given specifications. The table is not open when
* this is called.
*
* @param tableName Name of the table
* @param serializedTableSchema Serialized {@link AvroTableSchema} avro object
* @param autoInc Initial auto increment value
*/
public void createTable(String tableName, byte[] serializedTableSchema, long autoInc) {
Verify.isNotNullOrEmpty(tableName);
checkNotNull(serializedTableSchema, "Schema cannot be null");
store = storeFactory.createStore(tableName);
TableSchema tableSchema = TableSchema.deserialize(serializedTableSchema);
Verify.isValidTableSchema(tableSchema);
store.createTable(tableName, tableSchema);
store.incrementAutoInc(tableName, autoInc);
}
use of com.nearinfinity.honeycomb.mysql.schema.TableSchema in project honeycomb by altamiracorp.
the class HandlerProxy method updateRow.
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();
}
}
use of com.nearinfinity.honeycomb.mysql.schema.TableSchema in project honeycomb by altamiracorp.
the class HandlerProxy method insertRow.
/**
* 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();
}
}
Aggregations