use of org.datanucleus.store.rdbms.sql.SQLStatementParameter in project datanucleus-rdbms by datanucleus.
the class BulkFetchHandler method applyParametersToStatement.
/**
* Convenience method to apply the passed parameters to the provided bulk-fetch statement.
* Takes care of applying parameters across any UNIONs of elements.
* @param ec ExecutionContext
* @param ps PreparedStatement
* @param datastoreCompilation The datastore compilation for the query itself
* @param sqlStmt The bulk-fetch iterator statement
* @param parameters The map of parameters passed in to the query
*/
public static void applyParametersToStatement(ExecutionContext ec, PreparedStatement ps, RDBMSQueryCompilation datastoreCompilation, SQLStatement sqlStmt, Map parameters) {
Map<Integer, String> stmtParamNameByPosition = null;
List<SQLStatementParameter> stmtParams = null;
if (datastoreCompilation.getStatementParameters() != null) {
stmtParams = new ArrayList<>();
stmtParams.addAll(datastoreCompilation.getStatementParameters());
SelectStatement selectStmt = (SelectStatement) sqlStmt;
int numUnions = selectStmt.getNumberOfUnions();
for (int i = 0; i < numUnions; i++) {
stmtParams.addAll(datastoreCompilation.getStatementParameters());
}
if (datastoreCompilation.getParameterNameByPosition() != null && datastoreCompilation.getParameterNameByPosition().size() > 0) {
// ParameterNameByPosition is only populated with implicit parameters
stmtParamNameByPosition = new HashMap<>();
stmtParamNameByPosition.putAll(datastoreCompilation.getParameterNameByPosition());
int numParams = stmtParamNameByPosition.size();
for (int i = 0; i < numUnions; i++) {
Iterator<Map.Entry<Integer, String>> paramEntryIter = datastoreCompilation.getParameterNameByPosition().entrySet().iterator();
while (paramEntryIter.hasNext()) {
Map.Entry<Integer, String> paramEntry = paramEntryIter.next();
stmtParamNameByPosition.put(numParams * (i + 1) + paramEntry.getKey(), paramEntry.getValue());
}
}
}
SQLStatementHelper.applyParametersToStatement(ps, ec, stmtParams, stmtParamNameByPosition, parameters);
}
}
Aggregations