From 992031d07a0202757c5f0532e5dd87b98b95cd48 Mon Sep 17 00:00:00 2001 From: Maimoona Kausar Date: Mon, 1 Jan 2018 16:30:26 +0500 Subject: [PATCH] MK: Setup for OpenMRS 2.0.x compatibility --- .../module/atomfeed/AtomFeedActivator.java | 6 ++-- .../src/main/resources/liquibase.xml | 2 +- openmrs-atomfeed-common/pom.xml | 16 ++++++---- .../AtomFeedSpringTransactionManager.java | 29 ++++++++++++------- .../atomfeed/extension/html/AdminList.java | 3 +- pom.xml | 10 +++++-- 6 files changed, 42 insertions(+), 24 deletions(-) diff --git a/openmrs-atomfeed-api/src/main/java/org/openmrs/module/atomfeed/AtomFeedActivator.java b/openmrs-atomfeed-api/src/main/java/org/openmrs/module/atomfeed/AtomFeedActivator.java index fdc5f76..ab41bbb 100644 --- a/openmrs-atomfeed-api/src/main/java/org/openmrs/module/atomfeed/AtomFeedActivator.java +++ b/openmrs-atomfeed-api/src/main/java/org/openmrs/module/atomfeed/AtomFeedActivator.java @@ -14,14 +14,14 @@ package org.openmrs.module.atomfeed; -import org.apache.commons.logging.Log; +import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.openmrs.module.ModuleActivator; +import org.openmrs.module.BaseModuleActivator; /** * This class contains the logic that is run every time this module is either started or stopped. */ -public class AtomFeedActivator implements ModuleActivator { +public class AtomFeedActivator extends BaseModuleActivator { protected Log log = LogFactory.getLog(getClass()); diff --git a/openmrs-atomfeed-api/src/main/resources/liquibase.xml b/openmrs-atomfeed-api/src/main/resources/liquibase.xml index 07552e8..7e19d17 100644 --- a/openmrs-atomfeed-api/src/main/resources/liquibase.xml +++ b/openmrs-atomfeed-api/src/main/resources/liquibase.xml @@ -21,7 +21,7 @@ - + diff --git a/openmrs-atomfeed-common/pom.xml b/openmrs-atomfeed-common/pom.xml index 2b386e1..0383683 100644 --- a/openmrs-atomfeed-common/pom.xml +++ b/openmrs-atomfeed-common/pom.xml @@ -14,8 +14,8 @@ UTF-8 - 1.8.4 - 3.0.5.RELEASE + 2.0.4 + @@ -24,19 +24,25 @@ atomfeed-client ${atomfeed.version} provided + + + javax.persistence + persistence-api + + - + org.openmrs.api openmrs-api diff --git a/openmrs-atomfeed-common/src/main/java/org/openmrs/module/atomfeed/transaction/support/AtomFeedSpringTransactionManager.java b/openmrs-atomfeed-common/src/main/java/org/openmrs/module/atomfeed/transaction/support/AtomFeedSpringTransactionManager.java index 03559b1..615b1c4 100644 --- a/openmrs-atomfeed-common/src/main/java/org/openmrs/module/atomfeed/transaction/support/AtomFeedSpringTransactionManager.java +++ b/openmrs-atomfeed-common/src/main/java/org/openmrs/module/atomfeed/transaction/support/AtomFeedSpringTransactionManager.java @@ -1,11 +1,18 @@ package org.openmrs.module.atomfeed.transaction.support; -import org.hibernate.SessionFactory; -import org.hibernate.classic.Session; +import java.lang.reflect.Field; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +import org.hibernate.jdbc.ReturningWork; import org.ict4h.atomfeed.jdbc.JdbcConnectionProvider; import org.ict4h.atomfeed.transaction.AFTransactionManager; import org.ict4h.atomfeed.transaction.AFTransactionWork; import org.openmrs.api.context.ServiceContext; +import org.openmrs.api.db.hibernate.DbSession; +import org.openmrs.api.db.hibernate.DbSessionFactory; import org.springframework.context.ApplicationContext; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; @@ -13,12 +20,6 @@ import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; -import java.lang.reflect.Field; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; - public class AtomFeedSpringTransactionManager implements AFTransactionManager, JdbcConnectionProvider { private PlatformTransactionManager transactionManager; private Map propagationMap = new HashMap(); @@ -54,17 +55,23 @@ private Integer getTxPropagation(AFTransactionWork.PropagationDefinition propaga @Override public Connection getConnection() throws SQLException { //TODO: ensure that only connection associated with current thread current transaction is given - return getSession().connection(); + Connection connection = getSession().doReturningWork(new ReturningWork() { + @Override + public Connection execute(Connection conn) throws SQLException { + return conn; + } + }); + return connection; } - private Session getSession() { + private DbSession getSession() { ServiceContext serviceContext = ServiceContext.getInstance(); Class klass = serviceContext.getClass(); try { Field field = klass.getDeclaredField("applicationContext"); field.setAccessible(true); ApplicationContext applicationContext = (ApplicationContext) field.get(serviceContext); - SessionFactory factory = (SessionFactory) applicationContext.getBean("sessionFactory"); + DbSessionFactory factory = (DbSessionFactory) applicationContext.getBean("dbSessionFactory"); return factory.getCurrentSession(); } catch (Exception e) { throw new RuntimeException(e); diff --git a/openmrs-atomfeed-omod/src/main/java/org/openmrs/module/atomfeed/extension/html/AdminList.java b/openmrs-atomfeed-omod/src/main/java/org/openmrs/module/atomfeed/extension/html/AdminList.java index f6e1d5a..0f1749d 100644 --- a/openmrs-atomfeed-omod/src/main/java/org/openmrs/module/atomfeed/extension/html/AdminList.java +++ b/openmrs-atomfeed-omod/src/main/java/org/openmrs/module/atomfeed/extension/html/AdminList.java @@ -17,13 +17,12 @@ import java.util.Map; import org.openmrs.module.Extension; -import org.openmrs.module.web.extension.AdministrationSectionExt; /** * This class defines the links that will appear on the administration page under the * "atomfeed.title" heading. */ -public class AdminList extends AdministrationSectionExt { +public class AdminList extends Extension { /** * @see AdministrationSectionExt#getMediaType() diff --git a/pom.xml b/pom.xml index dd11ab8..72e7600 100644 --- a/pom.xml +++ b/pom.xml @@ -46,9 +46,9 @@ - 1.9.7 + 2.0.1 UTF-8 - 1.9.1 + 1.9.4 @@ -57,6 +57,12 @@ org.ict4h atomfeed-server ${atomfeed.version} + + + javax.persistence + persistence-api + +