stmt = conn.prepareStatement(processedSQL);
}
} else if (queryType == SQLQuery.DS_QUERY_TYPE_STORED_PROC) {
stmt = conn.prepareCall(processedSQL);
} else {
throw new DataServiceFault("Unsupported query type: " + queryType);
}
} else {
inTheMiddleOfABatch = true;
}
if (!inTheMiddleOfABatch) {
/* set query timeout */
if (this.isHasQueryTimeout()) {
stmt.setQueryTimeout(this.getQueryTimeout());
}
/* set fetch direction */
if (this.isHasFetchDirection()) {
stmt.setFetchDirection(this.getFetchDirection());
}
/* set fetch size - user's setting */
if (this.isHasFetchSize()) {
stmt.setFetchSize(this.getFetchSize());
} else {
/* stream data by sections - avoid the full result set to be loaded to memory,
* and only stream if there aren't any OUT parameters, MySQL fails in the scenario
* of streaming and OUT parameters, so the possibility is there for other DBMSs */
if (!this.hasOutParams()) {
stmt.setFetchSize(this.getOptimalRSFetchSize());
}
}
/* set max field size */
if (this.isHasMaxFieldSize()) {
stmt.setMaxFieldSize(this.getMaxFieldSize());
}
/* set max rows */
if (this.isHasMaxRows()) {
stmt.setMaxRows(this.getMaxRows());
}
}
int currentOrdinal = 0;
InternalParam param = null;
ParamValue value = null;
int count = this.getParamCount();
for (int i = 1; i <= count; i++) {
param = params.getParam(i);
value = param.getValue();
/* handle array values, if value is null, this param has to be an OUT param */
if (value != null && value.getValueType() == ParamValue.PARAM_VALUE_ARRAY) {
for (String arrayElement : value.getArrayValue()) {
this.setParamInPreparedStatement(stmt, param.getName(), arrayElement,
param.getSqlType(), param.getType(), queryType, currentOrdinal);
currentOrdinal++;
}
} else { /* scalar value */
this.setParamInPreparedStatement(stmt, param.getName(),
value != null ? value.getScalarValue() : null,
param.getSqlType(), param.getType(), queryType, currentOrdinal);
currentOrdinal++;
}
}
/* if we are in JDBC batch processing mode, batch it! */
if (this.isJDBCBatchRequest()) {
stmt.addBatch();
}
return stmt;
} catch (SQLException e) {
throw new DataServiceFault(e, "Error in 'createProcessedPreparedStatement'");
}
}