public void test() { // stored procedure call StoredProcedureCall spCall = new StoredProcedureCall(); spCall.setProcedureName("Read_All_Employees"); spCall.useNamedCursorOutputAsResultSet("RESULT_CURSOR"); // query DirectReadQuery query = new DirectReadQuery(); query.setCall(spCall); query.useScrollableCursor(); cursor = (ScrollableCursor) getSession().executeQuery(query); // If the driver returns a forward-only ResultSet initialized to afterLast there's nothing // ScrollableCursor can do with it. try { if ((cursor.getResultSet().isAfterLast()) && (cursor.getResultSet().getType() == java.sql.ResultSet.TYPE_FORWARD_ONLY)) { throwWarning( "The ResultSet returned from the query is TYPE_FORWARD_ONLY and initialized to afterLast."); } } catch (java.sql.SQLException sqle) { throwWarning("Unexpected SQLException thrown while checking the ResultSet."); } // iterate the cursor try { while (cursor.hasNext()) { cursor.next(); } } catch (org.eclipse.persistence.exceptions.DatabaseException dbe) { caughtException = dbe; } finally { if (cursor != null) { cursor.close(); } } }
public void test() { ReadAllQuery query = new ReadAllQuery(); ScrollableCursor cursor = null; try { query.setReferenceClass(Employee.class); if (TYPE_SCROLL_INSENSITIVE_isSupported && CONCUR_UPDATABLE_isSupported) { query.useScrollableCursor(2); } else { ScrollableCursorPolicy policy = new ScrollableCursorPolicy(); if (!TYPE_SCROLL_INSENSITIVE_isSupported) { policy.setResultSetType(ScrollableCursorPolicy.TYPE_SCROLL_SENSITIVE); } if (!CONCUR_UPDATABLE_isSupported) { policy.setResultSetConcurrency(ScrollableCursorPolicy.CONCUR_READ_ONLY); } policy.setPageSize(2); query.useScrollableCursor(policy); } // if (configuration != null) { ExpressionBuilder builder = new ExpressionBuilder(); Expression exp = builder.get("salary").greaterThan(50000); query.setSelectionCriteria(exp); query.conformResultsInUnitOfWork(); } cursor = (ScrollableCursor) getSession().executeQuery(query); try { // test to see if we can iterate through a list and then iterate // in reverse through the same list. int totalItems = 0; while (cursor.hasNext()) { readWithNext.addElement(cursor.next()); totalItems++; } while (cursor.hasPrevious()) { readWithPrevious.addElement(cursor.previous()); totalItems--; } cursorSuccess = (totalItems == 0); int size = readWithPrevious.size(); for (int i = 0; i < readWithNext.size(); i++) { cursorSuccess = (cursorSuccess && (readWithNext.elementAt(i) == readWithPrevious.elementAt((size - 1) - i))); } } catch (org.eclipse.persistence.exceptions.QueryException ex) { caughtException = ex; } } finally { if (cursor != null) { cursor.close(); } } }