From f419209f64249c4441920503582e194ba01e7195 Mon Sep 17 00:00:00 2001
From: Sebastian
Date: Sun, 3 Jun 2012 12:17:24 +0200
Subject: initial import
---
.gitignore | 6 +++
pom.xml | 68 ++++++++++++++++++++++++
src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java | 40 ++++++++++++++
src/main/java/nu/xss/jpa/dao/Dao.java | 10 ++++
src/main/java/nu/xss/jpa/dao/GenericJpaDao.java | 43 +++++++++++++++
src/main/java/nu/xss/jpa/entity/Entity.java | 5 ++
6 files changed, 172 insertions(+)
create mode 100644 .gitignore
create mode 100644 pom.xml
create mode 100644 src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java
create mode 100644 src/main/java/nu/xss/jpa/dao/Dao.java
create mode 100644 src/main/java/nu/xss/jpa/dao/GenericJpaDao.java
create mode 100644 src/main/java/nu/xss/jpa/entity/Entity.java
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c126559
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+.classpath
+.settings
+.project
+target
+build
+bin
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..2ce7f48
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,68 @@
+
+ 4.0.0
+ nu.xss
+ xss-jpa
+ 0.0.1-SNAPSHOT
+
+
+ UTF-8
+ 4.1.4.Final
+
+
+
+
+ org.hibernate
+ hibernate-core
+ ${hibernate.version}
+
+
+ org.hibernate
+ hibernate-entitymanager
+ ${hibernate.version}
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.5
+
+
+ 1.7
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 2.8.1
+
+ ${basedir}/src/main/javadoc/stylesheet.css
+ public
+
+
+
+
+
+
+
+ nexus-deploy
+ Nexus Staging Repo
+ http://localhost:8081/nexus/content/repositories/snapshots/
+
+
+
+
\ No newline at end of file
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 implements Dao, Serializable {
+
+ private static final long serialVersionUID = 4998055731089977476L;
+
+ @PersistenceContext(unitName="mainPU")
+ protected EntityManager entityManager;
+
+ protected Class entity;
+
+ public AbstractJpaDao(final Class entity) {
+ this.entity = (Class) 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 findAll() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/main/java/nu/xss/jpa/dao/Dao.java b/src/main/java/nu/xss/jpa/dao/Dao.java
new file mode 100644
index 0000000..b91c834
--- /dev/null
+++ b/src/main/java/nu/xss/jpa/dao/Dao.java
@@ -0,0 +1,10 @@
+package nu.xss.jpa.dao;
+
+import java.util.List;
+
+public interface Dao {
+ void persist(E entity);
+ void remove(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
new file mode 100644
index 0000000..5acfffc
--- /dev/null
+++ b/src/main/java/nu/xss/jpa/dao/GenericJpaDao.java
@@ -0,0 +1,43 @@
+package nu.xss.jpa.dao;
+
+import java.io.Serializable;
+import java.lang.reflect.ParameterizedType;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+public abstract class GenericJpaDao implements Dao, Serializable {
+
+ private static final long serialVersionUID = 4998055731089977476L;
+
+ @PersistenceContext
+ protected EntityManager entityManager;
+
+ protected Class entity;
+
+ @SuppressWarnings("unchecked")
+ public GenericJpaDao() {
+ ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
+ this.entity = (Class) genericSuperclass.getActualTypeArguments()[1];
+ }
+
+ 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 findAll() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/main/java/nu/xss/jpa/entity/Entity.java b/src/main/java/nu/xss/jpa/entity/Entity.java
new file mode 100644
index 0000000..1943e80
--- /dev/null
+++ b/src/main/java/nu/xss/jpa/entity/Entity.java
@@ -0,0 +1,5 @@
+package nu.xss.jpa.entity;
+
+public class Entity {
+
+}
--
cgit v1.2.3-55-g7522