use of com.ctrip.platform.dal.dao.StatementParameter in project dal by ctripcorp.
the class DalDirectClient method call.
@Override
public Map<String, ?> call(String callString, StatementParameters parameters, final DalHints hints) throws SQLException {
ConnectionAction<Map<String, ?>> action = new ConnectionAction<Map<String, ?>>() {
@Override
public Map<String, ?> execute() throws Exception {
List<StatementParameter> resultParameters = new ArrayList<StatementParameter>();
List<StatementParameter> callParameters = new ArrayList<StatementParameter>();
for (StatementParameter parameter : parameters.values()) {
if (parameter.isResultsParameter()) {
resultParameters.add(parameter);
} else if (parameter.isOutParameter()) {
callParameters.add(parameter);
}
}
if (hints.is(DalHintEnum.retrieveAllSpResults) && resultParameters.size() > 0)
throw new DalException("Dal hint 'autoRetrieveAllResults' should only be used when there is no special result parameter specified");
conn = getConnection(hints, this);
callableStatement = createCallableStatement(conn, callString, parameters, hints);
DalWatcher.beginExecute();
boolean retVal = callableStatement.execute();
int updateCount = callableStatement.getUpdateCount();
DalWatcher.endExectue();
Map<String, Object> returnedResults = new LinkedHashMap<String, Object>();
if (retVal || updateCount != -1) {
returnedResults.putAll(extractReturnedResults(callableStatement, resultParameters, updateCount, hints));
}
returnedResults.putAll(extractOutputParameters(callableStatement, callParameters));
return returnedResults;
}
};
action.populateSp(callString, parameters);
return doInConnection(action, hints);
}
use of com.ctrip.platform.dal.dao.StatementParameter in project dal by ctripcorp.
the class DalDirectClient method extractOutputParameters.
private Map<String, Object> extractOutputParameters(CallableStatement statement, List<StatementParameter> callParameters) throws SQLException {
Map<String, Object> returnedResults = new LinkedHashMap<String, Object>();
for (StatementParameter parameter : callParameters) {
Object value = parameter.getName() == null ? statement.getObject(parameter.getIndex()) : statement.getObject(parameter.getName());
parameter.setValue(value);
if (value instanceof ResultSet) {
value = parameter.getResultSetExtractor().extract(statement.getResultSet());
}
returnedResults.put(parameter.getName(), value);
}
return returnedResults;
}
use of com.ctrip.platform.dal.dao.StatementParameter in project dal by ctripcorp.
the class AbstractSqlBuilder method buildParameters.
/**
* 获取StatementParameters
* @return
*/
public StatementParameters buildParameters() {
parameters = new StatementParameters();
index = 1;
for (FieldEntry entry : selectOrUpdataFieldEntrys) {
parameters.add(new StatementParameter(index++, entry.getSqlType(), entry.getParamValue()).setSensitive(entry.isSensitive()).setName(entry.getFieldName()).setInParam(entry.isInParam()));
}
for (FieldEntry entry : whereFieldEntrys) {
parameters.add(new StatementParameter(index++, entry.getSqlType(), entry.getParamValue()).setSensitive(entry.isSensitive()).setName(entry.getFieldName()).setInParam(entry.isInParam()));
}
return this.parameters;
}
use of com.ctrip.platform.dal.dao.StatementParameter in project dal by ctripcorp.
the class DalSqlTaskRequest method getShards.
private Set<String> getShards() throws SQLException {
Set<String> shards = null;
if (!DalShardingHelper.isShardingEnabled(logicDbName))
return null;
if (hints.isAllShards()) {
shards = DalClientFactory.getDalConfigure().getDatabaseSet(logicDbName).getAllShards();
} else if (hints.isInShards()) {
shards = (Set<String>) hints.get(DalHintEnum.shards);
} else if (hints.isShardBy()) {
// The new code gen will set hints shardBy to indicate this is a potential cross shard operation
// Check parameters. It can only surpport DB shard at this level
StatementParameter parameter = parameters.get(hints.getShardBy(), ParameterDirection.Input);
parametersByShard = DalShardingHelper.shuffle(logicDbName, (List) parameter.getValue());
shards = parametersByShard.keySet();
}
if (shards != null && shards.size() > 1)
logger.warn("Execute on multiple shards detected: " + builder.build());
return shards;
}
Aggregations