summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhekeguang <hekeguang@chinamobile.com>2020-12-29 16:44:30 +0800
committerhekeguang <hekeguang@chinamobile.com>2020-12-29 17:11:39 +0800
commitb3cdc503caf5e84bd90e9c49281f5aa893bdcc64 (patch)
treebc0235d8583b28d8e2ad62411e902529d1057ee1
parentc49f0cf093f6818af97796d91fcac5ee4e4daaf3 (diff)
Error of "no transaction is in progress" at Service Creation from UUI
Issue-ID: USECASEUI-512 Change-Id: I1db2f25307c7b5b4c8c5daff18a4563b6986147b Signed-off-by: hekeguang <hekeguang@chinamobile.com>
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java11
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/csmf/impl/SlicingServiceImpl.java2
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java38
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java34
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java30
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java32
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java39
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/TaskMgtServiceImpl.java1
-rw-r--r--server/src/main/resources/application.properties6
9 files changed, 122 insertions, 71 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java b/server/src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java
index 1a3953de..09558bc0 100755
--- a/server/src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java
+++ b/server/src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java
@@ -22,6 +22,7 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
@@ -31,6 +32,9 @@ import org.springframework.transaction.PlatformTransactionManager;
public class HibernateConfiguration
{
@Autowired
+ private Environment environment;
+
+ @Autowired
private DataSource dataSource;
@Bean
@@ -45,8 +49,11 @@ public class HibernateConfiguration
private Properties hibernateProperties() {
Properties properties = new Properties();
- properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
- properties.put("hibernate.show_sql", "true");
+ properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect");
+ properties.setProperty("hibernate.current_session_context_class", environment.getProperty("spring.jpa.properties.hibernate.current_session_context_class"));
+ properties.setProperty("hibernate.show-sql", environment.getProperty("spring.jpa.properties.hibernate.show-sql"));
+ properties.setProperty("hibernate.cache.use_second_level_cache", environment.getProperty("spring.jpa.properties.hibernate.cache.use_second_level_cache"));
+ properties.setProperty("hibernate.cache.use_query_cache", environment.getProperty("spring.jpa.properties.hibernate.cache.use_query_cache"));
return properties;
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/csmf/impl/SlicingServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/csmf/impl/SlicingServiceImpl.java
index 4fa4eb63..2fe25f1c 100644
--- a/server/src/main/java/org/onap/usecaseui/server/service/csmf/impl/SlicingServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/csmf/impl/SlicingServiceImpl.java
@@ -137,7 +137,7 @@ public class SlicingServiceImpl implements SlicingService {
if (updateResponse.isSuccessful()) {
CreateResponse createResponse = updateResponse.body();
logger.info("createSlicingService: submitOrders reponse is:{}",
- gson.toJson(updateResponse).toString());
+ gson.toJson(createResponse).toString());
// set create operation result
createResult.setService_id(createResponse.getService().getServiceId());
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java
index cb8b1ae3..3c1870be 100755
--- a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImpl.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import javax.persistence.EntityManagerFactory;
import javax.transaction.Transactional;
import org.hibernate.Query;
@@ -48,14 +49,14 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
private static final Logger logger = LoggerFactory.getLogger(AlarmsHeaderServiceImpl.class);
@Autowired
- private SessionFactory sessionFactory;
+ private EntityManagerFactory entityManagerFactory;
- private Session getSession() {
- return sessionFactory.openSession();
- }
+ public Session getSession() {
+ return entityManagerFactory.unwrap(SessionFactory.class).getCurrentSession();}
public String saveAlarmsHeader(AlarmsHeader alarmsHeader) {
- try(Session session = getSession()){
+ Session session = getSession();
+ try{
if (null == alarmsHeader) {
logger.error("AlarmsHeaderServiceImpl saveAlarmsHeader alarmsHeader is null!");
return "0";
@@ -74,7 +75,8 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
@Override
public String updateAlarmsHeader(AlarmsHeader alarmsHeader) {
- try(Session session = getSession()){
+ Session session = getSession();
+ try{
if (null == alarmsHeader){
logger.error("AlarmsHeaderServiceImpl updateAlarmsHeader alarmsHeader is null!");
return "0";
@@ -92,7 +94,8 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
}
public int getAllCount(AlarmsHeader alarmsHeader,int currentPage,int pageSize) {
- try(Session session = getSession()){
+ Session session = getSession();
+ try{
StringBuffer count=new StringBuffer("select count(*) from AlarmsHeader a where 1=1");
if (null == alarmsHeader) {
logger.error("AlarmsHeaderServiceImpl getAllCount alarmsHeader is null!");
@@ -134,8 +137,8 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
Page<AlarmsHeader> page = new Page<AlarmsHeader>();
int allRow =this.getAllCount(alarmsHeader,currentPage,pageSize);
int offset = page.countOffset(currentPage, pageSize);
-
- try(Session session = getSession()){
+ Session session = getSession();
+ try{
StringBuffer hql =new StringBuffer("from AlarmsHeader a where 1=1");
if (null == alarmsHeader) {
logger.error("AlarmsHeaderServiceImpl queryAlarmsHeader alarmsHeader is null!");
@@ -181,7 +184,8 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
@SuppressWarnings("unchecked")
@Override
public List<AlarmsHeader> queryId(String[] id) {
- try(Session session = getSession()){
+ Session session = getSession();
+ try{
List<AlarmsHeader> list = new ArrayList<AlarmsHeader>();
if(id.length==0) {
logger.error("AlarmsHeaderServiceImpl queryId is null!");
@@ -198,8 +202,8 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
@Override
public String updateAlarmsHeader2018(String status, Timestamp date, String startEpochMicrosecCleared, String lastEpochMicroSecCleared, String eventName, String reportingEntityName, String specificProblem) {
-
- try(Session session = getSession()){
+ Session session = getSession();
+ try{
//try(Session session = sessionFactory.getCurrentSession();){
session.beginTransaction();
@@ -227,7 +231,8 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
@Override
public String queryStatusCount(String status) {
- try(Session session = getSession()){
+ Session session = getSession();
+ try{
String hql = "select count(status) from AlarmsHeader a";
if (!status.equals("0"))
hql+=" where a.status = :status";
@@ -243,7 +248,8 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
@Override
public AlarmsHeader getAlarmsHeaderById(String id) {
- try(Session session = getSession()) {
+ Session session = getSession();
+ try {
String string = "from AlarmsHeader a where 1=1 and a.id=:id";
Query q = session.createQuery(string);
@@ -259,8 +265,8 @@ public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
@Override
public List<SortMaster> listSortMasters(String sortType) {
-
- try(Session session = getSession()){
+ Session session = getSession();
+ try{
StringBuffer hql =new StringBuffer("from SortMaster a where 1=1 and a.sortType=:sortType");
Query query = session.createQuery(hql.toString());
query.setString("sortType",sortType);
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
index b8ba6e41..1d739047 100755
--- a/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/AlarmsInformationServiceImpl.java
@@ -18,6 +18,7 @@ package org.onap.usecaseui.server.service.impl;
import java.util.ArrayList;
import java.util.List;
+import javax.persistence.EntityManagerFactory;
import javax.transaction.Transactional;
import org.hibernate.Query;
import org.hibernate.Session;
@@ -42,15 +43,15 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
private static final Logger logger = LoggerFactory.getLogger(AlarmsInformationServiceImpl.class);
@Autowired
- private SessionFactory sessionFactory;
+ private EntityManagerFactory entityManagerFactory;
- private Session getSession() {
- return sessionFactory.openSession();
- }
+ public Session getSession() {
+ return entityManagerFactory.unwrap(SessionFactory.class).getCurrentSession();}
@Override
public String saveAlarmsInformation(AlarmsInformation alarmsInformation) {
- try(Session session = getSession()){
+ Session session = getSession();
+ try{
if (null == alarmsInformation) {
logger.error("alarmsInformation saveAlarmsInformation alarmsInformation is null!");
}
@@ -68,7 +69,8 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
@Override
public String updateAlarmsInformation(AlarmsInformation alarmsInformation) {
- try(Session session = getSession()){
+ Session session = getSession();
+ try{
if (null == alarmsInformation) {
logger.error("alarmsInformation updateAlarmsInformation alarmsInformation is null!");
}
@@ -85,7 +87,8 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
public int getAllCount(AlarmsInformation alarmsInformation, int currentPage, int pageSize) {
- try(Session session = getSession()){
+ Session session = getSession();
+ try{
StringBuilder hql = new StringBuilder("select count(*) from AlarmsInformation a where 1=1");
if (null == alarmsInformation) {
}else {
@@ -122,14 +125,14 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
@SuppressWarnings("unchecked")
@Override
public List<AlarmsInformation> queryId(String[] id) {
+ Session session = getSession();
try {
if(id.length==0) {
}
List<AlarmsInformation> list = new ArrayList<AlarmsInformation>();
- Session session = getSession();
+
Query query = session.createQuery("from AlarmsInformation a where a.sourceId IN (:alist)");
list = query.setParameterList("alist", id).list();
- session.close();
return list;
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsInformationServiceImpl queryId. Details:" + e.getMessage());
@@ -143,7 +146,8 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
if("1526554800000".equals(startTime)){
System.out.print(startTime);
}
- try(Session session = getSession()) {
+ Session session = getSession();
+ try {
String hql = "select count(*) from AlarmsHeader a where 1=1 ";
if (sourceName != null && !"".equals(sourceName)){
hql += " and a.sourceName = :sourceName";
@@ -151,10 +155,12 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
if (UuiCommonUtil.isNotNullOrEmpty(status)){
hql += " and a.status = :status";
}
+ String zero = "0";
if (startTime != null && !"".equals(startTime) && endTime != null && !"".equals(endTime)){
- hql += " and (CASE WHEN a.startEpochMicrosec=0 THEN a.lastEpochMicroSec ELSE a.startEpochMicrosec END) between :startTime and :endTime ";
+ hql += " and (CASE WHEN a.startEpochMicrosec=:zero THEN a.lastEpochMicroSec ELSE a.startEpochMicrosec END) between :startTime and :endTime ";
}
Query query = session.createQuery(hql);
+ query.setString("zero",zero);
if (sourceName != null && !"".equals(sourceName)){
query.setString("sourceName",sourceName);
}
@@ -175,7 +181,8 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
@Override
public List<maxAndMinTimeBean> queryMaxAndMinTime(){
List<maxAndMinTimeBean> list = new ArrayList<>();
- try (Session session = getSession()){
+ Session session = getSession();
+ try {
String sql = "select MAX(startEpochMicrosec),MIN(startEpochMicrosec) FROM alarms_commoneventheader";
Query query = session.createSQLQuery(sql);
list = query.list();
@@ -191,7 +198,8 @@ public class AlarmsInformationServiceImpl implements AlarmsInformationService {
@Override
public List<AlarmsInformation> getAllAlarmsInformationByHeaderId(String headerId) {
- try (Session session = getSession()){
+ Session session = getSession();
+ try {
String string = "from AlarmsInformation a where 1=1 and a.headerId=:headerId";
Query query = session.createQuery(string);
query.setString("headerId",headerId);
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java
index 3b49a7ee..bcf34c69 100755
--- a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImpl.java
@@ -19,6 +19,7 @@ package org.onap.usecaseui.server.service.impl;
import java.util.ArrayList;
import java.util.List;
+import javax.persistence.EntityManagerFactory;
import javax.transaction.Transactional;
import org.hibernate.Query;
@@ -45,15 +46,15 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
private static final Logger logger = LoggerFactory.getLogger(PerformanceHeaderServiceImpl.class);
@Autowired
- private SessionFactory sessionFactory;
+ private EntityManagerFactory entityManagerFactory;
- private Session getSession() {
- return sessionFactory.openSession();
- }
+ public Session getSession() {
+ return entityManagerFactory.unwrap(SessionFactory.class).getCurrentSession();}
@Override
public String savePerformanceHeader(PerformanceHeader performanceHeder) {
- try(Session session = getSession()){
+ Session session = getSession();
+ try{
if (null == performanceHeder){
logger.error("PerformanceHeaderServiceImpl savePerformanceHeader performanceHeder is null!");
return "0";
@@ -71,7 +72,8 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
@Override
public String updatePerformanceHeader(PerformanceHeader performanceHeder) {
- try(Session session = getSession()){
+ Session session = getSession();
+ try{
if (null == performanceHeder){
logger.error("PerformanceHeaderServiceImpl updatePerformanceHeader performanceHeder is null!");
return "0";
@@ -88,7 +90,8 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
}
public int getAllCount(PerformanceHeader performanceHeder, int currentPage, int pageSize) {
- try(Session session = getSession()){
+ Session session = getSession();
+ try{
StringBuffer hql = new StringBuffer("select count(*) from PerformanceHeader a where 1=1");
if (null == performanceHeder) {
return 0;
@@ -120,8 +123,8 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
Page<PerformanceHeader> page = new Page<PerformanceHeader>();
int allRow =this.getAllCount(performanceHeder,currentPage,pageSize);
int offset = page.countOffset(currentPage, pageSize);
-
- try(Session session = getSession()){
+ Session session = getSession();
+ try{
StringBuffer hql =new StringBuffer("from PerformanceHeader a where 1=1");
if(UuiCommonUtil.isNotNullOrEmpty(performanceHeder.getSourceName())) {
String ver =performanceHeder.getSourceName();
@@ -152,7 +155,8 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
@SuppressWarnings("unchecked")
@Override
public List<PerformanceHeader> queryId(String[] id) {
- try(Session session = getSession()) {
+ Session session = getSession();
+ try {
List<PerformanceHeader> list = new ArrayList<PerformanceHeader>();
if(id.length==0) {
return list;
@@ -168,7 +172,8 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
@Override
public List<String> queryAllSourceNames() {
- try(Session session = getSession()) {
+ Session session = getSession();
+ try {
Query query = session.createQuery("select distinct a.sourceName from PerformanceHeader a");
return query.list();
} catch (Exception e) {
@@ -179,7 +184,8 @@ public class PerformanceHeaderServiceImpl implements PerformanceHeaderService {
@Override
public PerformanceHeader getPerformanceHeaderById(String id) {
- try(Session session = getSession()) {
+ Session session = getSession();
+ try {
String string = "from PerformanceHeader a where 1=1 and a.id=:id";
Query q = session.createQuery(string);
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java
index e32cd766..34a7dec1 100755
--- a/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/impl/PerformanceInformationServiceImpl.java
@@ -21,6 +21,7 @@ import java.util.Date;
import java.util.List;
+import javax.persistence.EntityManagerFactory;
import javax.transaction.Transactional;
import com.google.common.base.Throwables;
@@ -47,15 +48,15 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
private static final Logger logger = LoggerFactory.getLogger(PerformanceInformationServiceImpl.class);
@Autowired
- private SessionFactory sessionFactory;
+ private EntityManagerFactory entityManagerFactory;
- private Session getSession() {
- return sessionFactory.openSession();
- }
+ public Session getSession() {
+ return entityManagerFactory.unwrap(SessionFactory.class).getCurrentSession();}
@Override
public String savePerformanceInformation(PerformanceInformation performanceInformation) {
- try(Session session = getSession()) {
+ Session session = getSession();
+ try {
if (null == performanceInformation) {
}
Transaction tx = session.beginTransaction();
@@ -71,7 +72,8 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
@Override
public String updatePerformanceInformation(PerformanceInformation performanceInformation) {
- try(Session session = getSession()) {
+ Session session = getSession();
+ try {
if (null == performanceInformation) {
}
logger.info("PerformanceInformationServiceImpl updatePerformanceInformation: performanceInformation={}", performanceInformation);
@@ -89,7 +91,8 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
@SuppressWarnings("unchecked")
@Override
public List<PerformanceInformation> queryId(String[] id) {
- try(Session session = getSession()) {
+ Session session = getSession();
+ try {
if(id.length==0) {
}
List<PerformanceInformation> list = new ArrayList<>();
@@ -106,7 +109,8 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
@SuppressWarnings("unchecked")
@Override
public List<PerformanceInformation> queryDateBetween(String sourceId, Date startDate, Date endDate) {
- try(Session session = getSession()) {
+ Session session = getSession();
+ try {
List<PerformanceInformation> list = new ArrayList<>();
Query query = session.createQuery("from PerformanceInformation a where a.sourceId = :sourceId and a.createTime BETWEEN :startDate and :endDate");
list = query.setParameter("sourceId",sourceId).setParameter("startDate", startDate).setParameter("endDate",endDate).list();
@@ -120,7 +124,8 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
@SuppressWarnings("unchecked")
@Override
public int queryDataBetweenSum(String sourceId, String name, Date startDate, Date endDate){
- try(Session session = getSession()) {
+ Session session = getSession();
+ try {
int sum = 0;
Query query = session.createQuery("select sum(a.value) from PerformanceInformation a where a.sourceId = :sourceId and a.name = :name and a.createTime BETWEEN :startDate and :endDate");
sum = Integer.parseInt(query.setParameter("sourceId",sourceId).setParameter("name",name).setParameter("startDate", startDate).setParameter("endDate",endDate).uniqueResult().toString());
@@ -133,7 +138,8 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
@Override
public List<PerformanceInformation> queryDateBetween(String resourceId, String name, String startTime, String endTime) {
- try(Session session = getSession()) {
+ Session session = getSession();
+ try {
String hql = "from PerformanceInformation a where 1=1 ";
if (resourceId != null && !"".equals(resourceId)){
hql += " and a.sourceId = :resourceId";
@@ -164,7 +170,8 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
@Override
public List<PerformanceInformation> getAllPerformanceInformationByHeaderId(String headerId) {
- try (Session session = getSession()){
+ Session session = getSession();
+ try {
String string = "from PerformanceInformation a where 1=1 and a.headerId=:headerId";
Query query = session.createQuery(string);
query.setString("headerId",headerId);
@@ -180,7 +187,8 @@ public class PerformanceInformationServiceImpl implements PerformanceInformation
@Override
public String queryMaxValueByBetweenDate(String sourceId, String name, String startTime, String endTime) {
- try(Session session = getSession()) {
+ Session session = getSession();
+ try {
String hql = "select max(a.value) from PerformanceInformation a where 1=1 ";
if (sourceId != null && !"".equals(sourceId)){
hql += " and a.sourceId = :resourceId";
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java
index ef5875cc..11e75aca 100644
--- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java
@@ -22,9 +22,13 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceContext;
import javax.servlet.http.HttpServletRequest;
import com.google.common.base.Throwables;
+import javax.transaction.Transactional;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
@@ -48,16 +52,16 @@ import okhttp3.RequestBody;
import retrofit2.Response;
@Service("ServiceLcmService")
+@Transactional
public class DefaultServiceLcmService implements ServiceLcmService {
private static final Logger logger = LoggerFactory.getLogger(DefaultServiceLcmService.class);
@Autowired
- private SessionFactory sessionFactory;
+ private EntityManagerFactory entityManagerFactory;
- private Session getSession() {
- return sessionFactory.openSession();
- }
+ public Session getSession() {
+ return entityManagerFactory.unwrap(SessionFactory.class).getCurrentSession();}
private SOService soService;
@@ -165,7 +169,8 @@ public class DefaultServiceLcmService implements ServiceLcmService {
@Override
public void saveOrUpdateServiceBean(ServiceBean serviceBean) {
- try (Session session = getSession()) {
+ Session session = getSession();
+ try {
if (null == serviceBean) {
logger.error("DefaultServiceLcmService saveOrUpdateServiceBean serviceBean is null!");
}
@@ -182,15 +187,14 @@ public class DefaultServiceLcmService implements ServiceLcmService {
@Override
public void updateServiceInstanceStatusById(String status, String serviceInstanceId) {
- try (Session session = getSession()) {
-
+ Session session = getSession();
+ try {
String string = "update ServiceBean set status=:status where 1=1 and serviceInstanceId=:serviceInstanceId";
Query q = session.createQuery(string);
q.setString("status", status);
q.setString("serviceInstanceId", serviceInstanceId);
q.executeUpdate();
session.flush();
-
} catch (Exception e) {
logger.error(
"exception occurred while performing DefaultServiceLcmService updateServiceInstanceStatusById.Detail."
@@ -201,7 +205,8 @@ public class DefaultServiceLcmService implements ServiceLcmService {
@Override
public ServiceBean getServiceBeanByServiceInStanceId(String serviceInstanceId) {
ServiceBean serviceBean = null;
- try (Session session = getSession()) {
+ Session session = getSession();
+ try {
String string = "from ServiceBean where 1=1 and serviceInstanceId=:serviceInstanceId";
Query q = session.createQuery(string);
@@ -224,7 +229,8 @@ public class DefaultServiceLcmService implements ServiceLcmService {
@Override
public List<String> getServiceInstanceIdByParentId(String parentServiceInstanceId) {
List<String> list = new ArrayList<>();
- try (Session session = getSession()) {
+ Session session = getSession();
+ try {
String string = "from ServiceBean where 1=1 and parentServiceInstanceId=:parentServiceInstanceId";
Query q = session.createQuery(string);
@@ -243,7 +249,8 @@ public class DefaultServiceLcmService implements ServiceLcmService {
@Override
public void saveOrUpdateServiceInstanceOperation(ServiceInstanceOperations serviceOperation) {
- try (Session session = getSession()) {
+ Session session = getSession();
+ try {
if (null == serviceOperation) {
logger.error("DefaultServiceLcmService saveOrUpdateServiceBean serviceOperation is null!");
}
@@ -263,7 +270,8 @@ public class DefaultServiceLcmService implements ServiceLcmService {
public void updateServiceInstanceOperation(String serviceInstanceId, String operationType, String progress,
String operationResult) {
List<ServiceInstanceOperations> list = new ArrayList<>();
- try (Session session = getSession()) {
+ Session session = getSession();
+ try {
String hql =
"select a.* from service_instance_operations a where service_instance_id =:serviceId and operation_type =:operationType and start_time = (select max(start_time) from service_instance_operations where service_instance_id=:serviceInstanceId )";
Query q = session.createSQLQuery(hql).addEntity(ServiceInstanceOperations.class);
@@ -291,7 +299,8 @@ public class DefaultServiceLcmService implements ServiceLcmService {
public ServiceInstanceOperations getServiceInstanceOperationById(String serviceId) {
ServiceInstanceOperations serviceOperation = null;
List<ServiceInstanceOperations> list = new ArrayList<>();
- try (Session session = getSession()) {
+ Session session = getSession();
+ try {
String hql =
"select a.* from service_instance_operations a where service_instance_id =:serviceId and start_time = (select max(start_time) from service_instance_operations where service_instance_id=:serviceInstanceId)";
Query q = session.createSQLQuery(hql).addEntity(ServiceInstanceOperations.class);
@@ -304,7 +313,6 @@ public class DefaultServiceLcmService implements ServiceLcmService {
} else {
serviceOperation = new ServiceInstanceOperations();
}
-
session.flush();
} catch (Exception e) {
@@ -320,7 +328,8 @@ public class DefaultServiceLcmService implements ServiceLcmService {
@Override
public List<ServiceBean> getAllServiceBean() {
List<ServiceBean> list = new ArrayList<ServiceBean>();
- try (Session session = getSession()) {
+ Session session = getSession();
+ try {
String string = "from ServiceBean";
Query q = session.createQuery(string);
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/TaskMgtServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/TaskMgtServiceImpl.java
index 830b24a9..1e0b4cee 100644
--- a/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/TaskMgtServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/TaskMgtServiceImpl.java
@@ -203,6 +203,7 @@ public class TaskMgtServiceImpl implements TaskMgtService {
taskMgtServiceConvert.convertTaskAuditToSoTask(soTaskInfo, slicingTaskAuditInfo);
String jsonstr = JSON.toJSONString(soTaskInfo);
+ logger.info("updateTaskAuditInfo: the requestBody body is:{}", jsonstr);
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonstr);
Response<ResponseBody> updateResponse = soSliceService
.updateService(slicingTaskAuditInfo.getTaskId(), requestBody).execute();
diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties
index 5a580083..732122a1 100644
--- a/server/src/main/resources/application.properties
+++ b/server/src/main/resources/application.properties
@@ -27,7 +27,13 @@ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect
spring.database.driver.classname=org.postgresql.Driver
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=false
+spring.jpa.properties.hibernate.show-sql=false
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
+spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
+spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
+spring.jpa.properties.hibernate.cache.use_second_level_cache=false
+spring.jpa.properties.hibernate.cache.use_query_cache=false
+#spring.jpa.properties.hibernate.allow_update_outside_transaction=true
## Basic Authentication Properties
# security.user.name=usecase