funky-eyes commented on code in PR #6348:
URL: https://github.com/apache/incubator-seata/pull/6348#discussion_r2190315352
##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/exec/UpdateExecutor.java:
##########
@@ -97,20 +98,30 @@ protected String buildBeforeImageSQL(TableMeta tableMeta,
ArrayList<List<Object>
@Override
protected TableRecords afterImage(TableRecords beforeImage) throws
SQLException {
- TableMeta tmeta = getTableMeta();
if (beforeImage == null || beforeImage.size() == 0) {
return TableRecords.empty(getTableMeta());
}
- String selectSQL = buildAfterImageSQL(tmeta, beforeImage);
+ TableMeta tmeta = getTableMeta();
PreparedStatement pst = null;
ResultSet rs = null;
- try {
- pst = statementProxy.getConnection().prepareStatement(selectSQL);
- SqlGenerateUtils.setParamForPk(beforeImage.pkRows(),
getTableMeta().getPrimaryKeyOnlyName(), pst);
- rs = pst.executeQuery();
- return TableRecords.buildRecords(tmeta, rs);
- } finally {
- IOUtil.close(rs, pst);
+ SQLUpdateRecognizer recognizer = (SQLUpdateRecognizer) sqlRecognizer;
+ List<String> whereColumns = recognizer.getWhereColumns();
+ boolean contain =
+ statementProxy.getConnection().getTransactionIsolation() ==
Connection.TRANSACTION_REPEATABLE_READ
+ || tmeta.containsPK(whereColumns);
+ if (contain) {
+ String selectSQL = buildAfterImageSQL(tmeta, beforeImage);
+ try {
+ pst =
statementProxy.getConnection().prepareStatement(selectSQL);
+ SqlGenerateUtils.setParamForPk(
+ beforeImage.pkRows(),
getTableMeta().getPrimaryKeyOnlyName(), pst);
+ rs = pst.executeQuery();
+ return TableRecords.buildRecords(tmeta, rs);
+ } finally {
+ IOUtil.close(rs, pst);
+ }
+ } else {
+ return beforeImage();
Review Comment:
Calling beforeImage() will re-execute the SQL for beforeImage and generate a
new beforeImage. If you directly return beforeImage, it will be the old image,
which is not the expected behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]