From 3571512d36c3aec28fdc8aa76c01f520f0c5fdbd Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 3 Jun 2012 16:07:07 +0200 Subject: fix gernericdao; add logging --- src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java | 2 +- src/main/java/nu/xss/jpa/dao/Dao.java | 4 ++-- src/main/java/nu/xss/jpa/dao/GenericJpaDao.java | 13 ++++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java b/src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java index aef1aaf..b1638ac 100644 --- a/src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java +++ b/src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java @@ -10,7 +10,7 @@ public abstract class AbstractJpaDao implements Dao, Serializable { private static final long serialVersionUID = 4998055731089977476L; - @PersistenceContext(unitName="mainPU") + @PersistenceContext protected EntityManager entityManager; protected Class entity; diff --git a/src/main/java/nu/xss/jpa/dao/Dao.java b/src/main/java/nu/xss/jpa/dao/Dao.java index b91c834..18d886f 100644 --- a/src/main/java/nu/xss/jpa/dao/Dao.java +++ b/src/main/java/nu/xss/jpa/dao/Dao.java @@ -3,8 +3,8 @@ package nu.xss.jpa.dao; import java.util.List; public interface Dao { - void persist(E entity); - void remove(E entity); + void save(E entity); + void delete(E entity); E findById(K id); List findAll(); } diff --git a/src/main/java/nu/xss/jpa/dao/GenericJpaDao.java b/src/main/java/nu/xss/jpa/dao/GenericJpaDao.java index 5acfffc..c5c2d91 100644 --- a/src/main/java/nu/xss/jpa/dao/GenericJpaDao.java +++ b/src/main/java/nu/xss/jpa/dao/GenericJpaDao.java @@ -7,9 +7,13 @@ import java.util.List; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public abstract class GenericJpaDao implements Dao, Serializable { private static final long serialVersionUID = 4998055731089977476L; + protected final Logger logger = LoggerFactory.getLogger(this.getClass()); @PersistenceContext protected EntityManager entityManager; @@ -19,15 +23,14 @@ public abstract class GenericJpaDao implements Dao, Serializable { @SuppressWarnings("unchecked") public GenericJpaDao() { ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass(); - this.entity = (Class) genericSuperclass.getActualTypeArguments()[1]; + this.entity = (Class) genericSuperclass.getActualTypeArguments()[0]; } - public void persist(E entity) { - entityManager.persist(entity); - + public void save(E entity) { + entityManager.merge(entity); } - public void remove(E entity) { + public void delete(E entity) { entityManager.remove(entity); } -- cgit v1.2.3-55-g7522