HistoryTableEngine extends AbstractTableEngine { @Override public void execute(final InsertOperation operation) { execute(operation, new CommitIndexRecordCallback(operation.getCommit(), "INSERT")); } HistoryTableEngine(DataSource dataSource, TypeMap typeMap);  HistoryTableEngine(DataSource dataSource, TypeMap typeMap, NameTranslator<Index<?>> indexNameTranslator);  HistoryTableEngine(DataSource dataSource, TypeMap typeMap, NameTranslator<Index<?>> indexNameTranslator,
            NameTranslator<IndexField<?>> indexFieldNameTranslator); protected  HistoryTableEngine(DataSource dataSource, TypeMap typeMap, NameTranslator<Index<?>> indexNameTranslator,
            NameTranslator<IndexField<?>> indexFieldNameTranslator, HistoryTableFactory tableFactory); @Override void execute(final InsertOperation operation); @Override void execute(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); try (ResultSet rs = connection.createStatement().executeQuery("SELECT * FROM HISTORY_TABLE")) { assertTrue(rs.next()); assertEquals("A", rs.getString("TESTID")); assertEquals(42, rs.getInt("TESTINTEGER")); assertEquals(1L, rs.getLong("REV_ID")); assertEquals("INSERT", rs.getString("REV_OPERATION")); assertEquals(new Date(42), rs.getTimestamp("REV_TIMESTAMP")); assertTrue(rs.next()); assertEquals("B", rs.getString("TESTID")); assertEquals(-42, rs.getInt("TESTINTEGER")); assertEquals(2L, rs.getLong("REV_ID")); assertEquals("INSERT", rs.getString("REV_OPERATION")); assertEquals(new Date(42), rs.getTimestamp("REV_TIMESTAMP")); 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); List<OpenEngSBModel> list = new ArrayList<>(); list.add((OpenEngSBModel) testModelA); list.add((OpenEngSBModel) testModelB); engine.execute(new InsertOperation(commit, testIndex, list)); 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(testModelB)))); try (ResultSet rs = connection.createStatement().executeQuery("SELECT * FROM HISTORY_TABLE")) { assertTrue(rs.next()); assertEquals("A", rs.getString("TESTID")); assertEquals(42, rs.getInt("TESTINTEGER")); assertEquals(1L, rs.getLong("REV_ID")); assertEquals("INSERT", rs.getString("REV_OPERATION")); assertEquals(new Date(42), rs.getTimestamp("REV_TIMESTAMP")); assertTrue(rs.next()); assertEquals("B", rs.getString("TESTID")); assertEquals(-42, rs.getInt("TESTINTEGER")); assertEquals(2L, rs.getLong("REV_ID")); assertEquals("INSERT", rs.getString("REV_OPERATION")); assertEquals(new Date(42), rs.getTimestamp("REV_TIMESTAMP")); assertTrue(rs.next()); assertEquals("B", rs.getString("TESTID")); assertEquals(43, rs.getInt("TESTINTEGER")); assertEquals(3L, rs.getLong("REV_ID")); assertEquals("UPDATE", rs.getString("REV_OPERATION")); assertEquals(new Date(84), rs.getTimestamp("REV_TIMESTAMP")); 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 HISTORY_TABLE")) { assertTrue(rs.next()); assertEquals("A", rs.getString("TESTID")); assertEquals(42, rs.getInt("TESTINTEGER")); assertEquals(1L, rs.getLong("REV_ID")); assertEquals("INSERT", rs.getString("REV_OPERATION")); assertEquals(new Date(42), rs.getTimestamp("REV_TIMESTAMP")); assertTrue(rs.next()); assertEquals("B", rs.getString("TESTID")); assertEquals(-42, rs.getInt("TESTINTEGER")); assertEquals(2L, rs.getLong("REV_ID")); assertEquals("INSERT", rs.getString("REV_OPERATION")); assertEquals(new Date(42), rs.getTimestamp("REV_TIMESTAMP")); assertTrue(rs.next()); assertEquals("B", rs.getString("TESTID")); assertEquals(-42, rs.getInt("TESTINTEGER")); assertEquals(3L, rs.getLong("REV_ID")); assertEquals("DELETE", rs.getString("REV_OPERATION")); assertEquals(new Date(84), rs.getTimestamp("REV_TIMESTAMP")); assertFalse(rs.next()); } }