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
Tutorial [ JBC + 06 ] for detailed explanations about everything
related to using JPA.
Download email_23/src/stripesbook/dao/ContactDao.java
package stripesbook.dao;
public interface ContactDao extends Dao<Contact,Integer> {
public Contact findByEmail(String email, User user);
}
The implementation is trivial:
Download email_23/src/stripesbook/dao/impl/stripersist/ContactDaoImpl.java
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:
Download email_23/src/stripesbook/action/BaseActionBean.java
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