TakeActionNow2019 commented on code in PR #6511:
URL: https://github.com/apache/incubator-seata/pull/6511#discussion_r1676709870
##########
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:
Good idea! However, we need to integrate the TableMetaCacheFactory at the
same time. To get the TableMeta instance of SqlServer, we need to prepare the
dbType, targetConnection and resourceId, which cannot be done with the
constructor of SqlServerUndoDeleteExecutor and parameter sqlUndoLog of
SQLUndoLog class. So we have to compromise in this way.

![Uploading image.png…]()
--
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]