Search in sources :

Example 16 with TableSchema

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()));
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) Test(org.junit.Test)

Example 17 with TableSchema

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);
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) Test(org.junit.Test)

Example 18 with 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);
}
Also used : AvroTableSchema(com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema)

Example 19 with TableSchema

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();
    }
}
Also used : AvroTableSchema(com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema)

Example 20 with TableSchema

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();
    }
}
Also used : AvroTableSchema(com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TableSchema (com.nearinfinity.honeycomb.mysql.schema.TableSchema)34 Test (org.junit.Test)17 IndexSchema (com.nearinfinity.honeycomb.mysql.schema.IndexSchema)12 ColumnSchema (com.nearinfinity.honeycomb.mysql.schema.ColumnSchema)9 IndexRowKey (com.nearinfinity.honeycomb.hbase.rowkey.IndexRowKey)5 AvroTableSchema (com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema)5 Predicate (com.google.common.base.Predicate)1 ImmutableList (com.google.common.collect.ImmutableList)1 UnsignedBytes (com.google.common.primitives.UnsignedBytes)1 MockHTable (com.nearinfinity.honeycomb.MockHTable)1 Scanner (com.nearinfinity.honeycomb.Scanner)1 Table (com.nearinfinity.honeycomb.Table)1 IndexRowKeyBuilder (com.nearinfinity.honeycomb.hbase.rowkey.IndexRowKeyBuilder)1 RowKey (com.nearinfinity.honeycomb.hbase.rowkey.RowKey)1 HandlerProxy (com.nearinfinity.honeycomb.mysql.HandlerProxy)1 Row (com.nearinfinity.honeycomb.mysql.Row)1 HoneycombIntegrationTest (integrationtests.HoneycombIntegrationTest)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1