Search in sources :

Example 1 with ScrollableCursor

use of org.eclipse.persistence.queries.ScrollableCursor in project eclipselink by eclipse-ee4j.

the class ScrollableCursorJoinedAttributeTest method test.

@Override
public void test() {
    if (getSession().getPlatform().isHANA() || getSession().getPlatform().isSQLServer()) {
        throw new TestWarningException("ScrollableCursor is not supported on this platform");
    }
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    cursoredResults = new Vector();
    ReadAllQuery cursoredQuery = new ReadAllQuery(Employee.class);
    cursoredQuery.useScrollableCursor();
    cursoredQuery.addJoinedAttribute(cursoredQuery.getExpressionBuilder().anyOfAllowingNone("phoneNumbers"));
    cursoredQuery.addOrdering(cursoredQuery.getExpressionBuilder().get("id"));
    try {
        ScrollableCursor cursor = (ScrollableCursor) getSession().executeQuery(cursoredQuery);
        while (cursor.hasNext()) {
            Object result = cursor.next();
            cursoredResults.add(result);
        }
        cursor.close();
    } catch (Exception e) {
        caughtException = e;
    }
}
Also used : ScrollableCursor(org.eclipse.persistence.queries.ScrollableCursor) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) Vector(java.util.Vector) TestWarningException(org.eclipse.persistence.testing.framework.TestWarningException) TestWarningException(org.eclipse.persistence.testing.framework.TestWarningException)

Example 2 with ScrollableCursor

use of org.eclipse.persistence.queries.ScrollableCursor in project eclipselink by eclipse-ee4j.

the class ScrollableCursorJoiningVerificationTest method test.

@Override
public void test() {
    if (getSession().getPlatform().isHANA() || getSession().getPlatform().isSQLServer()) {
        throw new TestWarningException("ScrollableCursor is not supported on this platform");
    }
    // non-cursored results
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    ReadAllQuery nonCursoredQuery = new ReadAllQuery(Employee.class);
    nonCursoredQuery.dontCheckCache();
    nonCursoredQuery.addJoinedAttribute(nonCursoredQuery.getExpressionBuilder().anyOfAllowingNone("phoneNumbers"));
    nonCursoredQuery.addOrdering(nonCursoredQuery.getExpressionBuilder().get("id"));
    nonCursoredResults = (List) getSession().executeQuery(nonCursoredQuery);
    // forward cursored results
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    forwardCursoredResults = new ArrayList<Employee>();
    ReadAllQuery cursoredQuery = new ReadAllQuery(Employee.class);
    nonCursoredQuery.dontCheckCache();
    cursoredQuery.useScrollableCursor();
    cursoredQuery.addJoinedAttribute(cursoredQuery.getExpressionBuilder().anyOfAllowingNone("phoneNumbers"));
    cursoredQuery.addOrdering(cursoredQuery.getExpressionBuilder().get("id"));
    ScrollableCursor cursor = (ScrollableCursor) getSession().executeQuery(cursoredQuery);
    while (cursor.hasNext()) {
        Employee result = (Employee) cursor.next();
        forwardCursoredResults.add(result);
    }
    // reverse cursored results - use the same cursor
    reverseCursoredResults = new ArrayList();
    while (cursor.hasPrevious()) {
        Employee result = (Employee) cursor.previous();
        reverseCursoredResults.add(result);
    }
    cursor.close();
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ScrollableCursor(org.eclipse.persistence.queries.ScrollableCursor) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ArrayList(java.util.ArrayList) TestWarningException(org.eclipse.persistence.testing.framework.TestWarningException)

Example 3 with ScrollableCursor

use of org.eclipse.persistence.queries.ScrollableCursor in project eclipselink by eclipse-ee4j.

the class RemoteSessionController method scrollableCursorNextObject.

/**
 * Retrieve next object from the scrollable cursor
 */
public Transporter scrollableCursorNextObject(Transporter remoteScrollableCursorOid) {
    Transporter transporter = new Transporter();
    try {
        ScrollableCursor stream = (ScrollableCursor) getRemoteCursors().get(remoteScrollableCursorOid.getObject());
        if (stream != null) {
            Object objectNext = null;
            // For bug 2797683 read beyond end of stream exception should not be thrown here: called first by RemoteScrollableCursor.hasNext().
            if (stream.hasNext()) {
                objectNext = stream.next();
            }
            if (objectNext == null) {
                // 2612538 - the default size of Map (32) is appropriate
                transporter.setObjectDescriptors(new IdentityHashMap());
            } else {
                if (stream.getQuery().isReadAllQuery() && (!stream.getQuery().isReportQuery())) {
                    transporter.setObjectDescriptors(replaceValueHoldersIn(objectNext));
                }
            }
            transporter.setObject(objectNext);
        }
    } catch (RuntimeException exception) {
        transporter.setException(exception);
    }
    return transporter;
}
Also used : ScrollableCursor(org.eclipse.persistence.queries.ScrollableCursor) IdentityHashMap(java.util.IdentityHashMap)

Example 4 with ScrollableCursor

use of org.eclipse.persistence.queries.ScrollableCursor in project eclipselink by eclipse-ee4j.

the class RemoteSessionController method scrollableCursorPreviousObject.

/**
 * Retrieve previous object from the scrollable cursor
 */
public Transporter scrollableCursorPreviousObject(Transporter remoteScrollableCursorOid) {
    Transporter transporter = new Transporter();
    try {
        ScrollableCursor stream = (ScrollableCursor) getRemoteCursors().get(remoteScrollableCursorOid.getObject());
        if (stream != null) {
            Object objectPrevious = null;
            // For bug 2797683 read beyond end of stream exception should not be thrown here: called first by RemoteScrollableCursor.hasNext().
            if (stream.hasPrevious()) {
                objectPrevious = stream.previous();
            }
            if (objectPrevious == null) {
                // 2612538 - the default size of Map (32) is appropriate
                transporter.setObjectDescriptors(new IdentityHashMap());
            } else {
                if (stream.getQuery().isReadAllQuery() && (!stream.getQuery().isReportQuery())) {
                    transporter.setObjectDescriptors(replaceValueHoldersIn(objectPrevious));
                }
            }
            transporter.setObject(objectPrevious);
        }
    } catch (RuntimeException exception) {
        transporter.setException(exception);
    }
    return transporter;
}
Also used : ScrollableCursor(org.eclipse.persistence.queries.ScrollableCursor) IdentityHashMap(java.util.IdentityHashMap)

Example 5 with ScrollableCursor

use of org.eclipse.persistence.queries.ScrollableCursor in project eclipselink by eclipse-ee4j.

the class RemoteSessionController method closeScrollableCursor.

/**
 * Used for closing scrolable cursor across RMI.
 */
public Transporter closeScrollableCursor(ObjID id) {
    Transporter transporter = new Transporter();
    try {
        ScrollableCursor stream = (ScrollableCursor) getRemoteCursors().get(id);
        if (stream != null) {
            stream.close();
        }
        getRemoteCursors().remove(id);
    } catch (RuntimeException exception) {
        transporter.setException(exception);
    }
    return transporter;
}
Also used : ScrollableCursor(org.eclipse.persistence.queries.ScrollableCursor)

Aggregations

ScrollableCursor (org.eclipse.persistence.queries.ScrollableCursor)11 EntityManager (jakarta.persistence.EntityManager)4 Query (jakarta.persistence.Query)4 TypedQuery (jakarta.persistence.TypedQuery)3 JpaQuery (org.eclipse.persistence.jpa.JpaQuery)3 Cursor (org.eclipse.persistence.queries.Cursor)3 CriteriaQuery (jakarta.persistence.criteria.CriteriaQuery)2 IdentityHashMap (java.util.IdentityHashMap)2 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)2 TestWarningException (org.eclipse.persistence.testing.framework.TestWarningException)2 Employee (org.eclipse.persistence.testing.models.jpa.advanced.Employee)2 ArrayList (java.util.ArrayList)1 Vector (java.util.Vector)1 CollectionContainerPolicy (org.eclipse.persistence.internal.queries.CollectionContainerPolicy)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 CursorPolicy (org.eclipse.persistence.queries.CursorPolicy)1 CursoredStream (org.eclipse.persistence.queries.CursoredStream)1 ReadQuery (org.eclipse.persistence.queries.ReadQuery)1 Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)1 Test (org.junit.Test)1