Open GoogleCodeExporter opened 9 years ago
Original comment by lhori...@gmail.com
on 18 Jan 2011 at 2:51
Currently I use the following for transforming entities into objects (and the
other way arround) in the Mapper API:
public class User {
private String name;
//...
public String getName() {
return name;
}
}
public class UserMapper extends AppEngineMapper<Key, Entity, NullWritable,
NullWritable> {
@Override
public void map(Key key, Entity value, Context context) throws IOException, InterruptedException {
DAOBase db = new DAOBase();
User user = db.ofy().getFactory().<User>getMetadata(value.getKey()).toObject(value, db.ofy());
if (!user.getName().equals("admin")) {
// use toEntity to transform the object into an entity
// Entity entity = toEntity(db, user);
DatastoreMutationPool mutationPool = getAppEngineContext(context).getMutationPool();
mutationPool.delete(value.getKey());
}
}
public Entity toEntity(DAOBase db, User object) {
final ObjectifyFactory factory = db.ofy().getFactory();
final com.googlecode.objectify.Key<User> key = factory.getKey(object);
return factory.<User>getMetadata(key).toEntity(object, db.ofy());
}
}
In this example every user except "admin" is deleted from the datastore. The
toObject method is used to create the object. You can use the toEntity method
to create an entity from the object.
Original comment by dilbert....@gmail.com
on 31 Mar 2011 at 4:05
Original issue reported on code.google.com by
toby.rothe@gmail.com
on 18 Jan 2011 at 9:58