public void openTable(String tableName) { Verify.isNotNullOrEmpty(tableName); this.tableName = tableName; store = storeFactory.createStore(tableName); table = store.openTable(this.tableName); }
/** * Returns a store implementation for a given table name. Returns a store type * for the adapter matching the database name, or if that does not exist, * the default adapter. * @param tableName * @return The store for the specified table name */ public Store createStore(String tableName) { try { return storeProviders.get(AdapterType.valueOf(databaseName(tableName).toUpperCase())).get(); } catch (IllegalArgumentException e) { return storeProviders.get(configuration.getDefaultAdapter()).get(); } }
private StoreFactory createFactory() { HoneycombConfiguration configurationHolder = new HoneycombConfiguration(adapterConfigs, "hbase"); Map<AdapterType, Provider<Store>> map = Maps.newHashMap(); map.put(AdapterType.HBASE, storeProvider); when(storeProvider.get()).thenReturn(store); return new StoreFactory(map, configurationHolder); } }
/** * Updates the existing SQL table name representation in the underlying * {@link Store} implementation to the specified new table name. The table * is not open when this is called. * * @param originalName The existing name of the table, not null or empty * @param newName The new table name to represent, not null or empty */ public void renameTable(final String originalName, final String newName) { Verify.isNotNullOrEmpty(originalName, "Original table name must have value."); Verify.isNotNullOrEmpty(newName, "New table name must have value."); checkArgument(!originalName.equals(newName), "New table name must be different than original."); Store store = storeFactory.createStore(originalName); store.renameTable(originalName, newName); tableName = newName; }
@Test public void testCreateTable() { when(storeFactory.createStore(anyString())).thenReturn(storageMock); final long incrementValue = 42; proxy.createTable(TEST_TABLE_NAME, TABLE_SCHEMA.serialize(), incrementValue); verify(storeFactory, times(1)).createStore(eq(TEST_TABLE_NAME)); verify(storageMock, times(1)).createTable(eq(TEST_TABLE_NAME), eq(TABLE_SCHEMA)); verify(storageMock, times(1)).incrementAutoInc(eq(TEST_TABLE_NAME), eq(incrementValue)); }
@Test public void testOpenTable() { when(storeFactory.createStore(anyString())).thenReturn(storageMock); when(storageMock.openTable(anyString())).thenReturn(tableMock); proxy.openTable(TEST_TABLE_NAME); verify(storeFactory, times(1)).createStore(eq(TEST_TABLE_NAME)); verify(storageMock, times(1)).openTable(eq(TEST_TABLE_NAME)); }
@Test public void testDropTable() { when(storeFactory.createStore(anyString())).thenReturn(storageMock); when(storageMock.openTable(anyString())).thenReturn(tableMock); proxy.dropTable(TEST_TABLE_NAME); verify(storeFactory, times(1)).createStore(eq(TEST_TABLE_NAME)); verify(storageMock, times(1)).openTable(eq(TEST_TABLE_NAME)); verify(tableMock, times(1)).deleteAllRows(); verify(storageMock, times(1)).deleteTable(eq(TEST_TABLE_NAME)); }
@Test(expected = IllegalStateException.class) public void testDropIndexTableNotOpen() { when(storeFactory.createStore(anyString())).thenReturn(storageMock); when(storageMock.openTable(anyString())).thenReturn(tableMock); proxy.dropIndex(TEST_INDEX); verify(storageMock, never()).getSchema(eq(TEST_TABLE_NAME)); verify(tableMock, never()).deleteTableIndex(eq(INDEX_SCHEMA)); verify(storageMock, never()).dropIndex(eq(TEST_TABLE_NAME), eq(TEST_INDEX)); } }
@Test public void testRenameTable() throws Exception { when(storeFactory.createStore(TEST_TABLE_NAME)).thenReturn(storageMock); final String renamedTableName = "bar/baz"; proxy.renameTable(TEST_TABLE_NAME, renamedTableName); verify(storageMock, times(1)).renameTable(eq(TEST_TABLE_NAME), eq(renamedTableName)); }
@Test public void testDropIndex() { when(storeFactory.createStore(anyString())).thenReturn(storageMock); when(storageMock.openTable(anyString())).thenReturn(tableMock); proxy.openTable(TEST_TABLE_NAME); verify(storeFactory, times(1)).createStore(eq(TEST_TABLE_NAME)); verify(storageMock, times(1)).openTable(eq(TEST_TABLE_NAME)); when(storageMock.getSchema(TEST_TABLE_NAME)).thenReturn(TABLE_SCHEMA); proxy.dropIndex(TEST_INDEX); verify(storageMock, times(1)).getSchema(eq(TEST_TABLE_NAME)); verify(tableMock, times(1)).deleteTableIndex(eq(INDEX_SCHEMA)); verify(storageMock, times(1)).dropIndex(eq(TEST_TABLE_NAME), eq(TEST_INDEX)); }
@Test public void testAddIndex() { when(storeFactory.createStore(anyString())).thenReturn(storageMock); when(storageMock.openTable(anyString())).thenReturn(tableMock); proxy.openTable(TEST_TABLE_NAME); verify(storeFactory, times(1)).createStore(eq(TEST_TABLE_NAME)); verify(storageMock, times(1)).openTable(eq(TEST_TABLE_NAME)); proxy.addIndex(TEST_INDEX, INDEX_SCHEMA.serialize()); verify(storageMock, times(1)).addIndex(eq(TEST_TABLE_NAME), eq(INDEX_SCHEMA)); verify(tableMock, times(1)).insertTableIndex(eq(INDEX_SCHEMA)); verify(tableMock, times(1)).flush(); }
@Test(expected = IllegalArgumentException.class) public void testAddUniqueIndex() { when(storeFactory.createStore(anyString())).thenReturn(storageMock); when(storageMock.openTable(anyString())).thenReturn(tableMock); proxy.openTable(TEST_TABLE_NAME); verify(storeFactory, times(1)).createStore(eq(TEST_TABLE_NAME)); verify(storageMock, times(1)).openTable(eq(TEST_TABLE_NAME)); final IndexSchema uniqueIndex = new IndexSchema("uniqueIdx", ImmutableList.<String>of(TEST_COLUMN), true); proxy.addIndex(TEST_INDEX, uniqueIndex.serialize()); verify(storageMock, never()).addIndex(eq(TEST_TABLE_NAME), eq(INDEX_SCHEMA)); verify(tableMock, never()).insertTableIndex(eq(INDEX_SCHEMA)); verify(tableMock, never()).flush(); }
@Test(expected = IllegalStateException.class) public void testAddIndexTableNotOpen() { when(storeFactory.createStore(anyString())).thenReturn(storageMock); when(storageMock.openTable(anyString())).thenReturn(tableMock); proxy.addIndex(TEST_INDEX, INDEX_SCHEMA.serialize()); verify(storageMock, never()).addIndex(eq(TEST_TABLE_NAME), eq(INDEX_SCHEMA)); verify(tableMock, never()).insertTableIndex(eq(INDEX_SCHEMA)); verify(tableMock, never()).flush(); }
/** * 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); }
/** * 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); }
@Test public void testDefaultTablespaceIsUsed() { StoreFactory factory = createFactory(); Store returnedStore = factory.createStore(tableName); assertEquals(returnedStore, this.store); }