use of io.seata.rm.datasource.sql.struct.TableMeta in project seata by seata.
the class TestUndoExecutor method testParsePK.
@Test
public void testParsePK() {
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();
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);
Map<String, List<Field>> pkValues = executor.parsePkValues(beforeImage);
Assertions.assertEquals(2, pkValues.get("id").size());
}
use of io.seata.rm.datasource.sql.struct.TableMeta in project seata by seata.
the class BaseH2Test method mockTableMeta.
protected static TableMeta mockTableMeta() {
TableMeta tableMeta = Mockito.mock(TableMeta.class);
Mockito.when(tableMeta.getPrimaryKeyOnlyName()).thenReturn(Arrays.asList(new String[] { "ID" }));
Mockito.when(tableMeta.getEscapePkNameList("h2")).thenReturn(Arrays.asList(new String[] { "ID" }));
Mockito.when(tableMeta.getTableName()).thenReturn("table_name");
ColumnMeta meta0 = Mockito.mock(ColumnMeta.class);
Mockito.when(meta0.getDataType()).thenReturn(Types.INTEGER);
Mockito.when(meta0.getColumnName()).thenReturn("ID");
Mockito.when(tableMeta.getColumnMeta("ID")).thenReturn(meta0);
ColumnMeta meta1 = Mockito.mock(ColumnMeta.class);
Mockito.when(meta1.getDataType()).thenReturn(Types.VARCHAR);
Mockito.when(meta1.getColumnName()).thenReturn("NAME");
Mockito.when(tableMeta.getColumnMeta("NAME")).thenReturn(meta1);
return tableMeta;
}
use of io.seata.rm.datasource.sql.struct.TableMeta in project seata by seata.
the class MySQLUndoUpdateExecutorTest method init.
@BeforeAll
public static void init() {
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, "12345");
addField(row0, "age", 1, "1");
beforeRows.add(row0);
Row row1 = new Row();
addField(row1, "id", 1, "12346");
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, "12345");
addField(row2, "age", 1, "2");
afterRows.add(row2);
Row row3 = new Row();
addField(row3, "id", 1, "12346");
addField(row3, "age", 1, "2");
afterRows.add(row3);
afterImage.setRows(afterRows);
SQLUndoLog sqlUndoLog = new SQLUndoLog();
sqlUndoLog.setSqlType(SQLType.UPDATE);
sqlUndoLog.setTableMeta(tableMeta);
sqlUndoLog.setTableName("table_name");
sqlUndoLog.setBeforeImage(beforeImage);
sqlUndoLog.setAfterImage(afterImage);
executor = new MySQLUndoUpdateExecutor(sqlUndoLog);
}
use of io.seata.rm.datasource.sql.struct.TableMeta in project seata by seata.
the class OracleUndoDeleteExecutorTest method upperCase.
private OracleUndoDeleteExecutor 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, "2");
afterRows.add(row2);
Row row3 = new Row();
addField(row3, "ID", 1, "1");
addField(row3, "AGE", 1, "2");
afterRows.add(row3);
afterImage.setRows(afterRows);
SQLUndoLog sqlUndoLog = new SQLUndoLog();
sqlUndoLog.setSqlType(SQLType.DELETE);
sqlUndoLog.setTableMeta(tableMeta);
sqlUndoLog.setTableName("TABLE_NAME");
sqlUndoLog.setBeforeImage(beforeImage);
sqlUndoLog.setAfterImage(afterImage);
return new OracleUndoDeleteExecutor(sqlUndoLog);
}
use of io.seata.rm.datasource.sql.struct.TableMeta in project seata by seata.
the class PostgresqlTableMetaCacheTest method getTableMetaTest.
@Test
public void getTableMetaTest() throws SQLException {
MockDriver mockDriver = new MockDriver(columnMetas, indexMetas, pkMetas);
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(mockDriver);
DataSourceProxy proxy = new DataSourceProxy(dataSource);
TableMetaCache tableMetaCache = TableMetaCacheFactory.getTableMetaCache(JdbcConstants.POSTGRESQL);
TableMeta tableMeta = tableMetaCache.getTableMeta(proxy.getPlainConnection(), "pt1", proxy.getResourceId());
Assertions.assertNotNull(tableMeta);
tableMeta = tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.pt1", proxy.getResourceId());
Assertions.assertNotNull(tableMeta);
tableMeta = tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.\"pt1\"", proxy.getResourceId());
Assertions.assertNotNull(tableMeta);
}
Aggregations