What is a DAO in the context of GAE, Java, JDO, etc.?

I just started writing GAE web applications in Java, so I'm new to this. I use JDO to store data. I read a lot of online materials (forums, tutorials ...) and I see DAO everywhere, but I really don't understand what it is. Yes, a data access object, a technique ... But when someone calls the userDAO variable, what will the variable contain?

Consider the following code (from the 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, it makes sense to me ... but what in this example would you call DAO?

This is probably a stupid question, but it helped me a lot.

+4
source share
1 answer

A "DAO" means a data access object . This is a way to encapsulate model logic by wrapping a given model object with a class that provides more intuitive accessors.

I am not sure about the example you provide, but I am willing to speculate. PersistanceManager seems to be an object that controls your data level for application data. Your Employee object is probably persisted through this PersistanceManager instance, and the Employee object you created is probably a DAO that provides an interface for managing the employee’s state that makes it easier to manage the state through the PersistanceManager directly.

In App Engine, one of the biggest performance limitations for a data warehouse is deserializing protocol buffers. If you add complex methods to your model objects, you will increase the size of the object, which will result in poor performance when you have to deserialize the object. The conclusion here is that you do not want to add anything more than basic properties to the datastore entity specification . The addition of helper methods will result in poor performance.

Thus, a common pattern in App Engine is to use DAO to transfer a model object with a class that can provide this higher-level logic without affecting serialization performance.

+7
source

All Articles