Return to Snippet

Revision: 33925
at October 15, 2010 00:47 by phantomas


Updated Code
PersistenceManager pm = JDOHelper.getPersistenceManagerFactory("transactions-optional").getPersistenceManager();
String keyAsString = "key of object";
Key objectDbKey = KeyFactory.createKey(MyDbObject.class.getSimpleName(), keyAsString);
DbObject_Device object = null;
try{
	object = pm.getObjectById(MyDbObject.class, objectDbKey);
}
if(object != null){
	// Object was present in database
} else{
	// .. not present
	object = new DbObject();
}
// change object values here
pm.makePersistent(object );
pm.close();

Revision: 33924
at October 15, 2010 00:37 by phantomas


Updated Code
PersistenceManager pm = JDOHelper.getPersistenceManagerFactory("transactions-optional").getPersistenceManager();
String keyAsString = "key of object";
Key objectDbKey = KeyFactory.createKey(MyDbObject.class.getSimpleName(), keyAsString);
DbObject_Device object = null;
try{
	object = pm.getObjectById(MyDbObject.class, keyAsString);
}
if(object != null){
	// Object was present in database
} else{
	// .. not present
	object = new DbObject();
}
// change object values here
pm.makePersistent(object );
pm.close();

Revision: 33923
at October 15, 2010 00:26 by phantomas


Updated Code
PersistenceManager pm = JDOHelper.getPersistenceManagerFactory("transactions-optional").getPersistenceManager();
String keyAsString = "key of object";
Key objectDbKey = KeyFactory.createKey(MyDbObject.class.getSimpleName(), keyAsString);
DbObject_Device object = null;
try{
	object = pm.getObjectById(MyDbObject.class, keyAsString);
}
if(object != null){
	// Object was present in database
} else{
	// .. not present
}

Revision: 33922
at October 15, 2010 00:24 by phantomas


Updated Code
String keyAsString = "key of object";
Key objectDbKey = KeyFactory.createKey(MyDbObject.class.getSimpleName(), keyAsString);
DbObject_Device object = null;
try{
	object = pm.getObjectById(MyDbObject.class, keyAsString);
}
if(object != null){
	// Object was present in database
} else{
	// .. not present
}

Revision: 33921
at October 15, 2010 00:20 by phantomas


Initial Code
String keyAsString = "key of object";
Key objectDbKey = KeyFactory.createKey(MyDbObject.class.getSimpleName(), keyAsString);
DbObject_Device object = pm.getObjectById(MyDbObject.class, keyAsString);
if(object != null){
	// Object was present in database
} else{
	// .. not present
}

Initial URL

                                

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

Initial Title
Appengine: Check if object is present in database

Initial Tags

                                

Initial Language
Java