[appengine-java] Re: How to make a query using low level API using the 'key' property?

2009-09-11 Thread Max Ross
Your use of key filters and sorts sounds appropriate.

On Wed, Sep 9, 2009 at 12:22 AM, Corneliu Paul Lupulet <
corneliu.lupu...@gmail.com> wrote:

> Hello,
>
> Thank you for you answers. I would like to make a clarification, why i am
> using the key "property" in a query.
>
> Using an order by key, I am saving the key of the last modified object as a
> bookmark/cursor to know where to resume the processing from. (i also use
> this for pagination according to a python article i read on app-engine site,
> which suggests this)
>
> Is there any other way to do this at the current moment ? (i've read in the
> roadmaps that you will be introducing cursors)
>
> Another thing:
> Quote:
> "A key is a complex object -- you can't query on it using a simple string
> literal"
>
Where are you quoting from?

>
> I have the encoded string version of the key (same thing i would obtain
> from KeyFactory.KeyToString() and i am using this string in the query.
>
> It appears to work correctly, because the fetched elements are returned by
> "key order", different from the order i were to get from comparing the
> corresponding key strings lexically.
>
> --
> Corneliu Paul Lupulet
>
>
>
> >
>

--~--~-~--~~~---~--~~
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 google-appengine-java@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~--~~~~--~~--~--~---



[appengine-java] Re: How to make a query using low level API using the 'key' property?

2009-09-09 Thread Corneliu Paul Lupulet
Hello,

Thank you for you answers. I would like to make a clarification, why i am
using the key "property" in a query.

Using an order by key, I am saving the key of the last modified object as a
bookmark/cursor to know where to resume the processing from. (i also use
this for pagination according to a python article i read on app-engine site,
which suggests this)

Is there any other way to do this at the current moment ? (i've read in the
roadmaps that you will be introducing cursors)

Another thing:
Quote:
"A key is a complex object -- you can't query on it using a simple string
literal"

I have the encoded string version of the key (same thing i would obtain from
KeyFactory.KeyToString() and i am using this string in the query.

It appears to work correctly, because the fetched elements are returned by
"key order", different from the order i were to get from comparing the
corresponding key strings lexically.

-- 
Corneliu Paul Lupulet

--~--~-~--~~~---~--~~
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 google-appengine-java@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~--~~~~--~~--~--~---



[appengine-java] Re: How to make a query using low level API using the 'key' property?

2009-09-08 Thread Max Ross
On Fri, Sep 4, 2009 at 5:08 AM, Corneliu Paul Lupulet <
corneliu.lupu...@gmail.com> wrote:

> I noticed that i can make a query like this:
>
> DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
> Query query = new Query("DbContact");
> query.addFilter("__key__", FilterOperator.GREATER_THAN,
> KeyFactory.stringToKey(a_key_string));
>
> And it works. It fetches the correct results.
>
> Yes, you can always filter by __key__.


> Then i also noticed i can do this (locally on my computer; i haven't tested
> this on app-engine yet):
>
> entity.put("__key__", "some value");
> ds.put(entity);
> Using the datastore viewer i can see the object with this property
> (__key__) and the corresponding value i've set.
>
> I'm pretty sure this should generate an exception locally and in
production.  If it isn't, please file a bug.


> Then if try a query like this:
> q1.addFilter("__key__", FilterOperator.EQUAL, "some value");
>
> it doesnt' fetch any results!
>
> Right.  __key__ always refers to the Key of the entity and there is no
Entity in the datastore with a Key equal to "some value."  This is the
correct behavior.

> So can someone explain the mechanism of what is happening over here? :)
>
> One last thing i've noticed:
> If i try the following line in DataViewer --> Query (using GQL):
> SELECT * FROM DbCategory where __key__ > 'a'
>
> I get:
>
> server error(500)
> Server Error
>
> A server error has occurred.
>
> Please file a separate bug for this.

> And also, are there any other "reserved" properties like "__key__" i should
> be aware of, or which are useful for special kinds of queries.?
>
No, that's the only one at the moment.
http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/Entity.html#KEY_RESERVED_PROPERTY

>
> On Fri, Sep 4, 2009 at 2:17 PM, Cornel  wrote:
> >
> > Hello,
> >
> > How can i make a Query using the lowlevel API, similar to this:
> > select * from Entity where key >  ?
> >
> > In JDO i would do something like this:
> > select * from Entity where encodedKey > 
> >
> > where encodedKey is my objects' primary key:
> >
> >@PrimaryKey
> >@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> >@Extension(vendorName="datanucleus", key="gae.encoded-pk",
> > value="true")
> >private String encodedKey;
>
>
> --
> Corneliu Paul Lupulet
>
>
>
>
> >
>

--~--~-~--~~~---~--~~
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 google-appengine-java@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~--~~~~--~~--~--~---



[appengine-java] Re: How to make a query using low level API using the 'key' property?

2009-09-08 Thread Jason (Google)
A key is a complex object -- you can't query on it using a simple string
literal. Also, you shouldn't be changing an entity's key after it's
persisted -- once a key is set, that key is associated with the entity for
its lifetime.

If you want to query by key, you should use the __key__ syntax and use a Key
object to filter against. I believe you can do this in JDO just as you can
with the low-level API; please let me know if I'm incorrect about this.

- Jason

On Fri, Sep 4, 2009 at 5:08 AM, Corneliu Paul Lupulet <
corneliu.lupu...@gmail.com> wrote:

> I noticed that i can make a query like this:
>
> DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
> Query query = new Query("DbContact");
> query.addFilter("__key__", FilterOperator.GREATER_THAN,
> KeyFactory.stringToKey(a_key_string));
>
> And it works. It fetches the correct results.
>
> Then i also noticed i can do this (locally on my computer; i haven't tested
> this on app-engine yet):
>
> entity.put("__key__", "some value");
> ds.put(entity);
> Using the datastore viewer i can see the object with this property
> (__key__) and the corresponding value i've set.
>
> Then if try a query like this:
> q1.addFilter("__key__", FilterOperator.EQUAL, "some value");
>
> it doesnt' fetch any results!
>
> So can someone explain the mechanism of what is happening over here? :)
>
> One last thing i've noticed:
> If i try the following line in DataViewer --> Query (using GQL):
> SELECT * FROM DbCategory where __key__ > 'a'
>
> I get:
>
> server error(500)
> Server Error
>
> A server error has occurred.
>
> And also, are there any other "reserved" properties like "__key__" i should
> be aware of, or which are useful for special kinds of queries.?
>
> On Fri, Sep 4, 2009 at 2:17 PM, Cornel  wrote:
> >
> > Hello,
> >
> > How can i make a Query using the lowlevel API, similar to this:
> > select * from Entity where key >  ?
> >
> > In JDO i would do something like this:
> > select * from Entity where encodedKey > 
> >
> > where encodedKey is my objects' primary key:
> >
> >@PrimaryKey
> >@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> >@Extension(vendorName="datanucleus", key="gae.encoded-pk",
> > value="true")
> >private String encodedKey;
>
>
> --
> Corneliu Paul Lupulet
>
>
>
>
> >
>

--~--~-~--~~~---~--~~
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 google-appengine-java@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~--~~~~--~~--~--~---



[appengine-java] Re: How to make a query using low level API using the 'key' property?

2009-09-04 Thread Corneliu Paul Lupulet
I noticed that i can make a query like this:

DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Query query = new Query("DbContact");
query.addFilter("__key__", FilterOperator.GREATER_THAN,
KeyFactory.stringToKey(a_key_string));

And it works. It fetches the correct results.

Then i also noticed i can do this (locally on my computer; i haven't tested
this on app-engine yet):

entity.put("__key__", "some value");
ds.put(entity);
Using the datastore viewer i can see the object with this property (__key__)
and the corresponding value i've set.

Then if try a query like this:
q1.addFilter("__key__", FilterOperator.EQUAL, "some value");

it doesnt' fetch any results!

So can someone explain the mechanism of what is happening over here? :)

One last thing i've noticed:
If i try the following line in DataViewer --> Query (using GQL):
SELECT * FROM DbCategory where __key__ > 'a'

I get:

server error(500)
Server Error

A server error has occurred.

And also, are there any other "reserved" properties like "__key__" i should
be aware of, or which are useful for special kinds of queries.?

On Fri, Sep 4, 2009 at 2:17 PM, Cornel  wrote:
>
> Hello,
>
> How can i make a Query using the lowlevel API, similar to this:
> select * from Entity where key >  ?
>
> In JDO i would do something like this:
> select * from Entity where encodedKey > 
>
> where encodedKey is my objects' primary key:
>
>@PrimaryKey
>@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>@Extension(vendorName="datanucleus", key="gae.encoded-pk",
> value="true")
>private String encodedKey;


--
Corneliu Paul Lupulet

--~--~-~--~~~---~--~~
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 google-appengine-java@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~--~~~~--~~--~--~---