Posted By

phantomas on 10/15/10


Tagged

appengine


Versions (?)

Appengine: Check if object is present in database


 / Published in: Java
 

import com.google.appengine.api.datastore.Key;\\\\\\\\r\\\\\\\\nimport com.google.appengine.api.datastore.KeyFactory;

  1. PersistenceManager pm = JDOHelper.getPersistenceManagerFactory("transactions-optional").getPersistenceManager();
  2. String keyAsString = "key of object";
  3. Key objectDbKey = KeyFactory.createKey(MyDbObject.class.getSimpleName(), keyAsString);
  4. DbObject_Device object = null;
  5. try{
  6. object = pm.getObjectById(MyDbObject.class, objectDbKey);
  7. }
  8. if(object != null){
  9. // Object was present in database
  10. } else{
  11. // .. not present
  12. object = new DbObject();
  13. }
  14. // change object values here
  15. pm.makePersistent(object );
  16. pm.close();

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: phantomas on October 15, 2010

import com.google.appengine.api.datastore.Key; import com.google.appengine.api.datastore.KeyFactory;

You need to login to post a comment.