use of org.datanucleus.store.query.QueryNotUniqueException in project datanucleus-rdbms by datanucleus.
the class StoredProcedureQuery method getNextResults.
@Override
public Object getNextResults() {
if (stmt == null) {
throw new NucleusUserException("Cannot check for more results until the stored procedure has been executed");
}
ManagedConnection mconn = storeMgr.getConnectionManager().getConnection(ec);
try {
resultSetNumber++;
ResultSet rs = stmt.getResultSet();
QueryResult qr = getResultsForResultSet((RDBMSStoreManager) storeMgr, rs, mconn);
if (shouldReturnSingleRow()) {
// Single row only needed so just take first row
try {
if (qr == null || qr.size() == 0) {
throw new NoQueryResultsException("No query results were returned");
}
Iterator qrIter = qr.iterator();
Object firstRow = qrIter.next();
if (qrIter.hasNext()) {
throw new QueryNotUniqueException();
}
return firstRow;
} finally {
// can close results right now because we don't return it
close(qr);
}
}
// Apply range?
return qr;
} catch (SQLException sqle) {
throw new NucleusDataStoreException("Exception from CallableStatement.getResultSet", sqle);
} finally {
mconn.release();
}
}
use of org.datanucleus.store.query.QueryNotUniqueException in project motech by motech.
the class LookupExecutor method execute.
public Object execute(Map<String, ?> lookupMap, QueryParams queryParams) {
List<Object> args = getLookupArgs(lookupMap);
List<Class> argTypes = buildArgTypes();
String lookupExceptionMessage = "Unable to execute lookup ";
String lookupExceptionMessageKey = "mds.error.lookupExecError";
if (queryParams != null) {
args.add(queryParams);
argTypes.add(QueryParams.class);
}
try {
return MethodUtils.invokeMethod(dataService, lookup.getMethodName(), args.toArray(new Object[args.size()]), argTypes.toArray(new Class[argTypes.size()]));
} catch (NoSuchMethodException | IllegalAccessException e) {
throw new LookupExecutorException(lookupExceptionMessage + lookup.getLookupName() + ".", e, null);
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof JDOUserException) {
JDOUserException userException = (JDOUserException) e.getTargetException();
lookupExceptionMessageKey = "mds.error.lookupExecUserError";
for (Throwable exception : userException.getNestedExceptions()) {
if (exception instanceof QueryNotUniqueException) {
lookupExceptionMessageKey = "mds.error.lookupExecNotUniqueError";
}
}
}
throw new LookupExecutorException(lookupExceptionMessage + lookup.getLookupName() + ".", e, lookupExceptionMessageKey);
}
}
Aggregations