use of io.seata.rm.datasource.sql.struct.TableRecords in project seata by seata.
the class MySQLKeywordCheckerTest method testDeleteKeywordCheck.
/**
* Test keyword check with DELETE case
*/
@Test
public void testDeleteKeywordCheck() {
SQLUndoLog sqlUndoLog = new SQLUndoLog();
sqlUndoLog.setTableName("`lock`");
sqlUndoLog.setSqlType(SQLType.DELETE);
TableRecords afterImage = TableRecords.empty(new UndoExecutorTest.MockTableMeta("product", "key"));
TableRecords beforeImage = 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);
beforeImage.add(afterRow1);
beforeImage.add(afterRow);
sqlUndoLog.setAfterImage(afterImage);
sqlUndoLog.setBeforeImage(beforeImage);
MySQLUndoDeleteExecutorExtension mySQLUndoDeleteExecutor = new MySQLUndoDeleteExecutorExtension(sqlUndoLog);
Assertions.assertEquals("INSERT INTO `lock` (`desc`, since, `key`) VALUES (?, ?, ?)", mySQLUndoDeleteExecutor.getSql());
}
use of io.seata.rm.datasource.sql.struct.TableRecords in project seata by seata.
the class MySQLKeywordCheckerTest method testUpdateKeywordCheck.
/**
* Test keyword check with UPDATE case
*/
@Test
public void testUpdateKeywordCheck() {
SQLUndoLog sqlUndoLog = new SQLUndoLog();
sqlUndoLog.setTableName("`lock`");
sqlUndoLog.setSqlType(SQLType.UPDATE);
TableRecords beforeImage = new TableRecords(new UndoExecutorTest.MockTableMeta("product", "key"));
Row beforeRow = new Row();
Field pkField = new Field();
pkField.setKeyType(KeyType.PRIMARY_KEY);
pkField.setName("`key`");
pkField.setType(Types.INTEGER);
pkField.setValue(213);
beforeRow.add(pkField);
Field name = new Field();
name.setName("`desc`");
name.setType(Types.VARCHAR);
name.setValue("SEATA");
beforeRow.add(name);
Field since = new Field();
since.setName("since");
since.setType(Types.VARCHAR);
since.setValue("2014");
beforeRow.add(since);
beforeImage.add(beforeRow);
TableRecords afterImage = new TableRecords(new UndoExecutorTest.MockTableMeta("product", "key"));
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(afterRow);
sqlUndoLog.setBeforeImage(beforeImage);
sqlUndoLog.setAfterImage(afterImage);
MySQLUndoUpdateExecutorExtension mySQLUndoUpdateExecutor = new MySQLUndoUpdateExecutorExtension(sqlUndoLog);
Assertions.assertEquals("UPDATE `lock` SET `desc` = ?, since = ? WHERE `key` = ?", mySQLUndoUpdateExecutor.getSql().trim());
}
Aggregations