HeadTableEngine extends AbstractTableEngine { @Override public void execute(final InsertOperation operation) { execute(operation, new IndexRecordCallback() { @Override public void call(IndexRecord record) { record.addValue("REV_CREATED", operation.getCommit().getTimestamp()); } }); } HeadTableEngine(DataSource dataSource, TypeMap typeMap);  HeadTableEngine(DataSource dataSource, TypeMap typeMap, NameTranslator<Index<?>> indexNameTranslator,
            NameTranslator<IndexField<?>> indexFieldNameTranslator); protected  HeadTableEngine(DataSource dataSource, TypeMap typeMap, NameTranslator<Index<?>> indexNameTranslator,
            NameTranslator<IndexField<?>> indexFieldNameTranslator, HeadTableFactory tableFactory); @Override void execute(final InsertOperation operation); @Override void execute(final UpdateOperation operation); @Override void execute(DeleteOperation operation); static final String TABLE_PREFIX; }
@Test public void execute_insert_createsRecordsCorrectly() throws Exception { engine.create(testIndex); IndexCommit commit = mock(IndexCommit.class); when(commit.getTimestamp()).thenReturn(new Date(42)); List models = new ArrayList<>(); models.add(new TestModel("A", 42)); models.add(new TestModel("B", -42)); InsertOperation operation = new InsertOperation(commit, testIndex, models); engine.execute(operation); String sql = "SELECT * FROM HEAD_TABLE"; try (ResultSet rs = connection.createStatement().executeQuery(sql)) { assertTrue(rs.next()); assertEquals("A", rs.getString("TESTID")); assertEquals(42, rs.getInt("TESTINTEGER")); assertEquals(new Date(42), rs.getTimestamp("REV_CREATED")); assertTrue(rs.next()); assertEquals("B", rs.getString("TESTID")); assertEquals(-42, rs.getInt("TESTINTEGER")); assertEquals(new Date(42), rs.getTimestamp("REV_CREATED")); assertFalse(rs.next()); } }
@Test public void execute_update_updatesRecordsCorrectly() throws Exception { engine.create(testIndex); IndexCommit commit = mock(IndexCommit.class); when(commit.getTimestamp()).thenReturn(new Date(42)); TestModel testModelA = new TestModel("A", 42); TestModel testModelB = new TestModel("B", -42); engine.execute(new InsertOperation(commit, testIndex, new ArrayList(Arrays.asList(testModelA, testModelB)))); testModelB.setTestInteger(43); IndexCommit updateCommit = mock(IndexCommit.class); when(updateCommit.getTimestamp()).thenReturn(new Date(84)); engine.execute(new UpdateOperation(updateCommit, testIndex, new ArrayList(Arrays.asList(testModelA, testModelB)))); try (ResultSet rs = connection.createStatement().executeQuery("SELECT * FROM HEAD_TABLE")) { assertTrue(rs.next()); assertEquals("A", rs.getString("TESTID")); assertEquals(42, rs.getInt("TESTINTEGER")); assertEquals(new Date(42), rs.getTimestamp("REV_CREATED")); assertTrue(rs.next()); assertEquals("B", rs.getString("TESTID")); assertEquals(43, rs.getInt("TESTINTEGER")); assertEquals(new Date(42), rs.getTimestamp("REV_CREATED")); assertFalse(rs.next()); } }
@Test public void execute_delete_deletesRecordsCorrectly() throws Exception { engine.create(testIndex); IndexCommit commit = mock(IndexCommit.class); when(commit.getTimestamp()).thenReturn(new Date(42)); TestModel testModelA = new TestModel("A", 42); TestModel testModelB = new TestModel("B", -42); engine.execute(new InsertOperation(commit, testIndex, new ArrayList(Arrays.asList(testModelA, testModelB)))); IndexCommit deleteCommit = mock(IndexCommit.class); when(deleteCommit.getTimestamp()).thenReturn(new Date(84)); engine.execute(new DeleteOperation(deleteCommit, testIndex, new ArrayList(Arrays.asList(testModelB)))); try (ResultSet rs = connection.createStatement().executeQuery("SELECT * FROM HEAD_TABLE")) { assertTrue(rs.next()); assertEquals("A", rs.getString("TESTID")); assertEquals(42, rs.getInt("TESTINTEGER")); assertEquals(new Date(42), rs.getTimestamp("REV_CREATED")); assertFalse(rs.next()); } }