From 3990b3badc8320a705c9899b0a63f40b4b219d1a Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 5 Apr 2019 13:00:01 +0200 Subject: [PATCH] Added tutorials of the hibernate-release 5.1.17.Final This commit contains the unchanged tutorials from the 5.1.17-Release See: http://docs.jboss.org/hibernate/orm/5.1/quickstart/html_single/#preface Download: http://docs.jboss.org/hibernate/orm/5.1/quickstart/html_single/hibernate-tutorials.zip --- src/it/tutorials-5.1.17/annotations/pom.xml | 28 +++++ .../AnnotationsIllustrationTest.java | 89 +++++++++++++++ .../hibernate/tutorial/annotations/Event.java | 83 ++++++++++++++ .../src/test/resources/hibernate.cfg.xml | 42 +++++++ src/it/tutorials-5.1.17/basic/pom.xml | 28 +++++ .../org/hibernate/tutorial/hbm/Event.hbm.xml | 23 ++++ .../org/hibernate/tutorial/hbm/Event.java | 67 +++++++++++ .../hbm/NativeApiIllustrationTest.java | 88 +++++++++++++++ .../src/test/resources/hibernate.cfg.xml | 41 +++++++ src/it/tutorials-5.1.17/entitymanager/pom.xml | 36 ++++++ .../em/EntityManagerIllustrationTest.java | 73 ++++++++++++ .../java/org/hibernate/tutorial/em/Event.java | 83 ++++++++++++++ .../test/resources/META-INF/persistence.xml | 31 ++++++ src/it/tutorials-5.1.17/envers/pom.xml | 41 +++++++ .../envers/EnversIllustrationTest.java | 105 ++++++++++++++++++ .../org/hibernate/tutorial/envers/Event.java | 92 +++++++++++++++ .../test/resources/META-INF/persistence.xml | 31 ++++++ .../tutorials-5.1.17/osgi/datasource-h2.xml | 28 +++++ .../osgi/managed-jpa/features.xml | 81 ++++++++++++++ .../tutorials-5.1.17/osgi/managed-jpa/pom.xml | 70 ++++++++++++ .../hibernate/osgitest/DataPointService.java | 37 ++++++ .../osgitest/DataPointServiceImpl.java | 58 ++++++++++ .../osgitest/command/AddCommand.java | 44 ++++++++ .../osgitest/command/DeleteAllCommand.java | 37 ++++++ .../osgitest/command/GetAllCommand.java | 43 +++++++ .../hibernate/osgitest/entity/DataPoint.java | 53 +++++++++ .../main/resources/META-INF/persistence.xml | 21 ++++ .../OSGI-INF/blueprint/blueprint.xml | 46 ++++++++ src/it/tutorials-5.1.17/osgi/pom.xml | 35 ++++++ .../osgi/unmanaged-jpa/features.xml | 47 ++++++++ .../osgi/unmanaged-jpa/pom.xml | 81 ++++++++++++++ .../hibernate/osgitest/DataPointService.java | 41 +++++++ .../osgitest/DataPointServiceImpl.java | 78 +++++++++++++ .../org/hibernate/osgitest/HibernateUtil.java | 57 ++++++++++ .../hibernate/osgitest/TestIntegrator.java | 45 ++++++++ .../TestStrategyRegistrationProvider.java | 37 ++++++ .../osgitest/TestTypeContributor.java | 37 ++++++ .../osgitest/command/AddCommand.java | 44 ++++++++ .../osgitest/command/DeleteAllCommand.java | 37 ++++++ .../osgitest/command/GetAllCommand.java | 43 +++++++ .../osgitest/command/UpdateCommand.java | 47 ++++++++ .../hibernate/osgitest/entity/DataPoint.java | 53 +++++++++ .../main/resources/META-INF/persistence.xml | 24 ++++ .../OSGI-INF/blueprint/blueprint.xml | 50 +++++++++ .../osgi/unmanaged-native/features.xml | 79 +++++++++++++ .../osgi/unmanaged-native/pom.xml | 89 +++++++++++++++ .../hibernate/osgitest/DataPointService.java | 47 ++++++++ .../osgitest/DataPointServiceImpl.java | 103 +++++++++++++++++ .../org/hibernate/osgitest/HibernateUtil.java | 53 +++++++++ .../hibernate/osgitest/TestIntegrator.java | 45 ++++++++ .../TestStrategyRegistrationProvider.java | 37 ++++++ .../osgitest/TestTypeContributor.java | 37 ++++++ .../osgitest/command/AddCommand.java | 44 ++++++++ .../osgitest/command/DeleteAllCommand.java | 37 ++++++ .../osgitest/command/GetAllCommand.java | 43 +++++++ .../osgitest/command/GetCommand.java | 43 +++++++ .../osgitest/command/GetRevisionsCommand.java | 48 ++++++++ .../osgitest/command/LoadCommand.java | 43 +++++++ .../osgitest/command/UpdateCommand.java | 47 ++++++++ .../hibernate/osgitest/entity/DataPoint.java | 58 ++++++++++ .../OSGI-INF/blueprint/blueprint.xml | 65 +++++++++++ .../src/main/resources/ehcache.xml | 94 ++++++++++++++++ .../src/main/resources/hibernate.cfg.xml | 52 +++++++++ .../src/main/resources/pool-one.properties | 13 +++ src/it/tutorials-5.1.17/pom.xml | 77 +++++++++++++ 65 files changed, 3409 insertions(+) create mode 100644 src/it/tutorials-5.1.17/annotations/pom.xml create mode 100644 src/it/tutorials-5.1.17/annotations/src/test/java/org/hibernate/tutorial/annotations/AnnotationsIllustrationTest.java create mode 100644 src/it/tutorials-5.1.17/annotations/src/test/java/org/hibernate/tutorial/annotations/Event.java create mode 100644 src/it/tutorials-5.1.17/annotations/src/test/resources/hibernate.cfg.xml create mode 100644 src/it/tutorials-5.1.17/basic/pom.xml create mode 100644 src/it/tutorials-5.1.17/basic/src/test/java/org/hibernate/tutorial/hbm/Event.hbm.xml create mode 100644 src/it/tutorials-5.1.17/basic/src/test/java/org/hibernate/tutorial/hbm/Event.java create mode 100644 src/it/tutorials-5.1.17/basic/src/test/java/org/hibernate/tutorial/hbm/NativeApiIllustrationTest.java create mode 100644 src/it/tutorials-5.1.17/basic/src/test/resources/hibernate.cfg.xml create mode 100644 src/it/tutorials-5.1.17/entitymanager/pom.xml create mode 100644 src/it/tutorials-5.1.17/entitymanager/src/test/java/org/hibernate/tutorial/em/EntityManagerIllustrationTest.java create mode 100644 src/it/tutorials-5.1.17/entitymanager/src/test/java/org/hibernate/tutorial/em/Event.java create mode 100644 src/it/tutorials-5.1.17/entitymanager/src/test/resources/META-INF/persistence.xml create mode 100644 src/it/tutorials-5.1.17/envers/pom.xml create mode 100644 src/it/tutorials-5.1.17/envers/src/test/java/org/hibernate/tutorial/envers/EnversIllustrationTest.java create mode 100644 src/it/tutorials-5.1.17/envers/src/test/java/org/hibernate/tutorial/envers/Event.java create mode 100644 src/it/tutorials-5.1.17/envers/src/test/resources/META-INF/persistence.xml create mode 100644 src/it/tutorials-5.1.17/osgi/datasource-h2.xml create mode 100644 src/it/tutorials-5.1.17/osgi/managed-jpa/features.xml create mode 100644 src/it/tutorials-5.1.17/osgi/managed-jpa/pom.xml create mode 100644 src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/DataPointService.java create mode 100644 src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java create mode 100644 src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/command/AddCommand.java create mode 100644 src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/command/DeleteAllCommand.java create mode 100644 src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/command/GetAllCommand.java create mode 100644 src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/entity/DataPoint.java create mode 100644 src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/resources/META-INF/persistence.xml create mode 100644 src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/resources/OSGI-INF/blueprint/blueprint.xml create mode 100644 src/it/tutorials-5.1.17/osgi/pom.xml create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-jpa/features.xml create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-jpa/pom.xml create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/DataPointService.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/HibernateUtil.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/TestIntegrator.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/TestStrategyRegistrationProvider.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/TestTypeContributor.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/AddCommand.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/DeleteAllCommand.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/GetAllCommand.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/UpdateCommand.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/entity/DataPoint.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/resources/META-INF/persistence.xml create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/resources/OSGI-INF/blueprint/blueprint.xml create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/features.xml create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/pom.xml create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/DataPointService.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/HibernateUtil.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/TestIntegrator.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/TestStrategyRegistrationProvider.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/TestTypeContributor.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/AddCommand.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/DeleteAllCommand.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/GetAllCommand.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/GetCommand.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/GetRevisionsCommand.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/LoadCommand.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/UpdateCommand.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/entity/DataPoint.java create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/OSGI-INF/blueprint/blueprint.xml create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/ehcache.xml create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/hibernate.cfg.xml create mode 100644 src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/pool-one.properties create mode 100644 src/it/tutorials-5.1.17/pom.xml diff --git a/src/it/tutorials-5.1.17/annotations/pom.xml b/src/it/tutorials-5.1.17/annotations/pom.xml new file mode 100644 index 00000000..086cb85d --- /dev/null +++ b/src/it/tutorials-5.1.17/annotations/pom.xml @@ -0,0 +1,28 @@ + + + + + 4.0.0 + + + org.hibernate.tutorials + hibernate-tutorials + 5.1.17.Final + ../pom.xml + + + hibernate-tutorial-annotations + Hibernate Annotations Tutorial + Hibernate tutorial illustrating the use of native APIs and annotations for mapping metadata + + + + true + + + diff --git a/src/it/tutorials-5.1.17/annotations/src/test/java/org/hibernate/tutorial/annotations/AnnotationsIllustrationTest.java b/src/it/tutorials-5.1.17/annotations/src/test/java/org/hibernate/tutorial/annotations/AnnotationsIllustrationTest.java new file mode 100644 index 00000000..33e28629 --- /dev/null +++ b/src/it/tutorials-5.1.17/annotations/src/test/java/org/hibernate/tutorial/annotations/AnnotationsIllustrationTest.java @@ -0,0 +1,89 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * 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, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY 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 + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.tutorial.annotations; + +import java.util.Date; +import java.util.List; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; + +import junit.framework.TestCase; + +/** + * Illustrates the use of Hibernate native APIs. The code here is unchanged from the {@code basic} example, the + * only difference being the use of annotations to supply the metadata instead of Hibernate mapping files. + * + * @author Steve Ebersole + */ +public class AnnotationsIllustrationTest extends TestCase { + private SessionFactory sessionFactory; + + @Override + protected void setUp() throws Exception { + // A SessionFactory is set up once for an application! + final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() + .configure() // configures settings from hibernate.cfg.xml + .build(); + try { + sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory(); + } + catch (Exception e) { + // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory + // so destroy it manually. + StandardServiceRegistryBuilder.destroy( registry ); + } + } + + @Override + protected void tearDown() throws Exception { + if ( sessionFactory != null ) { + sessionFactory.close(); + } + } + + @SuppressWarnings({ "unchecked" }) + public void testBasicUsage() { + // create a couple of events... + Session session = sessionFactory.openSession(); + session.beginTransaction(); + session.save( new Event( "Our very first event!", new Date() ) ); + session.save( new Event( "A follow up event", new Date() ) ); + session.getTransaction().commit(); + session.close(); + + // now lets pull events from the database and list them + session = sessionFactory.openSession(); + session.beginTransaction(); + List result = session.createQuery( "from Event" ).list(); + for ( Event event : (List) result ) { + System.out.println( "Event (" + event.getDate() + ") : " + event.getTitle() ); + } + session.getTransaction().commit(); + session.close(); + } +} diff --git a/src/it/tutorials-5.1.17/annotations/src/test/java/org/hibernate/tutorial/annotations/Event.java b/src/it/tutorials-5.1.17/annotations/src/test/java/org/hibernate/tutorial/annotations/Event.java new file mode 100644 index 00000000..c66349f9 --- /dev/null +++ b/src/it/tutorials-5.1.17/annotations/src/test/java/org/hibernate/tutorial/annotations/Event.java @@ -0,0 +1,83 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * 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, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY 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 + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.tutorial.annotations; + +import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.hibernate.annotations.GenericGenerator; + +@Entity +@Table( name = "EVENTS" ) +public class Event { + private Long id; + + private String title; + private Date date; + + public Event() { + // this form used by Hibernate + } + + public Event(String title, Date date) { + // for application use, to create new events + this.title = title; + this.date = date; + } + + @Id + @GeneratedValue(generator="increment") + @GenericGenerator(name="increment", strategy = "increment") + public Long getId() { + return id; + } + + private void setId(Long id) { + this.id = id; + } + + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "EVENT_DATE") + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} \ No newline at end of file diff --git a/src/it/tutorials-5.1.17/annotations/src/test/resources/hibernate.cfg.xml b/src/it/tutorials-5.1.17/annotations/src/test/resources/hibernate.cfg.xml new file mode 100644 index 00000000..a9590c18 --- /dev/null +++ b/src/it/tutorials-5.1.17/annotations/src/test/resources/hibernate.cfg.xml @@ -0,0 +1,42 @@ + + + + + + + + + + org.h2.Driver + jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE + sa + + + + 1 + + + org.hibernate.dialect.H2Dialect + + + org.hibernate.cache.internal.NoCacheProvider + + + true + + + create + + + + + + + \ No newline at end of file diff --git a/src/it/tutorials-5.1.17/basic/pom.xml b/src/it/tutorials-5.1.17/basic/pom.xml new file mode 100644 index 00000000..26c311c5 --- /dev/null +++ b/src/it/tutorials-5.1.17/basic/pom.xml @@ -0,0 +1,28 @@ + + + + + 4.0.0 + + + org.hibernate.tutorials + hibernate-tutorials + 5.1.17.Final + ../pom.xml + + + hibernate-tutorial-hbm + Hibernate hbm.xml Tutorial + Hibernate tutorial illustrating the use of native APIs and hbm.xml for mapping metadata + + + + true + + + diff --git a/src/it/tutorials-5.1.17/basic/src/test/java/org/hibernate/tutorial/hbm/Event.hbm.xml b/src/it/tutorials-5.1.17/basic/src/test/java/org/hibernate/tutorial/hbm/Event.hbm.xml new file mode 100644 index 00000000..f786e79e --- /dev/null +++ b/src/it/tutorials-5.1.17/basic/src/test/java/org/hibernate/tutorial/hbm/Event.hbm.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + diff --git a/src/it/tutorials-5.1.17/basic/src/test/java/org/hibernate/tutorial/hbm/Event.java b/src/it/tutorials-5.1.17/basic/src/test/java/org/hibernate/tutorial/hbm/Event.java new file mode 100644 index 00000000..ae4c2dfd --- /dev/null +++ b/src/it/tutorials-5.1.17/basic/src/test/java/org/hibernate/tutorial/hbm/Event.java @@ -0,0 +1,67 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * 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, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY 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 + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.tutorial.hbm; + +import java.util.Date; + +public class Event { + private Long id; + + private String title; + private Date date; + + public Event() { + // this form used by Hibernate + } + + public Event(String title, Date date) { + // for application use, to create new events + this.title = title; + this.date = date; + } + + public Long getId() { + return id; + } + + private void setId(Long id) { + this.id = id; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} \ No newline at end of file diff --git a/src/it/tutorials-5.1.17/basic/src/test/java/org/hibernate/tutorial/hbm/NativeApiIllustrationTest.java b/src/it/tutorials-5.1.17/basic/src/test/java/org/hibernate/tutorial/hbm/NativeApiIllustrationTest.java new file mode 100644 index 00000000..8ee5d084 --- /dev/null +++ b/src/it/tutorials-5.1.17/basic/src/test/java/org/hibernate/tutorial/hbm/NativeApiIllustrationTest.java @@ -0,0 +1,88 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * 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, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY 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 + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.tutorial.hbm; + +import java.util.Date; +import java.util.List; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; + +import junit.framework.TestCase; + +/** + * Illustrates use of Hibernate native APIs. + * + * @author Steve Ebersole + */ +public class NativeApiIllustrationTest extends TestCase { + private SessionFactory sessionFactory; + + @Override + protected void setUp() throws Exception { + // A SessionFactory is set up once for an application! + final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() + .configure() // configures settings from hibernate.cfg.xml + .build(); + try { + sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory(); + } + catch (Exception e) { + // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory + // so destroy it manually. + StandardServiceRegistryBuilder.destroy( registry ); + } + } + + @Override + protected void tearDown() throws Exception { + if ( sessionFactory != null ) { + sessionFactory.close(); + } + } + + @SuppressWarnings("unchecked") + public void testBasicUsage() { + // create a couple of events... + Session session = sessionFactory.openSession(); + session.beginTransaction(); + session.save( new Event( "Our very first event!", new Date() ) ); + session.save( new Event( "A follow up event", new Date() ) ); + session.getTransaction().commit(); + session.close(); + + // now lets pull events from the database and list them + session = sessionFactory.openSession(); + session.beginTransaction(); + List result = session.createQuery( "from Event" ).list(); + for ( Event event : (List) result ) { + System.out.println( "Event (" + event.getDate() + ") : " + event.getTitle() ); + } + session.getTransaction().commit(); + session.close(); + } +} diff --git a/src/it/tutorials-5.1.17/basic/src/test/resources/hibernate.cfg.xml b/src/it/tutorials-5.1.17/basic/src/test/resources/hibernate.cfg.xml new file mode 100644 index 00000000..03d39373 --- /dev/null +++ b/src/it/tutorials-5.1.17/basic/src/test/resources/hibernate.cfg.xml @@ -0,0 +1,41 @@ + + + + + + + + + + org.h2.Driver + jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE + sa + + + + 1 + + + org.hibernate.dialect.H2Dialect + + + org.hibernate.cache.internal.NoCacheProvider + + + true + + + create + + + + + + \ No newline at end of file diff --git a/src/it/tutorials-5.1.17/entitymanager/pom.xml b/src/it/tutorials-5.1.17/entitymanager/pom.xml new file mode 100644 index 00000000..152590bb --- /dev/null +++ b/src/it/tutorials-5.1.17/entitymanager/pom.xml @@ -0,0 +1,36 @@ + + + + + 4.0.0 + + + org.hibernate.tutorials + hibernate-tutorials + 5.1.17.Final + ../pom.xml + + + hibernate-tutorial-entitymanager + Hibernate JPA Tutorial + Hibernate tutorial illustrating the use of JPA APIs and annotations for mapping metadata + + + + true + + + + + org.hibernate + hibernate-entitymanager + 5.1.17.Final + + + + diff --git a/src/it/tutorials-5.1.17/entitymanager/src/test/java/org/hibernate/tutorial/em/EntityManagerIllustrationTest.java b/src/it/tutorials-5.1.17/entitymanager/src/test/java/org/hibernate/tutorial/em/EntityManagerIllustrationTest.java new file mode 100644 index 00000000..feebd89a --- /dev/null +++ b/src/it/tutorials-5.1.17/entitymanager/src/test/java/org/hibernate/tutorial/em/EntityManagerIllustrationTest.java @@ -0,0 +1,73 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * 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, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY 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 + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.tutorial.em; + +import java.util.Date; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import junit.framework.TestCase; + +/** + * Illustrates basic use of Hibernate as a JPA provider. + * + * @author Steve Ebersole + */ +public class EntityManagerIllustrationTest extends TestCase { + private EntityManagerFactory entityManagerFactory; + + @Override + protected void setUp() throws Exception { + // like discussed with regards to SessionFactory, an EntityManagerFactory is set up once for an application + // IMPORTANT: notice how the name here matches the name we gave the persistence-unit in persistence.xml! + entityManagerFactory = Persistence.createEntityManagerFactory( "org.hibernate.tutorial.jpa" ); + } + + @Override + protected void tearDown() throws Exception { + entityManagerFactory.close(); + } + + public void testBasicUsage() { + // create a couple of events... + EntityManager entityManager = entityManagerFactory.createEntityManager(); + entityManager.getTransaction().begin(); + entityManager.persist( new Event( "Our very first event!", new Date() ) ); + entityManager.persist( new Event( "A follow up event", new Date() ) ); + entityManager.getTransaction().commit(); + entityManager.close(); + + // now lets pull events from the database and list them + entityManager = entityManagerFactory.createEntityManager(); + entityManager.getTransaction().begin(); + List result = entityManager.createQuery( "from Event", Event.class ).getResultList(); + for ( Event event : result ) { + System.out.println( "Event (" + event.getDate() + ") : " + event.getTitle() ); + } + entityManager.getTransaction().commit(); + entityManager.close(); + } +} diff --git a/src/it/tutorials-5.1.17/entitymanager/src/test/java/org/hibernate/tutorial/em/Event.java b/src/it/tutorials-5.1.17/entitymanager/src/test/java/org/hibernate/tutorial/em/Event.java new file mode 100644 index 00000000..90fe4144 --- /dev/null +++ b/src/it/tutorials-5.1.17/entitymanager/src/test/java/org/hibernate/tutorial/em/Event.java @@ -0,0 +1,83 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * 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, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY 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 + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.tutorial.em; + +import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.hibernate.annotations.GenericGenerator; + +@Entity +@Table( name = "EVENTS" ) +public class Event { + private Long id; + + private String title; + private Date date; + + public Event() { + // this form used by Hibernate + } + + public Event(String title, Date date) { + // for application use, to create new events + this.title = title; + this.date = date; + } + + @Id + @GeneratedValue(generator="increment") + @GenericGenerator(name="increment", strategy = "increment") + public Long getId() { + return id; + } + + private void setId(Long id) { + this.id = id; + } + + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "EVENT_DATE") + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} \ No newline at end of file diff --git a/src/it/tutorials-5.1.17/entitymanager/src/test/resources/META-INF/persistence.xml b/src/it/tutorials-5.1.17/entitymanager/src/test/resources/META-INF/persistence.xml new file mode 100644 index 00000000..0fc95238 --- /dev/null +++ b/src/it/tutorials-5.1.17/entitymanager/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,31 @@ + + + + + + Persistence unit for the JPA tutorial of the Hibernate Getting Started Guide + + + org.hibernate.tutorial.em.Event + + + + + + + + + + + + + + diff --git a/src/it/tutorials-5.1.17/envers/pom.xml b/src/it/tutorials-5.1.17/envers/pom.xml new file mode 100644 index 00000000..56507f83 --- /dev/null +++ b/src/it/tutorials-5.1.17/envers/pom.xml @@ -0,0 +1,41 @@ + + + + + 4.0.0 + + + org.hibernate.tutorials + hibernate-tutorials + 5.1.17.Final + ../pom.xml + + + hibernate-tutorial-envers + Hibernate Envers Tutorial + Hibernate tutorial illustrating basic set up and use of Envers + + + + true + + + + + org.hibernate + hibernate-envers + 5.1.17.Final + + + org.hibernate + hibernate-entitymanager + 5.1.17.Final + + + + diff --git a/src/it/tutorials-5.1.17/envers/src/test/java/org/hibernate/tutorial/envers/EnversIllustrationTest.java b/src/it/tutorials-5.1.17/envers/src/test/java/org/hibernate/tutorial/envers/EnversIllustrationTest.java new file mode 100644 index 00000000..5e29faa6 --- /dev/null +++ b/src/it/tutorials-5.1.17/envers/src/test/java/org/hibernate/tutorial/envers/EnversIllustrationTest.java @@ -0,0 +1,105 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * 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, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY 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 + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.tutorial.envers; + +import java.util.Date; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import junit.framework.TestCase; + +import org.hibernate.envers.AuditReader; +import org.hibernate.envers.AuditReaderFactory; + +/** + * Illustrates the set up and use of Envers. + *

+ * This example is different from the others in that we really need to save multiple revisions to the entity in + * order to get a good look at Envers in action. + * + * @author Steve Ebersole + */ +public class EnversIllustrationTest extends TestCase { + private EntityManagerFactory entityManagerFactory; + + @Override + protected void setUp() throws Exception { + // like discussed with regards to SessionFactory, an EntityManagerFactory is set up once for an application + // IMPORTANT: notice how the name here matches the name we gave the persistence-unit in persistence.xml! + entityManagerFactory = Persistence.createEntityManagerFactory( "org.hibernate.tutorial.envers" ); + } + + @Override + protected void tearDown() throws Exception { + entityManagerFactory.close(); + } + + public void testBasicUsage() { + // create a couple of events + EntityManager entityManager = entityManagerFactory.createEntityManager(); + entityManager.getTransaction().begin(); + entityManager.persist( new Event( "Our very first event!", new Date() ) ); + entityManager.persist( new Event( "A follow up event", new Date() ) ); + entityManager.getTransaction().commit(); + entityManager.close(); + + // now lets pull events from the database and list them + entityManager = entityManagerFactory.createEntityManager(); + entityManager.getTransaction().begin(); + List result = entityManager.createQuery( "from Event", Event.class ).getResultList(); + for ( Event event : result ) { + System.out.println( "Event (" + event.getDate() + ") : " + event.getTitle() ); + } + entityManager.getTransaction().commit(); + entityManager.close(); + + // so far the code is the same as we have seen in previous tutorials. Now lets leverage Envers... + + // first lets create some revisions + entityManager = entityManagerFactory.createEntityManager(); + entityManager.getTransaction().begin(); + Event myEvent = entityManager.find( Event.class, 2L ); // we are using the increment generator, so we know 2 is a valid id + myEvent.setDate( new Date() ); + myEvent.setTitle( myEvent.getTitle() + " (rescheduled)" ); + entityManager.getTransaction().commit(); + entityManager.close(); + + // and then use an AuditReader to look back through history + entityManager = entityManagerFactory.createEntityManager(); + entityManager.getTransaction().begin(); + myEvent = entityManager.find( Event.class, 2L ); + assertEquals( "A follow up event (rescheduled)", myEvent.getTitle() ); + AuditReader reader = AuditReaderFactory.get( entityManager ); + Event firstRevision = reader.find( Event.class, 2L, 1 ); + assertFalse( firstRevision.getTitle().equals( myEvent.getTitle() ) ); + assertFalse( firstRevision.getDate().equals( myEvent.getDate() ) ); + Event secondRevision = reader.find( Event.class, 2L, 2 ); + assertTrue( secondRevision.getTitle().equals( myEvent.getTitle() ) ); + assertTrue( secondRevision.getDate().equals( myEvent.getDate() ) ); + entityManager.getTransaction().commit(); + entityManager.close(); + } +} diff --git a/src/it/tutorials-5.1.17/envers/src/test/java/org/hibernate/tutorial/envers/Event.java b/src/it/tutorials-5.1.17/envers/src/test/java/org/hibernate/tutorial/envers/Event.java new file mode 100644 index 00000000..64741a61 --- /dev/null +++ b/src/it/tutorials-5.1.17/envers/src/test/java/org/hibernate/tutorial/envers/Event.java @@ -0,0 +1,92 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * 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, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY 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 + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.tutorial.envers; + +import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.envers.Audited; + +@Entity +@Table( name = "EVENTS" ) +@Audited // <--- this tell Envers to audit (track changes to) this entity +public class Event { + private Long id; + + private String title; + private Date date; + + public Event() { + // this form used by Hibernate + } + + public Event(String title, Date date) { + // for application use, to create new events + this.title = title; + this.date = date; + } + + @Id + @GeneratedValue(generator="increment") + @GenericGenerator(name="increment", strategy = "increment") + public Long getId() { + return id; + } + + private void setId(Long id) { + this.id = id; + } + + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "EVENT_DATE") + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + @Override + public int hashCode() { + int result = title.hashCode(); + result = 31 * result + date.hashCode(); + return result; + } +} \ No newline at end of file diff --git a/src/it/tutorials-5.1.17/envers/src/test/resources/META-INF/persistence.xml b/src/it/tutorials-5.1.17/envers/src/test/resources/META-INF/persistence.xml new file mode 100644 index 00000000..45a7dafe --- /dev/null +++ b/src/it/tutorials-5.1.17/envers/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,31 @@ + + + + + + Persistence unit for the Envers tutorial of the Hibernate Getting Started Guide + + + org.hibernate.tutorial.envers.Event + + + + + + + + + + + + + + diff --git a/src/it/tutorials-5.1.17/osgi/datasource-h2.xml b/src/it/tutorials-5.1.17/osgi/datasource-h2.xml new file mode 100644 index 00000000..3bf738fd --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/datasource-h2.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/it/tutorials-5.1.17/osgi/managed-jpa/features.xml b/src/it/tutorials-5.1.17/osgi/managed-jpa/features.xml new file mode 100644 index 00000000..f62148c0 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/managed-jpa/features.xml @@ -0,0 +1,81 @@ + + + + + + + + aries.transaction.recoverable = true + aries.transaction.timeout = 600 + aries.transaction.howl.logFileDir = /tmp/karaf/txlog + aries.transaction.howl.maxLogFiles = 2 + aries.transaction.howl.maxBlocksPerFile = 512 + aries.transaction.howl.bufferSizeKBytes = 4 + + mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1 + mvn:org.apache.aries.transaction/org.apache.aries.transaction.blueprint/1.0.0 + mvn:org.apache.aries.transaction/org.apache.aries.transaction.manager/1.0.1 + + + mvn:org.hibernate.javax.persistence/hibernate-jpa-2.1-api/1.0.0.Final + + mvn:org.apache.aries/org.apache.aries.util/1.1.1-SNAPSHOT + mvn:org.apache.aries.jpa/org.apache.aries.jpa.api/1.0.1-SNAPSHOT + mvn:org.apache.aries.jpa/org.apache.aries.jpa.blueprint.aries/1.0.2-SNAPSHOT + mvn:org.apache.aries.jpa/org.apache.aries.jpa.container/1.0.1-SNAPSHOT + mvn:org.apache.aries.jpa/org.apache.aries.jpa.container.context/1.0.2-SNAPSHOT + + + mvn:org.apache.aries/org.apache.aries.util/1.0.0 + mvn:org.apache.aries.jndi/org.apache.aries.jndi.api/1.0.0 + mvn:org.apache.aries.jndi/org.apache.aries.jndi.core/1.0.0 + mvn:org.apache.aries.jndi/org.apache.aries.jndi.rmi/1.0.0 + mvn:org.apache.aries.jndi/org.apache.aries.jndi.url/1.0.0 + mvn:org.apache.aries.jndi/org.apache.aries.jndi.legacy.support/1.0.0 + + + mvn:commons-collections/commons-collections/3.2.1 + mvn:commons-pool/commons-pool/1.5.4 + mvn:commons-dbcp/commons-dbcp/1.4 + mvn:commons-lang/commons-lang/2.6 + wrap:mvn:net.sourceforge.serp/serp/1.13.1 + + mvn:com.h2database/h2/1.3.170 + blueprint:file:/[PATH]/datasource-h2.xml + + + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/2.7.7_5 + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5 + + + wrap:mvn:org.jboss/jandex/1.1.0.Final + + mvn:com.fasterxml/classmate/0.8.0 + mvn:org.apache.logging.log4j/log4j-api/2.0 + mvn:log4j/log4j/1.2.17 + mvn:org.jboss.logging/jboss-logging/3.2.1.Final + mvn:org.javassist/javassist/3.18.1-GA + + mvn:org.hibernate.common/hibernate-commons-annotations/4.0.5.Final + + mvn:org.hibernate/hibernate-core/5.1.17.Final + mvn:org.hibernate/hibernate-entitymanager/5.1.17.Final + + + mvn:org.hibernate.osgi/managed-jpa/1.0.0 + + mvn:org.hibernate/hibernate-osgi/5.1.17.Final + + diff --git a/src/it/tutorials-5.1.17/osgi/managed-jpa/pom.xml b/src/it/tutorials-5.1.17/osgi/managed-jpa/pom.xml new file mode 100644 index 00000000..55ccacd3 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/managed-jpa/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + org.hibernate.osgi + managed-jpa + 1.0.0 + bundle + + + + org.hibernate.javax.persistence + hibernate-jpa-2.1-api + 1.0.0.Final + + + org.osgi + org.osgi.core + 4.3.1 + + + org.osgi + org.osgi.enterprise + 4.2.0 + + + org.apache.karaf.shell + org.apache.karaf.shell.console + 2.3.0 + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + org.hibernate.osgi.managed-jpa + managed-jpa + 1.0.0 + + org.hibernate.osgitest, + org.hibernate.osgitest.entity + + + org.apache.felix.service.command, + org.apache.felix.gogo.commands, + org.apache.karaf.shell.console, + org.apache.karaf.shell.commands, + javax.persistence;version="[1.0.0,2.1.0]", + + org.hibernate.proxy, + javassist.util.proxy, + * + + META-INF/persistence.xml + + + + + + diff --git a/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/DataPointService.java b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/DataPointService.java new file mode 100644 index 00000000..bdeaace1 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/DataPointService.java @@ -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 getAll(); + + public void deleteAll(); +} diff --git a/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java new file mode 100644 index 00000000..f3248896 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java @@ -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 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; + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/command/AddCommand.java b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/command/AddCommand.java new file mode 100644 index 00000000..9e9844c3 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/command/AddCommand.java @@ -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; + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/command/DeleteAllCommand.java b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/command/DeleteAllCommand.java new file mode 100644 index 00000000..d6c4ccf6 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/command/DeleteAllCommand.java @@ -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; + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/command/GetAllCommand.java b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/command/GetAllCommand.java new file mode 100644 index 00000000..ebdac60e --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/command/GetAllCommand.java @@ -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 dps = dpService.getAll(); + for (DataPoint dp : dps) { + System.out.println(dp.getId() + ", " + dp.getName()); + } + return null; + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/entity/DataPoint.java b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/entity/DataPoint.java new file mode 100644 index 00000000..2a566d88 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/java/org/hibernate/osgitest/entity/DataPoint.java @@ -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; + } +} diff --git a/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/resources/META-INF/persistence.xml b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/resources/META-INF/persistence.xml new file mode 100644 index 00000000..77555cb4 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,21 @@ + + + + + osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/h2ds) + + + + + + + + + \ No newline at end of file diff --git a/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 00000000..2436aa74 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/managed-jpa/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/it/tutorials-5.1.17/osgi/pom.xml b/src/it/tutorials-5.1.17/osgi/pom.xml new file mode 100644 index 00000000..aa8bf9d5 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/pom.xml @@ -0,0 +1,35 @@ + + + + + 4.0.0 + + + org.hibernate.tutorials + hibernate-tutorials + 5.1.17.Final + ../pom.xml + + + hibernate-tutorial-osgi + Hibernate OSGI Tutorials + Hibernate tutoriasl illustrating basic set up and use of OSGI + pom + + + + true + + + + managed-jpa + unmanaged-jpa + unmanaged-native + + + diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/features.xml b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/features.xml new file mode 100644 index 00000000..46e6a6d0 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/features.xml @@ -0,0 +1,47 @@ + + + + + + + mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1 + + + mvn:org.hibernate.javax.persistence/hibernate-jpa-2.1-api/1.0.0.Final + + + mvn:commons-collections/commons-collections/3.2.1 + mvn:commons-pool/commons-pool/1.5.4 + mvn:commons-dbcp/commons-dbcp/1.4 + mvn:commons-lang/commons-lang/2.6 + wrap:mvn:net.sourceforge.serp/serp/1.13.1 + + mvn:com.h2database/h2/1.3.170 + + + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/2.7.7_5 + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5 + + + wrap:mvn:org.jboss/jandex/1.1.0.Final + + mvn:com.fasterxml/classmate/0.8.0 + mvn:org.apache.logging.log4j/log4j-api/2.0 + mvn:log4j/log4j/1.2.17 + mvn:org.jboss.logging/jboss-logging/3.2.1.Final + mvn:org.javassist/javassist/3.18.1-GA + + mvn:org.hibernate.common/hibernate-commons-annotations/4.0.5.Final + + mvn:org.hibernate/hibernate-core/5.1.17.Final + mvn:org.hibernate/hibernate-entitymanager/5.1.17.Final + mvn:org.hibernate/hibernate-osgi/5.1.17.Final + + mvn:org.hibernate.osgi/unmanaged-jpa/1.0.0 + + diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/pom.xml b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/pom.xml new file mode 100644 index 00000000..abb36a40 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/pom.xml @@ -0,0 +1,81 @@ + + + 4.0.0 + org.hibernate.osgi + unmanaged-jpa + 1.0.0 + bundle + + + + org.hibernate.javax.persistence + hibernate-jpa-2.1-api + 1.0.0.Final + + + org.osgi + org.osgi.core + 4.3.1 + + + org.osgi + org.osgi.enterprise + 4.2.0 + + + org.apache.karaf.shell + org.apache.karaf.shell.console + 2.3.0 + + + org.hibernate + hibernate-entitymanager + 5.1.17.Final + + + com.h2database + h2 + 1.3.170 + + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + org.hibernate.osgi.unmanaged-jpa + unmanaged-jpa + 1.0.0 + + org.hibernate.osgitest, + org.hibernate.osgitest.entity + + + org.apache.felix.service.command, + org.apache.felix.gogo.commands, + org.apache.karaf.shell.console, + org.apache.karaf.shell.commands, + org.h2, + javax.persistence;version="[1.0.0,2.1.0]", + + org.hibernate.proxy, + javassist.util.proxy, + * + + + + + + + diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/DataPointService.java b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/DataPointService.java new file mode 100644 index 00000000..de8c960c --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/DataPointService.java @@ -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 getAll(); + + public void deleteAll(); +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java new file mode 100644 index 00000000..dba3609e --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java @@ -0,0 +1,78 @@ +/* + * 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 HibernateUtil hibernateUtil = new HibernateUtil(); + + 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 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(); + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/HibernateUtil.java b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/HibernateUtil.java new file mode 100644 index 00000000..0927f15f --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/HibernateUtil.java @@ -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 EntityManagerFactory emf; + + public EntityManager getEntityManager() { + return getEntityManagerFactory().createEntityManager(); + } + + private 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; + } +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/TestIntegrator.java b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/TestIntegrator.java new file mode 100644 index 00000000..f4436346 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/TestIntegrator.java @@ -0,0 +1,45 @@ +/* + * 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.boot.Metadata; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.integrator.spi.Integrator; +import org.hibernate.service.spi.SessionFactoryServiceRegistry; + + +/** + * @author Brett Meyer + */ +public class TestIntegrator implements Integrator { + + public void integrate( + Metadata metadata, + SessionFactoryImplementor sessionFactory, + SessionFactoryServiceRegistry serviceRegistry) { + System.out.println("Integrator#integrate"); + } + + public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { + System.out.println("Integrator#disintegrate"); + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/TestStrategyRegistrationProvider.java b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/TestStrategyRegistrationProvider.java new file mode 100644 index 00000000..f7ad26f5 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/TestStrategyRegistrationProvider.java @@ -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.Collections; + +import org.hibernate.boot.registry.selector.StrategyRegistration; +import org.hibernate.boot.registry.selector.StrategyRegistrationProvider; + +/** + * @author Brett Meyer + */ +public class TestStrategyRegistrationProvider implements StrategyRegistrationProvider { + + public Iterable getStrategyRegistrations() { + System.out.println("StrategyRegistrationProvider#getStrategyRegistrations"); + return Collections.EMPTY_LIST; + } +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/TestTypeContributor.java b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/TestTypeContributor.java new file mode 100644 index 00000000..0da11cb6 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/TestTypeContributor.java @@ -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 org.hibernate.boot.model.TypeContributions; +import org.hibernate.boot.model.TypeContributor; +import org.hibernate.service.ServiceRegistry; + + +/** + * @author Brett Meyer + */ +public class TestTypeContributor implements TypeContributor { + + public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { + System.out.println("TypeContributor#contribute"); + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/AddCommand.java b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/AddCommand.java new file mode 100644 index 00000000..c1b906c0 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/AddCommand.java @@ -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; + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/DeleteAllCommand.java b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/DeleteAllCommand.java new file mode 100644 index 00000000..0d404ae1 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/DeleteAllCommand.java @@ -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; + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/GetAllCommand.java b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/GetAllCommand.java new file mode 100644 index 00000000..6873e463 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/GetAllCommand.java @@ -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 dps = dpService.getAll(); + for (DataPoint dp : dps) { + System.out.println(dp.getId() + ", " + dp.getName()); + } + return null; + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/UpdateCommand.java b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/UpdateCommand.java new file mode 100644 index 00000000..5de8983d --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/command/UpdateCommand.java @@ -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; + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/entity/DataPoint.java b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/entity/DataPoint.java new file mode 100644 index 00000000..2a566d88 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/entity/DataPoint.java @@ -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; + } +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/resources/META-INF/persistence.xml b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/resources/META-INF/persistence.xml new file mode 100644 index 00000000..b0ebfe70 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,24 @@ + + + + + org.hibernate.osgitest.entity.DataPoint + true + + + + + + + + + + + \ No newline at end of file diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 00000000..283ee107 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-jpa/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/features.xml b/src/it/tutorials-5.1.17/osgi/unmanaged-native/features.xml new file mode 100644 index 00000000..7991beb1 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/features.xml @@ -0,0 +1,79 @@ + + + + + + + + + mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1 + + + mvn:org.hibernate.javax.persistence/hibernate-jpa-2.1-api/1.0.0.Final + + + mvn:commons-collections/commons-collections/3.2.1 + mvn:commons-pool/commons-pool/1.5.4 + mvn:commons-dbcp/commons-dbcp/1.4 + mvn:commons-lang/commons-lang/2.6 + wrap:mvn:net.sourceforge.serp/serp/1.13.1 + + mvn:com.h2database/h2/1.3.170 + + + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/2.7.7_5 + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5 + + + wrap:mvn:org.jboss/jandex/1.1.0.Final + + + + + + + + mvn:com.fasterxml/classmate/0.8.0 + mvn:org.apache.logging.log4j/log4j-api/2.0 + mvn:log4j/log4j/1.2.17 + mvn:org.jboss.logging/jboss-logging/3.2.1.Final + mvn:org.javassist/javassist/3.18.1-GA + + mvn:org.hibernate.common/hibernate-commons-annotations/4.0.5.Final + + + + + + + + + + + + mvn:org.hibernate/hibernate-core/5.1.17.Final + + mvn:org.hibernate/hibernate-entitymanager/5.1.17.Final + mvn:org.hibernate/hibernate-envers/5.1.17.Final + + + + + mvn:org.hibernate/hibernate-osgi/5.1.17.Final + + mvn:org.hibernate.osgi/unmanaged-native/1.0.0 + + diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/pom.xml b/src/it/tutorials-5.1.17/osgi/unmanaged-native/pom.xml new file mode 100644 index 00000000..c32e578c --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/pom.xml @@ -0,0 +1,89 @@ + + + 4.0.0 + org.hibernate.osgi + unmanaged-native + 1.0.0 + bundle + + + + org.hibernate.javax.persistence + hibernate-jpa-2.1-api + 1.0.0.Final + + + org.osgi + org.osgi.core + 4.3.1 + + + org.osgi + org.osgi.enterprise + 4.2.0 + + + org.apache.karaf.shell + org.apache.karaf.shell.console + 2.3.0 + + + org.hibernate + hibernate-core + 5.1.17.Final + + + org.hibernate + hibernate-envers + 5.1.17.Final + + + com.h2database + h2 + 1.3.170 + + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + org.hibernate.osgi.unmanaged-native + unmanaged-native + 1.0.0 + + org.hibernate.osgitest, + org.hibernate.osgitest.entity + + + 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, + javax.persistence;version="[1.0.0,2.1.0]", + + org.hibernate.proxy, + javassist.util.proxy, + * + + + + + + + diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/DataPointService.java b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/DataPointService.java new file mode 100644 index 00000000..12fb79a9 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/DataPointService.java @@ -0,0 +1,47 @@ +/* + * 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 java.util.Map; + +import org.hibernate.envers.DefaultRevisionEntity; +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 DataPoint load(long id); + + public List getAll(); + + public Map getRevisions(long id); + + public void deleteAll(); +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java new file mode 100644 index 00000000..a8f6f720 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java @@ -0,0 +1,103 @@ +/* + * 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.criterion.Restrictions; +import org.hibernate.envers.AuditReader; +import org.hibernate.envers.AuditReaderFactory; +import org.hibernate.envers.DefaultRevisionEntity; +import org.hibernate.osgitest.entity.DataPoint; + +import java.util.HashSet; +import java.util.List; +import java.util.Map; + +/** + * @author Brett Meyer + */ +public class DataPointServiceImpl implements DataPointService { + + private HibernateUtil hibernateUtil = new HibernateUtil(); + + 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; + } + + // Test lazy loading (mainly to make sure the proxy classes work in OSGi) + public DataPoint load(long id) { + Session s = hibernateUtil.getSession(); + s.getTransaction().begin(); + DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long(id) ); + // initialize + dp.getName(); + s.getTransaction().commit(); + s.close(); + return dp; + } + + public List getAll() { + Session s = hibernateUtil.getSession(); + s.getTransaction().begin(); + List list = s.createQuery( "from DataPoint" ).list(); + s.getTransaction().commit(); + s.close(); + return list; + } + + public Map getRevisions(long id) { + Session s = hibernateUtil.getSession(); + AuditReader reader = AuditReaderFactory.get(s); + List revisionNums = reader.getRevisions( DataPoint.class, id ); + return reader.findRevisions( DefaultRevisionEntity.class, new HashSet(revisionNums) ); + } + + public void deleteAll() { + Session s = hibernateUtil.getSession(); + s.getTransaction().begin(); + s.createQuery( "delete from DataPoint" ).executeUpdate(); + s.getTransaction().commit(); + s.close(); + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/HibernateUtil.java b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/HibernateUtil.java new file mode 100644 index 00000000..15fb4c7d --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/HibernateUtil.java @@ -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 SessionFactory sf; + + public Session getSession() { + return getSessionFactory().openSession(); + } + + private 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; + } +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/TestIntegrator.java b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/TestIntegrator.java new file mode 100644 index 00000000..95b2e631 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/TestIntegrator.java @@ -0,0 +1,45 @@ +/* + * 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.boot.Metadata; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.integrator.spi.Integrator; +import org.hibernate.service.spi.SessionFactoryServiceRegistry; + + +/** + * @author Brett Meyer + */ +public class TestIntegrator implements Integrator { + + public void integrate( + Metadata metadata, + SessionFactoryImplementor sessionFactory, + SessionFactoryServiceRegistry serviceRegistry) { + System.out.println("Integrator#integrate"); + } + + public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { + System.out.println("Integrator#disintegrate"); + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/TestStrategyRegistrationProvider.java b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/TestStrategyRegistrationProvider.java new file mode 100644 index 00000000..f7ad26f5 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/TestStrategyRegistrationProvider.java @@ -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.Collections; + +import org.hibernate.boot.registry.selector.StrategyRegistration; +import org.hibernate.boot.registry.selector.StrategyRegistrationProvider; + +/** + * @author Brett Meyer + */ +public class TestStrategyRegistrationProvider implements StrategyRegistrationProvider { + + public Iterable getStrategyRegistrations() { + System.out.println("StrategyRegistrationProvider#getStrategyRegistrations"); + return Collections.EMPTY_LIST; + } +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/TestTypeContributor.java b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/TestTypeContributor.java new file mode 100644 index 00000000..87a83841 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/TestTypeContributor.java @@ -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 org.hibernate.boot.model.TypeContributions; +import org.hibernate.boot.model.TypeContributor; +import org.hibernate.service.ServiceRegistry; + + +/** + * @author Brett Meyer + */ +public class TestTypeContributor implements TypeContributor { + + public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { + System.out.println("TypeContributor#contribute"); + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/AddCommand.java b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/AddCommand.java new file mode 100644 index 00000000..9e9844c3 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/AddCommand.java @@ -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; + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/DeleteAllCommand.java b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/DeleteAllCommand.java new file mode 100644 index 00000000..d6c4ccf6 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/DeleteAllCommand.java @@ -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; + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/GetAllCommand.java b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/GetAllCommand.java new file mode 100644 index 00000000..ebdac60e --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/GetAllCommand.java @@ -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 dps = dpService.getAll(); + for (DataPoint dp : dps) { + System.out.println(dp.getId() + ", " + dp.getName()); + } + return null; + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/GetCommand.java b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/GetCommand.java new file mode 100644 index 00000000..0597d709 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/GetCommand.java @@ -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 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 = "get") +public class GetCommand implements Action { + @Argument(index = 0, name = "Id", required = true, description = "Id", multiValued = false) + String id; + + 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 ) ); + System.out.println( dp.getId() + ", " + dp.getName() ); + return null; + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/GetRevisionsCommand.java b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/GetRevisionsCommand.java new file mode 100644 index 00000000..b4573f62 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/GetRevisionsCommand.java @@ -0,0 +1,48 @@ +/* + * 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.Map; + +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.envers.DefaultRevisionEntity; +import org.hibernate.osgitest.DataPointService; + +@Command(scope = "dp", name = "getRevisions") +public class GetRevisionsCommand implements Action { + @Argument(index=0, name="Id", required=true, description="Id", multiValued=false) + String id; + + private DataPointService dpService; + + public void setDpService(DataPointService dpService) { + this.dpService = dpService; + } + + public Object execute(CommandSession session) throws Exception { + Map revisions = dpService.getRevisions(Long.valueOf( id )); + for (Number revisionNum : revisions.keySet()) { + DefaultRevisionEntity dre = revisions.get( revisionNum ); + System.out.println(revisionNum + ": " + dre.getId() + ", " + dre.getTimestamp()); + } + return null; + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/LoadCommand.java b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/LoadCommand.java new file mode 100644 index 00000000..3451a986 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/LoadCommand.java @@ -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 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 = "load") +public class LoadCommand implements Action { + @Argument(index = 0, name = "Id", required = true, description = "Id", multiValued = false) + String id; + + private DataPointService dpService; + + public void setDpService(DataPointService dpService) { + this.dpService = dpService; + } + + public Object execute(CommandSession session) throws Exception { + DataPoint dp = dpService.load( Long.valueOf( id ) ); + System.out.println( dp.getId() + ", " + dp.getName() ); + return null; + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/UpdateCommand.java b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/UpdateCommand.java new file mode 100644 index 00000000..f6949674 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/command/UpdateCommand.java @@ -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; + } + +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/entity/DataPoint.java b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/entity/DataPoint.java new file mode 100644 index 00000000..2e5ef724 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/entity/DataPoint.java @@ -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.entity; + +import java.io.Serializable; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import org.hibernate.envers.Audited; + +/** + * @author Brett Meyer + */ +@Entity +@Audited +public class DataPoint implements Serializable { + @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; + } +} diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 00000000..f62626a1 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/ehcache.xml b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/ehcache.xml new file mode 100644 index 00000000..52d198d6 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/ehcache.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + --> + + + + diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/hibernate.cfg.xml b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/hibernate.cfg.xml new file mode 100644 index 00000000..7f9f2380 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/hibernate.cfg.xml @@ -0,0 +1,52 @@ + + + + + + + org.h2.Driver + jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE + sa + + org.hibernate.dialect.H2Dialect + create-drop + + + + + + + + + + + + + diff --git a/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/pool-one.properties b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/pool-one.properties new file mode 100644 index 00000000..7e1c4cf1 --- /dev/null +++ b/src/it/tutorials-5.1.17/osgi/unmanaged-native/src/main/resources/pool-one.properties @@ -0,0 +1,13 @@ +# +# Hibernate, Relational Persistence for Idiomatic Java +# +# License: GNU Lesser General Public License (LGPL), version 2.1 or later. +# See the lgpl.txt file in the root directory or . +# +jdbc-0.proxool.alias=pool-one +jdbc-0.proxool.driver-url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE +jdbc-0.proxool.driver-class=org.h2.Driver +jdbc-0.user=sa +jdbc-0.password= +jdbc-0.proxool.maximum-connection-count=2 +jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE \ No newline at end of file diff --git a/src/it/tutorials-5.1.17/pom.xml b/src/it/tutorials-5.1.17/pom.xml new file mode 100644 index 00000000..d7abcae7 --- /dev/null +++ b/src/it/tutorials-5.1.17/pom.xml @@ -0,0 +1,77 @@ + + + + + 4.0.0 + + org.hibernate.tutorials + hibernate-tutorials + 5.1.17.Final + pom + + Hibernate Getting Started Guide Tutorials + Aggregator for the Hibernate tutorials presented in the Getting Started Guide + + + + true + + + + basic + annotations + entitymanager + envers + osgi + + + + + org.hibernate + hibernate-core + 5.1.17.Final + + + + + org.slf4j + slf4j-simple + 1.7.5 + + + + + junit + junit + 4.11 + + + + + com.h2database + h2 + 1.3.176 + + + + + + + false + src/test/java + + **/*.xml + + + + src/test/resources + + + + + -- 2.20.1