Here is the reworked query for posterity:
def getComments() {
List comments
List results
if (this.comments.isEmpty()) {
return this.comments
}
PersistenceManager pm = PMF.get().getPersistenceManager()
try {
javax.jdo.Query q = pm.newQuery("select from " +
Comment.class.getName() +
" where host == :host")
q.setOrdering("datetime desc");
q.setRange(0, 5);
results = q.execute(this.key);
Cursor cursor = JDOCursorHelper.getCursor(results);
if(cursor != null){
this.cursorString = cursor.toWebSafeString();
}
comments = pm.detachCopyAll((List) results)
comments.size();
return comments
} finally {
pm.close()
}
}
Thanks again!
On Mon, Mar 8, 2010 at 12:45 PM, atomi <[email protected]> wrote:
> Nevermind, I think I got this. Thanks all.
>
>
> On Mon, Mar 8, 2010 at 12:41 PM, atomi <[email protected]> wrote:
>
>> Sorry to have to ask, But can you hint as to how I should rewrite this
>> query so as to have cursors working?
>>
>>
>> On Mon, Mar 8, 2010 at 12:40 PM, atomi <[email protected]> wrote:
>>
>>> Thank you John, I wasn't clear IN was contains() as well.
>>>
>>>
>>> On Mon, Mar 8, 2010 at 12:36 PM, John Patterson
>>> <[email protected]>wrote:
>>>
>>>> Cursors are not supported for queries that use IN (contains) because
>>>> under the covers they are broken into multiple queries and merged together.
>>>>
>>>>
>>>> http://code.google.com/appengine/docs/java/datastore/queriesandindexes.html#Query_Cursors
>>>>
>>>>
>>>> On 9 Mar 2010, at 03:21, atomi wrote:
>>>>
>>>> I'm trying to get cursors working with a result set but the
>>>>> JDOCursorHelper.getCursor() method returns null for every query result
>>>>> that
>>>>> is greater than 1
>>>>> here is my entity method
>>>>> Item entity:
>>>>>
>>>>> @Element(dependent = "true")
>>>>> @Persistent(defaultFetchGroup="true",loadFetchGroup="true")
>>>>> List<String> comments = new ArrayList<String>();
>>>>>
>>>>> def getComments() {
>>>>> List comments
>>>>> List results
>>>>>
>>>>> if (this.comments.isEmpty()) {
>>>>> return this.comments
>>>>> }
>>>>>
>>>>> PersistenceManager pm =
>>>>> PMF.get().getPersistenceManager()
>>>>> try {
>>>>> javax.jdo.Query q = pm.newQuery("select from " +
>>>>> Comment.class.getName() +
>>>>> " where :keys.contains(key)")
>>>>> q.setOrdering("datetime desc");
>>>>> q.setRange(0, 5);
>>>>> results = q.execute(this.comments);
>>>>>
>>>>> Cursor cursor =
>>>>> JDOCursorHelper.getCursor(results);
>>>>> if(cursor != null){
>>>>> this.cursorString =
>>>>> cursor.toWebSafeString();
>>>>> }
>>>>>
>>>>> comments = pm.detachCopyAll((List) results)
>>>>> comments.size();
>>>>>
>>>>> return comments
>>>>> } finally {
>>>>> pm.close()
>>>>> }
>>>>> }
>>>>>
>>>>> Can someone tell me why?
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Google App Engine for Java" group.
>>>>> To post to this group, send email to
>>>>> [email protected].
>>>>> To unsubscribe from this group, send email to
>>>>> [email protected]<google-appengine-java%[email protected]>
>>>>> .
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/google-appengine-java?hl=en.
>>>>>
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Google App Engine for Java" group.
>>>> To post to this group, send email to
>>>> [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected]<google-appengine-java%[email protected]>
>>>> .
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/google-appengine-java?hl=en.
>>>>
>>>>
>>>
>>
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.