summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohann Latocha2012-07-05 13:39:31 +0200
committerJohann Latocha2012-07-05 13:39:31 +0200
commit2907d0cb9fd535155a46144dbcff447ab495d77c (patch)
tree80722d060867cee01f6040d0c560945536c6341c
parentupdate pom (diff)
downloadxss-jpa-2907d0cb9fd535155a46144dbcff447ab495d77c.tar.gz
xss-jpa-2907d0cb9fd535155a46144dbcff447ab495d77c.tar.xz
xss-jpa-2907d0cb9fd535155a46144dbcff447ab495d77c.zip
add merge
-rw-r--r--src/main/java/nu/xss/jpa/dao/Dao.java1
-rw-r--r--src/main/java/nu/xss/jpa/dao/GenericJpaDao.java28
2 files changed, 20 insertions, 9 deletions
diff --git a/src/main/java/nu/xss/jpa/dao/Dao.java b/src/main/java/nu/xss/jpa/dao/Dao.java
index 18d886f..2c541c9 100644
--- a/src/main/java/nu/xss/jpa/dao/Dao.java
+++ b/src/main/java/nu/xss/jpa/dao/Dao.java
@@ -4,6 +4,7 @@ import java.util.List;
public interface Dao<E, K> {
void save(E entity);
+ void merge(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 e282911..cac96e6 100644
--- a/src/main/java/nu/xss/jpa/dao/GenericJpaDao.java
+++ b/src/main/java/nu/xss/jpa/dao/GenericJpaDao.java
@@ -10,30 +10,40 @@ import javax.persistence.PersistenceContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class GenericJpaDao<E,K> implements Dao<E,K>, Serializable {
-
+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;
-
+
protected Class<E> entity;
-
+
@SuppressWarnings("unchecked")
public GenericJpaDao() {
- ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
+ ParameterizedType genericSuperclass = (ParameterizedType) getClass()
+ .getGenericSuperclass();
this.entity = (Class<E>) genericSuperclass.getActualTypeArguments()[0];
}
-
+
public void save(E entity) {
+ logger.info("Persist Entity: {}.", entity.toString());
entityManager.persist(entity);
- logger.info("Saved entity: {}.", entity.toString());
+ entityManager.flush();
+ logger.info("Saved entity: {}.", entity.toString());
+ }
+
+ public void merge(E entity) {
+ logger.info("Merge Entity: {}.", entity.toString());
+ entityManager.merge(entity);
+ entityManager.flush();
+ logger.info("Saved entity: {}.", entity.toString());
}
public void delete(E entity) {
entityManager.remove(entity);
- logger.info("Deleted entity: {}.", entity.toString());
+ logger.info("Deleted entity: {}.", entity.toString());
}
public E findById(K id) {