HHH-8112 OSGi quickstart tutorial projects
This commit is contained in:
parent
6f6e3c62b2
commit
61f0843a94
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
First install the H2 driver using:
|
||||||
|
> install -s mvn:com.h2database/h2/1.3.163
|
||||||
|
|
||||||
|
Then copy this file to the deploy folder
|
||||||
|
-->
|
||||||
|
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
|
||||||
|
|
||||||
|
<bean id="dataSource" class="org.h2.jdbcx.JdbcDataSource">
|
||||||
|
<property name="URL" value="jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE"/>
|
||||||
|
<property name="user" value="sa"/>
|
||||||
|
<property name="password" value=""/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<service interface="javax.sql.DataSource" ref="dataSource">
|
||||||
|
<service-properties>
|
||||||
|
<entry key="osgi.jndi.service.name" value="jdbc/h2ds"/>
|
||||||
|
</service-properties>
|
||||||
|
</service>
|
||||||
|
</blueprint>
|
|
@ -0,0 +1,72 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<features>
|
||||||
|
<feature name="hibernate-test">
|
||||||
|
|
||||||
|
<feature>karaf-framework</feature>
|
||||||
|
|
||||||
|
<!-- JTA -->
|
||||||
|
<config name="org.apache.aries.transaction">
|
||||||
|
aries.transaction.recoverable = true
|
||||||
|
aries.transaction.timeout = 600
|
||||||
|
aries.transaction.howl.logFileDir = ${karaf.data}/txlog
|
||||||
|
aries.transaction.howl.maxLogFiles = 2
|
||||||
|
aries.transaction.howl.maxBlocksPerFile = 512
|
||||||
|
aries.transaction.howl.bufferSizeKBytes = 4
|
||||||
|
</config>
|
||||||
|
<bundle start-level="30">mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1</bundle>
|
||||||
|
<bundle start-level="30">mvn:org.apache.aries.transaction/org.apache.aries.transaction.blueprint/1.0.0</bundle>
|
||||||
|
<bundle start-level="30">mvn:org.apache.aries.transaction/org.apache.aries.transaction.manager/1.0.1</bundle>
|
||||||
|
|
||||||
|
<!-- JPA -->
|
||||||
|
<bundle start-level="30">mvn:org.apache.geronimo.specs/geronimo-jpa_2.0_spec/1.1</bundle>
|
||||||
|
<bundle start-level="30">mvn:org.apache.aries/org.apache.aries.util/1.0.0</bundle>
|
||||||
|
<bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.api/1.0.0</bundle>
|
||||||
|
<bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.blueprint.aries/1.0.0</bundle>
|
||||||
|
<bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.container/1.0.0</bundle>
|
||||||
|
<bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.container.context/1.0.1</bundle>
|
||||||
|
|
||||||
|
<!-- JNDI -->
|
||||||
|
<bundle start-level="30">mvn:org.apache.aries.jndi/org.apache.aries.jndi.api/1.0.0</bundle>
|
||||||
|
<bundle start-level="30">mvn:org.apache.aries.jndi/org.apache.aries.jndi.core/1.0.0</bundle>
|
||||||
|
<bundle start-level="30">mvn:org.apache.aries.jndi/org.apache.aries.jndi.rmi/1.0.0</bundle>
|
||||||
|
<bundle start-level="30">mvn:org.apache.aries.jndi/org.apache.aries.jndi.url/1.0.0</bundle>
|
||||||
|
<bundle start-level="30">mvn:org.apache.aries.jndi/org.apache.aries.jndi.legacy.support/1.0.0</bundle>
|
||||||
|
|
||||||
|
<!-- Taken from Karaf-Tutorial -->
|
||||||
|
<bundle>mvn:commons-collections/commons-collections/3.2.1</bundle>
|
||||||
|
<bundle>mvn:commons-pool/commons-pool/1.5.4</bundle>
|
||||||
|
<bundle>mvn:commons-dbcp/commons-dbcp/1.4</bundle>
|
||||||
|
<bundle>mvn:commons-lang/commons-lang/2.6</bundle>
|
||||||
|
<bundle>wrap:mvn:net.sourceforge.serp/serp/1.13.1</bundle>
|
||||||
|
|
||||||
|
<bundle>mvn:com.h2database/h2/1.3.170</bundle>
|
||||||
|
<bundle>blueprint:file:/home/bmeyer2/workspace_hibernate_master/HibernateOSGi/datasource-h2.xml</bundle>
|
||||||
|
|
||||||
|
<!-- These do not natively support OSGi, so using 3rd party bundles. -->
|
||||||
|
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/2.7.7_5</bundle>
|
||||||
|
<bundle>mvn:org.jboss.javassist/com.springsource.javassist/3.15.0.GA</bundle>
|
||||||
|
<bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jsr303-api-1.0.0/2.2.0</bundle>
|
||||||
|
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.ant/1.8.2_2</bundle>
|
||||||
|
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5</bundle>
|
||||||
|
|
||||||
|
<!-- These do not natively support OSGi, so wrap with BND. -->
|
||||||
|
<bundle>wrap:mvn:org.jboss/jandex/1.1.0.Alpha1</bundle>
|
||||||
|
|
||||||
|
<bundle>wrap:mvn:org.hibernate.common/hibernate-commons-annotations/4.0.2.Final</bundle>
|
||||||
|
<bundle>mvn:com.fasterxml/classmate/0.5.4</bundle>
|
||||||
|
<bundle>mvn:org.jboss.logging/jboss-logging/3.1.0.GA</bundle>
|
||||||
|
|
||||||
|
<bundle>mvn:org.hibernate/hibernate-core/4.2.2-SNAPSHOT</bundle>
|
||||||
|
<bundle>mvn:org.hibernate/hibernate-entitymanager/4.2.2-SNAPSHOT</bundle>
|
||||||
|
|
||||||
|
<!-- TODO: It seems that the persistence unit bundle needs to be started
|
||||||
|
before hibernate-osgi. When the BundleActivator is started,
|
||||||
|
the persistence unit is provided even though managed-jpa
|
||||||
|
hasn't completely started yet. If that happens, you'll get an "illegal
|
||||||
|
bundle state" exception. Is there a way for the activator to
|
||||||
|
watch for bundles with PUs before registering the persistence provider? -->
|
||||||
|
<bundle>mvn:org.hibernate.osgi/managed-jpa/1.0.0</bundle>
|
||||||
|
|
||||||
|
<bundle>mvn:org.hibernate/hibernate-osgi/4.2.2-SNAPSHOT</bundle>
|
||||||
|
</feature>
|
||||||
|
</features>
|
|
@ -0,0 +1,62 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.hibernate.osgi</groupId>
|
||||||
|
<artifactId>managed-jpa</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.geronimo.specs</groupId>
|
||||||
|
<artifactId>geronimo-jpa_2.0_spec</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.osgi</groupId>
|
||||||
|
<artifactId>org.osgi.core</artifactId>
|
||||||
|
<version>4.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.osgi</groupId>
|
||||||
|
<artifactId>org.osgi.enterprise</artifactId>
|
||||||
|
<version>4.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.karaf.shell</groupId>
|
||||||
|
<artifactId>org.apache.karaf.shell.console</artifactId>
|
||||||
|
<version>2.3.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<instructions>
|
||||||
|
<Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
|
||||||
|
<Bundle-Name>${pom.artifactId}</Bundle-Name>
|
||||||
|
<Bundle-Version>1.0.0</Bundle-Version>
|
||||||
|
<Export-Package>
|
||||||
|
org.hibernate.osgitest,
|
||||||
|
org.hibernate.osgitest.entity
|
||||||
|
</Export-Package>
|
||||||
|
<Import-Package>
|
||||||
|
org.apache.felix.service.command,
|
||||||
|
org.apache.felix.gogo.commands,
|
||||||
|
org.apache.karaf.shell.console,
|
||||||
|
org.apache.karaf.shell.commands,
|
||||||
|
org.hibernate.proxy,
|
||||||
|
javassist.util.proxy,
|
||||||
|
*
|
||||||
|
</Import-Package>
|
||||||
|
<Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||||
|
* as indicated by the @authors tag. All rights reserved.
|
||||||
|
* See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use,
|
||||||
|
* modify, copy, or redistribute it subject to the terms and conditions
|
||||||
|
* of the GNU Lesser General Public License, v. 2.1.
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License,
|
||||||
|
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package org.hibernate.osgitest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brett Meyer
|
||||||
|
*/
|
||||||
|
public interface DataPointService {
|
||||||
|
|
||||||
|
public void add(DataPoint dp);
|
||||||
|
|
||||||
|
public List<DataPoint> getAll();
|
||||||
|
|
||||||
|
public void deleteAll();
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||||
|
* as indicated by the @authors tag. All rights reserved.
|
||||||
|
* See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use,
|
||||||
|
* modify, copy, or redistribute it subject to the terms and conditions
|
||||||
|
* of the GNU Lesser General Public License, v. 2.1.
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License,
|
||||||
|
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package org.hibernate.osgitest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brett Meyer
|
||||||
|
*/
|
||||||
|
public class DataPointServiceImpl implements DataPointService {
|
||||||
|
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
public void add(DataPoint dp) {
|
||||||
|
entityManager.persist( dp );
|
||||||
|
entityManager.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DataPoint> getAll() {
|
||||||
|
return entityManager.createQuery( "select d from DataPoint d", DataPoint.class ).getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteAll() {
|
||||||
|
entityManager.createQuery( "delete from DataPoint" ).executeUpdate();
|
||||||
|
entityManager.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityManager getEntityManager() {
|
||||||
|
return entityManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEntityManager(EntityManager entityManager) {
|
||||||
|
this.entityManager = entityManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* 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 org.hibernate.osgitest.command;
|
||||||
|
|
||||||
|
import org.apache.felix.gogo.commands.Action;
|
||||||
|
import org.apache.felix.gogo.commands.Argument;
|
||||||
|
import org.apache.felix.gogo.commands.Command;
|
||||||
|
import org.apache.felix.service.command.CommandSession;
|
||||||
|
import org.hibernate.osgitest.DataPointService;
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
@Command(scope = "dp", name = "add")
|
||||||
|
public class AddCommand implements Action {
|
||||||
|
@Argument(index=0, name="Name", required=true, description="Name", multiValued=false)
|
||||||
|
String name;
|
||||||
|
|
||||||
|
private DataPointService dpService;
|
||||||
|
|
||||||
|
public void setDpService(DataPointService dpService) {
|
||||||
|
this.dpService = dpService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute(CommandSession session) throws Exception {
|
||||||
|
DataPoint dp = new DataPoint();
|
||||||
|
dp.setName( name );
|
||||||
|
dpService.add( dp );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* 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 org.hibernate.osgitest.command;
|
||||||
|
|
||||||
|
import org.apache.felix.gogo.commands.Action;
|
||||||
|
import org.apache.felix.gogo.commands.Command;
|
||||||
|
import org.apache.felix.service.command.CommandSession;
|
||||||
|
import org.hibernate.osgitest.DataPointService;
|
||||||
|
|
||||||
|
@Command(scope = "dp", name = "deleteAll")
|
||||||
|
public class DeleteAllCommand implements Action {
|
||||||
|
private DataPointService dpService;
|
||||||
|
|
||||||
|
public void setDpService(DataPointService dpService) {
|
||||||
|
this.dpService = dpService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute(CommandSession session) throws Exception {
|
||||||
|
dpService.deleteAll();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* 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 org.hibernate.osgitest.command;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.felix.gogo.commands.Action;
|
||||||
|
import org.apache.felix.gogo.commands.Command;
|
||||||
|
import org.apache.felix.service.command.CommandSession;
|
||||||
|
import org.hibernate.osgitest.DataPointService;
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
@Command(scope = "dp", name = "getAll")
|
||||||
|
public class GetAllCommand implements Action {
|
||||||
|
private DataPointService dpService;
|
||||||
|
|
||||||
|
public void setDpService(DataPointService dpService) {
|
||||||
|
this.dpService = dpService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute(CommandSession session) throws Exception {
|
||||||
|
List<DataPoint> dps = dpService.getAll();
|
||||||
|
for (DataPoint dp : dps) {
|
||||||
|
System.out.println(dp.getId() + ", " + dp.getName());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||||
|
* as indicated by the @authors tag. All rights reserved.
|
||||||
|
* See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use,
|
||||||
|
* modify, copy, or redistribute it subject to the terms and conditions
|
||||||
|
* of the GNU Lesser General Public License, v. 2.1.
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License,
|
||||||
|
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package org.hibernate.osgitest.entity;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brett Meyer
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class DataPoint {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
version="1.0">
|
||||||
|
<persistence-unit name="managed-jpa" transaction-type="JTA">
|
||||||
|
<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/h2ds)</jta-data-source>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
|
||||||
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
|
||||||
|
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
|
||||||
|
<property name="hibernate.archive.autodetection" value="class"/>
|
||||||
|
</properties>
|
||||||
|
</persistence-unit>
|
||||||
|
</persistence>
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
-->
|
||||||
|
<blueprint default-activation="eager"
|
||||||
|
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0"
|
||||||
|
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0">
|
||||||
|
|
||||||
|
<bean id="dpService" class="org.hibernate.osgitest.DataPointServiceImpl">
|
||||||
|
<jpa:context unitname="managed-jpa" property="entityManager"/>
|
||||||
|
<tx:transaction method="*" value="Required"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<service ref="dpService" interface="org.hibernate.osgitest.DataPointService" />
|
||||||
|
|
||||||
|
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
|
||||||
|
<command name="dp/add">
|
||||||
|
<action class="org.hibernate.osgitest.command.AddCommand">
|
||||||
|
<property name="dpService" ref="dpService"/>
|
||||||
|
</action>
|
||||||
|
</command>
|
||||||
|
<command name="dp/getAll">
|
||||||
|
<action class="org.hibernate.osgitest.command.GetAllCommand">
|
||||||
|
<property name="dpService" ref="dpService"/>
|
||||||
|
</action>
|
||||||
|
</command>
|
||||||
|
<command name="dp/deleteAll">
|
||||||
|
<action class="org.hibernate.osgitest.command.DeleteAllCommand">
|
||||||
|
<property name="dpService" ref="dpService"/>
|
||||||
|
</action>
|
||||||
|
</command>
|
||||||
|
</command-bundle>
|
||||||
|
</blueprint>
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<features>
|
||||||
|
<feature name="hibernate-test">
|
||||||
|
|
||||||
|
<feature>karaf-framework</feature>
|
||||||
|
|
||||||
|
<!-- JTA -->
|
||||||
|
<bundle start-level="30">mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1</bundle>
|
||||||
|
|
||||||
|
<!-- JPA -->
|
||||||
|
<bundle start-level="30">mvn:org.apache.geronimo.specs/geronimo-jpa_2.0_spec/1.1</bundle>
|
||||||
|
|
||||||
|
<!-- Taken from Karaf-Tutorial -->
|
||||||
|
<bundle>mvn:commons-collections/commons-collections/3.2.1</bundle>
|
||||||
|
<bundle>mvn:commons-pool/commons-pool/1.5.4</bundle>
|
||||||
|
<bundle>mvn:commons-dbcp/commons-dbcp/1.4</bundle>
|
||||||
|
<bundle>mvn:commons-lang/commons-lang/2.6</bundle>
|
||||||
|
<bundle>wrap:mvn:net.sourceforge.serp/serp/1.13.1</bundle>
|
||||||
|
|
||||||
|
<bundle>mvn:com.h2database/h2/1.3.170</bundle>
|
||||||
|
|
||||||
|
<!-- These do not natively support OSGi, so using 3rd party bundles. -->
|
||||||
|
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/2.7.7_5</bundle>
|
||||||
|
<bundle>mvn:org.jboss.javassist/com.springsource.javassist/3.15.0.GA</bundle>
|
||||||
|
<bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jsr303-api-1.0.0/2.2.0</bundle>
|
||||||
|
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.ant/1.8.2_2</bundle>
|
||||||
|
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5</bundle>
|
||||||
|
|
||||||
|
<!-- These do not natively support OSGi, so wrap with BND. -->
|
||||||
|
<bundle>wrap:mvn:org.hibernate.common/hibernate-commons-annotations/4.0.2.Final</bundle>
|
||||||
|
<bundle>wrap:mvn:org.jboss/jandex/1.1.0.Alpha1</bundle>
|
||||||
|
|
||||||
|
<bundle>mvn:com.fasterxml/classmate/0.5.4</bundle>
|
||||||
|
<bundle>mvn:org.jboss.logging/jboss-logging/3.1.0.GA</bundle>
|
||||||
|
|
||||||
|
<bundle>mvn:org.hibernate/hibernate-core/4.2.2-SNAPSHOT</bundle>
|
||||||
|
<bundle>mvn:org.hibernate/hibernate-entitymanager/4.2.2-SNAPSHOT</bundle>
|
||||||
|
<bundle>mvn:org.hibernate/hibernate-osgi/4.2.2-SNAPSHOT</bundle>
|
||||||
|
|
||||||
|
<bundle>mvn:org.hibernate.osgi/unmanaged-jpa/1.0.0</bundle>
|
||||||
|
</feature>
|
||||||
|
</features>
|
|
@ -0,0 +1,73 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.hibernate.osgi</groupId>
|
||||||
|
<artifactId>unmanaged-jpa</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.geronimo.specs</groupId>
|
||||||
|
<artifactId>geronimo-jpa_2.0_spec</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.osgi</groupId>
|
||||||
|
<artifactId>org.osgi.core</artifactId>
|
||||||
|
<version>4.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.osgi</groupId>
|
||||||
|
<artifactId>org.osgi.enterprise</artifactId>
|
||||||
|
<version>4.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.karaf.shell</groupId>
|
||||||
|
<artifactId>org.apache.karaf.shell.console</artifactId>
|
||||||
|
<version>2.3.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate</groupId>
|
||||||
|
<artifactId>hibernate-entitymanager</artifactId>
|
||||||
|
<version>4.2.2-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<version>1.3.170</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<instructions>
|
||||||
|
<Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
|
||||||
|
<Bundle-Name>${pom.artifactId}</Bundle-Name>
|
||||||
|
<Bundle-Version>1.0.0</Bundle-Version>
|
||||||
|
<Export-Package>
|
||||||
|
org.hibernate.osgitest,
|
||||||
|
org.hibernate.osgitest.entity
|
||||||
|
</Export-Package>
|
||||||
|
<Import-Package>
|
||||||
|
org.apache.felix.service.command,
|
||||||
|
org.apache.felix.gogo.commands,
|
||||||
|
org.apache.karaf.shell.console,
|
||||||
|
org.apache.karaf.shell.commands,
|
||||||
|
org.h2,
|
||||||
|
org.hibernate.proxy,
|
||||||
|
javassist.util.proxy,
|
||||||
|
*
|
||||||
|
</Import-Package>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||||
|
* as indicated by the @authors tag. All rights reserved.
|
||||||
|
* See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use,
|
||||||
|
* modify, copy, or redistribute it subject to the terms and conditions
|
||||||
|
* of the GNU Lesser General Public License, v. 2.1.
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License,
|
||||||
|
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package org.hibernate.osgitest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brett Meyer
|
||||||
|
*/
|
||||||
|
public interface DataPointService {
|
||||||
|
|
||||||
|
public void add(DataPoint dp);
|
||||||
|
|
||||||
|
public void update(DataPoint dp);
|
||||||
|
|
||||||
|
public DataPoint get(long id);
|
||||||
|
|
||||||
|
public List<DataPoint> getAll();
|
||||||
|
|
||||||
|
public void deleteAll();
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||||
|
* as indicated by the @authors tag. All rights reserved.
|
||||||
|
* See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use,
|
||||||
|
* modify, copy, or redistribute it subject to the terms and conditions
|
||||||
|
* of the GNU Lesser General Public License, v. 2.1.
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License,
|
||||||
|
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package org.hibernate.osgitest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brett Meyer
|
||||||
|
*/
|
||||||
|
public class DataPointServiceImpl implements DataPointService {
|
||||||
|
|
||||||
|
public void add(DataPoint dp) {
|
||||||
|
EntityManager em = HibernateUtil.getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
em.persist( dp );
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(DataPoint dp) {
|
||||||
|
EntityManager em = HibernateUtil.getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
em.merge( dp );
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataPoint get(long id) {
|
||||||
|
EntityManager em = HibernateUtil.getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
DataPoint dp = (DataPoint) em.createQuery( "from DataPoint dp where dp.id=" + id ).getSingleResult();
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
|
return dp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DataPoint> getAll() {
|
||||||
|
EntityManager em = HibernateUtil.getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
List list = em.createQuery( "from DataPoint" ).getResultList();
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteAll() {
|
||||||
|
EntityManager em = HibernateUtil.getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
em.createQuery( "delete from DataPoint" ).executeUpdate();
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||||
|
* as indicated by the @authors tag. All rights reserved.
|
||||||
|
* See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use,
|
||||||
|
* modify, copy, or redistribute it subject to the terms and conditions
|
||||||
|
* of the GNU Lesser General Public License, v. 2.1.
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License,
|
||||||
|
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package org.hibernate.osgitest;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.EntityManagerFactory;
|
||||||
|
import javax.persistence.spi.PersistenceProvider;
|
||||||
|
|
||||||
|
import org.osgi.framework.Bundle;
|
||||||
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.osgi.framework.FrameworkUtil;
|
||||||
|
import org.osgi.framework.ServiceReference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brett Meyer
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class HibernateUtil {
|
||||||
|
|
||||||
|
private static EntityManagerFactory emf;
|
||||||
|
|
||||||
|
public static EntityManager getEntityManager() {
|
||||||
|
return getEntityManagerFactory().createEntityManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static EntityManagerFactory getEntityManagerFactory() {
|
||||||
|
if ( emf == null ) {
|
||||||
|
Bundle thisBundle = FrameworkUtil.getBundle( HibernateUtil.class );
|
||||||
|
// Could get this by wiring up OsgiTestBundleActivator as well.
|
||||||
|
BundleContext context = thisBundle.getBundleContext();
|
||||||
|
|
||||||
|
ServiceReference serviceReference = context.getServiceReference( PersistenceProvider.class.getName() );
|
||||||
|
PersistenceProvider persistenceProvider = (PersistenceProvider) context.getService( serviceReference );
|
||||||
|
|
||||||
|
emf = persistenceProvider.createEntityManagerFactory( "unmanaged-jpa", null );
|
||||||
|
}
|
||||||
|
return emf;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* 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 org.hibernate.osgitest.command;
|
||||||
|
|
||||||
|
import org.apache.felix.gogo.commands.Action;
|
||||||
|
import org.apache.felix.gogo.commands.Argument;
|
||||||
|
import org.apache.felix.gogo.commands.Command;
|
||||||
|
import org.apache.felix.service.command.CommandSession;
|
||||||
|
import org.hibernate.osgitest.DataPointService;
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
@Command(scope = "dp", name = "addJPA")
|
||||||
|
public class AddCommand implements Action {
|
||||||
|
@Argument(index=0, name="Name", required=true, description="Name", multiValued=false)
|
||||||
|
String name;
|
||||||
|
|
||||||
|
private DataPointService dpService;
|
||||||
|
|
||||||
|
public void setDpService(DataPointService dpService) {
|
||||||
|
this.dpService = dpService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute(CommandSession session) throws Exception {
|
||||||
|
DataPoint dp = new DataPoint();
|
||||||
|
dp.setName( name );
|
||||||
|
dpService.add( dp );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* 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 org.hibernate.osgitest.command;
|
||||||
|
|
||||||
|
import org.apache.felix.gogo.commands.Action;
|
||||||
|
import org.apache.felix.gogo.commands.Command;
|
||||||
|
import org.apache.felix.service.command.CommandSession;
|
||||||
|
import org.hibernate.osgitest.DataPointService;
|
||||||
|
|
||||||
|
@Command(scope = "dp", name = "deleteAllJPA")
|
||||||
|
public class DeleteAllCommand implements Action {
|
||||||
|
private DataPointService dpService;
|
||||||
|
|
||||||
|
public void setDpService(DataPointService dpService) {
|
||||||
|
this.dpService = dpService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute(CommandSession session) throws Exception {
|
||||||
|
dpService.deleteAll();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* 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 org.hibernate.osgitest.command;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.felix.gogo.commands.Action;
|
||||||
|
import org.apache.felix.gogo.commands.Command;
|
||||||
|
import org.apache.felix.service.command.CommandSession;
|
||||||
|
import org.hibernate.osgitest.DataPointService;
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
@Command(scope = "dp", name = "getAllJPA")
|
||||||
|
public class GetAllCommand implements Action {
|
||||||
|
private DataPointService dpService;
|
||||||
|
|
||||||
|
public void setDpService(DataPointService dpService) {
|
||||||
|
this.dpService = dpService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute(CommandSession session) throws Exception {
|
||||||
|
List<DataPoint> dps = dpService.getAll();
|
||||||
|
for (DataPoint dp : dps) {
|
||||||
|
System.out.println(dp.getId() + ", " + dp.getName());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* 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 org.hibernate.osgitest.command;
|
||||||
|
|
||||||
|
import org.apache.felix.gogo.commands.Action;
|
||||||
|
import org.apache.felix.gogo.commands.Argument;
|
||||||
|
import org.apache.felix.gogo.commands.Command;
|
||||||
|
import org.apache.felix.service.command.CommandSession;
|
||||||
|
import org.hibernate.osgitest.DataPointService;
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
@Command(scope = "dp", name = "updateJPA")
|
||||||
|
public class UpdateCommand implements Action {
|
||||||
|
@Argument(index=0, name="Id", required=true, description="Id", multiValued=false)
|
||||||
|
String id;
|
||||||
|
|
||||||
|
@Argument(index=1, name="Name", required=true, description="Name", multiValued=false)
|
||||||
|
String name;
|
||||||
|
|
||||||
|
private DataPointService dpService;
|
||||||
|
|
||||||
|
public void setDpService(DataPointService dpService) {
|
||||||
|
this.dpService = dpService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute(CommandSession session) throws Exception {
|
||||||
|
DataPoint dp = dpService.get( Long.valueOf( id ) );
|
||||||
|
dp.setName( name );
|
||||||
|
dpService.update( dp );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||||
|
* as indicated by the @authors tag. All rights reserved.
|
||||||
|
* See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use,
|
||||||
|
* modify, copy, or redistribute it subject to the terms and conditions
|
||||||
|
* of the GNU Lesser General Public License, v. 2.1.
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License,
|
||||||
|
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package org.hibernate.osgitest.entity;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brett Meyer
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class DataPoint {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
version="1.0">
|
||||||
|
<persistence-unit name="unmanaged-jpa">
|
||||||
|
<class>org.hibernate.osgitest.entity.DataPoint</class>
|
||||||
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
|
||||||
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
|
||||||
|
<property name="hibernate.connection.url" value="jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE"/>
|
||||||
|
<property name="hibernate.connection.username" value="sa"/>
|
||||||
|
<property name="hibernate.connection.password" value=""/>
|
||||||
|
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
|
||||||
|
</properties>
|
||||||
|
</persistence-unit>
|
||||||
|
</persistence>
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
-->
|
||||||
|
<blueprint default-activation="eager"
|
||||||
|
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
|
||||||
|
<bean id="dpService" class="org.hibernate.osgitest.DataPointServiceImpl"/>
|
||||||
|
|
||||||
|
<service ref="dpService" interface="org.hibernate.osgitest.DataPointService" />
|
||||||
|
|
||||||
|
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
|
||||||
|
<command name="dp:add">
|
||||||
|
<action class="org.hibernate.osgitest.command.AddCommand">
|
||||||
|
<property name="dpService" ref="dpService"/>
|
||||||
|
</action>
|
||||||
|
</command>
|
||||||
|
<command name="dp:update">
|
||||||
|
<action class="org.hibernate.osgitest.command.UpdateCommand">
|
||||||
|
<property name="dpService" ref="dpService"/>
|
||||||
|
</action>
|
||||||
|
</command>
|
||||||
|
<command name="dp:getAll">
|
||||||
|
<action class="org.hibernate.osgitest.command.GetAllCommand">
|
||||||
|
<property name="dpService" ref="dpService"/>
|
||||||
|
</action>
|
||||||
|
</command>
|
||||||
|
<command name="dp:deleteAll">
|
||||||
|
<action class="org.hibernate.osgitest.command.DeleteAllCommand">
|
||||||
|
<property name="dpService" ref="dpService"/>
|
||||||
|
</action>
|
||||||
|
</command>
|
||||||
|
</command-bundle>
|
||||||
|
</blueprint>
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<features>
|
||||||
|
<feature name="hibernate-test">
|
||||||
|
|
||||||
|
<feature>karaf-framework</feature>
|
||||||
|
|
||||||
|
<!-- JTA -->
|
||||||
|
<bundle start-level="30">mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1</bundle>
|
||||||
|
|
||||||
|
<!-- JPA -->
|
||||||
|
<bundle start-level="30">mvn:org.apache.geronimo.specs/geronimo-jpa_2.0_spec/1.1</bundle>
|
||||||
|
|
||||||
|
<!-- Taken from Karaf-Tutorial -->
|
||||||
|
<bundle>mvn:commons-collections/commons-collections/3.2.1</bundle>
|
||||||
|
<bundle>mvn:commons-pool/commons-pool/1.5.4</bundle>
|
||||||
|
<bundle>mvn:commons-dbcp/commons-dbcp/1.4</bundle>
|
||||||
|
<bundle>mvn:commons-lang/commons-lang/2.6</bundle>
|
||||||
|
<bundle>wrap:mvn:net.sourceforge.serp/serp/1.13.1</bundle>
|
||||||
|
|
||||||
|
<bundle>mvn:com.h2database/h2/1.3.170</bundle>
|
||||||
|
|
||||||
|
<!-- These do not natively support OSGi, so using 3rd party bundles. -->
|
||||||
|
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/2.7.7_5</bundle>
|
||||||
|
<bundle>mvn:org.jboss.javassist/com.springsource.javassist/3.15.0.GA</bundle>
|
||||||
|
<bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jsr303-api-1.0.0/2.2.0</bundle>
|
||||||
|
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.ant/1.8.2_2</bundle>
|
||||||
|
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5</bundle>
|
||||||
|
|
||||||
|
<!-- These do not natively support OSGi, so wrap with BND. -->
|
||||||
|
<bundle>wrap:mvn:org.hibernate.common/hibernate-commons-annotations/4.0.2.Final</bundle>
|
||||||
|
<bundle>wrap:mvn:org.jboss/jandex/1.1.0.Alpha1</bundle>
|
||||||
|
<!-- Optional. Needed to test C3P0 connection pools. -->
|
||||||
|
<!-- <bundle>wrap:mvn:c3p0/c3p0/0.9.1</bundle> -->
|
||||||
|
<!-- Optional. Needed to test Proxool connection pools. -->
|
||||||
|
<!-- <bundle>wrap:mvn:proxool/proxool/0.8.3</bundle> -->
|
||||||
|
<!-- Optional. Needed to test ehcache 2lc. -->
|
||||||
|
<!-- <bundle>wrap:mvn:net.sf.ehcache/ehcache-core/2.4.3</bundle> -->
|
||||||
|
|
||||||
|
<bundle>mvn:com.fasterxml/classmate/0.5.4</bundle>
|
||||||
|
<bundle>mvn:org.jboss.logging/jboss-logging/3.1.0.GA</bundle>
|
||||||
|
|
||||||
|
<!-- JACC is optional. -->
|
||||||
|
<!--<bundle>mvn:javax.servlet/javax.servlet-api/3.0.1</bundle>
|
||||||
|
<bundle>mvn:org.jboss.spec.javax.security.jacc/jboss-jacc-api_1.4_spec/1.0.2.Final</bundle>-->
|
||||||
|
|
||||||
|
<!-- hibernate-validator is optional. -->
|
||||||
|
<!--<bundle>wrap:mvn:javax.validation/validation-api/1.0.0.GA</bundle>
|
||||||
|
<bundle>mvn:org.hibernate/hibernate-validator/4.2.0.Final</bundle>-->
|
||||||
|
|
||||||
|
<!-- Optional. Needed to test infinispan 2lc. -->
|
||||||
|
<!-- IMPORTANT: Infinispan requires the JRE sun.misc package. You
|
||||||
|
MUST enable this in your OSGi container. For Karaf, add
|
||||||
|
"org.osgi.framework.system.packages.extra=sun.misc" to etc/config.properties -->
|
||||||
|
<!-- <bundle>wrap:mvn:org.jboss.marshalling/jboss-marshalling/1.3.17.GA</bundle>
|
||||||
|
<bundle>wrap:mvn:org.jboss.marshalling/jboss-marshalling-river/1.3.17.GA</bundle>
|
||||||
|
<bundle>wrap:mvn:org.jboss/staxmapper/1.1.0.Final</bundle>
|
||||||
|
<bundle>mvn:org.jgroups/jgroups/3.2.8.Final</bundle>
|
||||||
|
<bundle>mvn:org.infinispan/infinispan-core/5.2.0.Beta3</bundle> -->
|
||||||
|
|
||||||
|
<bundle>mvn:org.hibernate/hibernate-core/4.2.2-SNAPSHOT</bundle>
|
||||||
|
<!-- TODO: Shouldn't need this, but hibernate-osgi's activator is a catch-all for SF and EMF. -->
|
||||||
|
<bundle>mvn:org.hibernate/hibernate-entitymanager/4.2.2-SNAPSHOT</bundle>
|
||||||
|
<!-- <bundle>mvn:org.hibernate/hibernate-c3p0/4.3.0-SNAPSHOT</bundle> -->
|
||||||
|
<!-- <bundle>mvn:org.hibernate/hibernate-proxool/4.3.0-SNAPSHOT</bundle> -->
|
||||||
|
<!-- <bundle>mvn:org.hibernate/hibernate-ehcache/4.3.0-SNAPSHOT</bundle> -->
|
||||||
|
<!-- <bundle>mvn:org.hibernate/hibernate-infinispan/4.3.0-SNAPSHOT</bundle> -->
|
||||||
|
<bundle>mvn:org.hibernate/hibernate-osgi/4.2.2-SNAPSHOT</bundle>
|
||||||
|
|
||||||
|
<bundle>mvn:org.hibernate.osgi/unmanaged-native/1.0.0</bundle>
|
||||||
|
</feature>
|
||||||
|
</features>
|
|
@ -0,0 +1,76 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.hibernate.osgi</groupId>
|
||||||
|
<artifactId>unmanaged-native</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.geronimo.specs</groupId>
|
||||||
|
<artifactId>geronimo-jpa_2.0_spec</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.osgi</groupId>
|
||||||
|
<artifactId>org.osgi.core</artifactId>
|
||||||
|
<version>4.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.osgi</groupId>
|
||||||
|
<artifactId>org.osgi.enterprise</artifactId>
|
||||||
|
<version>4.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.karaf.shell</groupId>
|
||||||
|
<artifactId>org.apache.karaf.shell.console</artifactId>
|
||||||
|
<version>2.3.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate</groupId>
|
||||||
|
<artifactId>hibernate-core</artifactId>
|
||||||
|
<version>4.2.2-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<version>1.3.170</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<instructions>
|
||||||
|
<Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
|
||||||
|
<Bundle-Name>${pom.artifactId}</Bundle-Name>
|
||||||
|
<Bundle-Version>1.0.0</Bundle-Version>
|
||||||
|
<Export-Package>
|
||||||
|
org.hibernate.osgitest,
|
||||||
|
org.hibernate.osgitest.entity
|
||||||
|
</Export-Package>
|
||||||
|
<Import-Package>
|
||||||
|
org.apache.felix.service.command,
|
||||||
|
org.apache.felix.gogo.commands,
|
||||||
|
org.apache.karaf.shell.console,
|
||||||
|
org.apache.karaf.shell.commands,
|
||||||
|
org.h2,
|
||||||
|
org.hibernate,
|
||||||
|
org.hibernate.cfg,
|
||||||
|
org.hibernate.service,
|
||||||
|
org.hibernate.proxy,
|
||||||
|
javassist.util.proxy,
|
||||||
|
*
|
||||||
|
</Import-Package>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||||
|
* as indicated by the @authors tag. All rights reserved.
|
||||||
|
* See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use,
|
||||||
|
* modify, copy, or redistribute it subject to the terms and conditions
|
||||||
|
* of the GNU Lesser General Public License, v. 2.1.
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License,
|
||||||
|
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package org.hibernate.osgitest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brett Meyer
|
||||||
|
*/
|
||||||
|
public interface DataPointService {
|
||||||
|
|
||||||
|
public void add(DataPoint dp);
|
||||||
|
|
||||||
|
public void update(DataPoint dp);
|
||||||
|
|
||||||
|
public DataPoint get(long id);
|
||||||
|
|
||||||
|
public List<DataPoint> getAll();
|
||||||
|
|
||||||
|
public void deleteAll();
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||||
|
* as indicated by the @authors tag. All rights reserved.
|
||||||
|
* See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use,
|
||||||
|
* modify, copy, or redistribute it subject to the terms and conditions
|
||||||
|
* of the GNU Lesser General Public License, v. 2.1.
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License,
|
||||||
|
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package org.hibernate.osgitest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brett Meyer
|
||||||
|
*/
|
||||||
|
public class DataPointServiceImpl implements DataPointService {
|
||||||
|
|
||||||
|
public void add(DataPoint dp) {
|
||||||
|
Session s = HibernateUtil.getSession();
|
||||||
|
s.getTransaction().begin();
|
||||||
|
s.persist( dp );
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(DataPoint dp) {
|
||||||
|
Session s = HibernateUtil.getSession();
|
||||||
|
s.getTransaction().begin();
|
||||||
|
s.update( dp );
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataPoint get(long id) {
|
||||||
|
Session s = HibernateUtil.getSession();
|
||||||
|
s.getTransaction().begin();
|
||||||
|
DataPoint dp = (DataPoint) s.createCriteria( DataPoint.class ).add(
|
||||||
|
Restrictions.eq( "id", id ) ).uniqueResult();
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
return dp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DataPoint> getAll() {
|
||||||
|
Session s = HibernateUtil.getSession();
|
||||||
|
s.getTransaction().begin();
|
||||||
|
List list = s.createQuery( "from DataPoint" ).list();
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteAll() {
|
||||||
|
Session s = HibernateUtil.getSession();
|
||||||
|
s.getTransaction().begin();
|
||||||
|
s.createQuery( "delete from DataPoint" ).executeUpdate();
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||||
|
* as indicated by the @authors tag. All rights reserved.
|
||||||
|
* See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use,
|
||||||
|
* modify, copy, or redistribute it subject to the terms and conditions
|
||||||
|
* of the GNU Lesser General Public License, v. 2.1.
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License,
|
||||||
|
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package org.hibernate.osgitest;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.osgi.framework.Bundle;
|
||||||
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.osgi.framework.FrameworkUtil;
|
||||||
|
import org.osgi.framework.ServiceReference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brett Meyer
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class HibernateUtil {
|
||||||
|
|
||||||
|
private static SessionFactory sf;
|
||||||
|
|
||||||
|
public static Session getSession() {
|
||||||
|
return getSessionFactory().openSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SessionFactory getSessionFactory() {
|
||||||
|
if ( sf == null ) {
|
||||||
|
Bundle thisBundle = FrameworkUtil.getBundle( HibernateUtil.class );
|
||||||
|
// Could get this by wiring up OsgiTestBundleActivator as well.
|
||||||
|
BundleContext context = thisBundle.getBundleContext();
|
||||||
|
|
||||||
|
ServiceReference sr = context.getServiceReference( SessionFactory.class.getName() );
|
||||||
|
sf = (SessionFactory) context.getService( sr );
|
||||||
|
}
|
||||||
|
return sf;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* 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 org.hibernate.osgitest.command;
|
||||||
|
|
||||||
|
import org.apache.felix.gogo.commands.Action;
|
||||||
|
import org.apache.felix.gogo.commands.Argument;
|
||||||
|
import org.apache.felix.gogo.commands.Command;
|
||||||
|
import org.apache.felix.service.command.CommandSession;
|
||||||
|
import org.hibernate.osgitest.DataPointService;
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
@Command(scope = "dp", name = "add")
|
||||||
|
public class AddCommand implements Action {
|
||||||
|
@Argument(index=0, name="Name", required=true, description="Name", multiValued=false)
|
||||||
|
String name;
|
||||||
|
|
||||||
|
private DataPointService dpService;
|
||||||
|
|
||||||
|
public void setDpService(DataPointService dpService) {
|
||||||
|
this.dpService = dpService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute(CommandSession session) throws Exception {
|
||||||
|
DataPoint dp = new DataPoint();
|
||||||
|
dp.setName( name );
|
||||||
|
dpService.add( dp );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* 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 org.hibernate.osgitest.command;
|
||||||
|
|
||||||
|
import org.apache.felix.gogo.commands.Action;
|
||||||
|
import org.apache.felix.gogo.commands.Command;
|
||||||
|
import org.apache.felix.service.command.CommandSession;
|
||||||
|
import org.hibernate.osgitest.DataPointService;
|
||||||
|
|
||||||
|
@Command(scope = "dp", name = "deleteAll")
|
||||||
|
public class DeleteAllCommand implements Action {
|
||||||
|
private DataPointService dpService;
|
||||||
|
|
||||||
|
public void setDpService(DataPointService dpService) {
|
||||||
|
this.dpService = dpService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute(CommandSession session) throws Exception {
|
||||||
|
dpService.deleteAll();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* 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 org.hibernate.osgitest.command;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.felix.gogo.commands.Action;
|
||||||
|
import org.apache.felix.gogo.commands.Command;
|
||||||
|
import org.apache.felix.service.command.CommandSession;
|
||||||
|
import org.hibernate.osgitest.DataPointService;
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
@Command(scope = "dp", name = "getAll")
|
||||||
|
public class GetAllCommand implements Action {
|
||||||
|
private DataPointService dpService;
|
||||||
|
|
||||||
|
public void setDpService(DataPointService dpService) {
|
||||||
|
this.dpService = dpService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute(CommandSession session) throws Exception {
|
||||||
|
List<DataPoint> dps = dpService.getAll();
|
||||||
|
for (DataPoint dp : dps) {
|
||||||
|
System.out.println(dp.getId() + ", " + dp.getName());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* 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 org.hibernate.osgitest.command;
|
||||||
|
|
||||||
|
import org.apache.felix.gogo.commands.Action;
|
||||||
|
import org.apache.felix.gogo.commands.Argument;
|
||||||
|
import org.apache.felix.gogo.commands.Command;
|
||||||
|
import org.apache.felix.service.command.CommandSession;
|
||||||
|
import org.hibernate.osgitest.DataPointService;
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
@Command(scope = "dp", name = "update")
|
||||||
|
public class UpdateCommand implements Action {
|
||||||
|
@Argument(index=0, name="Id", required=true, description="Id", multiValued=false)
|
||||||
|
String id;
|
||||||
|
|
||||||
|
@Argument(index=1, name="Name", required=true, description="Name", multiValued=false)
|
||||||
|
String name;
|
||||||
|
|
||||||
|
private DataPointService dpService;
|
||||||
|
|
||||||
|
public void setDpService(DataPointService dpService) {
|
||||||
|
this.dpService = dpService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute(CommandSession session) throws Exception {
|
||||||
|
DataPoint dp = dpService.get( Long.valueOf( id ) );
|
||||||
|
dp.setName( name );
|
||||||
|
dpService.update( dp );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||||
|
* as indicated by the @authors tag. All rights reserved.
|
||||||
|
* See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use,
|
||||||
|
* modify, copy, or redistribute it subject to the terms and conditions
|
||||||
|
* of the GNU Lesser General Public License, v. 2.1.
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License,
|
||||||
|
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package org.hibernate.osgitest.entity;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brett Meyer
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class DataPoint {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
-->
|
||||||
|
<blueprint default-activation="eager"
|
||||||
|
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
|
||||||
|
<bean id="dpService" class="org.hibernate.osgitest.DataPointServiceImpl"/>
|
||||||
|
|
||||||
|
<service ref="dpService" interface="org.hibernate.osgitest.DataPointService" />
|
||||||
|
|
||||||
|
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
|
||||||
|
<command name="dp:add">
|
||||||
|
<action class="org.hibernate.osgitest.command.AddCommand">
|
||||||
|
<property name="dpService" ref="dpService"/>
|
||||||
|
</action>
|
||||||
|
</command>
|
||||||
|
<command name="dp:update">
|
||||||
|
<action class="org.hibernate.osgitest.command.UpdateCommand">
|
||||||
|
<property name="dpService" ref="dpService"/>
|
||||||
|
</action>
|
||||||
|
</command>
|
||||||
|
<command name="dp:getAll">
|
||||||
|
<action class="org.hibernate.osgitest.command.GetAllCommand">
|
||||||
|
<property name="dpService" ref="dpService"/>
|
||||||
|
</action>
|
||||||
|
</command>
|
||||||
|
<command name="dp:deleteAll">
|
||||||
|
<action class="org.hibernate.osgitest.command.DeleteAllCommand">
|
||||||
|
<property name="dpService" ref="dpService"/>
|
||||||
|
</action>
|
||||||
|
</command>
|
||||||
|
</command-bundle>
|
||||||
|
</blueprint>
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<!DOCTYPE hibernate-configuration PUBLIC
|
||||||
|
"-//Hibernate/Hibernate Configuration DTD//EN"
|
||||||
|
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
|
||||||
|
|
||||||
|
<hibernate-configuration>
|
||||||
|
<session-factory>
|
||||||
|
<property name="hibernate.connection.driver_class">org.h2.Driver</property>
|
||||||
|
<property name="hibernate.connection.url">jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE</property>
|
||||||
|
<property name="hibernate.connection.username">sa</property>
|
||||||
|
<property name="hibernate.connection.password"></property>
|
||||||
|
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
|
||||||
|
<property name="hibernate.hbm2ddl.auto">create-drop</property>
|
||||||
|
|
||||||
|
<mapping class="org.hibernate.osgitest.entity.DataPoint"/>
|
||||||
|
</session-factory>
|
||||||
|
|
||||||
|
</hibernate-configuration>
|
|
@ -44,6 +44,7 @@
|
||||||
<module>annotations</module>
|
<module>annotations</module>
|
||||||
<module>entitymanager</module>
|
<module>entitymanager</module>
|
||||||
<module>envers</module>
|
<module>envers</module>
|
||||||
|
<module>osgi</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
Loading…
Reference in New Issue