funky-eyes commented on code in PR #6511:
URL: https://github.com/apache/incubator-seata/pull/6511#discussion_r1669887254
##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/undo/sqlserver/SqlServerUndoDeleteExecutor.java:
##########
@@ -59,17 +71,75 @@ protected String buildUndoSQL() {
String insertValues = fields.stream().map(field -> "?")
.collect(Collectors.joining(", "));
- return "SET IDENTITY_INSERT " +
- sqlUndoLog.getTableName() +
- " ON; INSERT INTO " +
- sqlUndoLog.getTableName() +
- " (" +
- insertColumns +
- ") VALUES (" +
- insertValues +
- "); SET IDENTITY_INSERT " +
- sqlUndoLog.getTableName() +
- " OFF;";
+ if (tableIdentifyExistence) {
+ return "begin " +
+ "SET IDENTITY_INSERT " + sqlUndoLog.getTableName() + "
ON;" +
+ "INSERT INTO " + sqlUndoLog.getTableName() + "(" +
insertColumns + ") VALUES (" + insertValues + ");" +
+ "SET IDENTITY_INSERT " + sqlUndoLog.getTableName() + "
OFF; " +
+ "end";
+ }
+ return "INSERT INTO " + sqlUndoLog.getTableName() + "(" +
insertColumns + ") VALUES (" + insertValues + ");";
+ }
+
+ /**
+ * Judge whether there is a column of a SQLServer table is with a
"IDENTITY"
+ *
+ * @param connectionProxy
+ */
+ private void judgeTableIdentifyExistence(ConnectionProxy connectionProxy) {
+ TableMeta tableMeta =
TableMetaCacheFactory.getTableMetaCache(connectionProxy.getDbType())
+ .getTableMeta(
+ connectionProxy.getTargetConnection(),
+ sqlUndoLog.getTableName(),
+ connectionProxy.getDataSourceProxy().getResourceId()
+ );
+ tableIdentifyExistence = ((SqlServerTableMeta)
tableMeta).isTableIdentifyExistence();
+ }
+
+ /**
+ * Execute on.
+ *
+ * @param connectionProxy the connection proxy
+ * @throws SQLException the sql exception
+ */
+ @Override
+ public void executeOn(ConnectionProxy connectionProxy) throws SQLException
{
+ Connection conn = connectionProxy.getTargetConnection();
+ if (IS_UNDO_DATA_VALIDATION_ENABLE &&
!dataValidationAndGoOn(connectionProxy)) {
+ return;
+ }
+
+ judgeTableIdentifyExistence(connectionProxy);
Review Comment:
我认为这个方法应该放在构造方法中,这样就不需要重写executeOn了
I think this method should be placed in the constructor so that there's no
need to override executeOn.
--
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]