Search in sources :

Example 21 with SQLUndoLog

use of io.seata.rm.datasource.undo.SQLUndoLog 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());
}
Also used : TableRecords(io.seata.rm.datasource.sql.struct.TableRecords) Field(io.seata.rm.datasource.sql.struct.Field) SQLUndoLog(io.seata.rm.datasource.undo.SQLUndoLog) UndoExecutorTest(io.seata.rm.datasource.undo.UndoExecutorTest) Row(io.seata.rm.datasource.sql.struct.Row) UndoExecutorTest(io.seata.rm.datasource.undo.UndoExecutorTest) Test(org.junit.jupiter.api.Test)

Example 22 with SQLUndoLog

use of io.seata.rm.datasource.undo.SQLUndoLog 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());
}
Also used : TableRecords(io.seata.rm.datasource.sql.struct.TableRecords) Field(io.seata.rm.datasource.sql.struct.Field) SQLUndoLog(io.seata.rm.datasource.undo.SQLUndoLog) UndoExecutorTest(io.seata.rm.datasource.undo.UndoExecutorTest) Row(io.seata.rm.datasource.sql.struct.Row) UndoExecutorTest(io.seata.rm.datasource.undo.UndoExecutorTest) Test(org.junit.jupiter.api.Test)

Aggregations

SQLUndoLog (io.seata.rm.datasource.undo.SQLUndoLog)22 TableRecords (io.seata.rm.datasource.sql.struct.TableRecords)13 Test (org.junit.jupiter.api.Test)12 Row (io.seata.rm.datasource.sql.struct.Row)11 ArrayList (java.util.ArrayList)9 TableMeta (io.seata.rm.datasource.sql.struct.TableMeta)6 Field (io.seata.rm.datasource.sql.struct.Field)4 BeforeAll (org.junit.jupiter.api.BeforeAll)4 UndoExecutorTest (io.seata.rm.datasource.undo.UndoExecutorTest)3 Savepoint (java.sql.Savepoint)3 MockSavepoint (com.alibaba.druid.mock.MockSavepoint)2 ShouldNeverHappenException (io.seata.common.exception.ShouldNeverHappenException)2 ConnectionProxy (io.seata.rm.datasource.ConnectionProxy)2 BranchUndoLog (io.seata.rm.datasource.undo.BranchUndoLog)2 SQLType (io.seata.sqlparser.SQLType)2 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 SQLException (java.sql.SQLException)2 List (java.util.List)2 Map (java.util.Map)2