karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [34/35] karaf-boot git commit: Working jpa example with hibernate
Date Mon, 09 May 2016 14:48:53 GMT
Working jpa example with hibernate


Project: http://git-wip-us.apache.org/repos/asf/karaf-boot/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-boot/commit/6e4e7ed2
Tree: http://git-wip-us.apache.org/repos/asf/karaf-boot/tree/6e4e7ed2
Diff: http://git-wip-us.apache.org/repos/asf/karaf-boot/diff/6e4e7ed2

Branch: refs/heads/master
Commit: 6e4e7ed2e93845485a26e48dcdabdec6f7c9e3e2
Parents: af03889
Author: Christian Schneider <chris@die-schneider.net>
Authored: Wed Apr 27 14:15:01 2016 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Wed Apr 27 14:15:01 2016 +0200

----------------------------------------------------------------------
 samples/jpa/src/main/java/sample/jpa/Task.java    | 14 +++++++-------
 starters/karaf-boot-starter-blueprint/pom.xml     | 18 ++++++++++++++----
 starters/karaf-boot-starter-jpa/pom.xml           | 13 ++++++++++---
 .../java/org/apache/karaf/boot/jpa/Hibernate.java | 16 +++++++++++-----
 .../apache/karaf/boot/jpa/impl/JpaProcessor.java  |  9 ++++++++-
 5 files changed, 50 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/6e4e7ed2/samples/jpa/src/main/java/sample/jpa/Task.java
----------------------------------------------------------------------
diff --git a/samples/jpa/src/main/java/sample/jpa/Task.java b/samples/jpa/src/main/java/sample/jpa/Task.java
index cd431a7..2391d2a 100644
--- a/samples/jpa/src/main/java/sample/jpa/Task.java
+++ b/samples/jpa/src/main/java/sample/jpa/Task.java
@@ -18,20 +18,21 @@ package sample.jpa;
 
 import javax.persistence.Entity;
 import javax.persistence.Id;
-import javax.xml.bind.annotation.XmlRootElement;
 
 import org.apache.karaf.boot.jpa.Hibernate;
 import org.apache.karaf.boot.jpa.PersistentUnit;
 import org.apache.karaf.boot.jpa.Property;
 import org.apache.karaf.boot.jpa.Provider;
 
-@PersistentUnit(name = "tasklist", provider = Provider.Hibernate, properties = {
-        @Property(name = "hibernate.hbm2ddl.auto", value = "create-drop")
-})
+@PersistentUnit( //
+    name = "task", provider = Provider.Hibernate, properties = //
+    {
+     @Property(name = "hibernate.hbm2ddl.auto", value = "create-drop"),
+     @Property(name = "javax.persistence.jdbc.driver", value = "org.apache.derby.jdbc.EmbeddedDriver"),
+     @Property(name = "javax.persistence.jdbc.url", value = "jdbc:derby:memory:DSFTEST;create=true")
+    })
 @Hibernate.Dialect(Hibernate.Dialect.Value.HSQL)
-@Hibernate.Hbm2DdlAuto(Hibernate.Hbm2DdlAuto.Value.CreateDrop)
 @Entity
-@XmlRootElement
 public class Task {
     @Id
     Integer id;
@@ -40,7 +41,6 @@ public class Task {
     public Task() {
     }
 
-
     public Task(Integer id, String title) {
         super();
         this.id = id;

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/6e4e7ed2/starters/karaf-boot-starter-blueprint/pom.xml
----------------------------------------------------------------------
diff --git a/starters/karaf-boot-starter-blueprint/pom.xml b/starters/karaf-boot-starter-blueprint/pom.xml
index 14db02e..e958058 100644
--- a/starters/karaf-boot-starter-blueprint/pom.xml
+++ b/starters/karaf-boot-starter-blueprint/pom.xml
@@ -42,14 +42,24 @@
             <version>1.0.0</version>
         </dependency>
         <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.cmpn</artifactId>
+            <version>${osgi.version}</version>
+        </dependency>
+        <dependency>
             <groupId>org.ops4j.pax.cdi</groupId>
             <artifactId>pax-cdi-api</artifactId>
-            <version>0.5.0</version>
+            <version>${pax.cdi.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.enterprise</groupId>
+            <artifactId>cdi-api</artifactId>
+            <version>1.2</version>
         </dependency>
         <dependency>
-            <groupId>javax.inject</groupId>
-            <artifactId>javax.inject</artifactId>
-            <version>1</version>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-atinject_1.0_spec</artifactId>
+            <version>1.0</version>
         </dependency>
     </dependencies>
 

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/6e4e7ed2/starters/karaf-boot-starter-jpa/pom.xml
----------------------------------------------------------------------
diff --git a/starters/karaf-boot-starter-jpa/pom.xml b/starters/karaf-boot-starter-jpa/pom.xml
index 7a89d90..6db476f 100644
--- a/starters/karaf-boot-starter-jpa/pom.xml
+++ b/starters/karaf-boot-starter-jpa/pom.xml
@@ -26,11 +26,18 @@
 
     <dependencies>
         <dependency>
-            <groupId>org.apache.geronimo.specs</groupId>
-            <artifactId>geronimo-jpa_2.0_spec</artifactId>
-            <version>1.1</version>
+            <groupId>org.hibernate.javax.persistence</groupId>
+            <artifactId>hibernate-jpa-2.1-api</artifactId>
+            <version>1.0.0.Final</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.aries.jpa</groupId>
+            <artifactId>org.apache.aries.jpa.api</artifactId>
+            <version>2.3.0</version>
+        </dependency>
+        
+        <!-- For the stax indenting -->
+        <dependency>
             <groupId>net.java.dev.stax-utils</groupId>
             <artifactId>stax-utils</artifactId>
             <version>20070216</version>

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/6e4e7ed2/starters/karaf-boot-starter-jpa/src/main/java/org/apache/karaf/boot/jpa/Hibernate.java
----------------------------------------------------------------------
diff --git a/starters/karaf-boot-starter-jpa/src/main/java/org/apache/karaf/boot/jpa/Hibernate.java
b/starters/karaf-boot-starter-jpa/src/main/java/org/apache/karaf/boot/jpa/Hibernate.java
index ae4dab3..0944c20 100644
--- a/starters/karaf-boot-starter-jpa/src/main/java/org/apache/karaf/boot/jpa/Hibernate.java
+++ b/starters/karaf-boot-starter-jpa/src/main/java/org/apache/karaf/boot/jpa/Hibernate.java
@@ -22,13 +22,19 @@ public interface Hibernate {
     @interface Hbm2DdlAuto {
         Value value();
         enum Value {
-            Validate,
-            Update,
-            Create,
-            CreateDrop;
+            Validate("validate"),
+            Update("update"),
+            Create("create"),
+            CreateDrop("create-drop");
+            
+            private String value;
+
+            private Value(String value) {
+                this.value = value;
+            }
 
             public String toString() {
-                return super.toString().toLowerCase();
+                return value;
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/6e4e7ed2/starters/karaf-boot-starter-jpa/src/main/java/org/apache/karaf/boot/jpa/impl/JpaProcessor.java
----------------------------------------------------------------------
diff --git a/starters/karaf-boot-starter-jpa/src/main/java/org/apache/karaf/boot/jpa/impl/JpaProcessor.java
b/starters/karaf-boot-starter-jpa/src/main/java/org/apache/karaf/boot/jpa/impl/JpaProcessor.java
index f160fec..622643b 100644
--- a/starters/karaf-boot-starter-jpa/src/main/java/org/apache/karaf/boot/jpa/impl/JpaProcessor.java
+++ b/starters/karaf-boot-starter-jpa/src/main/java/org/apache/karaf/boot/jpa/impl/JpaProcessor.java
@@ -32,6 +32,8 @@ import javanet.staxutils.IndentingXMLStreamWriter;
 
 public class JpaProcessor extends AbstractProcessor {
 
+    private boolean useHibernate;
+
     public JpaProcessor() {
     }
 
@@ -59,7 +61,11 @@ public class JpaProcessor extends AbstractProcessor {
                 processingEnv.getMessager().printMessage(Kind.ERROR, "Error: " + e.getMessage());
             }
             try (PrintWriter w = appendResource("META-INF/org.apache.karaf.boot.bnd")) {
-                w.println("Private-Package: META-INF");
+                w.println("Private-Package: META-INF.*");
+                w.println("Meta-Persistence: META-INF/persistence.xml");
+                if (useHibernate) {
+                    w.println("Import-Package: org.hibernate.proxy, javassist.util.proxy");
+                }
             } catch (Exception e) {
                 processingEnv.getMessager().printMessage(Kind.ERROR, "Error writing to META-INF/org.apache.karaf.boot.bnd:
" + e.getMessage());
             }
@@ -164,6 +170,7 @@ public class JpaProcessor extends AbstractProcessor {
         if (pu.provider() != null) {
             switch (pu.provider()) {
             case Hibernate:
+                useHibernate = true;
                 return "org.hibernate.jpa.HibernatePersistenceProvider";
             default:
                 // TODO


Mime
View raw message