Spring-Data GitHub App at v.0.0.3 with Generic DAO Interface

My Spring-Data app on GitHub goes v0.0.3 with the addition of a Generic DAO Interface to reduce redundancy in the DAO layer. In the process I added a Service facade to structure the Persistence Tier into Model, DAO and Service layers.

Benefits of a Generic DAO Interface

Along with our Generic DAO Interface we have an Generic Abstract DAO class from which domain classes are derived. This makes our Domain DAO classes cleaner, using the generic CRUD and session objects from the AbstractDAO class.

@Repository
public class ContactHbnDao extends AbstractHbnDao<Contact> implements ContactDao {

    @Override
    @SuppressWarnings("unchecked")
    @Transactional(readOnly=true)
    public List<Contact> findByEmail(String email) {
        return getSession()
                .getNamedQuery("Contact.findContactsByEmail")
                .setString("email", "%" + email + "%")
                .list();
    }
    ...

 Separating Concerns in the Service Facade

The Service Facade takes advantage of our nicely structured DAO layer by first Injecting the ContactDAO, wiring up @Repository ContactHbnDao which implements ContactDao. Then it makes simple method calls to the DAO layer resulting in a clean separation between domain logic and persistence logic.

@Service(value="contactService")
@Transactional
public class ContactServiceImpl implements ContactService {

    @Autowired
    private ContactDao contactDao;

    @Override
    public List<Contact> getContactsByEmail(String email) {
        return contactDao.findByEmail(email);
    }
    ...

You can download Spring-Data v0.0.3 from the GitHub Repository here.