/** * Construct a new {@link HandlerProxy} * * @return {@link HandlerProxy} */ public HandlerProxy createHandlerProxy() { return new HandlerProxy(storeFactory); } }
/** * 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); }
/** * 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(); }
/** * 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; }
@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 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(expected = NullPointerException.class) public void testCreateTableInvalidTableSchema() { proxy.createTable(TEST_TABLE_NAME, null, 0); }
@Test(expected = NullPointerException.class) public void testAddIndexInvalidIndexSchema() { proxy.addIndex(TEST_INDEX, null); }
@Test(expected = NullPointerException.class) public void testDropIndexInvalidIndexName() { proxy.dropIndex(null); }
@Test(expected = IllegalArgumentException.class) public void testDropTableEmptyTableName() { proxy.dropTable(""); }
@Test(expected = IllegalArgumentException.class) public void testOpenTableEmptyTableName() { proxy.openTable(""); }
public void startIndexScan(byte[] indexKeys) { checkTableOpen(); if (currentScanner != null) { endScan();
@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 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(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(); }
@Test(expected = IllegalArgumentException.class) public void testDropIndexEmptyIndexName() { proxy.dropIndex(""); }
@Test(expected = NullPointerException.class) public void testDropTableInvalidTableName() { proxy.dropTable(null); }
@Test(expected = NullPointerException.class) public void testOpenTableInvalidTableName() { proxy.openTable(null); }
public void incrementRowCount(long amount) { checkTableOpen(); store.incrementRowCount(tableName, amount); }