Be wary of a try/get/catch/persist combo.  I was doing this initially, but
found it triggered a memory leak.  I resorted to a query by business key.  I
can't confirm whats most efficient.  It's certainly not in terms of index
storage overhead.  I just wanted to throw out the warning.

On Dec 21, 2009 12:08 PM, "t3jem" <t3j...@gmail.com> wrote:

Ok,

So I'm writing my first game using the Google App Engine and have been
finding that using RPC and the datastore is much different than I'm
use to.  I've managed to get along, but I'm pretty stuck on this one,
I can't find it anywhere.

My problem is, I need to be able to create a new object with a unique
ID when a new user logs into the game.  I was doing this by randomly
generating a key and then using a query to the datastore to retrieve
an object by that ID.  If nothing turns up then I persist the new
object with that ID.  I understand that with an exceedingly great
amount of users this method could become a bit slow, but I don't
intend to have more than 1000 objects of this type in the datastore so
I don't foresee any problems with this method (please tell me if I'm
terribly mistaken).

I get my error when I go to attempt a retrieval of the missing object
from the datastore.  I use PersistenceManager.getObjectById(foo.class,
Key)

when my program reaches the call it throws a
NucleusObjectNotFoundException.  I understand this is probably normal
behavior, the problem is, I can't seem to find a way to check if the
key already exists in the datastore or not.

Is there a cheap way to check for a key? the only other method I can
think of is to get a collection of all the objects of that class and
check the created key against all existing ones, but that seems much
to expensive.

Thank you for your time

--

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-j...@googlegroups.com.
To unsubscribe from this group, send email to
google-appengine-java+unsubscr...@googlegroups.com<google-appengine-java%2bunsubscr...@googlegroups.com>
.
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 google-appengine-j...@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.


Reply via email to