|
|
@ -36,17 +36,15 @@ import org.apache.dolphinscheduler.spi.task.request.TaskRequest; |
|
|
|
import org.apache.dolphinscheduler.spi.utils.JSONUtils; |
|
|
|
import org.apache.dolphinscheduler.spi.utils.JSONUtils; |
|
|
|
import org.apache.dolphinscheduler.spi.utils.StringUtils; |
|
|
|
import org.apache.dolphinscheduler.spi.utils.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.sql.CallableStatement; |
|
|
|
import java.sql.CallableStatement; |
|
|
|
import java.sql.Connection; |
|
|
|
import java.sql.Connection; |
|
|
|
import java.sql.PreparedStatement; |
|
|
|
import java.sql.PreparedStatement; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.sql.Types; |
|
|
|
import java.sql.Types; |
|
|
|
import java.util.Collection; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* procedure task |
|
|
|
* procedure task |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -102,18 +100,17 @@ public class ProcedureTask extends AbstractTaskExecutor { |
|
|
|
|
|
|
|
|
|
|
|
// get jdbc connection
|
|
|
|
// get jdbc connection
|
|
|
|
connection = DataSourceClientProvider.getInstance().getConnection(dbType, connectionParam); |
|
|
|
connection = DataSourceClientProvider.getInstance().getConnection(dbType, connectionParam); |
|
|
|
|
|
|
|
Map<Integer, Property> sqlParamsMap = new HashMap<>(); |
|
|
|
// combining local and global parameters
|
|
|
|
|
|
|
|
Map<String, Property> paramsMap = ParamUtils.convert(taskExecutionContext, getParameters()); |
|
|
|
Map<String, Property> paramsMap = ParamUtils.convert(taskExecutionContext, getParameters()); |
|
|
|
|
|
|
|
String proceduerSql = formatSql(sqlParamsMap, paramsMap); |
|
|
|
// call method
|
|
|
|
// call method
|
|
|
|
stmt = connection.prepareCall(procedureParameters.getMethod()); |
|
|
|
stmt = connection.prepareCall(proceduerSql); |
|
|
|
|
|
|
|
|
|
|
|
// set timeout
|
|
|
|
// set timeout
|
|
|
|
setTimeout(stmt); |
|
|
|
setTimeout(stmt); |
|
|
|
|
|
|
|
|
|
|
|
// outParameterMap
|
|
|
|
// outParameterMap
|
|
|
|
Map<Integer, Property> outParameterMap = getOutParameterMap(stmt, paramsMap); |
|
|
|
Map<Integer, Property> outParameterMap = getOutParameterMap(stmt, sqlParamsMap, paramsMap); |
|
|
|
|
|
|
|
|
|
|
|
stmt.executeUpdate(); |
|
|
|
stmt.executeUpdate(); |
|
|
|
|
|
|
|
|
|
|
@ -130,6 +127,12 @@ public class ProcedureTask extends AbstractTaskExecutor { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String formatSql(Map<Integer, Property> sqlParamsMap, Map<String, Property> paramsMap) { |
|
|
|
|
|
|
|
// combining local and global parameters
|
|
|
|
|
|
|
|
setSqlParamsMap(procedureParameters.getMethod(), rgex, sqlParamsMap, paramsMap, taskExecutionContext.getTaskInstanceId()); |
|
|
|
|
|
|
|
return procedureParameters.getMethod().replaceAll(rgex, "?"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* print outParameter |
|
|
|
* print outParameter |
|
|
|
* |
|
|
|
* |
|
|
@ -145,7 +148,7 @@ public class ProcedureTask extends AbstractTaskExecutor { |
|
|
|
String prop = property.getProp(); |
|
|
|
String prop = property.getProp(); |
|
|
|
DataType dataType = property.getType(); |
|
|
|
DataType dataType = property.getType(); |
|
|
|
// get output parameter
|
|
|
|
// get output parameter
|
|
|
|
getOutputParameter(stmt, index, prop, dataType); |
|
|
|
procedureParameters.dealOutParam4Procedure(getOutputParameter(stmt, index, prop, dataType), prop); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -157,35 +160,26 @@ public class ProcedureTask extends AbstractTaskExecutor { |
|
|
|
* @return outParameterMap |
|
|
|
* @return outParameterMap |
|
|
|
* @throws Exception Exception |
|
|
|
* @throws Exception Exception |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Map<Integer, Property> getOutParameterMap(CallableStatement stmt, Map<String, Property> paramsMap) throws Exception { |
|
|
|
private Map<Integer, Property> getOutParameterMap(CallableStatement stmt, Map<Integer, Property> paramsMap |
|
|
|
|
|
|
|
, Map<String, Property> totalParamsMap) throws Exception { |
|
|
|
Map<Integer, Property> outParameterMap = new HashMap<>(); |
|
|
|
Map<Integer, Property> outParameterMap = new HashMap<>(); |
|
|
|
if (procedureParameters.getLocalParametersMap() == null) { |
|
|
|
if (procedureParameters.getLocalParametersMap() == null) { |
|
|
|
return outParameterMap; |
|
|
|
return outParameterMap; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Collection<Property> userDefParamsList = procedureParameters.getLocalParametersMap().values(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(userDefParamsList)) { |
|
|
|
|
|
|
|
return outParameterMap; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int index = 1; |
|
|
|
int index = 1; |
|
|
|
for (Property property : userDefParamsList) { |
|
|
|
if (paramsMap != null) { |
|
|
|
logger.info("localParams : prop : {} , dirct : {} , type : {} , value : {}" |
|
|
|
for (Map.Entry<Integer, Property> entry : paramsMap.entrySet()) { |
|
|
|
, property.getProp(), |
|
|
|
Property property = entry.getValue(); |
|
|
|
property.getDirect(), |
|
|
|
|
|
|
|
property.getType(), |
|
|
|
|
|
|
|
property.getValue()); |
|
|
|
|
|
|
|
// set parameters
|
|
|
|
|
|
|
|
if (property.getDirect().equals(Direct.IN)) { |
|
|
|
if (property.getDirect().equals(Direct.IN)) { |
|
|
|
ParameterUtils.setInParameter(index, stmt, property.getType(), paramsMap.get(property.getProp()).getValue()); |
|
|
|
ParameterUtils.setInParameter(index, stmt, property.getType(), totalParamsMap.get(property.getProp()).getValue()); |
|
|
|
} else if (property.getDirect().equals(Direct.OUT)) { |
|
|
|
} else if (property.getDirect().equals(Direct.OUT)) { |
|
|
|
setOutParameter(index, stmt, property.getType(), paramsMap.get(property.getProp()).getValue()); |
|
|
|
setOutParameter(index, stmt, property.getType(), totalParamsMap.get(property.getProp()).getValue()); |
|
|
|
property.setValue(paramsMap.get(property.getProp()).getValue()); |
|
|
|
|
|
|
|
outParameterMap.put(index, property); |
|
|
|
outParameterMap.put(index, property); |
|
|
|
} |
|
|
|
} |
|
|
|
index++; |
|
|
|
index++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return outParameterMap; |
|
|
|
return outParameterMap; |
|
|
|
} |
|
|
|
} |
|
|
@ -235,38 +229,49 @@ public class ProcedureTask extends AbstractTaskExecutor { |
|
|
|
* @param dataType dataType |
|
|
|
* @param dataType dataType |
|
|
|
* @throws SQLException SQLException |
|
|
|
* @throws SQLException SQLException |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void getOutputParameter(CallableStatement stmt, int index, String prop, DataType dataType) throws SQLException { |
|
|
|
private Object getOutputParameter(CallableStatement stmt, int index, String prop, DataType dataType) throws SQLException { |
|
|
|
|
|
|
|
Object value = null; |
|
|
|
switch (dataType) { |
|
|
|
switch (dataType) { |
|
|
|
case VARCHAR: |
|
|
|
case VARCHAR: |
|
|
|
logger.info("out prameter varchar key : {} , value : {}", prop, stmt.getString(index)); |
|
|
|
logger.info("out prameter varchar key : {} , value : {}", prop, stmt.getString(index)); |
|
|
|
|
|
|
|
value = stmt.getString(index); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case INTEGER: |
|
|
|
case INTEGER: |
|
|
|
logger.info("out prameter integer key : {} , value : {}", prop, stmt.getInt(index)); |
|
|
|
logger.info("out prameter integer key : {} , value : {}", prop, stmt.getInt(index)); |
|
|
|
|
|
|
|
value = stmt.getInt(index); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case LONG: |
|
|
|
case LONG: |
|
|
|
logger.info("out prameter long key : {} , value : {}", prop, stmt.getLong(index)); |
|
|
|
logger.info("out prameter long key : {} , value : {}", prop, stmt.getLong(index)); |
|
|
|
|
|
|
|
value = stmt.getLong(index); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case FLOAT: |
|
|
|
case FLOAT: |
|
|
|
logger.info("out prameter float key : {} , value : {}", prop, stmt.getFloat(index)); |
|
|
|
logger.info("out prameter float key : {} , value : {}", prop, stmt.getFloat(index)); |
|
|
|
|
|
|
|
value = stmt.getFloat(index); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DOUBLE: |
|
|
|
case DOUBLE: |
|
|
|
logger.info("out prameter double key : {} , value : {}", prop, stmt.getDouble(index)); |
|
|
|
logger.info("out prameter double key : {} , value : {}", prop, stmt.getDouble(index)); |
|
|
|
|
|
|
|
value = stmt.getDouble(index); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DATE: |
|
|
|
case DATE: |
|
|
|
logger.info("out prameter date key : {} , value : {}", prop, stmt.getDate(index)); |
|
|
|
logger.info("out prameter date key : {} , value : {}", prop, stmt.getDate(index)); |
|
|
|
|
|
|
|
value = stmt.getDate(index); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case TIME: |
|
|
|
case TIME: |
|
|
|
logger.info("out prameter time key : {} , value : {}", prop, stmt.getTime(index)); |
|
|
|
logger.info("out prameter time key : {} , value : {}", prop, stmt.getTime(index)); |
|
|
|
|
|
|
|
value = stmt.getTime(index); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case TIMESTAMP: |
|
|
|
case TIMESTAMP: |
|
|
|
logger.info("out prameter timestamp key : {} , value : {}", prop, stmt.getTimestamp(index)); |
|
|
|
logger.info("out prameter timestamp key : {} , value : {}", prop, stmt.getTimestamp(index)); |
|
|
|
|
|
|
|
value = stmt.getTimestamp(index); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BOOLEAN: |
|
|
|
case BOOLEAN: |
|
|
|
logger.info("out prameter boolean key : {} , value : {}", prop, stmt.getBoolean(index)); |
|
|
|
logger.info("out prameter boolean key : {} , value : {}", prop, stmt.getBoolean(index)); |
|
|
|
|
|
|
|
value = stmt.getBoolean(index); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|