Search in sources :

Example 1 with NoQueryResultsException

use of org.datanucleus.store.query.NoQueryResultsException in project datanucleus-api-jdo by datanucleus.

the class JDOQuery method deletePersistentInternal.

protected long deletePersistentInternal() {
    try {
        if (parameterValues != null) {
            return query.deletePersistentAll(parameterValues);
        } else if (parameterValueByName != null) {
            return query.deletePersistentAll(parameterValueByName);
        }
        return query.deletePersistentAll();
    } catch (NoQueryResultsException nqre) {
        return 0;
    } catch (QueryTimeoutException qte) {
        throw new JDODataStoreException("Query has timed out : " + qte.getMessage());
    } catch (QueryInterruptedException qie) {
        throw new JDOQueryInterruptedException("Query has been cancelled : " + qie.getMessage());
    } catch (NucleusException jpe) {
        throw NucleusJDOHelper.getJDOExceptionForNucleusException(jpe);
    } finally {
        // Parameter values are not retained beyond subsequent execute/deletePersistentAll
        this.parameterValueByName = null;
        this.parameterValues = null;
    }
}
Also used : QueryTimeoutException(org.datanucleus.store.query.QueryTimeoutException) NucleusException(org.datanucleus.exceptions.NucleusException) NoQueryResultsException(org.datanucleus.store.query.NoQueryResultsException) JDODataStoreException(javax.jdo.JDODataStoreException) QueryInterruptedException(org.datanucleus.store.query.QueryInterruptedException) JDOQueryInterruptedException(javax.jdo.JDOQueryInterruptedException) JDOQueryInterruptedException(javax.jdo.JDOQueryInterruptedException)

Example 2 with NoQueryResultsException

use of org.datanucleus.store.query.NoQueryResultsException in project datanucleus-api-jdo by datanucleus.

the class JDOQuery method executeInternal.

protected Object executeInternal() {
    try {
        if (parameterValues != null) {
            return query.executeWithArray(parameterValues);
        } else if (parameterValueByName != null) {
            return query.executeWithMap(parameterValueByName);
        }
        return query.execute();
    } catch (NoQueryResultsException nqre) {
        return null;
    } catch (QueryTimeoutException qte) {
        throw new JDODataStoreException("Query has timed out : " + qte.getMessage());
    } catch (QueryInterruptedException qie) {
        throw new JDOQueryInterruptedException("Query has been cancelled : " + qie.getMessage());
    } catch (NucleusException jpe) {
        // Convert any exceptions into what JDO expects
        throw NucleusJDOHelper.getJDOExceptionForNucleusException(jpe);
    } finally {
        // Parameter values are not retained beyond subsequent execute/deletePersistentAll
        this.parameterValueByName = null;
        this.parameterValues = null;
    }
}
Also used : QueryTimeoutException(org.datanucleus.store.query.QueryTimeoutException) NucleusException(org.datanucleus.exceptions.NucleusException) NoQueryResultsException(org.datanucleus.store.query.NoQueryResultsException) JDODataStoreException(javax.jdo.JDODataStoreException) QueryInterruptedException(org.datanucleus.store.query.QueryInterruptedException) JDOQueryInterruptedException(javax.jdo.JDOQueryInterruptedException) JDOQueryInterruptedException(javax.jdo.JDOQueryInterruptedException)

Example 3 with NoQueryResultsException

use of org.datanucleus.store.query.NoQueryResultsException 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)

Aggregations

NoQueryResultsException (org.datanucleus.store.query.NoQueryResultsException)3 JDODataStoreException (javax.jdo.JDODataStoreException)2 JDOQueryInterruptedException (javax.jdo.JDOQueryInterruptedException)2 NucleusException (org.datanucleus.exceptions.NucleusException)2 QueryInterruptedException (org.datanucleus.store.query.QueryInterruptedException)2 QueryTimeoutException (org.datanucleus.store.query.QueryTimeoutException)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Iterator (java.util.Iterator)1 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)1 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 ManagedConnection (org.datanucleus.store.connection.ManagedConnection)1 QueryNotUniqueException (org.datanucleus.store.query.QueryNotUniqueException)1 QueryResult (org.datanucleus.store.query.QueryResult)1