Skip to content

Commit 61f0843

Browse files
committed
HHH-8112 OSGi quickstart tutorial projects
1 parent 6f6e3c6 commit 61f0843

File tree

36 files changed

+1684
-0
lines changed

36 files changed

+1684
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
First install the H2 driver using:
4+
> install -s mvn:com.h2database/h2/1.3.163
5+
6+
Then copy this file to the deploy folder
7+
-->
8+
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
9+
10+
<bean id="dataSource" class="org.h2.jdbcx.JdbcDataSource">
11+
<property name="URL" value="jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE"/>
12+
<property name="user" value="sa"/>
13+
<property name="password" value=""/>
14+
</bean>
15+
16+
<service interface="javax.sql.DataSource" ref="dataSource">
17+
<service-properties>
18+
<entry key="osgi.jndi.service.name" value="jdbc/h2ds"/>
19+
</service-properties>
20+
</service>
21+
</blueprint>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<features>
3+
<feature name="hibernate-test">
4+
5+
<feature>karaf-framework</feature>
6+
7+
<!-- JTA -->
8+
<config name="org.apache.aries.transaction">
9+
aries.transaction.recoverable = true
10+
aries.transaction.timeout = 600
11+
aries.transaction.howl.logFileDir = ${karaf.data}/txlog
12+
aries.transaction.howl.maxLogFiles = 2
13+
aries.transaction.howl.maxBlocksPerFile = 512
14+
aries.transaction.howl.bufferSizeKBytes = 4
15+
</config>
16+
<bundle start-level="30">mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1</bundle>
17+
<bundle start-level="30">mvn:org.apache.aries.transaction/org.apache.aries.transaction.blueprint/1.0.0</bundle>
18+
<bundle start-level="30">mvn:org.apache.aries.transaction/org.apache.aries.transaction.manager/1.0.1</bundle>
19+
20+
<!-- JPA -->
21+
<bundle start-level="30">mvn:org.apache.geronimo.specs/geronimo-jpa_2.0_spec/1.1</bundle>
22+
<bundle start-level="30">mvn:org.apache.aries/org.apache.aries.util/1.0.0</bundle>
23+
<bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.api/1.0.0</bundle>
24+
<bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.blueprint.aries/1.0.0</bundle>
25+
<bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.container/1.0.0</bundle>
26+
<bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.container.context/1.0.1</bundle>
27+
28+
<!-- JNDI -->
29+
<bundle start-level="30">mvn:org.apache.aries.jndi/org.apache.aries.jndi.api/1.0.0</bundle>
30+
<bundle start-level="30">mvn:org.apache.aries.jndi/org.apache.aries.jndi.core/1.0.0</bundle>
31+
<bundle start-level="30">mvn:org.apache.aries.jndi/org.apache.aries.jndi.rmi/1.0.0</bundle>
32+
<bundle start-level="30">mvn:org.apache.aries.jndi/org.apache.aries.jndi.url/1.0.0</bundle>
33+
<bundle start-level="30">mvn:org.apache.aries.jndi/org.apache.aries.jndi.legacy.support/1.0.0</bundle>
34+
35+
<!-- Taken from Karaf-Tutorial -->
36+
<bundle>mvn:commons-collections/commons-collections/3.2.1</bundle>
37+
<bundle>mvn:commons-pool/commons-pool/1.5.4</bundle>
38+
<bundle>mvn:commons-dbcp/commons-dbcp/1.4</bundle>
39+
<bundle>mvn:commons-lang/commons-lang/2.6</bundle>
40+
<bundle>wrap:mvn:net.sourceforge.serp/serp/1.13.1</bundle>
41+
42+
<bundle>mvn:com.h2database/h2/1.3.170</bundle>
43+
<bundle>blueprint:file:/home/bmeyer2/workspace_hibernate_master/HibernateOSGi/datasource-h2.xml</bundle>
44+
45+
<!-- These do not natively support OSGi, so using 3rd party bundles. -->
46+
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/2.7.7_5</bundle>
47+
<bundle>mvn:org.jboss.javassist/com.springsource.javassist/3.15.0.GA</bundle>
48+
<bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jsr303-api-1.0.0/2.2.0</bundle>
49+
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.ant/1.8.2_2</bundle>
50+
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5</bundle>
51+
52+
<!-- These do not natively support OSGi, so wrap with BND. -->
53+
<bundle>wrap:mvn:org.jboss/jandex/1.1.0.Alpha1</bundle>
54+
55+
<bundle>wrap:mvn:org.hibernate.common/hibernate-commons-annotations/4.0.2.Final</bundle>
56+
<bundle>mvn:com.fasterxml/classmate/0.5.4</bundle>
57+
<bundle>mvn:org.jboss.logging/jboss-logging/3.1.0.GA</bundle>
58+
59+
<bundle>mvn:org.hibernate/hibernate-core/4.2.2-SNAPSHOT</bundle>
60+
<bundle>mvn:org.hibernate/hibernate-entitymanager/4.2.2-SNAPSHOT</bundle>
61+
62+
<!-- TODO: It seems that the persistence unit bundle needs to be started
63+
before hibernate-osgi. When the BundleActivator is started,
64+
the persistence unit is provided even though managed-jpa
65+
hasn't completely started yet. If that happens, you'll get an "illegal
66+
bundle state" exception. Is there a way for the activator to
67+
watch for bundles with PUs before registering the persistence provider? -->
68+
<bundle>mvn:org.hibernate.osgi/managed-jpa/1.0.0</bundle>
69+
70+
<bundle>mvn:org.hibernate/hibernate-osgi/4.2.2-SNAPSHOT</bundle>
71+
</feature>
72+
</features>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.hibernate.osgi</groupId>
5+
<artifactId>managed-jpa</artifactId>
6+
<version>1.0.0</version>
7+
<packaging>bundle</packaging>
8+
9+
<dependencies>
10+
<dependency>
11+
<groupId>org.apache.geronimo.specs</groupId>
12+
<artifactId>geronimo-jpa_2.0_spec</artifactId>
13+
<version>1.1</version>
14+
</dependency>
15+
<dependency>
16+
<groupId>org.osgi</groupId>
17+
<artifactId>org.osgi.core</artifactId>
18+
<version>4.3.1</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.osgi</groupId>
22+
<artifactId>org.osgi.enterprise</artifactId>
23+
<version>4.2.0</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.apache.karaf.shell</groupId>
27+
<artifactId>org.apache.karaf.shell.console</artifactId>
28+
<version>2.3.0</version>
29+
</dependency>
30+
</dependencies>
31+
32+
<build>
33+
<plugins>
34+
<plugin>
35+
<groupId>org.apache.felix</groupId>
36+
<artifactId>maven-bundle-plugin</artifactId>
37+
<extensions>true</extensions>
38+
<configuration>
39+
<instructions>
40+
<Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
41+
<Bundle-Name>${pom.artifactId}</Bundle-Name>
42+
<Bundle-Version>1.0.0</Bundle-Version>
43+
<Export-Package>
44+
org.hibernate.osgitest,
45+
org.hibernate.osgitest.entity
46+
</Export-Package>
47+
<Import-Package>
48+
org.apache.felix.service.command,
49+
org.apache.felix.gogo.commands,
50+
org.apache.karaf.shell.console,
51+
org.apache.karaf.shell.commands,
52+
org.hibernate.proxy,
53+
javassist.util.proxy,
54+
*
55+
</Import-Package>
56+
<Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
57+
</instructions>
58+
</configuration>
59+
</plugin>
60+
</plugins>
61+
</build>
62+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* JBoss, Home of Professional Open Source
5+
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
6+
* as indicated by the @authors tag. All rights reserved.
7+
* See the copyright.txt in the distribution for a
8+
* full listing of individual contributors.
9+
*
10+
* This copyrighted material is made available to anyone wishing to use,
11+
* modify, copy, or redistribute it subject to the terms and conditions
12+
* of the GNU Lesser General Public License, v. 2.1.
13+
* This program is distributed in the hope that it will be useful, but WITHOUT A
14+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16+
* You should have received a copy of the GNU Lesser General Public License,
17+
* v.2.1 along with this distribution; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19+
* MA 02110-1301, USA.
20+
*/
21+
package org.hibernate.osgitest;
22+
23+
import java.util.List;
24+
25+
import org.hibernate.osgitest.entity.DataPoint;
26+
27+
/**
28+
* @author Brett Meyer
29+
*/
30+
public interface DataPointService {
31+
32+
public void add(DataPoint dp);
33+
34+
public List<DataPoint> getAll();
35+
36+
public void deleteAll();
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* JBoss, Home of Professional Open Source
5+
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
6+
* as indicated by the @authors tag. All rights reserved.
7+
* See the copyright.txt in the distribution for a
8+
* full listing of individual contributors.
9+
*
10+
* This copyrighted material is made available to anyone wishing to use,
11+
* modify, copy, or redistribute it subject to the terms and conditions
12+
* of the GNU Lesser General Public License, v. 2.1.
13+
* This program is distributed in the hope that it will be useful, but WITHOUT A
14+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16+
* You should have received a copy of the GNU Lesser General Public License,
17+
* v.2.1 along with this distribution; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19+
* MA 02110-1301, USA.
20+
*/
21+
package org.hibernate.osgitest;
22+
23+
import java.util.List;
24+
25+
import javax.persistence.EntityManager;
26+
27+
import org.hibernate.osgitest.entity.DataPoint;
28+
29+
/**
30+
* @author Brett Meyer
31+
*/
32+
public class DataPointServiceImpl implements DataPointService {
33+
34+
private EntityManager entityManager;
35+
36+
public void add(DataPoint dp) {
37+
entityManager.persist( dp );
38+
entityManager.flush();
39+
}
40+
41+
public List<DataPoint> getAll() {
42+
return entityManager.createQuery( "select d from DataPoint d", DataPoint.class ).getResultList();
43+
}
44+
45+
public void deleteAll() {
46+
entityManager.createQuery( "delete from DataPoint" ).executeUpdate();
47+
entityManager.flush();
48+
}
49+
50+
public EntityManager getEntityManager() {
51+
return entityManager;
52+
}
53+
54+
public void setEntityManager(EntityManager entityManager) {
55+
this.entityManager = entityManager;
56+
}
57+
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.hibernate.osgitest.command;
18+
19+
import org.apache.felix.gogo.commands.Action;
20+
import org.apache.felix.gogo.commands.Argument;
21+
import org.apache.felix.gogo.commands.Command;
22+
import org.apache.felix.service.command.CommandSession;
23+
import org.hibernate.osgitest.DataPointService;
24+
import org.hibernate.osgitest.entity.DataPoint;
25+
26+
@Command(scope = "dp", name = "add")
27+
public class AddCommand implements Action {
28+
@Argument(index=0, name="Name", required=true, description="Name", multiValued=false)
29+
String name;
30+
31+
private DataPointService dpService;
32+
33+
public void setDpService(DataPointService dpService) {
34+
this.dpService = dpService;
35+
}
36+
37+
public Object execute(CommandSession session) throws Exception {
38+
DataPoint dp = new DataPoint();
39+
dp.setName( name );
40+
dpService.add( dp );
41+
return null;
42+
}
43+
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.hibernate.osgitest.command;
18+
19+
import org.apache.felix.gogo.commands.Action;
20+
import org.apache.felix.gogo.commands.Command;
21+
import org.apache.felix.service.command.CommandSession;
22+
import org.hibernate.osgitest.DataPointService;
23+
24+
@Command(scope = "dp", name = "deleteAll")
25+
public class DeleteAllCommand implements Action {
26+
private DataPointService dpService;
27+
28+
public void setDpService(DataPointService dpService) {
29+
this.dpService = dpService;
30+
}
31+
32+
public Object execute(CommandSession session) throws Exception {
33+
dpService.deleteAll();
34+
return null;
35+
}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.hibernate.osgitest.command;
18+
19+
import java.util.List;
20+
21+
import org.apache.felix.gogo.commands.Action;
22+
import org.apache.felix.gogo.commands.Command;
23+
import org.apache.felix.service.command.CommandSession;
24+
import org.hibernate.osgitest.DataPointService;
25+
import org.hibernate.osgitest.entity.DataPoint;
26+
27+
@Command(scope = "dp", name = "getAll")
28+
public class GetAllCommand implements Action {
29+
private DataPointService dpService;
30+
31+
public void setDpService(DataPointService dpService) {
32+
this.dpService = dpService;
33+
}
34+
35+
public Object execute(CommandSession session) throws Exception {
36+
List<DataPoint> dps = dpService.getAll();
37+
for (DataPoint dp : dps) {
38+
System.out.println(dp.getId() + ", " + dp.getName());
39+
}
40+
return null;
41+
}
42+
43+
}

0 commit comments

Comments
 (0)