Search in sources :

Example 1 with QueryNotUniqueException

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();
    }
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) QueryResult(org.datanucleus.store.query.QueryResult) SQLException(java.sql.SQLException) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) QueryNotUniqueException(org.datanucleus.store.query.QueryNotUniqueException) ResultSet(java.sql.ResultSet) Iterator(java.util.Iterator) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) NoQueryResultsException(org.datanucleus.store.query.NoQueryResultsException)

Example 2 with QueryNotUniqueException

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);
    }
}
Also used : JDOUserException(javax.jdo.JDOUserException) InvocationTargetException(java.lang.reflect.InvocationTargetException) QueryNotUniqueException(org.datanucleus.store.query.QueryNotUniqueException) LookupExecutorException(org.motechproject.mds.exception.lookup.LookupExecutorException)

Aggregations

QueryNotUniqueException (org.datanucleus.store.query.QueryNotUniqueException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Iterator (java.util.Iterator)1 JDOUserException (javax.jdo.JDOUserException)1 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)1 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 ManagedConnection (org.datanucleus.store.connection.ManagedConnection)1 NoQueryResultsException (org.datanucleus.store.query.NoQueryResultsException)1 QueryResult (org.datanucleus.store.query.QueryResult)1 LookupExecutorException (org.motechproject.mds.exception.lookup.LookupExecutorException)1