use of io.seata.rm.datasource.sql.struct.Row in project seata by seata.
the class PostgresqlUndoInsertExecutor method buildUndoSQL.
@Override
protected String buildUndoSQL() {
TableRecords afterImage = sqlUndoLog.getAfterImage();
List<Row> afterImageRows = afterImage.getRows();
if (CollectionUtils.isEmpty(afterImageRows)) {
throw new ShouldNeverHappenException("Invalid UNDO LOG");
}
return generateDeleteSql(afterImageRows, afterImage);
}
use of io.seata.rm.datasource.sql.struct.Row in project seata by seata.
the class DataCompareUtilsTest method testRowListToMapWithMultipPk.
@Test
public void testRowListToMapWithMultipPk() {
List<String> primaryKeyList = new ArrayList<>();
primaryKeyList.add("id1");
primaryKeyList.add("id2");
List<Row> rows = new ArrayList<>();
Field field1 = new Field("id1", 1, "1");
Field field11 = new Field("id2", 1, "2");
Row row = new Row();
row.add(field1);
row.add(field11);
rows.add(row);
Field field2 = new Field("id1", 1, "3");
Field field22 = new Field("id2", 1, "4");
Row row2 = new Row();
row2.add(field2);
row2.add(field22);
rows.add(row2);
Field field3 = new Field("id1", 1, "5");
Field field33 = new Field("id2", 1, "6");
Row row3 = new Row();
row3.add(field3);
row3.add(field33);
rows.add(row3);
Map<String, Map<String, Field>> result = DataCompareUtils.rowListToMap(rows, primaryKeyList);
Assertions.assertTrue(result.size() == 3);
Assertions.assertEquals(result.keySet().iterator().next(), "1_2");
}
use of io.seata.rm.datasource.sql.struct.Row in project seata by seata.
the class MySQLUndoLogManagerTest method getUndoLogItem.
private SQLUndoLog getUndoLogItem(int size) throws NoSuchFieldException, IllegalAccessException {
SQLUndoLog sqlUndoLog = new SQLUndoLog();
sqlUndoLog.setTableName("table_plain_executor_test");
sqlUndoLog.setSqlType(SQLType.INSERT);
sqlUndoLog.setTableMeta(tableMeta);
Field rowsField = TableRecords.class.getDeclaredField("rows");
rowsField.setAccessible(true);
List<Row> rows = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
Row row = new Row();
row.add(new io.seata.rm.datasource.sql.struct.Field("id", 1, "value_id_" + i));
row.add(new io.seata.rm.datasource.sql.struct.Field("name", 1, "value_name_" + i));
rows.add(row);
}
sqlUndoLog.setAfterImage(TableRecords.empty(tableMeta));
TableRecords afterImage = new TableRecords(tableMeta);
rowsField.set(afterImage, rows);
sqlUndoLog.setAfterImage(afterImage);
return sqlUndoLog;
}
use of io.seata.rm.datasource.sql.struct.Row in project seata by seata.
the class MySQLKeywordCheckerTest method testInsertKeywordCheck.
/**
* Test keyword check with INSERT case
*/
@Test
public void testInsertKeywordCheck() {
SQLUndoLog sqlUndoLog = new SQLUndoLog();
sqlUndoLog.setTableName("`lock`");
sqlUndoLog.setSqlType(SQLType.INSERT);
TableRecords beforeImage = TableRecords.empty(new UndoExecutorTest.MockTableMeta("product", "key"));
TableRecords afterImage = new TableRecords(new UndoExecutorTest.MockTableMeta("product", "key"));
Row afterRow1 = new Row();
Field pkField = new Field();
pkField.setKeyType(KeyType.PRIMARY_KEY);
pkField.setName("`key`");
pkField.setType(Types.INTEGER);
pkField.setValue(213);
afterRow1.add(pkField);
Field name = new Field();
name.setName("`desc`");
name.setType(Types.VARCHAR);
name.setValue("SEATA");
afterRow1.add(name);
Field since = new Field();
since.setName("since");
since.setType(Types.VARCHAR);
since.setValue("2014");
afterRow1.add(since);
Row afterRow = new Row();
Field pkField1 = new Field();
pkField1.setKeyType(KeyType.PRIMARY_KEY);
pkField1.setName("`key`");
pkField1.setType(Types.INTEGER);
pkField1.setValue(214);
afterRow.add(pkField1);
Field name1 = new Field();
name1.setName("`desc`");
name1.setType(Types.VARCHAR);
name1.setValue("GTS");
afterRow.add(name1);
Field since1 = new Field();
since1.setName("since");
since1.setType(Types.VARCHAR);
since1.setValue("2016");
afterRow.add(since1);
afterImage.add(afterRow1);
afterImage.add(afterRow);
sqlUndoLog.setBeforeImage(beforeImage);
sqlUndoLog.setAfterImage(afterImage);
MySQLUndoInsertExecutorExtension mySQLUndoInsertExecutor = new MySQLUndoInsertExecutorExtension(sqlUndoLog);
Assertions.assertEquals("DELETE FROM `lock` WHERE `key` = ?", mySQLUndoInsertExecutor.getSql().trim());
}
use of io.seata.rm.datasource.sql.struct.Row in project seata by seata.
the class OracleUndoInsertExecutorTest method upperCase.
public OracleUndoInsertExecutor upperCase() {
TableMeta tableMeta = Mockito.mock(TableMeta.class);
Mockito.when(tableMeta.getPrimaryKeyOnlyName()).thenReturn(Arrays.asList(new String[] { "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();
addField(row0, "ID", 1, "1");
addField(row0, "AGE", 1, "1");
beforeRows.add(row0);
Row row1 = new Row();
addField(row1, "ID", 1, "1");
addField(row1, "AGE", 1, "1");
beforeRows.add(row1);
beforeImage.setRows(beforeRows);
TableRecords afterImage = new TableRecords();
afterImage.setTableName("TABLE_NAME");
afterImage.setTableMeta(tableMeta);
List<Row> afterRows = new ArrayList<>();
Row row2 = new Row();
addField(row2, "ID", 1, "1");
addField(row2, "AGE", 1, "1");
afterRows.add(row2);
Row row3 = new Row();
addField(row3, "ID", 1, "1");
addField(row3, "AGE", 1, "1");
afterRows.add(row3);
afterImage.setRows(afterRows);
SQLUndoLog sqlUndoLog = new SQLUndoLog();
sqlUndoLog.setSqlType(SQLType.INSERT);
sqlUndoLog.setTableMeta(tableMeta);
sqlUndoLog.setTableName("TABLE_NAME");
sqlUndoLog.setBeforeImage(beforeImage);
sqlUndoLog.setAfterImage(afterImage);
return new OracleUndoInsertExecutor(sqlUndoLog);
}
Aggregations