diff options
author | Sebastian | 2012-06-03 16:07:07 +0200 |
---|---|---|
committer | Sebastian | 2012-06-03 16:07:07 +0200 |
commit | 3571512d36c3aec28fdc8aa76c01f520f0c5fdbd (patch) | |
tree | adeca21bb1b23bdb9f8b2cb7c5c369bda326003e /src | |
parent | initial import (diff) | |
download | xss-jpa-3571512d36c3aec28fdc8aa76c01f520f0c5fdbd.tar.gz xss-jpa-3571512d36c3aec28fdc8aa76c01f520f0c5fdbd.tar.xz xss-jpa-3571512d36c3aec28fdc8aa76c01f520f0c5fdbd.zip |
fix gernericdao; add logging
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java | 2 | ||||
-rw-r--r-- | src/main/java/nu/xss/jpa/dao/Dao.java | 4 | ||||
-rw-r--r-- | src/main/java/nu/xss/jpa/dao/GenericJpaDao.java | 13 |
3 files changed, 11 insertions, 8 deletions
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<E, K> implements Dao<E, K>, Serializable { private static final long serialVersionUID = 4998055731089977476L; - @PersistenceContext(unitName="mainPU") + @PersistenceContext protected EntityManager entityManager; protected Class<E> 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<E, K> { - void persist(E entity); - void remove(E entity); + void save(E entity); + void delete(E entity); E findById(K id); List<E> 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<E,K> implements Dao<E,K>, 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<E,K> implements Dao<E,K>, Serializable { @SuppressWarnings("unchecked") public GenericJpaDao() { ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass(); - this.entity = (Class<E>) genericSuperclass.getActualTypeArguments()[1]; + this.entity = (Class<E>) 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); } |