I am using MS SQL Server
It has been recommended to use some hints to help our Report Queries.
option (maxdop 1)
to the end of the query
i.e. SELECT xxx FROM CUSTOMERS WHERE customerID = 'ALFK' order by customerType option (maxdop 1)
The following method does not work, but it conveys the idea of what I would like to accomplish. Our report queries are created using the ExpressionBuilders and not "Raw SQL".
private Object doExecuteQuery(Session session, DatabaseQuery request)
String HINT = "option (maxdop 1)"
if (request instanceof ReportQuery)
String sql = request.getSQLString();
request.setSQLString(sql + " " + HINT);
Is there a way to append SQL to the end of a query? The postFixSQL() methods only append to the end of the where clause, not the end of the whole query, which is what I need.
At this point I believe you are limited to providing the full SQL in your named query. There is not a way to use the query/expression API to specify that this additional hint should be appended.
The following is what you need to do to get the actual SQL that TopLink will send (regardless of query type, binding or no binding), and then modify it:
SQLCall call = request.getCall();
String sql = call.getSQLString();
call.setSQLString(sql + " " + HINT);
The vectorOfQueryArgs is the collection of arguments needed to execute the query - this can be an empty Vector if the query doesn't take any. Since the query has been prepared already, SQL string changes can be set on the SQLCall itself to save TopLink having to create a new SQLCall object and parse the string.