surinder-insonix / datanucleus-appengine

Automatically exported from code.google.com/p/datanucleus-appengine
0 stars 0 forks source link

JPACursorHelper.getCursor return null for 2.0.1 #288

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

 Query query = em.createQuery(queryString);        
        cursor = Cursor.fromWebSafeString(cursorString);
    query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
        query.setMaxResults(pageSize);

        final List<Key> friendList = (List<Key>) query.getResultList();
        cursor = JPACursorHelper.getCursor(friendList);

cursor is always null

What is the expected output? What do you see instead?

expect cursor to be non null.

What version of the product are you using? On what operating system?

appengine sdk 1.6.6

<dependency>
            <groupId>com.google.appengine.orm</groupId>
            <artifactId>datanucleus-appengine</artifactId>
            <version>2.0.1</version>            
</dependency>

Please provide any additional information below.

the above code works fine upto version 2.0.0 but broken on 2.0.1

Original issue reported on code.google.com by lu...@miiingle.com on 27 Jun 2012 at 1:05

GoogleCodeExporter commented 8 years ago
All tests for "JPACursorHelper" are clearly shown in public SVN at
http://code.google.com/p/datanucleus-appengine/source/browse/trunk/tests/com/goo
gle/appengine/datanucleus/query/JPQLCursorTest.java

They demonstrate all supported usages, and pass with every release (1.x, 2.0, 
2.1). I'd suggest you inspect them and identify why yours is different, and/or 
contribuet a patch to SVN trunk to add on a further test, and preferably a 
patch to add that capability too

Original comment by googleco...@yahoo.co.uk on 8 Jul 2012 at 9:47

GoogleCodeExporter commented 8 years ago

Original comment by googleco...@yahoo.co.uk on 15 Jul 2012 at 11:37

GoogleCodeExporter commented 8 years ago
the null cursor occurs when doing a key only query.
i have a test case that shows issue.

test case attached.

i havent got a fix for it yet.

class  JPQLCursorTest
--------------------------

 public void testGetCursor_KeyOnlyList() {
    Entity e1 = Book.newBookEntity("auth", "34", "yar");
    Entity e2 = Book.newBookEntity("auth", "34", "yar");
    Entity e3 = Book.newBookEntity("auth", "34", "yar");
    ds.put(Arrays.asList(e1, e2, e3));

    beginTxn();
    Query q = em.createQuery("select id from " + Book.class.getName() + " b");
    q.setMaxResults(1);
    List<String> books = (List<String>) q.getResultList();
    assertEquals(1, books.size());
    assertEquals(e1.getKey(), KeyFactory.stringToKey(books.get(0)));
    Cursor c = JPACursorHelper.getCursor(books);
    assertNotNull(c);

    q.setHint(JPACursorHelper.CURSOR_HINT, c);
    books = (List<String>) q.getResultList();
    assertEquals(1, books.size());
    assertEquals(e2.getKey(), KeyFactory.stringToKey(books.get(0)));
    assertNotNull(JPACursorHelper.getCursor(books));

    q.setHint(JPACursorHelper.CURSOR_HINT, c.toWebSafeString());
    books = (List<String>) q.getResultList();
    assertEquals(1, books.size());
    assertEquals(e2.getKey(), KeyFactory.stringToKey(books.get(0)));
    c = JPACursorHelper.getCursor(books);
    assertNotNull(c);

    q.setHint(JPACursorHelper.CURSOR_HINT, c);
    books = (List<String>) q.getResultList();
    assertEquals(1, books.size());
    assertEquals(e3.getKey(), KeyFactory.stringToKey(books.get(0)));
    assertNotNull(JPACursorHelper.getCursor(books));

    q.setHint(JPACursorHelper.CURSOR_HINT, c.toWebSafeString());
    books = (List<String>) q.getResultList();
    assertEquals(1, books.size());
    assertEquals(e3.getKey(), KeyFactory.stringToKey(books.get(0)));
    assertNotNull(JPACursorHelper.getCursor(books));

    commitTxn();
  }

Original comment by lu...@miiingle.com on 19 Jul 2012 at 12:03

GoogleCodeExporter commented 8 years ago
Hi, I have the same problem, with the generated code by Google eclipse plugin 
the Cursor is NULL, this is the generated code, this always return null

APP Engine 1.9.3
Eclipse Kepler Standard.

Best Regards

@SuppressWarnings({ "unchecked", "unused" })
    @ApiMethod(name = "listPedido")
    public CollectionResponse<Pedido> listPedido(
            @Nullable @Named("cursor") String cursorString,
            @Nullable @Named("limit") Integer limit) {

        EntityManager mgr = null;
        Cursor cursor = null;
        List<Pedido> execute = null;

        try {
            mgr = getEntityManager();
            Query query = mgr.createQuery("select from Pedido as Pedido");
            if (cursorString != null && cursorString != "") {
                cursor = Cursor.fromWebSafeString(cursorString);
                query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
            }

            if (limit != null) {
                query.setFirstResult(0);
                query.setMaxResults(limit);
            }

            execute = (List<Pedido>) query.getResultList();
            cursor = JPACursorHelper.getCursor(execute);
            if (cursor != null)
                cursorString = cursor.toWebSafeString();

            // Tight loop for fetching all entities from datastore and accomodate
            // for lazy fetch.
            for (Pedido obj : execute)
                ;
        } finally {
            mgr.close();
        }

        return CollectionResponse.<Pedido> builder().setItems(execute)
                .setNextPageToken(cursorString).build();
    }

Original comment by Ramses.B...@gmail.com on 12 Aug 2014 at 6:50