use of io.seata.rm.datasource.sql.struct.TableMeta in project seata by seata.
the class DeleteExecutor method beforeImage.
@Override
protected TableRecords beforeImage() throws SQLException {
SQLDeleteRecognizer visitor = (SQLDeleteRecognizer) sqlRecognizer;
TableMeta tmeta = getTableMeta(visitor.getTableName());
ArrayList<List<Object>> paramAppenderList = new ArrayList<>();
String selectSQL = buildBeforeImageSQL(visitor, tmeta, paramAppenderList);
return buildTableRecords(tmeta, selectSQL, paramAppenderList);
}
use of io.seata.rm.datasource.sql.struct.TableMeta in project seata by seata.
the class AbstractConnectionProxy method prepareStatement.
@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {
String dbType = getDbType();
// support oracle 10.2+
PreparedStatement targetPreparedStatement = null;
if (BranchType.AT == RootContext.getBranchType()) {
List<SQLRecognizer> sqlRecognizers = SQLVisitorFactory.get(sql, dbType);
if (sqlRecognizers != null && sqlRecognizers.size() == 1) {
SQLRecognizer sqlRecognizer = sqlRecognizers.get(0);
if (sqlRecognizer != null && sqlRecognizer.getSQLType() == SQLType.INSERT) {
TableMeta tableMeta = TableMetaCacheFactory.getTableMetaCache(dbType).getTableMeta(getTargetConnection(), sqlRecognizer.getTableName(), getDataSourceProxy().getResourceId());
String[] pkNameArray = new String[tableMeta.getPrimaryKeyOnlyName().size()];
tableMeta.getPrimaryKeyOnlyName().toArray(pkNameArray);
targetPreparedStatement = getTargetConnection().prepareStatement(sql, pkNameArray);
}
}
}
if (targetPreparedStatement == null) {
targetPreparedStatement = getTargetConnection().prepareStatement(sql);
}
return new PreparedStatementProxy(this, targetPreparedStatement, sql);
}
use of io.seata.rm.datasource.sql.struct.TableMeta in project seata by seata.
the class MySQLUndoDeleteExecutorTest 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 MySQLUndoDeleteExecutor(sqlUndoLog);
}
Aggregations