use of io.seata.rm.datasource.StatementProxy in project seata by seata.
the class UpdateExecutorTest method testBeforeImage.
@Test
public void testBeforeImage() throws SQLException {
Assertions.assertNotNull(updateExecutor.beforeImage());
String sql = "update table_update_executor_test set name = 'WILL' where id = 1";
List<SQLStatement> asts = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
MySQLUpdateRecognizer recognizer = new MySQLUpdateRecognizer(sql, asts.get(0));
updateExecutor = new UpdateExecutor(statementProxy, (statement, args) -> null, recognizer);
Assertions.assertNotNull(updateExecutor.beforeImage());
}
use of io.seata.rm.datasource.StatementProxy in project seata by seata.
the class DeleteExecutorTest method init.
@BeforeAll
public static void init() {
List<String> returnValueColumnLabels = Lists.newArrayList("id", "name");
Object[][] returnValue = new Object[][] { new Object[] { 1, "Tom" }, new Object[] { 2, "Jack" } };
Object[][] columnMetas = new Object[][] { new Object[] { "", "", "table_delete_executor_test", "id", Types.INTEGER, "INTEGER", 64, 0, 10, 1, "", "", 0, 0, 64, 1, "NO", "YES" }, new Object[] { "", "", "table_delete_executor_test", "name", Types.VARCHAR, "VARCHAR", 64, 0, 10, 0, "", "", 0, 0, 64, 2, "YES", "NO" } };
Object[][] indexMetas = new Object[][] { new Object[] { "PRIMARY", "id", false, "", 3, 1, "A", 34 } };
MockDriver mockDriver = new MockDriver(returnValueColumnLabels, returnValue, columnMetas, indexMetas);
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(mockDriver);
DataSourceProxy dataSourceProxy = new DataSourceProxy(dataSource);
try {
Field field = dataSourceProxy.getClass().getDeclaredField("dbType");
field.setAccessible(true);
field.set(dataSourceProxy, "mysql");
ConnectionProxy connectionProxy = new ConnectionProxy(dataSourceProxy, dataSource.getConnection().getConnection());
MockStatementBase mockStatement = new MockStatement(dataSource.getConnection().getConnection());
statementProxy = new StatementProxy(connectionProxy, mockStatement);
} catch (Exception e) {
throw new RuntimeException("init failed");
}
String sql = "delete from t where id = 1";
List<SQLStatement> asts = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
MySQLDeleteRecognizer recognizer = new MySQLDeleteRecognizer(sql, asts.get(0));
deleteExecutor = new DeleteExecutor(statementProxy, (statement, args) -> {
return null;
}, recognizer);
}
use of io.seata.rm.datasource.StatementProxy in project seata by seata.
the class DeleteExecutorTest method testBeforeImage.
@Test
public void testBeforeImage() throws SQLException {
Assertions.assertNotNull(deleteExecutor.beforeImage());
String sql = "delete from t";
List<SQLStatement> asts = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
MySQLDeleteRecognizer recognizer = new MySQLDeleteRecognizer(sql, asts.get(0));
deleteExecutor = new DeleteExecutor(statementProxy, (statement, args) -> null, recognizer);
Assertions.assertNotNull(deleteExecutor.beforeImage());
}
use of io.seata.rm.datasource.StatementProxy in project seata by seata.
the class OracleInsertExecutorTest method testStatement_pkValueByAuto_NotSupportYetException.
@Test
public void testStatement_pkValueByAuto_NotSupportYetException() throws Exception {
mockInsertColumns();
mockStatementInsertRows();
statementProxy = mock(StatementProxy.class);
when(statementProxy.getConnectionProxy()).thenReturn(connectionProxy);
when(connectionProxy.getDbType()).thenReturn(JdbcConstants.ORACLE);
insertExecutor = Mockito.spy(new OracleInsertExecutor(statementProxy, statementCallback, sqlInsertRecognizer));
doReturn(tableMeta).when(insertExecutor).getTableMeta();
Map<String, ColumnMeta> map = new HashMap<>();
map.put(ID_COLUMN, mock(ColumnMeta.class));
doReturn(map).when(tableMeta).getPrimaryKeyMap();
ResultSet rs = mock(ResultSet.class);
doReturn(rs).when(statementProxy).getGeneratedKeys();
doReturn(false).when(rs).next();
Assertions.assertThrows(NotSupportYetException.class, () -> {
insertExecutor.getGeneratedKeys();
});
doReturn(pkIndexMap).when(insertExecutor).getPkIndex();
Assertions.assertThrows(NotSupportYetException.class, () -> {
insertExecutor.getPkValuesByColumn();
});
}
use of io.seata.rm.datasource.StatementProxy in project seata by seata.
the class PlainExecutorTest method init.
@BeforeEach
public void init() throws SQLException {
List<String> returnValueColumnLabels = Lists.newArrayList("id", "name");
Object[][] returnValue = new Object[][] { new Object[] { 1, "Tom" }, new Object[] { 2, "Jack" } };
Object[][] columnMetas = new Object[][] { new Object[] { "", "", "table_plain_executor_test", "id", Types.INTEGER, "INTEGER", 64, 0, 10, 1, "", "", 0, 0, 64, 1, "NO", "YES" }, new Object[] { "", "", "table_plain_executor_test", "name", Types.VARCHAR, "VARCHAR", 64, 0, 10, 0, "", "", 0, 0, 64, 2, "YES", "NO" } };
Object[][] indexMetas = new Object[][] { new Object[] { "PRIMARY", "id", false, "", 3, 1, "A", 34 } };
MockDriver mockDriver = new MockDriver(returnValueColumnLabels, returnValue, columnMetas, indexMetas);
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(mockDriver);
DataSourceProxy dataSourceProxy = new DataSourceProxy(dataSource);
ConnectionProxy connectionProxy = new ConnectionProxy(dataSourceProxy, dataSource.getConnection().getConnection());
MockStatementBase mockStatement = new MockStatement(dataSource.getConnection().getConnection());
StatementProxy statementProxy = new StatementProxy(connectionProxy, mockStatement);
plainExecutor = new PlainExecutor(statementProxy, (statement, args) -> null);
}
Aggregations