Hi all. I didn't find any answer or info for this:
Context: Java Google App Engine project, using Datastore. For a certain kind, Sale, I save the entities in two ways:
- From a typical SaleDAO#save(saleEntity)
- During MapReduce, from my SaleReducer#emit(saleEntity)
So I was investigating how to reuse some behavior as part of both cases, so I made something like:
class SaleDAO {
DatastoreService datastore
public save(Entity entity) {
// My common behavior that I want to reuse
datastore.put(entity)
// Some more common behavior that I want to reuse
}
}
And then for the MapReduce part, I extended OutputWriter to call my DAO, instead of the DatastoreMutationPool#put(entity) method provided for that purpose.
public class SaleOutputWriter extends OutputWriter<Entity> {
@Override
public void write(Entity entity) {
//pool.put(entity); - try to invoke the DAO instead
saleDAO.save(sale)
}
}
- My surprise is that it works! Well, the MR jobs seem to go to a strange state, but the entities are correctly saved. Still I'm 99% sure that this must be a bad practice or bring some problems. Can somebody tell me
- If that's not the case, why are we given a certain API for MapReduce and another one for normal persistence? Will be the same to invoke DatastoreMutationPool.put than DatastoreService.put (any implementation)?
Honestly, this idea sounded crazy in my head and now that it seems to work I want to know more about it.