From c7e1d0aff0c2b9077ea488a9875b7d213a2b925f Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Mon, 8 Apr 2013 18:48:08 -0400 Subject: [PATCH 1/8] Updated for JPA 2.1 --- HibernateOSGi_AppManaged/features.xml | 8 ++++---- HibernateOSGi_AppManaged/pom.xml | 12 ++++++------ HibernateOSGi_ContainerManaged/features.xml | 17 ++++++++--------- HibernateOSGi_ContainerManaged/pom.xml | 7 ++++--- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/HibernateOSGi_AppManaged/features.xml b/HibernateOSGi_AppManaged/features.xml index 4a83437..373c140 100644 --- a/HibernateOSGi_AppManaged/features.xml +++ b/HibernateOSGi_AppManaged/features.xml @@ -8,7 +8,7 @@ mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1 - mvn:org.apache.geronimo.specs/geronimo-jpa_2.0_spec/1.1 + mvn:org.hibernate.javax.persistence/hibernate-jpa-2.1-api/1.0.0-SNAPSHOT mvn:commons-collections/commons-collections/3.2.1 @@ -41,9 +41,9 @@ - mvn:org.hibernate/hibernate-core/4.2.1-SNAPSHOT - mvn:org.hibernate/hibernate-entitymanager/4.2.1-SNAPSHOT - mvn:org.hibernate/hibernate-osgi/4.2.1-SNAPSHOT + mvn:org.hibernate/hibernate-core/4.3.0-SNAPSHOT + mvn:org.hibernate/hibernate-entitymanager/4.3.0-SNAPSHOT + mvn:org.hibernate/hibernate-osgi/4.3.0-SNAPSHOT mvn:org.hibernate/HibernateOSGi_AppManaged/1.0.0 diff --git a/HibernateOSGi_AppManaged/pom.xml b/HibernateOSGi_AppManaged/pom.xml index 756919e..b7aff87 100644 --- a/HibernateOSGi_AppManaged/pom.xml +++ b/HibernateOSGi_AppManaged/pom.xml @@ -8,10 +8,10 @@ - org.apache.geronimo.specs - geronimo-jpa_2.0_spec - 1.1 - + org.hibernate.javax.persistence + hibernate-jpa-2.1-api + 1.0.0-SNAPSHOT + org.osgi org.osgi.core @@ -30,12 +30,12 @@ org.hibernate hibernate-core - 4.2.1-SNAPSHOT + 4.3.0-SNAPSHOT org.hibernate hibernate-entitymanager - 4.2.1-SNAPSHOT + 4.3.0-SNAPSHOT com.h2database diff --git a/HibernateOSGi_ContainerManaged/features.xml b/HibernateOSGi_ContainerManaged/features.xml index 9e1493b..9cf210e 100644 --- a/HibernateOSGi_ContainerManaged/features.xml +++ b/HibernateOSGi_ContainerManaged/features.xml @@ -18,13 +18,12 @@ mvn:org.apache.aries.transaction/org.apache.aries.transaction.manager/1.0.1 - - mvn:org.apache.geronimo.specs/geronimo-jpa_2.0_spec/1.1 + mvn:org.hibernate.javax.persistence/hibernate-jpa-2.1-api/1.0.0-SNAPSHOT mvn:org.apache.aries/org.apache.aries.util/1.0.0 - mvn:org.apache.aries.jpa/org.apache.aries.jpa.api/1.0.0 - mvn:org.apache.aries.jpa/org.apache.aries.jpa.blueprint.aries/1.0.0 - mvn:org.apache.aries.jpa/org.apache.aries.jpa.container/1.0.0 - mvn:org.apache.aries.jpa/org.apache.aries.jpa.container.context/1.0.1 + 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.jndi/org.apache.aries.jndi.api/1.0.0 @@ -65,8 +64,8 @@ - mvn:org.hibernate/hibernate-core/4.2.1-SNAPSHOT - mvn:org.hibernate/hibernate-entitymanager/4.2.1-SNAPSHOT + mvn:org.hibernate/hibernate-core/4.3.0-SNAPSHOT + mvn:org.hibernate/hibernate-entitymanager/4.3.0-SNAPSHOT mvn:org.hibernate/HibernateOSGi_ContainerManaged/1.0.0 - mvn:org.hibernate/hibernate-osgi/4.2.1-SNAPSHOT + mvn:org.hibernate/hibernate-osgi/4.3.0-SNAPSHOT diff --git a/HibernateOSGi_ContainerManaged/pom.xml b/HibernateOSGi_ContainerManaged/pom.xml index 9c4108a..b550e6d 100644 --- a/HibernateOSGi_ContainerManaged/pom.xml +++ b/HibernateOSGi_ContainerManaged/pom.xml @@ -8,9 +8,9 @@ - org.apache.geronimo.specs - geronimo-jpa_2.0_spec - 1.1 + org.hibernate.javax.persistence + hibernate-jpa-2.1-api + 1.0.0-SNAPSHOT org.osgi @@ -51,6 +51,7 @@ org.apache.karaf.shell.commands, org.hibernate.proxy, javassist.util.proxy, + javax.persistence;version="[1.0.0,2.1.0]", * META-INF/persistence.xml From deb9566b9cdc6c20ed1fbb02dddc6ebba795cfb8 Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Wed, 10 Apr 2013 14:27:30 -0400 Subject: [PATCH 2/8] Added envers test --- HibernateOSGi_AppManaged/features.xml | 1 + HibernateOSGi_AppManaged/pom.xml | 5 ++ .../hibernate/osgitest/DataPointService.java | 7 +++ .../osgitest/DataPointServiceImpl.java | 30 ++++++++++++ .../osgitest/command/GetRevisionsCommand.java | 48 +++++++++++++++++++ .../osgitest/command/UpdateCommand.java | 47 ++++++++++++++++++ .../hibernate/osgitest/entity/DataPoint.java | 3 ++ .../OSGI-INF/blueprint/blueprint.xml | 10 ++++ 8 files changed, 151 insertions(+) create mode 100644 HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/GetRevisionsCommand.java create mode 100644 HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/UpdateCommand.java diff --git a/HibernateOSGi_AppManaged/features.xml b/HibernateOSGi_AppManaged/features.xml index 373c140..c340ac7 100644 --- a/HibernateOSGi_AppManaged/features.xml +++ b/HibernateOSGi_AppManaged/features.xml @@ -43,6 +43,7 @@ mvn:org.hibernate/hibernate-core/4.3.0-SNAPSHOT mvn:org.hibernate/hibernate-entitymanager/4.3.0-SNAPSHOT + mvn:org.hibernate/hibernate-envers/4.3.0-SNAPSHOT mvn:org.hibernate/hibernate-osgi/4.3.0-SNAPSHOT mvn:org.hibernate/HibernateOSGi_AppManaged/1.0.0 diff --git a/HibernateOSGi_AppManaged/pom.xml b/HibernateOSGi_AppManaged/pom.xml index b7aff87..cea2265 100644 --- a/HibernateOSGi_AppManaged/pom.xml +++ b/HibernateOSGi_AppManaged/pom.xml @@ -36,6 +36,11 @@ org.hibernate hibernate-entitymanager 4.3.0-SNAPSHOT + + + org.hibernate + hibernate-envers + 4.3.0-SNAPSHOT com.h2database diff --git a/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointService.java b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointService.java index 46ccc92..e6e2609 100644 --- a/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointService.java +++ b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointService.java @@ -21,6 +21,7 @@ package org.hibernate.osgitest; import java.util.List; +import java.util.Map; import org.hibernate.osgitest.entity.DataPoint; @@ -31,8 +32,14 @@ public interface DataPointService { public void add(DataPoint dp); + public void update(DataPoint dp); + + public DataPoint get(long id); + public List getAll(); + public Map getRevisions(long id); + public void deleteAll(); public void addJPA(DataPoint dp); diff --git a/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java index f8a55cd..c423823 100644 --- a/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java +++ b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java @@ -20,11 +20,16 @@ */ package org.hibernate.osgitest; +import java.util.HashSet; import java.util.List; +import java.util.Map; import javax.persistence.EntityManager; import org.hibernate.Session; +import org.hibernate.criterion.Restrictions; +import org.hibernate.envers.AuditReader; +import org.hibernate.envers.AuditReaderFactory; import org.hibernate.osgitest.entity.DataPoint; /** @@ -40,6 +45,24 @@ public void add(DataPoint dp) { s.close(); } + public void update(DataPoint dp) { + Session s = HibernateUtil.getSession(); + s.getTransaction().begin(); + s.update( dp ); + s.getTransaction().commit(); + s.close(); + } + + public DataPoint get(long id) { + Session s = HibernateUtil.getSession(); + s.getTransaction().begin(); + DataPoint dp = (DataPoint) s.createCriteria( DataPoint.class ).add( + Restrictions.eq( "id", id ) ).uniqueResult(); + s.getTransaction().commit(); + s.close(); + return dp; + } + public List getAll() { Session s = HibernateUtil.getSession(); s.getTransaction().begin(); @@ -48,6 +71,13 @@ public List getAll() { s.close(); return list; } + + public Map getRevisions(long id) { + EntityManager em = HibernateUtil.getEntityManager(); + AuditReader reader = AuditReaderFactory.get(em); + List revisionNums = reader.getRevisions( DataPoint.class, id ); + return reader.findRevisions( DataPoint.class, new HashSet(revisionNums) ); + } public void deleteAll() { Session s = HibernateUtil.getSession(); diff --git a/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/GetRevisionsCommand.java b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/GetRevisionsCommand.java new file mode 100644 index 0000000..ba7d731 --- /dev/null +++ b/HibernateOSGi_AppManaged/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.osgitest.DataPointService; +import org.hibernate.osgitest.entity.DataPoint; + +@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()) { + DataPoint dp = revisions.get( revisionNum ); + System.out.println(revisionNum + ": " + dp.getId() + ", " + dp.getName()); + } + return null; + } + +} diff --git a/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/UpdateCommand.java b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/UpdateCommand.java new file mode 100644 index 0000000..f694967 --- /dev/null +++ b/HibernateOSGi_AppManaged/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/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/entity/DataPoint.java b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/entity/DataPoint.java index 2a566d8..6f7126f 100644 --- a/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/entity/DataPoint.java +++ b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/entity/DataPoint.java @@ -24,10 +24,13 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; +import org.hibernate.envers.Audited; + /** * @author Brett Meyer */ @Entity +@Audited public class DataPoint { @Id @GeneratedValue diff --git a/HibernateOSGi_AppManaged/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/HibernateOSGi_AppManaged/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 8ded25c..b144069 100644 --- a/HibernateOSGi_AppManaged/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/HibernateOSGi_AppManaged/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -31,11 +31,21 @@ + + + + + + + + + + From e4a47e09de9bc81b0eb4bfe1ed7d4398a7b228bd Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Mon, 22 Apr 2013 13:50:52 -0400 Subject: [PATCH 3/8] 4.3.1 osgi core --- HibernateOSGi_AppManaged/pom.xml | 2 +- HibernateOSGi_ContainerManaged/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/HibernateOSGi_AppManaged/pom.xml b/HibernateOSGi_AppManaged/pom.xml index cea2265..b788d45 100644 --- a/HibernateOSGi_AppManaged/pom.xml +++ b/HibernateOSGi_AppManaged/pom.xml @@ -15,7 +15,7 @@ org.osgi org.osgi.core - 4.3.0 + 4.3.1 org.osgi diff --git a/HibernateOSGi_ContainerManaged/pom.xml b/HibernateOSGi_ContainerManaged/pom.xml index b550e6d..bc7d877 100644 --- a/HibernateOSGi_ContainerManaged/pom.xml +++ b/HibernateOSGi_ContainerManaged/pom.xml @@ -15,7 +15,7 @@ org.osgi org.osgi.core - 4.3.0 + 4.3.1 org.osgi From a25fd0a05cc11e38a737384ac22c6a60db6b35e0 Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Mon, 29 Apr 2013 11:16:44 -0400 Subject: [PATCH 4/8] Added C3P0 test --- HibernateOSGi_AppManaged/features.xml | 3 +++ .../src/main/resources/META-INF/persistence.xml | 9 +++++++++ .../src/main/resources/hibernate.cfg.xml | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/HibernateOSGi_AppManaged/features.xml b/HibernateOSGi_AppManaged/features.xml index c340ac7..2904dae 100644 --- a/HibernateOSGi_AppManaged/features.xml +++ b/HibernateOSGi_AppManaged/features.xml @@ -28,6 +28,8 @@ wrap:mvn:org.jboss/jandex/1.1.0.Alpha1 + + wrap:mvn:org.hibernate.common/hibernate-commons-annotations/4.0.1.Final mvn:com.fasterxml/classmate/0.5.4 @@ -43,6 +45,7 @@ mvn:org.hibernate/hibernate-core/4.3.0-SNAPSHOT mvn:org.hibernate/hibernate-entitymanager/4.3.0-SNAPSHOT + mvn:org.hibernate/hibernate-c3p0/4.3.0-SNAPSHOT mvn:org.hibernate/hibernate-envers/4.3.0-SNAPSHOT mvn:org.hibernate/hibernate-osgi/4.3.0-SNAPSHOT diff --git a/HibernateOSGi_AppManaged/src/main/resources/META-INF/persistence.xml b/HibernateOSGi_AppManaged/src/main/resources/META-INF/persistence.xml index 74ede90..d72fa87 100644 --- a/HibernateOSGi_AppManaged/src/main/resources/META-INF/persistence.xml +++ b/HibernateOSGi_AppManaged/src/main/resources/META-INF/persistence.xml @@ -13,6 +13,15 @@ + + \ No newline at end of file diff --git a/HibernateOSGi_AppManaged/src/main/resources/hibernate.cfg.xml b/HibernateOSGi_AppManaged/src/main/resources/hibernate.cfg.xml index a0bdf1e..732016b 100644 --- a/HibernateOSGi_AppManaged/src/main/resources/hibernate.cfg.xml +++ b/HibernateOSGi_AppManaged/src/main/resources/hibernate.cfg.xml @@ -11,6 +11,15 @@ org.hibernate.dialect.H2Dialect create-drop + + From 2978503501a8f247967b5253778e24cd80bd6156 Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Mon, 29 Apr 2013 11:47:37 -0400 Subject: [PATCH 5/8] proxool test --- HibernateOSGi_AppManaged/features.xml | 5 ++++- .../src/main/resources/hibernate.cfg.xml | 6 ++++++ .../src/main/resources/pool-one.properties | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 HibernateOSGi_AppManaged/src/main/resources/pool-one.properties diff --git a/HibernateOSGi_AppManaged/features.xml b/HibernateOSGi_AppManaged/features.xml index 2904dae..5ab1f0f 100644 --- a/HibernateOSGi_AppManaged/features.xml +++ b/HibernateOSGi_AppManaged/features.xml @@ -30,6 +30,8 @@ wrap:mvn:org.jboss/jandex/1.1.0.Alpha1 + + wrap:mvn:org.hibernate.common/hibernate-commons-annotations/4.0.1.Final mvn:com.fasterxml/classmate/0.5.4 @@ -45,7 +47,8 @@ mvn:org.hibernate/hibernate-core/4.3.0-SNAPSHOT mvn:org.hibernate/hibernate-entitymanager/4.3.0-SNAPSHOT - mvn:org.hibernate/hibernate-c3p0/4.3.0-SNAPSHOT + + mvn:org.hibernate/hibernate-envers/4.3.0-SNAPSHOT mvn:org.hibernate/hibernate-osgi/4.3.0-SNAPSHOT diff --git a/HibernateOSGi_AppManaged/src/main/resources/hibernate.cfg.xml b/HibernateOSGi_AppManaged/src/main/resources/hibernate.cfg.xml index 732016b..4509069 100644 --- a/HibernateOSGi_AppManaged/src/main/resources/hibernate.cfg.xml +++ b/HibernateOSGi_AppManaged/src/main/resources/hibernate.cfg.xml @@ -20,6 +20,12 @@ 300 3000 true --> + + diff --git a/HibernateOSGi_AppManaged/src/main/resources/pool-one.properties b/HibernateOSGi_AppManaged/src/main/resources/pool-one.properties new file mode 100644 index 0000000..abaee38 --- /dev/null +++ b/HibernateOSGi_AppManaged/src/main/resources/pool-one.properties @@ -0,0 +1,7 @@ +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 From de42a89bd3eb07a5a32796cccee447e6c09c012a Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Tue, 30 Apr 2013 23:34:29 -0400 Subject: [PATCH 6/8] Updated for Hibernate ORM 4.2.2-SNAPSHOT. Added envers test and numerous commands to AppManaged. Conflicts: HibernateOSGi_AppManaged/features.xml HibernateOSGi_AppManaged/pom.xml HibernateOSGi_ContainerManaged/features.xml --- .../hibernate/osgitest/DataPointService.java | 9 +++- .../osgitest/DataPointServiceImpl.java | 33 +++++++++++-- .../osgitest/command/GetRevisionsCommand.java | 8 ++-- .../command/GetRevisionsCommandJPA.java | 48 +++++++++++++++++++ .../osgitest/command/UpdateCommandJPA.java | 47 ++++++++++++++++++ .../OSGI-INF/blueprint/blueprint.xml | 10 ++++ 6 files changed, 146 insertions(+), 9 deletions(-) create mode 100644 HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/GetRevisionsCommandJPA.java create mode 100644 HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/UpdateCommandJPA.java diff --git a/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointService.java b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointService.java index e6e2609..7017fdb 100644 --- a/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointService.java +++ b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointService.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; +import org.hibernate.envers.DefaultRevisionEntity; import org.hibernate.osgitest.entity.DataPoint; /** @@ -38,13 +39,19 @@ public interface DataPointService { public List getAll(); - public Map getRevisions(long id); + public Map getRevisions(long id); public void deleteAll(); public void addJPA(DataPoint dp); + public void updateJPA(DataPoint dp); + + public DataPoint getJPA(long id); + public List getAllJPA(); + public Map getRevisionsJPA(long id); + public void deleteAllJPA(); } diff --git a/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java index c423823..0b463ca 100644 --- a/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java +++ b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java @@ -30,6 +30,7 @@ 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; /** @@ -72,11 +73,11 @@ public List getAll() { return list; } - public Map getRevisions(long id) { - EntityManager em = HibernateUtil.getEntityManager(); - AuditReader reader = AuditReaderFactory.get(em); + public Map getRevisions(long id) { + Session s = HibernateUtil.getSession(); + AuditReader reader = AuditReaderFactory.get(s); List revisionNums = reader.getRevisions( DataPoint.class, id ); - return reader.findRevisions( DataPoint.class, new HashSet(revisionNums) ); + return reader.findRevisions( DefaultRevisionEntity.class, new HashSet(revisionNums) ); } public void deleteAll() { @@ -95,6 +96,23 @@ public void addJPA(DataPoint dp) { em.close(); } + public void updateJPA(DataPoint dp) { + EntityManager em = HibernateUtil.getEntityManager(); + em.getTransaction().begin(); + em.merge( dp ); + em.getTransaction().commit(); + em.close(); + } + + public DataPoint getJPA(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 getAllJPA() { EntityManager em = HibernateUtil.getEntityManager(); em.getTransaction().begin(); @@ -103,6 +121,13 @@ public List getAllJPA() { em.close(); return list; } + + public Map getRevisionsJPA(long id) { + EntityManager em = HibernateUtil.getEntityManager(); + AuditReader reader = AuditReaderFactory.get(em); + List revisionNums = reader.getRevisions( DataPoint.class, id ); + return reader.findRevisions( DefaultRevisionEntity.class, new HashSet(revisionNums) ); + } public void deleteAllJPA() { EntityManager em = HibernateUtil.getEntityManager(); diff --git a/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/GetRevisionsCommand.java b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/GetRevisionsCommand.java index ba7d731..b4573f6 100644 --- a/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/GetRevisionsCommand.java +++ b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/GetRevisionsCommand.java @@ -22,8 +22,8 @@ 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; -import org.hibernate.osgitest.entity.DataPoint; @Command(scope = "dp", name = "getRevisions") public class GetRevisionsCommand implements Action { @@ -37,10 +37,10 @@ public void setDpService(DataPointService dpService) { } public Object execute(CommandSession session) throws Exception { - Map revisions = dpService.getRevisions(Long.valueOf( id )); + Map revisions = dpService.getRevisions(Long.valueOf( id )); for (Number revisionNum : revisions.keySet()) { - DataPoint dp = revisions.get( revisionNum ); - System.out.println(revisionNum + ": " + dp.getId() + ", " + dp.getName()); + DefaultRevisionEntity dre = revisions.get( revisionNum ); + System.out.println(revisionNum + ": " + dre.getId() + ", " + dre.getTimestamp()); } return null; } diff --git a/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/GetRevisionsCommandJPA.java b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/GetRevisionsCommandJPA.java new file mode 100644 index 0000000..ec0e8ec --- /dev/null +++ b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/GetRevisionsCommandJPA.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 = "getRevisionsJPA") +public class GetRevisionsCommandJPA 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.getRevisionsJPA(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/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/UpdateCommandJPA.java b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/UpdateCommandJPA.java new file mode 100644 index 0000000..a454a9e --- /dev/null +++ b/HibernateOSGi_AppManaged/src/main/java/org/hibernate/osgitest/command/UpdateCommandJPA.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 UpdateCommandJPA 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.getJPA( Long.valueOf( id ) ); + dp.setName( name ); + dpService.updateJPA( dp ); + return null; + } + +} diff --git a/HibernateOSGi_AppManaged/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/HibernateOSGi_AppManaged/src/main/resources/OSGI-INF/blueprint/blueprint.xml index b144069..b0595bd 100644 --- a/HibernateOSGi_AppManaged/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/HibernateOSGi_AppManaged/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -57,11 +57,21 @@ + + + + + + + + + + From 9db4b7f6a70cd6b699f1568767240c68f3fda457 Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Wed, 1 May 2013 00:30:10 -0400 Subject: [PATCH 7/8] Updated AppManaged for JPA 2.1 --- HibernateOSGi_AppManaged/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/HibernateOSGi_AppManaged/pom.xml b/HibernateOSGi_AppManaged/pom.xml index b788d45..19ed91c 100644 --- a/HibernateOSGi_AppManaged/pom.xml +++ b/HibernateOSGi_AppManaged/pom.xml @@ -76,6 +76,7 @@ org.hibernate.service, org.hibernate.proxy, javassist.util.proxy, + javax.persistence;version="[1.0.0,2.1.0]", * From 3d83dbbf0b4b662546ac7474577ff0b75e8a4f0b Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Wed, 1 May 2013 14:28:16 -0400 Subject: [PATCH 8/8] Added ehcache and infinispan 2lc tests --- HibernateOSGi_AppManaged/features.xml | 18 ++- .../main/resources/META-INF/persistence.xml | 9 -- .../src/main/resources/ehcache.xml | 111 ++++++++++++++++++ .../src/main/resources/hibernate.cfg.xml | 13 ++ 4 files changed, 140 insertions(+), 11 deletions(-) create mode 100644 HibernateOSGi_AppManaged/src/main/resources/ehcache.xml diff --git a/HibernateOSGi_AppManaged/features.xml b/HibernateOSGi_AppManaged/features.xml index 5ab1f0f..f900842 100644 --- a/HibernateOSGi_AppManaged/features.xml +++ b/HibernateOSGi_AppManaged/features.xml @@ -27,13 +27,15 @@ mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5 + wrap:mvn:org.hibernate.common/hibernate-commons-annotations/4.0.1.Final wrap:mvn:org.jboss/jandex/1.1.0.Alpha1 + + - wrap:mvn:org.hibernate.common/hibernate-commons-annotations/4.0.1.Final mvn:com.fasterxml/classmate/0.5.4 mvn:org.jboss.logging/jboss-logging/3.1.0.GA @@ -44,12 +46,24 @@ + + + + mvn:org.hibernate/hibernate-core/4.3.0-SNAPSHOT mvn:org.hibernate/hibernate-entitymanager/4.3.0-SNAPSHOT + mvn:org.hibernate/hibernate-envers/4.3.0-SNAPSHOT - mvn:org.hibernate/hibernate-envers/4.3.0-SNAPSHOT + + mvn:org.hibernate/hibernate-osgi/4.3.0-SNAPSHOT mvn:org.hibernate/HibernateOSGi_AppManaged/1.0.0 diff --git a/HibernateOSGi_AppManaged/src/main/resources/META-INF/persistence.xml b/HibernateOSGi_AppManaged/src/main/resources/META-INF/persistence.xml index d72fa87..74ede90 100644 --- a/HibernateOSGi_AppManaged/src/main/resources/META-INF/persistence.xml +++ b/HibernateOSGi_AppManaged/src/main/resources/META-INF/persistence.xml @@ -13,15 +13,6 @@ - - \ No newline at end of file diff --git a/HibernateOSGi_AppManaged/src/main/resources/ehcache.xml b/HibernateOSGi_AppManaged/src/main/resources/ehcache.xml new file mode 100644 index 0000000..11fddc7 --- /dev/null +++ b/HibernateOSGi_AppManaged/src/main/resources/ehcache.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + --> + + + + diff --git a/HibernateOSGi_AppManaged/src/main/resources/hibernate.cfg.xml b/HibernateOSGi_AppManaged/src/main/resources/hibernate.cfg.xml index 4509069..17244a1 100644 --- a/HibernateOSGi_AppManaged/src/main/resources/hibernate.cfg.xml +++ b/HibernateOSGi_AppManaged/src/main/resources/hibernate.cfg.xml @@ -26,7 +26,20 @@ proxool pool-one.properties pool-one --> + + + + pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy