This is an automated email from the ASF dual-hosted git repository.

zihaoxiang pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new c3cc8172a2 [Fix-17971] Fix local parameter defined in ProcedureTask 
not being passed correctly (#17973)
c3cc8172a2 is described below

commit c3cc8172a2c25ed5bc1805248982bab92158060b
Author: Wenjun Ruan <[email protected]>
AuthorDate: Thu Feb 26 09:24:32 2026 +0800

    [Fix-17971] Fix local parameter defined in ProcedureTask not being passed 
correctly (#17973)
---
 .../service/expand/CuringParamsServiceImpl.java    |  23 ++--
 .../task/api/parameters/AbstractParameters.java    |  42 +------
 .../api/parameters/AbstractParametersTest.java     | 139 ---------------------
 .../plugin/task/grpc/GrpcParametersTest.java       |   1 -
 .../plugin/task/http/HttpParametersTest.java       |   1 -
 .../plugin/task/procedure/ProcedureParameters.java |  82 +-----------
 .../plugin/task/procedure/ProcedureTask.java       | 109 ++++++++--------
 7 files changed, 75 insertions(+), 322 deletions(-)

diff --git 
a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/expand/CuringParamsServiceImpl.java
 
b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/expand/CuringParamsServiceImpl.java
index 225bb06917..6b812c3a61 100644
--- 
a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/expand/CuringParamsServiceImpl.java
+++ 
b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/expand/CuringParamsServiceImpl.java
@@ -198,7 +198,7 @@ public class CuringParamsServiceImpl implements 
CuringParamsService {
         String timeZone = commandParam.getTimeZone();
 
         // 1. Built-in parameters (lowest precedence)
-        Map<String, String> builtInParams = setBuiltInParamsMap(
+        Map<String, String> builtInParams = parseBuiltInParamsMap(
                 taskInstance, workflowInstance, timeZone, projectName, 
workflowDefinitionName);
         safePutAll(prepareParamsMap, 
ParameterUtils.getUserDefParamsMap(builtInParams));
 
@@ -211,7 +211,7 @@ public class CuringParamsServiceImpl implements 
CuringParamsService {
         safePutAll(prepareParamsMap, globalParams);
 
         // 4. Task-local parameters
-        Map<String, Property> localParams = 
parameters.getInputLocalParametersMap();
+        Map<String, Property> localParams = parseLocalParamsMap(parameters);
         safePutAll(prepareParamsMap, localParams);
 
         // 5. Command-line / complement parameters
@@ -293,11 +293,11 @@ public class CuringParamsServiceImpl implements 
CuringParamsService {
      * @param projectName
      * @param workflowDefinitionName
      */
-    private Map<String, String> setBuiltInParamsMap(@NonNull TaskInstance 
taskInstance,
-                                                    WorkflowInstance 
workflowInstance,
-                                                    String timeZone,
-                                                    String projectName,
-                                                    String 
workflowDefinitionName) {
+    private Map<String, String> parseBuiltInParamsMap(@NonNull TaskInstance 
taskInstance,
+                                                      WorkflowInstance 
workflowInstance,
+                                                      String timeZone,
+                                                      String projectName,
+                                                      String 
workflowDefinitionName) {
         CommandType commandType = workflowInstance.getCmdTypeIfComplement();
         Date scheduleTime = workflowInstance.getScheduleTime();
 
@@ -317,6 +317,15 @@ public class CuringParamsServiceImpl implements 
CuringParamsService {
         return params;
     }
 
+    private Map<String, Property> parseLocalParamsMap(AbstractParameters 
parameters) {
+        Map<String, Property> localParametersMaps = new LinkedHashMap<>();
+        if (CollectionUtils.isNotEmpty(parameters.getLocalParams())) {
+            parameters.getLocalParams()
+                    .forEach(localParam -> 
localParametersMaps.put(localParam.getProp(), localParam));
+        }
+        return localParametersMaps;
+    }
+
     private Map<String, Property> parseGlobalParamsMap(WorkflowInstance 
workflowInstance) {
         final Map<String, Property> globalParametersMaps = new 
LinkedHashMap<>();
         if (StringUtils.isNotEmpty(workflowInstance.getGlobalParams())) {
diff --git 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParameters.java
 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParameters.java
index 3bc808c2fa..735a0f78fc 100644
--- 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParameters.java
+++ 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParameters.java
@@ -28,10 +28,8 @@ import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
 
 import java.util.ArrayList;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.stream.Collectors;
 
 import lombok.Getter;
@@ -49,6 +47,7 @@ public abstract class AbstractParameters implements 
IParameters {
     @Setter
     public List<Property> localParams;
 
+    @Setter
     public List<Property> varPool = new ArrayList<>();
 
     @Override
@@ -59,49 +58,16 @@ public abstract class AbstractParameters implements 
IParameters {
         return new ArrayList<>();
     }
 
-    public Map<String, Property> getLocalParametersMap() {
-        Map<String, Property> localParametersMaps = new LinkedHashMap<>();
-        if (localParams != null) {
-            for (Property property : localParams) {
-                localParametersMaps.put(property.getProp(), property);
-            }
-        }
-        return localParametersMaps;
-    }
-
-    /**
-     * get input local parameters map if the param direct is IN
-     *
-     * @return parameters map
-     */
-    public Map<String, Property> getInputLocalParametersMap() {
-        Map<String, Property> localParametersMaps = new LinkedHashMap<>();
-        if (localParams != null) {
-            for (Property property : localParams) {
-                // The direct of some tasks is empty, default IN
-                if (property.getDirect() == null || Objects.equals(Direct.IN, 
property.getDirect())) {
-                    localParametersMaps.put(property.getProp(), property);
-                }
-            }
-        }
-        return localParametersMaps;
-    }
-
-    public void setVarPool(List<Property> varPool) {
-        this.varPool = varPool;
-    }
-
     public void dealOutParam(Map<String, String> taskOutputParams) {
         List<Property> outProperty = getOutProperty(localParams);
         if (CollectionUtils.isEmpty(outProperty)) {
             return;
         }
-        if (CollectionUtils.isNotEmpty(outProperty) && 
MapUtils.isNotEmpty(taskOutputParams)) {
+        if (MapUtils.isNotEmpty(taskOutputParams)) {
             // Inject the value
             for (Property info : outProperty) {
-                String value = taskOutputParams.get(info.getProp());
-                if (value != null) {
-                    info.setValue(value);
+                if (taskOutputParams.containsKey(info.getProp())) {
+                    info.setValue(taskOutputParams.get(info.getProp()));
                 }
             }
         }
diff --git 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParametersTest.java
 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParametersTest.java
deleted file mode 100644
index 7197dbe07e..0000000000
--- 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParametersTest.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.dolphinscheduler.plugin.task.api.parameters;
-
-import org.apache.dolphinscheduler.plugin.task.api.enums.DataType;
-import org.apache.dolphinscheduler.plugin.task.api.enums.Direct;
-import org.apache.dolphinscheduler.plugin.task.api.model.Property;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-public class AbstractParametersTest {
-
-    /**
-     * Verifies that getInputLocalParametersMap() includes parameters with:
-     * - direct = null (treated as IN by default)
-     * - direct = Direct.IN
-     * and excludes parameters with:
-     * - direct = Direct.OUT
-     */
-    @Test
-    public void testGetInputLocalParametersMap() {
-        AbstractParameters parameters = new AbstractParameters() {
-
-            @Override
-            public boolean checkParameters() {
-                return false;
-            }
-        };
-        List<Property> localParams = new ArrayList<>();
-        localParams.add(new Property("key1", null, null, "value1"));
-        localParams.add(new Property("key2", Direct.IN, DataType.VARCHAR, 
"value2"));
-        localParams.add(new Property("key3", Direct.OUT, DataType.VARCHAR, 
null));
-        parameters.setLocalParams(localParams);
-
-        // should return property key1 and key2 (direct null and IN)
-        Map<String, Property> inputLocalParametersMap = 
parameters.getInputLocalParametersMap();
-
-        Assertions.assertEquals(2, inputLocalParametersMap.size());
-        Assertions.assertTrue(inputLocalParametersMap.containsKey("key1"));
-        Assertions.assertTrue(inputLocalParametersMap.containsKey("key2"));
-    }
-
-    /**
-     * Tests behavior when a Property has a null 'prop' field.
-     *
-     * ⚠️ WARNING: The current implementation will insert a (null, Property) 
entry into the map,
-     * which causes JSON serialization to fail with:
-     * "Null key for a Map not allowed in JSON"
-     *
-     * This test exposes the risk. After fixing the method to skip null/empty 
prop names,
-     * this test should assert size == 0.
-     */
-    @Test
-    public void 
testGetInputLocalParametersMap_withNullProp_shouldNotPutNullKey() {
-        AbstractParameters parameters = new AbstractParameters() {
-
-            @Override
-            public boolean checkParameters() {
-                return false;
-            }
-        };
-
-        List<Property> localParams = new ArrayList<>();
-        // Dangerous: prop is null
-        localParams.add(new Property(null, Direct.IN, DataType.VARCHAR, 
"dangerValue"));
-
-        parameters.setLocalParams(localParams);
-
-        Map<String, Property> inputLocalParametersMap = 
parameters.getInputLocalParametersMap();
-
-        // Current behavior: null key is inserted
-        Assertions.assertEquals(1, inputLocalParametersMap.size());
-        Assertions.assertTrue(inputLocalParametersMap.containsKey(null)); // ❌ 
This breaks JSON serialization!
-
-    }
-
-    /**
-     * Tests behavior when a Property has an empty string as 'prop'.
-     * While Java allows empty string keys, they may cause issues downstream 
(e.g., template parsing).
-     */
-    @Test
-    public void testGetInputLocalParametersMap_withEmptyProp() {
-        AbstractParameters parameters = new AbstractParameters() {
-
-            @Override
-            public boolean checkParameters() {
-                return false;
-            }
-        };
-
-        List<Property> localParams = new ArrayList<>();
-        localParams.add(new Property("", Direct.IN, DataType.VARCHAR, 
"emptyKeyVal"));
-
-        parameters.setLocalParams(localParams);
-
-        Map<String, Property> inputLocalParametersMap = 
parameters.getInputLocalParametersMap();
-
-        Assertions.assertEquals(1, inputLocalParametersMap.size());
-        Assertions.assertTrue(inputLocalParametersMap.containsKey(""));
-    }
-
-    /**
-     * Ensures the method handles null localParams gracefully (returns empty 
map).
-     */
-    @Test
-    public void testGetInputLocalParametersMap_localParamsIsNull() {
-        AbstractParameters parameters = new AbstractParameters() {
-
-            @Override
-            public boolean checkParameters() {
-                return false;
-            }
-        };
-        parameters.setLocalParams(null);
-
-        Map<String, Property> result = parameters.getInputLocalParametersMap();
-        Assertions.assertEquals(0, result.size());
-    }
-}
diff --git 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-grpc/src/test/java/org/apache/dolphinscheduler/plugin/task/grpc/GrpcParametersTest.java
 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-grpc/src/test/java/org/apache/dolphinscheduler/plugin/task/grpc/GrpcParametersTest.java
index 913e77395b..430f50fb06 100644
--- 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-grpc/src/test/java/org/apache/dolphinscheduler/plugin/task/grpc/GrpcParametersTest.java
+++ 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-grpc/src/test/java/org/apache/dolphinscheduler/plugin/task/grpc/GrpcParametersTest.java
@@ -99,7 +99,6 @@ public class GrpcParametersTest {
         Assertions.assertEquals("{ \"username\":\"test username\" }", 
grpcParameters.getMessage());
         Assertions.assertEquals(GrpcCheckCondition.STATUS_CODE_DEFAULT, 
grpcParameters.getGrpcCheckCondition());
         Assertions.assertEquals("", grpcParameters.getCondition());
-        Assertions.assertEquals(0, 
grpcParameters.getLocalParametersMap().size());
         Assertions.assertEquals(0, 
grpcParameters.getResourceFilesList().size());
     }
 
diff --git 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpParametersTest.java
 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpParametersTest.java
index 00fbde0502..4970825efb 100644
--- 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpParametersTest.java
+++ 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpParametersTest.java
@@ -68,7 +68,6 @@ public class HttpParametersTest {
         Assertions.assertEquals(HttpRequestMethod.GET, 
httpParameters.getHttpRequestMethod());
         Assertions.assertEquals(HttpCheckCondition.STATUS_CODE_DEFAULT, 
httpParameters.getHttpCheckCondition());
         Assertions.assertEquals("", httpParameters.getCondition());
-        Assertions.assertEquals(0, 
httpParameters.getLocalParametersMap().size());
         Assertions.assertEquals(0, 
httpParameters.getResourceFilesList().size());
     }
 
diff --git 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-procedure/src/main/java/org/apache/dolphinscheduler/plugin/task/procedure/ProcedureParameters.java
 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-procedure/src/main/java/org/apache/dolphinscheduler/plugin/task/procedure/ProcedureParameters.java
index c20c18101a..03d04ddcd2 100644
--- 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-procedure/src/main/java/org/apache/dolphinscheduler/plugin/task/procedure/ProcedureParameters.java
+++ 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-procedure/src/main/java/org/apache/dolphinscheduler/plugin/task/procedure/ProcedureParameters.java
@@ -18,24 +18,17 @@
 package org.apache.dolphinscheduler.plugin.task.procedure;
 
 import org.apache.dolphinscheduler.plugin.task.api.enums.ResourceType;
-import org.apache.dolphinscheduler.plugin.task.api.model.Property;
-import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
 import 
org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters;
 import 
org.apache.dolphinscheduler.plugin.task.api.parameters.resource.DataSourceParameters;
 import 
org.apache.dolphinscheduler.plugin.task.api.parameters.resource.ResourceParametersHelper;
 
-import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 import java.util.Objects;
 
-/**
- * procedure parameter
- */
+import lombok.Data;
+
+@Data
 public class ProcedureParameters extends AbstractParameters {
 
     /**
@@ -48,85 +41,16 @@ public class ProcedureParameters extends AbstractParameters 
{
      */
     private int datasource;
 
-    private Map<String, Property> outProperty;
-
     /**
      * procedure name
      */
     private String method;
 
-    public String getType() {
-        return type;
-    }
-
-    public void setType(String type) {
-        this.type = type;
-    }
-
-    public int getDatasource() {
-        return datasource;
-    }
-
-    public void setDatasource(int datasource) {
-        this.datasource = datasource;
-    }
-
-    public String getMethod() {
-        return method;
-    }
-
-    public void setMethod(String method) {
-        this.method = method;
-    }
-
     @Override
     public boolean checkParameters() {
         return datasource != 0 && StringUtils.isNotEmpty(type) && 
StringUtils.isNotEmpty(method);
     }
 
-    @Override
-    public List<ResourceInfo> getResourceFilesList() {
-        return new ArrayList<>();
-    }
-
-    @Override
-    public String toString() {
-        return "ProcessdureParam{"
-                + "type='" + type + '\''
-                + ", datasource=" + datasource
-                + ", method='" + method + '\''
-                + '}';
-    }
-
-    public void dealOutParam4Procedure(Object result, String pop) {
-        Map<String, Property> properties = getOutProperty();
-        if (this.outProperty == null) {
-            return;
-        }
-        properties.get(pop).setValue(String.valueOf(result));
-        varPool.add(properties.get(pop));
-    }
-
-    public Map<String, Property> getOutProperty() {
-        if (this.outProperty != null) {
-            return this.outProperty;
-        }
-        if (CollectionUtils.isEmpty(localParams)) {
-            return null;
-        }
-        List<Property> outPropertyList = getOutProperty(localParams);
-        Map<String, Property> outProperty = new HashMap<>();
-        for (Property info : outPropertyList) {
-            outProperty.put(info.getProp(), info);
-        }
-        this.outProperty = outProperty;
-        return this.outProperty;
-    }
-
-    public void setOutProperty(Map<String, Property> outProperty) {
-        this.outProperty = outProperty;
-    }
-
     @Override
     public ResourceParametersHelper getResources() {
         ResourceParametersHelper resources = super.getResources();
diff --git 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-procedure/src/main/java/org/apache/dolphinscheduler/plugin/task/procedure/ProcedureTask.java
 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-procedure/src/main/java/org/apache/dolphinscheduler/plugin/task/procedure/ProcedureTask.java
index 70b1042168..8a0d571fde 100644
--- 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-procedure/src/main/java/org/apache/dolphinscheduler/plugin/task/procedure/ProcedureTask.java
+++ 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-procedure/src/main/java/org/apache/dolphinscheduler/plugin/task/procedure/ProcedureTask.java
@@ -38,6 +38,7 @@ import 
org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
 import org.apache.dolphinscheduler.spi.datasource.ConnectionParam;
 import org.apache.dolphinscheduler.spi.enums.DbType;
 
+import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.StringUtils;
 
 import java.sql.CallableStatement;
@@ -50,8 +51,6 @@ import java.util.Map;
 
 import lombok.extern.slf4j.Slf4j;
 
-import com.google.common.collect.Maps;
-
 @Slf4j
 public class ProcedureTask extends AbstractTask {
 
@@ -63,11 +62,6 @@ public class ProcedureTask extends AbstractTask {
 
     private volatile Statement sessionStatement;
 
-    /**
-     * constructor
-     *
-     * @param taskExecutionContext taskExecutionContext
-     */
     public ProcedureTask(TaskExecutionContext taskExecutionContext) {
         super(taskExecutionContext);
 
@@ -99,29 +93,39 @@ public class ProcedureTask extends AbstractTask {
         ConnectionParam connectionParams =
                 
dataSourceProcessor.createConnectionParams(procedureTaskExecutionContext.getConnectionParams());
         try (Connection connection = 
DataSourceClientProvider.getAdHocConnection(dbType, connectionParams)) {
-            Map<Integer, Property> sqlParamsMap = new HashMap<>();
-            Map<String, Property> paramsMap = 
taskExecutionContext.getPrepareParamsMap() == null ? Maps.newHashMap()
-                    : taskExecutionContext.getPrepareParamsMap();
-            if (procedureParameters.getOutProperty() != null) {
-                // set out params before format sql
-                paramsMap.putAll(procedureParameters.getOutProperty());
-            }
-            String proceduerSql = formatSql(sqlParamsMap, paramsMap);
+            // Record the placeholder index and parameter mapping relationship
+            Map<Integer, Property> sqlPlaceHolders = new HashMap<>();
+
+            Map<String, Property> prepareParams = 
taskExecutionContext.getPrepareParamsMap();
+
+            // todo: rename to resolveSqlPlaceHolder and make it return 
placeHolderIndex map
+            setSqlParamsMap(procedureParameters.getMethod(), sqlPlaceHolders, 
prepareParams,
+                    taskExecutionContext.getTaskInstanceId());
+
+            // Replace the SQL statement's parameter placeholders with "?" for 
CallableStatement
+            // Then will set the parameters through CallableStatement's 
setObject method
+            // todo: maybe we can directly replace the parameter placeholders 
with the actual parameter values, don't
+            // use ? here
+            String proceduerSql = 
procedureParameters.getMethod().replaceAll(TaskConstants.SQL_PARAMS_REGEX, "?");
             // call method
-            try (CallableStatement tmpStatement = 
connection.prepareCall(proceduerSql)) {
-                sessionStatement = tmpStatement;
+            try (CallableStatement stat = 
connection.prepareCall(proceduerSql)) {
+                sessionStatement = stat;
                 // set timeout
-                setTimeout(tmpStatement);
+                setTimeout(stat);
 
                 // outParameterMap
-                Map<Integer, Property> outParameterMap = 
getOutParameterMap(tmpStatement, sqlParamsMap, paramsMap);
+                Map<Integer, Property> sqlOutPlaceHolders =
+                        assemblySqlPlaceHolder(stat, sqlPlaceHolders, 
prepareParams);
 
-                tmpStatement.executeUpdate();
+                // todo: deal with the result
+                stat.execute();
 
-                // print the output parameters to the log
-                printOutParameter(tmpStatement, outParameterMap);
+                Map<String, String> sqlOutParameters = 
parseOutParameters(stat, sqlOutPlaceHolders);
 
-                // set varPool
+                // todo: If the task is failed, do we need to deal with the 
output parameters? otherwise the localparam
+                // cannot pass to post.
+                // If so, we can set the output parameters in the finally 
block.
+                procedureParameters.dealOutParam(sqlOutParameters);
                 
taskExecutionContext.setVarPool(procedureParameters.getVarPool());
                 setExitStatusCode(EXIT_CODE_SUCCESS);
             }
@@ -154,59 +158,50 @@ public class ProcedureTask extends AbstractTask {
         }
     }
 
-    private String formatSql(Map<Integer, Property> sqlParamsMap, Map<String, 
Property> paramsMap) {
-        setSqlParamsMap(procedureParameters.getMethod(), sqlParamsMap, 
paramsMap,
-                taskExecutionContext.getTaskInstanceId());
-        return 
procedureParameters.getMethod().replaceAll(TaskConstants.SQL_PARAMS_REGEX, "?");
-    }
-
-    /**
-     * print outParameter
-     *
-     * @param stmt            CallableStatement
-     * @param outParameterMap outParameterMap
-     * @throws SQLException SQLException
-     */
-    private void printOutParameter(CallableStatement stmt,
-                                   Map<Integer, Property> outParameterMap) 
throws SQLException {
-        for (Map.Entry<Integer, Property> en : outParameterMap.entrySet()) {
-            int index = en.getKey();
-            Property property = en.getValue();
+    // parse the out parameter from stmt and put them into varPool
+    private Map<String, String> parseOutParameters(CallableStatement stmt,
+                                                   Map<Integer, Property> 
sqlOutPlaceHolders) throws SQLException {
+        Map<String, String> sqlOutParameters = new HashMap<>();
+        for (Map.Entry<Integer, Property> out : sqlOutPlaceHolders.entrySet()) 
{
+            int index = out.getKey();
+            Property property = out.getValue();
             String prop = property.getProp();
             DataType dataType = property.getType();
             // get output parameter
-            
procedureParameters.dealOutParam4Procedure(getOutputParameter(stmt, index, 
prop, dataType), prop);
+            Object outputParameterValue = getOutputParameter(stmt, index, 
prop, dataType);
+            sqlOutParameters.put(prop, String.valueOf(outputParameterValue));
         }
+        return sqlOutParameters;
     }
 
     /**
      * get output parameter
      *
      * @param stmt      CallableStatement
-     * @param paramsMap paramsMap
+     * @param sqlParams paramsMap
      * @return outParameterMap
      * @throws Exception Exception
      */
-    private Map<Integer, Property> getOutParameterMap(CallableStatement stmt, 
Map<Integer, Property> paramsMap,
-                                                      Map<String, Property> 
totalParamsMap) throws Exception {
+    private Map<Integer, Property> assemblySqlPlaceHolder(CallableStatement 
stmt,
+                                                          Map<Integer, 
Property> sqlParams,
+                                                          Map<String, 
Property> prepareParams) throws Exception {
         Map<Integer, Property> outParameterMap = new HashMap<>();
-        if (procedureParameters.getLocalParametersMap() == null) {
+        if (MapUtils.isEmpty(sqlParams)) {
             return outParameterMap;
         }
 
         int index = 1;
-        if (paramsMap != null) {
-            for (Map.Entry<Integer, Property> entry : paramsMap.entrySet()) {
-                Property property = entry.getValue();
-                if (property.getDirect().equals(Direct.IN)) {
-                    ParameterUtils.setInParameter(index, stmt, 
property.getType(),
-                            totalParamsMap.get(property.getProp()).getValue());
-                } else if (property.getDirect().equals(Direct.OUT)) {
-                    setOutParameter(index, stmt, property.getType(), 
totalParamsMap.get(property.getProp()).getValue());
-                    outParameterMap.put(index, property);
-                }
-                index++;
+        for (Map.Entry<Integer, Property> entry : sqlParams.entrySet()) {
+            Property sqlProperty = entry.getValue();
+            Property prepareParam = prepareParams.get(sqlProperty.getProp());
+            if (sqlProperty.getDirect().equals(Direct.IN)) {
+                ParameterUtils.setInParameter(index, stmt, 
sqlProperty.getType(), prepareParam.getValue());
+            } else if (sqlProperty.getDirect().equals(Direct.OUT)) {
+                // todo: It's reasonable to set the value here?
+                setOutParameter(index, stmt, sqlProperty.getType(), 
prepareParam.getValue());
+                outParameterMap.put(index, sqlProperty);
             }
+            index++;
         }
 
         return outParameterMap;

Reply via email to