From a91b3bdb40bad4bd2caed47475f58175987824ad Mon Sep 17 00:00:00 2001 From: Donald Woods Date: Thu, 8 Oct 2009 20:15:00 +0000 Subject: [PATCH] OPENJPA-1101 hellojpa as a bundle and steps on how to deploy openjpa to Apache Felix Karaf. Tests are disabled for now, as we need better Karaf integration with maven. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@823304 13f79535-47bb-0310-9956-ffa450edef68 --- openjpa-integration/osgi-itests/pom.xml | 104 +++++++++++- openjpa-integration/osgi-itests/readme.txt | 104 ++++++++++++ .../osgi-itests/src/main/ant/enhancer.xml | 85 ++++++++++ .../osgi-itests/src/main/java/build.xml | 156 ++++++++++++++++++ .../src/main/java/hellojpa/Main.java | 89 ++++++++++ .../src/main/java/hellojpa/Message.java | 72 ++++++++ .../src/main/java/hellojpa/build.xml | 23 +++ .../main/resources/META-INF/persistence.xml | 34 ++++ openjpa-integration/pom.xml | 2 +- 9 files changed, 659 insertions(+), 10 deletions(-) create mode 100644 openjpa-integration/osgi-itests/readme.txt create mode 100644 openjpa-integration/osgi-itests/src/main/ant/enhancer.xml create mode 100644 openjpa-integration/osgi-itests/src/main/java/build.xml create mode 100644 openjpa-integration/osgi-itests/src/main/java/hellojpa/Main.java create mode 100644 openjpa-integration/osgi-itests/src/main/java/hellojpa/Message.java create mode 100644 openjpa-integration/osgi-itests/src/main/java/hellojpa/build.xml create mode 100644 openjpa-integration/osgi-itests/src/main/resources/META-INF/persistence.xml diff --git a/openjpa-integration/osgi-itests/pom.xml b/openjpa-integration/osgi-itests/pom.xml index 50a58f302..0a8ebf0b2 100644 --- a/openjpa-integration/osgi-itests/pom.xml +++ b/openjpa-integration/osgi-itests/pom.xml @@ -30,6 +30,8 @@ 4.0.0 openjpa-integration-osgi-itests 2.0.0-SNAPSHOT + jar + OpenJPA Integration Tests - OSGi OpenJPA Integration Tests - OSGi @@ -42,8 +44,14 @@ org.apache.openjpa openjpa ${version} - test + provided + + org.apache.geronimo.specs + geronimo-jpa_2.0_spec + provided + + org.apache.geronimo.specs geronimo-jms_1.1_spec @@ -52,12 +60,7 @@ org.apache.geronimo.specs geronimo-jta_1.1_spec - test - - - org.apache.geronimo.specs - geronimo-jpa_2.0_spec - test + provided org.apache.geronimo.specs @@ -75,12 +78,11 @@ commons-lang commons-lang 2.4 - test + provided commons-pool commons-pool - 1.4 test @@ -155,6 +157,7 @@ org.apache.felix org.osgi.core 1.2.0 + provided @@ -194,6 +197,11 @@ + + + src/main/resources + + src/test/resources @@ -210,6 +218,49 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + org.apache.maven.plugins + maven-antrun-plugin + + + process-classes + + + + + + + + + + + + + + run + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + + org.apache.felix + maven-bundle-plugin + true + + + ${artifactId} + ${groupId}.${artifactId};singleton=true + http://openjpa.apache.org/documentation.html + + hellojpa*,META-INF* + + hellojpa.Main + + false + . + + true + + + + bundle-manifest + process-classes + + manifest + + + + org.apache.maven.plugins maven-surefire-plugin pertest + ${surefire.jvm.args} + + + org/apache/openjpa/**/Test*.java + diff --git a/openjpa-integration/osgi-itests/readme.txt b/openjpa-integration/osgi-itests/readme.txt new file mode 100644 index 000000000..5a61fb33b --- /dev/null +++ b/openjpa-integration/osgi-itests/readme.txt @@ -0,0 +1,104 @@ +Setting up Apache Felix Karaf for OpenJPA 2.0.x + +Installing and running Apache Felix Karaf +--------------------------------------------------- +1) Download and extract Apache Felix Karaf 1.0.0 from: + + http://www.apache.org/dist/felix/apache-felix-karaf-1.0.0.zip + http://www.apache.org/dist/felix/apache-felix-karaf-1.0.0.tar.gz + +2) Start Karaf under Java SE 5 or 6: + + cd apache-felix-karaf-1.0.0/bin + karaf + + +Installing and running the Felix Web Console and Jetty: +------------------------------------------------------- +1) Install the following bundles: + + a) osgi:install http://www.apache.org/dist/felix/org.osgi.compendium-1.4.0.jar + b) osgi:install http://www.apache.org/dist/felix/org.apache.felix.scr-1.0.8.jar + c) osgi:install http://www.apache.org/dist/felix/org.apache.felix.http.jetty-2.0.2.jar + d) osgi:install http://www.apache.org/dist/felix/org.apache.felix.webconsole-2.0.0.jar + +2) Start the web console: + + a) osgi:start + b) osgi:start + + Note: You will have to start the Config, Event and Scr bundles for those + tabs to function in the web console. + +3) Access the web console in a browser: + + http://localhost:8080/system/console + uid = admin + pwd = admin + + +Installing OpenJPA 2.0.x +-------------------------------------------- +1) Install the following prereq bundles: + + a) osgi:install http://repo1.maven.org/maven2/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar + b) osgi:install http://repo1.maven.org/maven2/commons-lang/commons-lang/2.4/commons-lang-2.4.jar + c) osgi:install http://repo1.maven.org/maven2/commons-pool/commons-pool/1.5/commons-pool-1.5.jar + d) osgi:install http://repo1.maven.org/maven2/org/apache/geronimo/specs/geronimo-jms_1.1_spec/1.1.1/geronimo-jms_1.1_spec-1.1.1.jar + e) osgi:install http://repo1.maven.org/maven2/org/apache/geronimo/specs/geronimo-jta_1.1_spec/1.1.1/geronimo-jta_1.1_spec-1.1.1.jar + f) osgi:install http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/geronimo/specs/geronimo-jpa_2.0_spec/1.0-PFD2/geronimo-jpa_2.0_spec-1.0-PFD2.jar + g) osgi:install http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/geronimo/specs/geronimo-validation_1.0_spec/1.0-CR5/geronimo-validation_1.0_spec-1.0-CR5.jar + +2) Install OpenJPA 2.0.x: + + For OpenJPA 2.0.0-M3: + a) osgi:install http://people.apache.org/~dwoods/openjpa/2.0.0-M3/staging-repo/org/apache/openjpa/openjpa/2.0.0-M3/openjpa-2.0.0-M3.jar + + For a locally built OpenJPA trunk (2.0.0-SNAPSHOT): + a) osgi:install file:////org/apache/openjpa/openjpa/2.0.0-SNAPSHOT/openjpa-2.0.0-SNAPSHOT.jar + +3) Check the Karaf logfile for any problems: + + apache-felix-karaf-1.0.0/data/log/karaf.log + + +Installing an OSGi and/or Blueprint based sample app: +----------------------------------------------------- +This step is still a work-in-progress and TBD... + +1) Build the openjpa-integration/osgi-itests module in trunk (2.0.0-SNAPSHOT) +from source. + +2) Install the bundlized HelloJPA example: + + a) osgi:install file:////org/apache/openjpa/openjpa-integration-osgi-itests/2.0.0-SNAPSHOT/openjpa-integration-osgi-itests-2.0.0-SNAPSHOT.jar + b) osgi:start + +Note: At this point the start should fail with a message like: + Bundle start + org.osgi.framework.BundleException: Activator start error in bundle + org.apache.openjpa.openjpa-integration-osgi-itests [45]. + . . . + Caused by: javax.persistence.PersistenceException: No persistence providers + available for "hellojpa" after trying the following discovered + implementations: NONE + at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:189) + at hellojpa.Main.main(Main.java:38) + at hellojpa.Main.start(Main.java:81) + at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:667) + at org.apache.felix.framework.Felix.activateBundle(Felix.java:1699) + ... 15 more + + +2) To reinstall the sample app, you'll need to stop and uninstall it first, even if the initial install failed: + + a) osgi:stop + b) osgi:uninstall + + +Shutting down Karaf: +--------------------- +1) From the Karaf cmdline: + + osgi:shutdown + diff --git a/openjpa-integration/osgi-itests/src/main/ant/enhancer.xml b/openjpa-integration/osgi-itests/src/main/ant/enhancer.xml new file mode 100644 index 000000000..9baedf82f --- /dev/null +++ b/openjpa-integration/osgi-itests/src/main/ant/enhancer.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + running enhancer + + + + + + + + + + + + + + + + + + + + diff --git a/openjpa-integration/osgi-itests/src/main/java/build.xml b/openjpa-integration/osgi-itests/src/main/java/build.xml new file mode 100644 index 000000000..55dc44947 --- /dev/null +++ b/openjpa-integration/osgi-itests/src/main/java/build.xml @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + +Please traverse to a sub-directory, like hellojpa, and run "ant" from there. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/openjpa-integration/osgi-itests/src/main/java/hellojpa/Main.java b/openjpa-integration/osgi-itests/src/main/java/hellojpa/Main.java new file mode 100644 index 000000000..c27cdcf84 --- /dev/null +++ b/openjpa-integration/osgi-itests/src/main/java/hellojpa/Main.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package hellojpa; + +import java.util.*; +import javax.persistence.*; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + + +/** + * A very simple, stand-alone program that stores a new entity in the + * database and then performs a query to retrieve it. + */ +public class Main implements BundleActivator { + + @SuppressWarnings("unchecked") + public static void main(String[] args) { + // Create a new EntityManagerFactory using the System properties. + // The "hellojpa" name will be used to configure based on the + // corresponding name in the META-INF/persistence.xml file + EntityManagerFactory factory = Persistence. + createEntityManagerFactory("hellojpa", System.getProperties()); + + // Create a new EntityManager from the EntityManagerFactory. The + // EntityManager is the main object in the persistence API, and is + // used to create, delete, and query objects, as well as access + // the current transaction + EntityManager em = factory.createEntityManager(); + + // Begin a new local transaction so that we can persist a new entity + em.getTransaction().begin(); + + // Create and persist a new Message entity + em.persist(new Message("Hello Persistence!")); + + // Commit the transaction, which will cause the entity to + // be stored in the database + em.getTransaction().commit(); + + // It is always good practice to close the EntityManager so that + // resources are conserved. + em.close(); + + // Create a fresh, new EntityManager + EntityManager em2 = factory.createEntityManager(); + + // Perform a simple query for all the Message entities + Query q = em2.createQuery("select m from Message m"); + + // Go through each of the entities and print out each of their + // messages, as well as the date on which it was created + for (Message m : (List) q.getResultList()) { + System.out.println(m.getMessage() + + " (created on: " + m.getCreated() + ")"); + } + + // Again, it is always good to clean up after ourselves + em2.close(); + factory.close(); + } + + public void start(BundleContext context) { + System.out.println("Bundle start"); + main(null); + } + + public void stop(BundleContext context) { + System.out.println("Bundle stop"); + } + +} + diff --git a/openjpa-integration/osgi-itests/src/main/java/hellojpa/Message.java b/openjpa-integration/osgi-itests/src/main/java/hellojpa/Message.java new file mode 100644 index 000000000..38a084d04 --- /dev/null +++ b/openjpa-integration/osgi-itests/src/main/java/hellojpa/Message.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package hellojpa; + +import java.util.*; +import javax.persistence.*; + + +/** + * A very simple persistent entity that holds a "message", has a + * "created" field that is initialized to the time at which the + * object was created, and an id field that is initialized to the + * current time. + */ +@Entity +public class Message { + @Id + private long id = System.currentTimeMillis(); + + @Basic + private String message; + + @Basic + private Date created = new Date(); + + public Message() { + } + + public Message(String msg) { + message = msg; + } + + public void setId(long val) { + id = val; + } + + public long getId() { + return id; + } + + public void setMessage(String msg) { + message = msg; + } + + public String getMessage() { + return message; + } + + public void setCreated(Date date) { + created = date; + } + + public Date getCreated() { + return created; + } +} diff --git a/openjpa-integration/osgi-itests/src/main/java/hellojpa/build.xml b/openjpa-integration/osgi-itests/src/main/java/hellojpa/build.xml new file mode 100644 index 000000000..007f64d77 --- /dev/null +++ b/openjpa-integration/osgi-itests/src/main/java/hellojpa/build.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/openjpa-integration/osgi-itests/src/main/resources/META-INF/persistence.xml b/openjpa-integration/osgi-itests/src/main/resources/META-INF/persistence.xml new file mode 100644 index 000000000..bdb1c067f --- /dev/null +++ b/openjpa-integration/osgi-itests/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,34 @@ + + + + + + PU for hellojpa + hellojpa + + + + + + + diff --git a/openjpa-integration/pom.xml b/openjpa-integration/pom.xml index 1a582f3d8..804976f2c 100644 --- a/openjpa-integration/pom.xml +++ b/openjpa-integration/pom.xml @@ -35,6 +35,6 @@ examples tck validation - + osgi-itests