* @see {@link Operation}
*/
@SuppressWarnings("rawtypes")
@Override
public Object invoke(XRServiceAdapter xrService, Invocation invocation) {
DatabaseQuery query = classDescriptor.getQueryManager().getQuery(getFindByPKQuery());
// a named query created via ORM metadata processing needs initialization
if (query instanceof JPAQuery) {
query = ((JPAQuery) query).processSQLQuery(xrService.getORSession().getActiveSession());
}
UnitOfWork uow = xrService.getORSession().acquireUnitOfWork();
Object toBeDeleted;
// a query created via ORM metadata processing does not have parameters set, however, the operation should
if (query.getArguments().size() == 0) {
int idx = 0;
for (Parameter param : getParameters()) {
// for custom SQL query (as configured via ORM metadata processing) we add args by position
query.addArgument(Integer.toString(++idx), Util.SCHEMA_2_CLASS.get(param.getType()));
query.addArgumentValue(invocation.getParameter(param.getName()));
}
toBeDeleted = uow.executeQuery(query);
} else {
// set query args or execute args for the non-JPAQuery case,
// i.e. stored proc/funcs get populated from ORM metadata
// whereas named queries (SQL strings) do not...
List queryArguments = query.getArguments();
int queryArgumentsSize = queryArguments.size();
Vector executeArguments = new NonSynchronizedVector();
for (int i = 0; i < queryArgumentsSize; i++) {
String argName = (String)queryArguments.get(i);
executeArguments.add(invocation.getParameter(argName));