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;
}
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;
}
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);
}
}
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();
}
}
}
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();
}
Aggregations