Defining the generic DAO implementation
We will once again use Java generics to define a common ancestor class that will be extended by each of our implementation classes (CompanyDaoImpl
, ProjectDaoImpl
, TaskDaoImpl
, TaskLogDaoImpl
, and UserDaoImpl
). The GenericDaoImpl
and all other implementing classes will be added to the same com.gieman.tttracker.dao
package as our DAO interfaces. Key lines of code in GenericDaoImpl
are highlighted and will be explained in the following sections:
package com.gieman.tttracker.dao; import java.io.Serializable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; public class GenericDaoImpl<T, ID extends Serializable> implements GenericDao<T, ID> { final protected Logger logger = LoggerFactory.getLogger(this.getClass()); ...