Created
March 25, 2013 10:36
-
-
Save senthilmuthiah/5236275 to your computer and use it in GitHub Desktop.
Address Book Using JPA +ZK + Spring.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package addressbook.dao; | |
import java.util.List; | |
import javax.persistence.EntityManager; | |
import javax.persistence.PersistenceContext; | |
import javax.persistence.PersistenceContextType; | |
import org.springframework.stereotype.Repository; | |
@Repository | |
public class CRUDDaoImpl implements CRUDDao { | |
@PersistenceContext(type = PersistenceContextType.EXTENDED) | |
private EntityManager em; | |
public EntityManager getEm() { | |
return em; | |
} | |
public void setEm(EntityManager em) { | |
this.em = em; | |
} | |
@SuppressWarnings("unchecked") | |
public <T> List<T> getAll(Class<T> klass) { | |
return em.createQuery("Select t from " + klass.getSimpleName() + " t") | |
.getResultList(); | |
} | |
public <T> T save(T t) { | |
T newRecord = null; | |
newRecord = em.merge(t); | |
return newRecord; | |
} | |
public <T> void delete(T t) { | |
em.remove(em.merge(t)); | |
em.flush(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment