@Test public void testParsePK() { TableMeta tableMeta = Mockito.mock(TableMeta.class); Mockito.when(tableMeta.getPkName()).thenReturn("id"); Mockito.when(tableMeta.getTableName()).thenReturn("table_name"); TableRecords beforeImage = new TableRecords(); beforeImage.setTableName("table_name"); beforeImage.setTableMeta(tableMeta); List<Row> beforeRows = new ArrayList<>(); Row row0 = new Row(); Field field01 = addField(row0, "id", 1, "12345"); Field field02 = addField(row0, "age", 1, "2"); beforeRows.add(row0); Row row1 = new Row(); Field field11 = addField(row1, "id", 1, "12346"); Field field12 = addField(row1, "age", 1, "2"); beforeRows.add(row1); beforeImage.setRows(beforeRows); SQLUndoLog sqlUndoLog = new SQLUndoLog(); sqlUndoLog.setSqlType(SQLType.UPDATE); sqlUndoLog.setTableMeta(tableMeta); sqlUndoLog.setTableName("table_name"); sqlUndoLog.setBeforeImage(beforeImage); sqlUndoLog.setAfterImage(null); TestUndoExecutor executor = new TestUndoExecutor(sqlUndoLog, true); Object[] pkValues = executor.parsePkValues(beforeImage); Assertions.assertEquals(2, pkValues.length); }
protected Object[] parsePkValues(TableRecords records) { String pkName = records.getTableMeta().getPkName(); List<Row> undoRows = records.getRows(); Object[] pkValues = new Object[undoRows.size()]; for (int i = 0; i < undoRows.size(); i++) { List<Field> fields = undoRows.get(i).getFields(); if (fields != null) { for (Field field : fields) { if (StringUtils.equalsIgnoreCase(pkName, field.getName())) { pkValues[i] = field.getValue(); } } } } return pkValues; }
AbstractUndoExecutor { protected Object[] parsePkValues(TableRecords records) { String pkName = records.getTableMeta().getPkName(); List<Row> undoRows = records.getRows(); Object[] pkValues = new Object[undoRows.size()]; for (int i = 0; i < undoRows.size(); i++) { List<Field> fields = undoRows.get(i).getFields(); if (fields != null) { for (Field field : fields) { if (StringUtils.equalsIgnoreCase(pkName, field.getName())) { pkValues[i] = field.getValue(); } } } } return pkValues; } }
AbstractUndoExecutor { protected Object[] parsePkValues(TableRecords records) { String pkName = records.getTableMeta().getPkName(); List<Row> undoRows = records.getRows(); Object[] pkValues = new Object[undoRows.size()]; for (int i = 0; i < undoRows.size(); i++) { List<Field> fields = undoRows.get(i).getFields(); if (fields != null) { for (Field field : fields) { if (StringUtils.equalsIgnoreCase(pkName, field.getName())) { pkValues[i] = field.getValue(); } } } } return pkValues; } AbstractUndoExecutor(SQLUndoLog sqlUndoLog); }
AbstractUndoExecutor { protected Object[] parsePkValues(TableRecords records) { String pkName = records.getTableMeta().getPkName(); List<Row> undoRows = records.getRows(); Object[] pkValues = new Object[undoRows.size()]; for (int i = 0; i < undoRows.size(); i++) { List<Field> fields = undoRows.get(i).getFields(); if (fields != null) { for (Field field : fields) { if (StringUtils.equalsIgnoreCase(pkName, field.getName())) { pkValues[i] = field.getValue(); } } } } return pkValues; } AbstractUndoExecutor(SQLUndoLog sqlUndoLog); SQLUndoLog getSqlUndoLog(); void executeOn(Connection conn); }
AbstractUndoExecutor { protected Object[] parsePkValues(TableRecords records) { String pkName = records.getTableMeta().getPkName(); List<Row> undoRows = records.getRows(); Object[] pkValues = new Object[undoRows.size()]; for (int i = 0; i < undoRows.size(); i++) { List<Field> fields = undoRows.get(i).getFields(); if (fields != null) { for (Field field : fields) { if (StringUtils.equalsIgnoreCase(pkName, field.getName())) { pkValues[i] = field.getValue(); } } } } return pkValues; } AbstractUndoExecutor(SQLUndoLog sqlUndoLog); SQLUndoLog getSqlUndoLog(); void executeOn(Connection conn); static final boolean IS_UNDO_DATA_VALIDATION_ENABLE; }