Search in sources :

Example 1 with Table

use of com.nearinfinity.honeycomb.Table in project honeycomb by altamiracorp.

the class HandlerProxy method dropTable.

/**
     * Drop the table with the given specifications.  The table is not open when
     * this is called.
     *
     * @param tableName Name of the table to be dropped
     */
public void dropTable(String tableName) {
    Verify.isNotNullOrEmpty(tableName);
    Store store = storeFactory.createStore(tableName);
    Table table = store.openTable(tableName);
    table.deleteAllRows();
    Util.closeQuietly(table);
    store.deleteTable(tableName);
}
Also used : Table(com.nearinfinity.honeycomb.Table) Store(com.nearinfinity.honeycomb.Store)

Example 2 with Table

use of com.nearinfinity.honeycomb.Table in project honeycomb by altamiracorp.

the class HandlerProxy method indexContainsDuplicate.

/**
     * Check whether the index contains a row with the same field values and a
     * distinct UUID.
     *
     * @param indexName
     * @param serializedRow
     * @return True If a duplicate is found, False otherwise
     */
public boolean indexContainsDuplicate(String indexName, byte[] serializedRow) {
    // This method must get its own table because it may be called during
    // a full table scan.
    Verify.isNotNullOrEmpty(indexName);
    checkNotNull(serializedRow);
    Row row = Row.deserialize(serializedRow);
    Table t = store.openTable(tableName);
    TableSchema schema = store.getSchema(tableName);
    IndexSchema indexSchema = schema.getIndexSchema(indexName);
    QueryKey key = new QueryKey(indexName, QueryType.EXACT_KEY, row.getRecords());
    Scanner scanner = t.indexScanExact(key);
    try {
        while (scanner.hasNext()) {
            Row next = Row.deserialize(scanner.next());
            if (!next.getUUID().equals(row.getUUID())) {
                // Special case for inserting nulls
                for (String column : indexSchema.getColumns()) {
                    boolean isNullInRecord = !row.getRecords().containsKey(column);
                    if (isNullInRecord) {
                        return false;
                    }
                }
                return true;
            }
        }
        return false;
    } finally {
        Util.closeQuietly(scanner);
        Util.closeQuietly(t);
    }
}
Also used : Scanner(com.nearinfinity.honeycomb.Scanner) Table(com.nearinfinity.honeycomb.Table) AvroTableSchema(com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema)

Aggregations

Table (com.nearinfinity.honeycomb.Table)2 Scanner (com.nearinfinity.honeycomb.Scanner)1 Store (com.nearinfinity.honeycomb.Store)1 AvroTableSchema (com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema)1 IndexSchema (com.nearinfinity.honeycomb.mysql.schema.IndexSchema)1 TableSchema (com.nearinfinity.honeycomb.mysql.schema.TableSchema)1