summaryrefslogtreecommitdiffstats
path: root/src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java')
-rw-r--r--src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java b/src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java
new file mode 100644
index 0000000..aef1aaf
--- /dev/null
+++ b/src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java
@@ -0,0 +1,40 @@
+package nu.xss.jpa.dao;
+
+import java.io.Serializable;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+public abstract class AbstractJpaDao<E, K> implements Dao<E, K>, Serializable {
+
+ private static final long serialVersionUID = 4998055731089977476L;
+
+ @PersistenceContext(unitName="mainPU")
+ protected EntityManager entityManager;
+
+ protected Class<E> entity;
+
+ public AbstractJpaDao(final Class<E> entity) {
+ this.entity = (Class<E>) entity;
+ }
+
+ public void persist(E entity) {
+ entityManager.persist(entity);
+
+ }
+
+ public void remove(E entity) {
+ entityManager.remove(entity);
+ }
+
+ public E findById(K id) {
+ return entityManager.find(entity, id);
+ }
+
+ public List<E> findAll() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}