I need you opinions and suggestions on this 2 kinds of implementation
in finding if an entity is
not in the datastore and doing a task if it is not in the datastore.
1. use getObjectbyID
try {
Object object = pm.getObjectbyId(Object.class, "some-key");
// since it is already in the datastore, do nothing
} catch (JDOObjectNotFoundException e){
// since it is not in the datastore, do task
task();
}
2. use query
String query = "select from " + Object.class.getName() +
" where id == idParam parameters String
idParam";
List<Object> object = (List<Object>) pm.newQuery(query).execute
("some-key");
if (object.isEmpty()){
//since it is not in the datastore, do task
task();
}
I heard that using getObjectbyId is faster but it is inside the try-
catch block... My goal is to do task if the object is not in the
datastore. And when the object is not in the datastore, it will throw
an exception and we know that catching an exception takes more time
and processing compared to an if -else block in the sample 2, but we
used a pm.newQuery(), which is based from my understanding, slower
compared to pm.getObjectbyId().
So people, what do you think???
-mar_novice
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---