import org.springframework.beans.factory.annotation.Autowired;\r
import org.springframework.context.annotation.Bean;\r
import org.springframework.context.annotation.Configuration;\r
+import org.springframework.core.env.Environment;\r
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;\r
import org.springframework.orm.jpa.JpaTransactionManager;\r
import org.springframework.transaction.PlatformTransactionManager;\r
@Configuration\r
public class HibernateConfiguration\r
{\r
+ @Autowired\r
+ private Environment environment;\r
+\r
@Autowired\r
private DataSource dataSource;\r
\r
\r
private Properties hibernateProperties() {\r
Properties properties = new Properties();\r
- properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");\r
- properties.put("hibernate.show_sql", "true");\r
+ properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect");\r
+ properties.setProperty("hibernate.current_session_context_class", environment.getProperty("spring.jpa.properties.hibernate.current_session_context_class"));\r
+ properties.setProperty("hibernate.show-sql", environment.getProperty("spring.jpa.properties.hibernate.show-sql"));\r
+ properties.setProperty("hibernate.cache.use_second_level_cache", environment.getProperty("spring.jpa.properties.hibernate.cache.use_second_level_cache"));\r
+ properties.setProperty("hibernate.cache.use_query_cache", environment.getProperty("spring.jpa.properties.hibernate.cache.use_query_cache"));\r
return properties; \r
}\r
\r
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());
import java.util.Collections;\r
import java.util.List;\r
\r
+import javax.persistence.EntityManagerFactory;\r
import javax.transaction.Transactional;\r
\r
import org.hibernate.Query;\r
private static final Logger logger = LoggerFactory.getLogger(AlarmsHeaderServiceImpl.class);\r
\r
@Autowired\r
- private SessionFactory sessionFactory;\r
+ private EntityManagerFactory entityManagerFactory;\r
\r
- private Session getSession() {\r
- return sessionFactory.openSession();\r
- }\r
+ public Session getSession() {\r
+ return entityManagerFactory.unwrap(SessionFactory.class).getCurrentSession();}\r
\r
public String saveAlarmsHeader(AlarmsHeader alarmsHeader) {\r
- try(Session session = getSession()){\r
+ Session session = getSession();\r
+ try{\r
if (null == alarmsHeader) {\r
logger.error("AlarmsHeaderServiceImpl saveAlarmsHeader alarmsHeader is null!");\r
return "0";\r
\r
@Override\r
public String updateAlarmsHeader(AlarmsHeader alarmsHeader) {\r
- try(Session session = getSession()){\r
+ Session session = getSession();\r
+ try{\r
if (null == alarmsHeader){\r
logger.error("AlarmsHeaderServiceImpl updateAlarmsHeader alarmsHeader is null!");\r
return "0";\r
}\r
\r
public int getAllCount(AlarmsHeader alarmsHeader,int currentPage,int pageSize) {\r
- try(Session session = getSession()){\r
+ Session session = getSession();\r
+ try{\r
StringBuffer count=new StringBuffer("select count(*) from AlarmsHeader a where 1=1");\r
if (null == alarmsHeader) {\r
logger.error("AlarmsHeaderServiceImpl getAllCount alarmsHeader is null!");\r
Page<AlarmsHeader> page = new Page<AlarmsHeader>();\r
int allRow =this.getAllCount(alarmsHeader,currentPage,pageSize);\r
int offset = page.countOffset(currentPage, pageSize);\r
-\r
- try(Session session = getSession()){\r
+ Session session = getSession();\r
+ try{\r
StringBuffer hql =new StringBuffer("from AlarmsHeader a where 1=1");\r
if (null == alarmsHeader) {\r
logger.error("AlarmsHeaderServiceImpl queryAlarmsHeader alarmsHeader is null!");\r
@SuppressWarnings("unchecked")\r
@Override\r
public List<AlarmsHeader> queryId(String[] id) {\r
- try(Session session = getSession()){\r
+ Session session = getSession();\r
+ try{\r
List<AlarmsHeader> list = new ArrayList<AlarmsHeader>();\r
if(id.length==0) {\r
logger.error("AlarmsHeaderServiceImpl queryId is null!");\r
\r
@Override\r
public String updateAlarmsHeader2018(String status, Timestamp date, String startEpochMicrosecCleared, String lastEpochMicroSecCleared, String eventName, String reportingEntityName, String specificProblem) {\r
-\r
- try(Session session = getSession()){\r
+ Session session = getSession();\r
+ try{\r
//try(Session session = sessionFactory.getCurrentSession();){\r
session.beginTransaction();\r
\r
\r
@Override\r
public String queryStatusCount(String status) {\r
- try(Session session = getSession()){\r
+ Session session = getSession();\r
+ try{\r
String hql = "select count(status) from AlarmsHeader a";\r
if (!status.equals("0"))\r
hql+=" where a.status = :status";\r
\r
@Override\r
public AlarmsHeader getAlarmsHeaderById(String id) {\r
- try(Session session = getSession()) {\r
+ Session session = getSession();\r
+ try {\r
\r
String string = "from AlarmsHeader a where 1=1 and a.id=:id";\r
Query q = session.createQuery(string);\r
\r
@Override\r
public List<SortMaster> listSortMasters(String sortType) {\r
- \r
- try(Session session = getSession()){\r
+ Session session = getSession();\r
+ try{\r
StringBuffer hql =new StringBuffer("from SortMaster a where 1=1 and a.sortType=:sortType");\r
Query query = session.createQuery(hql.toString());\r
query.setString("sortType",sortType);\r
\r
import java.util.ArrayList;\r
import java.util.List;\r
+import javax.persistence.EntityManagerFactory;\r
import javax.transaction.Transactional;\r
import org.hibernate.Query;\r
import org.hibernate.Session;\r
private static final Logger logger = LoggerFactory.getLogger(AlarmsInformationServiceImpl.class);\r
\r
@Autowired\r
- private SessionFactory sessionFactory;\r
+ private EntityManagerFactory entityManagerFactory;\r
\r
- private Session getSession() {\r
- return sessionFactory.openSession();\r
- }\r
+ public Session getSession() {\r
+ return entityManagerFactory.unwrap(SessionFactory.class).getCurrentSession();}\r
\r
@Override\r
public String saveAlarmsInformation(AlarmsInformation alarmsInformation) {\r
- try(Session session = getSession()){\r
+ Session session = getSession();\r
+ try{\r
if (null == alarmsInformation) {\r
logger.error("alarmsInformation saveAlarmsInformation alarmsInformation is null!");\r
}\r
\r
@Override\r
public String updateAlarmsInformation(AlarmsInformation alarmsInformation) {\r
- try(Session session = getSession()){\r
+ Session session = getSession();\r
+ try{\r
if (null == alarmsInformation) {\r
logger.error("alarmsInformation updateAlarmsInformation alarmsInformation is null!");\r
}\r
\r
\r
public int getAllCount(AlarmsInformation alarmsInformation, int currentPage, int pageSize) {\r
- try(Session session = getSession()){\r
+ Session session = getSession();\r
+ try{\r
StringBuilder hql = new StringBuilder("select count(*) from AlarmsInformation a where 1=1");\r
if (null == alarmsInformation) {\r
}else {\r
@SuppressWarnings("unchecked")\r
@Override\r
public List<AlarmsInformation> queryId(String[] id) {\r
+ Session session = getSession();\r
try {\r
if(id.length==0) {\r
}\r
List<AlarmsInformation> list = new ArrayList<AlarmsInformation>();\r
- Session session = getSession();\r
+\r
Query query = session.createQuery("from AlarmsInformation a where a.sourceId IN (:alist)");\r
list = query.setParameterList("alist", id).list();\r
- session.close();\r
return list;\r
} catch (Exception e) {\r
logger.error("exception occurred while performing AlarmsInformationServiceImpl queryId. Details:" + e.getMessage());\r
if("1526554800000".equals(startTime)){\r
System.out.print(startTime);\r
}\r
- try(Session session = getSession()) {\r
+ Session session = getSession();\r
+ try {\r
String hql = "select count(*) from AlarmsHeader a where 1=1 ";\r
if (sourceName != null && !"".equals(sourceName)){\r
hql += " and a.sourceName = :sourceName";\r
if (UuiCommonUtil.isNotNullOrEmpty(status)){\r
hql += " and a.status = :status";\r
}\r
+ String zero = "0";\r
if (startTime != null && !"".equals(startTime) && endTime != null && !"".equals(endTime)){\r
- hql += " and (CASE WHEN a.startEpochMicrosec=0 THEN a.lastEpochMicroSec ELSE a.startEpochMicrosec END) between :startTime and :endTime ";\r
+ hql += " and (CASE WHEN a.startEpochMicrosec=:zero THEN a.lastEpochMicroSec ELSE a.startEpochMicrosec END) between :startTime and :endTime ";\r
}\r
Query query = session.createQuery(hql);\r
+ query.setString("zero",zero);\r
if (sourceName != null && !"".equals(sourceName)){\r
query.setString("sourceName",sourceName);\r
}\r
@Override\r
public List<maxAndMinTimeBean> queryMaxAndMinTime(){\r
List<maxAndMinTimeBean> list = new ArrayList<>();\r
- try (Session session = getSession()){\r
+ Session session = getSession();\r
+ try {\r
String sql = "select MAX(startEpochMicrosec),MIN(startEpochMicrosec) FROM alarms_commoneventheader";\r
Query query = session.createSQLQuery(sql);\r
list = query.list();\r
\r
@Override\r
public List<AlarmsInformation> getAllAlarmsInformationByHeaderId(String headerId) {\r
- try (Session session = getSession()){\r
+ Session session = getSession();\r
+ try {\r
String string = "from AlarmsInformation a where 1=1 and a.headerId=:headerId";\r
Query query = session.createQuery(string);\r
query.setString("headerId",headerId);\r
import java.util.ArrayList;\r
import java.util.List;\r
\r
+import javax.persistence.EntityManagerFactory;\r
import javax.transaction.Transactional;\r
\r
import org.hibernate.Query;\r
private static final Logger logger = LoggerFactory.getLogger(PerformanceHeaderServiceImpl.class);\r
\r
@Autowired\r
- private SessionFactory sessionFactory;\r
+ private EntityManagerFactory entityManagerFactory;\r
\r
- private Session getSession() {\r
- return sessionFactory.openSession();\r
- }\r
+ public Session getSession() {\r
+ return entityManagerFactory.unwrap(SessionFactory.class).getCurrentSession();}\r
\r
@Override\r
public String savePerformanceHeader(PerformanceHeader performanceHeder) {\r
- try(Session session = getSession()){\r
+ Session session = getSession();\r
+ try{\r
if (null == performanceHeder){\r
logger.error("PerformanceHeaderServiceImpl savePerformanceHeader performanceHeder is null!");\r
return "0";\r
\r
@Override\r
public String updatePerformanceHeader(PerformanceHeader performanceHeder) {\r
- try(Session session = getSession()){\r
+ Session session = getSession();\r
+ try{\r
if (null == performanceHeder){\r
logger.error("PerformanceHeaderServiceImpl updatePerformanceHeader performanceHeder is null!");\r
return "0";\r
}\r
\r
public int getAllCount(PerformanceHeader performanceHeder, int currentPage, int pageSize) {\r
- try(Session session = getSession()){\r
+ Session session = getSession();\r
+ try{\r
StringBuffer hql = new StringBuffer("select count(*) from PerformanceHeader a where 1=1");\r
if (null == performanceHeder) {\r
return 0;\r
Page<PerformanceHeader> page = new Page<PerformanceHeader>();\r
int allRow =this.getAllCount(performanceHeder,currentPage,pageSize);\r
int offset = page.countOffset(currentPage, pageSize);\r
-\r
- try(Session session = getSession()){\r
+ Session session = getSession();\r
+ try{\r
StringBuffer hql =new StringBuffer("from PerformanceHeader a where 1=1");\r
if(UuiCommonUtil.isNotNullOrEmpty(performanceHeder.getSourceName())) {\r
String ver =performanceHeder.getSourceName();\r
@SuppressWarnings("unchecked")\r
@Override\r
public List<PerformanceHeader> queryId(String[] id) {\r
- try(Session session = getSession()) {\r
+ Session session = getSession();\r
+ try {\r
List<PerformanceHeader> list = new ArrayList<PerformanceHeader>();\r
if(id.length==0) {\r
return list;\r
\r
@Override\r
public List<String> queryAllSourceNames() {\r
- try(Session session = getSession()) {\r
+ Session session = getSession();\r
+ try {\r
Query query = session.createQuery("select distinct a.sourceName from PerformanceHeader a");\r
return query.list();\r
} catch (Exception e) {\r
\r
@Override\r
public PerformanceHeader getPerformanceHeaderById(String id) {\r
- try(Session session = getSession()) {\r
+ Session session = getSession();\r
+ try {\r
\r
String string = "from PerformanceHeader a where 1=1 and a.id=:id";\r
Query q = session.createQuery(string);\r
import java.util.List;\r
\r
\r
+import javax.persistence.EntityManagerFactory;\r
import javax.transaction.Transactional;\r
\r
import com.google.common.base.Throwables;\r
private static final Logger logger = LoggerFactory.getLogger(PerformanceInformationServiceImpl.class);\r
\r
@Autowired\r
- private SessionFactory sessionFactory;\r
+ private EntityManagerFactory entityManagerFactory;\r
\r
- private Session getSession() {\r
- return sessionFactory.openSession();\r
- }\r
+ public Session getSession() {\r
+ return entityManagerFactory.unwrap(SessionFactory.class).getCurrentSession();}\r
\r
@Override\r
public String savePerformanceInformation(PerformanceInformation performanceInformation) {\r
- try(Session session = getSession()) {\r
+ Session session = getSession();\r
+ try {\r
if (null == performanceInformation) {\r
}\r
Transaction tx = session.beginTransaction();\r
\r
@Override\r
public String updatePerformanceInformation(PerformanceInformation performanceInformation) {\r
- try(Session session = getSession()) {\r
+ Session session = getSession();\r
+ try {\r
if (null == performanceInformation) {\r
}\r
logger.info("PerformanceInformationServiceImpl updatePerformanceInformation: performanceInformation={}", performanceInformation);\r
@SuppressWarnings("unchecked")\r
@Override\r
public List<PerformanceInformation> queryId(String[] id) {\r
- try(Session session = getSession()) {\r
+ Session session = getSession();\r
+ try {\r
if(id.length==0) {\r
}\r
List<PerformanceInformation> list = new ArrayList<>();\r
@SuppressWarnings("unchecked")\r
@Override\r
public List<PerformanceInformation> queryDateBetween(String sourceId, Date startDate, Date endDate) {\r
- try(Session session = getSession()) {\r
+ Session session = getSession();\r
+ try {\r
List<PerformanceInformation> list = new ArrayList<>();\r
Query query = session.createQuery("from PerformanceInformation a where a.sourceId = :sourceId and a.createTime BETWEEN :startDate and :endDate");\r
list = query.setParameter("sourceId",sourceId).setParameter("startDate", startDate).setParameter("endDate",endDate).list();\r
@SuppressWarnings("unchecked")\r
@Override\r
public int queryDataBetweenSum(String sourceId, String name, Date startDate, Date endDate){\r
- try(Session session = getSession()) {\r
+ Session session = getSession();\r
+ try {\r
int sum = 0;\r
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");\r
sum = Integer.parseInt(query.setParameter("sourceId",sourceId).setParameter("name",name).setParameter("startDate", startDate).setParameter("endDate",endDate).uniqueResult().toString());\r
\r
@Override\r
public List<PerformanceInformation> queryDateBetween(String resourceId, String name, String startTime, String endTime) {\r
- try(Session session = getSession()) {\r
+ Session session = getSession();\r
+ try {\r
String hql = "from PerformanceInformation a where 1=1 ";\r
if (resourceId != null && !"".equals(resourceId)){\r
hql += " and a.sourceId = :resourceId";\r
\r
@Override\r
public List<PerformanceInformation> getAllPerformanceInformationByHeaderId(String headerId) {\r
- try (Session session = getSession()){\r
+ Session session = getSession();\r
+ try {\r
String string = "from PerformanceInformation a where 1=1 and a.headerId=:headerId";\r
Query query = session.createQuery(string);\r
query.setString("headerId",headerId);\r
\r
@Override\r
public String queryMaxValueByBetweenDate(String sourceId, String name, String startTime, String endTime) {\r
- try(Session session = getSession()) {\r
+ Session session = getSession();\r
+ try {\r
String hql = "select max(a.value) from PerformanceInformation a where 1=1 ";\r
if (sourceId != null && !"".equals(sourceId)){\r
hql += " and a.sourceId = :resourceId";\r
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;
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;
@Override
public void saveOrUpdateServiceBean(ServiceBean serviceBean) {
- try (Session session = getSession()) {
+ Session session = getSession();
+ try {
if (null == serviceBean) {
logger.error("DefaultServiceLcmService saveOrUpdateServiceBean serviceBean is null!");
}
@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."
@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);
@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);
@Override
public void saveOrUpdateServiceInstanceOperation(ServiceInstanceOperations serviceOperation) {
- try (Session session = getSession()) {
+ Session session = getSession();
+ try {
if (null == serviceOperation) {
logger.error("DefaultServiceLcmService saveOrUpdateServiceBean serviceOperation is null!");
}
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);
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);
} else {
serviceOperation = new ServiceInstanceOperations();
}
-
session.flush();
} catch (Exception e) {
@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);
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();
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