Search in sources :

Example 1 with CursoredStream

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

the class RemoteSessionController method cursoredStreamClose.

/**
 * Used for closing cursored streams across RMI.
 */
public Transporter cursoredStreamClose(Transporter remoteCursoredStreamOid) {
    Transporter transporter = new Transporter();
    try {
        ObjID id = (ObjID) (remoteCursoredStreamOid.getObject());
        CursoredStream stream = (CursoredStream) getRemoteCursors().get(id);
        if (stream != null) {
            stream.close();
        }
        getRemoteCursors().remove(id);
    } catch (RuntimeException exception) {
        transporter.setException(exception);
    }
    return transporter;
}
Also used : CursoredStream(org.eclipse.persistence.queries.CursoredStream) ObjID(java.rmi.server.ObjID)

Example 2 with CursoredStream

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

the class RemoteSessionController method cursoredStreamNextpage.

/**
 * Retrieve next page of objects from the remote cursored stream once, avoid page size round trips from the server to the client
 */
public Transporter cursoredStreamNextpage(Transporter remoteCursoredId, int pageSize) {
    Transporter transporter = new Transporter();
    Vector nextPagesObjects = null;
    Map objectDescriptors = new IdentityHashMap(pageSize);
    try {
        CursoredStream stream = (CursoredStream) getRemoteCursors().get(remoteCursoredId.getObject());
        if (stream != null) {
            // retrieve page size of objects from the cursored stream
            nextPagesObjects = stream.nextElements(pageSize);
            for (Enumeration enumtr = nextPagesObjects.elements(); enumtr.hasMoreElements(); ) {
                Object objectNext = enumtr.nextElement();
                if (objectNext == null) {
                    break;
                } else {
                    if (stream.getQuery().isReadAllQuery() && (!stream.getQuery().isReportQuery())) {
                        replaceValueHoldersIn(objectNext, objectDescriptors);
                    }
                }
            }
        } else {
            nextPagesObjects = new Vector(0);
        }
    } catch (RuntimeException exception) {
        transporter.setException(exception);
    }
    transporter.setObjectDescriptors(objectDescriptors);
    transporter.setObject(nextPagesObjects);
    return transporter;
}
Also used : CursoredStream(org.eclipse.persistence.queries.CursoredStream) Enumeration(java.util.Enumeration) IdentityHashMap(java.util.IdentityHashMap) Vector(java.util.Vector) IdentityHashMap(java.util.IdentityHashMap) Map(java.util.Map)

Example 3 with CursoredStream

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

the class AdvancedJPAJunitTest method testCursorStream.

public void testCursorStream() {
    EntityManager em = createEntityManager();
    beginTransaction(em);
    Room room1 = new Room();
    Door east = new Door();
    try {
        // Setup Rooms and Doors
        room1.setId(10001);
        east.setId(100);
        east.setHeight(8);
        east.setWidth(5);
        int year = 2013;
        int month = 1;
        int day = 30;
        east.setSaleDate(Helper.dateFromYearMonthDate(year, month - 1, day));
        east.setRoom(room1);
        room1.addDoor(east);
        try {
            em.persist(room1);
            commitTransaction(em);
        } finally {
            if (isTransactionActive(em)) {
                rollbackTransaction(em);
            }
            closeEntityManager(em);
        }
        em = createEntityManager();
        Query resultsXferQuery = em.createQuery("SELECT r, d " + "FROM Room r " + "JOIN FETCH r.doors " + "LEFT JOIN Door d " + "WHERE d MEMBER OF r.doors");
        resultsXferQuery.setHint(QueryHints.CURSOR, true);
        try {
            CursoredStream stream = (CursoredStream) resultsXferQuery.getSingleResult();
            while (!stream.atEnd()) {
                stream.read();
            }
            stream.clear();
            stream.close();
        } catch (NullPointerException npe) {
            fail("CursoredStream with join threw an NPE");
        }
        // clean up
        beginTransaction(em);
        room1 = em.find(Room.class, room1.getId());
        em.remove(room1);
        commitTransaction(em);
    } finally {
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        closeEntityManager(em);
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) CursoredStream(org.eclipse.persistence.queries.CursoredStream) Query(jakarta.persistence.Query) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) DoesExistQuery(org.eclipse.persistence.queries.DoesExistQuery) TypedQuery(jakarta.persistence.TypedQuery) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) Room(org.eclipse.persistence.testing.models.jpa.advanced.Room) Door(org.eclipse.persistence.testing.models.jpa.advanced.Door)

Example 4 with CursoredStream

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

the class CustomSQLCursoredStreamReadTest method test.

@Override
protected void test() {
    ReadAllQuery query = new ReadAllQuery(Employee.class);
    query.setSQLString("SELECT * FROM EMPLOYEE");
    query.useCursoredStream();
    CursoredStream stream = null;
    try {
        stream = (CursoredStream) getSession().executeQuery(query);
        try {
            stream.size();
        } catch (Exception e) {
            m_exceptionCaughtOnSizeQueryExecution = true;
        }
    } catch (Exception e) {
        m_exceptionCaughtOnSQLQueryExecution = true;
    } finally {
        if (stream != null) {
            stream.close();
        }
    }
}
Also used : CursoredStream(org.eclipse.persistence.queries.CursoredStream) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException)

Example 5 with CursoredStream

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

the class ReportQueryRetrievePrimaryKeysCursorTest method test.

@Override
public void test() {
    CursoredStream stream = (CursoredStream) getSession().executeQuery(reportQuery);
    while (!stream.atEnd()) {
        ReportQueryResult result = (ReportQueryResult) stream.read();
        cursoredResults.put(result.getId(), result);
        stream.releasePrevious();
    }
    stream.close();
}
Also used : CursoredStream(org.eclipse.persistence.queries.CursoredStream) ReportQueryResult(org.eclipse.persistence.queries.ReportQueryResult)

Aggregations

CursoredStream (org.eclipse.persistence.queries.CursoredStream)7 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)3 EntityManager (jakarta.persistence.EntityManager)2 Query (jakarta.persistence.Query)2 TypedQuery (jakarta.persistence.TypedQuery)2 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)2 DatabaseQuery (org.eclipse.persistence.queries.DatabaseQuery)2 DoesExistQuery (org.eclipse.persistence.queries.DoesExistQuery)2 ObjID (java.rmi.server.ObjID)1 Enumeration (java.util.Enumeration)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 Vector (java.util.Vector)1 QueryException (org.eclipse.persistence.exceptions.QueryException)1 CollectionContainerPolicy (org.eclipse.persistence.internal.queries.CollectionContainerPolicy)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 CursorPolicy (org.eclipse.persistence.queries.CursorPolicy)1 ReportQueryResult (org.eclipse.persistence.queries.ReportQueryResult)1 ScrollableCursor (org.eclipse.persistence.queries.ScrollableCursor)1 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)1