Reputation: 7198
I've just started writing GAE web applications in Java so I'm kind of new to all this stuff. I use JDO for storing data. I'm reading a lot of online materials (forums, tutorials...) and I see DAO everywhere but I really don't understand what it is. Yes, Data Access Object, technique... But when someone names a variable userDAO
what is the variable going to contain?
Let's consider following code (from GAE documentation):
PersistenceManager pm = PMF.get().getPersistenceManager();
Employee e = new Employee("Alfred", "Smith", new Date());
try {
pm.makePersistent(e);
} finally {
pm.close();
}
It's really simple, makes sense to me... but what in this example would you call DAO?
It is probably a stupid question but it would help me a lot.
Upvotes: 4
Views: 880
Reputation: 10038
A "DAO" stands for data access object. It's a way to encapsulate model logic by wrapping a given model entity with a class that provides more intuitive accessors.
I am not certain about the example you provide, but I'm willing to speculate. It looks like the PersistanceManager is an object which manages your application's data persistance layer. Your Employee
object is likely persistently stored through this PersistanceManager
instance, and the Employee
object you've constructed is probably a DAO providing a interface for managing that employee's state that is simpler than managing state through the PersistanceManager
directly.
On App Engine, one of the big performance constraints for the datastore is deserializing protocol buffers. If you add complicated methods to your model entities, you will increase the object size, which will cause a performance hit when you have to deserialize the object. The takeaway here is that you don't want to add anything more than the base properties onto a datastore entity specification. Adding helper methods will cause a performance hit.
Thus, a common pattern on App Engine is to use a DAO to wrap the model entity with a class that can provide this higher level logic without impacting serialization performance.
Upvotes: 7