Java Reference
In-Depth Information
More About JPA
Going into a more in-depth discussion about JPA annotations,
the JPA query language, and other JPA classes is—wait for it—
outside the scope of this topic. See Part V of The Java EE 5
related to using JPA.
package
stripesbook.dao;
public interface
ContactDao
extends
Dao<Contact,Integer> {
public
Contact findByEmail(String email, User user);
}
The implementation is trivial:
package
stripesbook.dao.impl.stripersist;
public class
ContactDaoImpl
extends
BaseDaoImpl<Contact,Integer>
implements
ContactDao
{
public
Contact findByEmail(String email, User user) {
return
findBy("email", email, user);
}
}
Our DAOs can now use Stripersist and JPA very easily, and the rest of
the application can use the DAOs as before without being exposed to
the details of the persistence layer.
Using the DAOs
We can now use the DAOs in the action beans. The
BaseActionBean
is a
convenient place to create instances that all action beans can use:
public abstract class
BaseActionBean
implements
ActionBean {
protected
AttachmentDao attachmentDao =
new
AttachmentDaoImpl();
protected
ContactDao contactDao =
new
ContactDaoImpl();
protected
FolderDao folderDao =
new
FolderDaoImpl();
protected
MessageDao messageDao =
new
MessageDaoImpl();
protected
UserDao userDao =
new
UserDaoImpl();
}
Search WWH ::
Custom Search