diff options
author | rb7147 <rb7147@att.com> | 2017-06-20 19:14:14 -0400 |
---|---|---|
committer | rb7147 <rb7147@att.com> | 2017-06-20 19:17:06 -0400 |
commit | 4fe8e3866576d86c36157466e349edd45af6db39 (patch) | |
tree | 46897bc80535f1a07860cc4af6de2196b666f86b /ECOMP-PAP-REST | |
parent | 620d69f26cbbea1deb5000c7a341e8012a5ad080 (diff) |
[Policy-24,Policy-27] Resolved PushPolicy Issue
Autowired the Hibernate Session Factory.
Removed the Wait timeout and interactive timeout variables from sql
script.
Updated the fwTagpicker sql error.
Change-Id: I567e845f7ba3153241178687310cb734095e8771
Signed-off-by: rb7147 <rb7147@att.com>
Diffstat (limited to 'ECOMP-PAP-REST')
3 files changed, 138 insertions, 85 deletions
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/HibernateSession.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/HibernateSession.java deleted file mode 100644 index e2fa702cb..000000000 --- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/HibernateSession.java +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-PAP-REST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pap.xacml.rest; - -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.cfg.Configuration; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; - -public class HibernateSession{ - - private static final Logger LOGGER = FlexLogger.getLogger(HibernateSession.class); - private static SessionFactory xacmlsessionFactory; - - private HibernateSession(){ - //Default Constructor - } - - static { - try { - Configuration configuration= new Configuration(); - configuration.setProperty("hibernate.connection.url", XACMLPapServlet.getPapDbUrl()); - configuration.setProperty("hibernate.connection.username", XACMLPapServlet.getPapDbUser()); - configuration.setProperty("hibernate.connection.password", XACMLPapServlet.getPapDbPassword()); - configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); - configuration.setProperty("hibernate.connection.driver_class", XACMLPapServlet.getPapDbDriver()); - configuration.setProperty("hibernate.show_sql", "false"); - configuration.setProperty("hibernate.connection.autocommit", "true"); - configuration.setProperty("hibernate.c3p0.min_size", "5"); - configuration.setProperty("hibernate.c3p0.max_size", "200"); - configuration.setProperty("hibernate.c3p0.timeout", "2147483"); - configuration.setProperty("hibernate.c3p0.idle_test_period", "3600"); - configuration.setProperty("hibernate.cache.use.query_cache", "false"); - configuration.setProperty("hibernate.cache.use_second_level_cache", "false"); - - StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()); - xacmlsessionFactory = configuration.configure("/hibernate.cfg.xml").buildSessionFactory(builder.build()); - - } catch (Exception ex) { - LOGGER.error("Exception Occured While Creating Hiberante Session Factory"+ex); - } - } - - public static Session getSessionFactory(){ - return xacmlsessionFactory.openSession(); - } - -} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/PAPRestConfig.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/PAPRestConfig.java index 801387380..bbacabab0 100644 --- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/PAPRestConfig.java +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/PAPRestConfig.java @@ -19,8 +19,24 @@ */ package org.openecomp.policy.pap.xacml.rest; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import javax.annotation.PostConstruct; +import javax.sql.DataSource; + +import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; +import org.hibernate.SessionFactory; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import org.springframework.orm.hibernate4.HibernateTransactionManager; +import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @@ -30,6 +46,100 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter @EnableTransactionManagement @ComponentScan(basePackages = { "org.openecomp.*", "com.*" }) public class PAPRestConfig extends WebMvcConfigurerAdapter { + private static final Logger LOGGER = FlexLogger.getLogger(PAPRestConfig.class); + + private static String dbDriver = null; + private static String dbUrl = null; + private static String dbUserName = null; + private static String dbPassword = null; + + @PostConstruct + public void init(){ + Properties prop = new Properties(); + InputStream input = null; + try { + input = new FileInputStream("xacml.pap.properties"); + // load a properties file + prop.load(input); + setDbDriver(prop.getProperty("javax.persistence.jdbc.driver")); + setDbUrl(prop.getProperty("javax.persistence.jdbc.url")); + setDbUserName(prop.getProperty("javax.persistence.jdbc.user")); + setDbPassword(prop.getProperty("javax.persistence.jdbc.password")); + }catch(Exception e){ + LOGGER.error("Exception Occured while loading properties file"+e); + }finally{ + if(input != null){ + try { + input.close(); + } catch (IOException e) { + LOGGER.error("Exception Occured while clsoing the stream"+e); + } + } + } + } + + @Bean(name = "dataSource") + public DataSource getDataSource() { + BasicDataSource dataSource = new BasicDataSource(); + dataSource.setDriverClassName(PAPRestConfig.getDbDriver()); + dataSource.setUrl(PAPRestConfig.getDbUrl()); + dataSource.setUsername(PAPRestConfig.getDbUserName()); + dataSource.setPassword(PAPRestConfig.getDbPassword()); + return dataSource; + } + + @Autowired + @Bean(name = "sessionFactory") + public SessionFactory getSessionFactory(DataSource dataSource) { + LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource); + sessionBuilder.scanPackages("org.openecomp.*", "com.*"); + sessionBuilder.addProperties(getHibernateProperties()); + return sessionBuilder.buildSessionFactory(); + } + + private Properties getHibernateProperties() { + Properties properties = new Properties(); + properties.put("hibernate.show_sql", "true"); + properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); + return properties; + } + + @Autowired + @Bean(name = "transactionManager") + public HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory) { + return new HibernateTransactionManager(sessionFactory); + } + + public static String getDbDriver() { + return dbDriver; + } + + public static void setDbDriver(String dbDriver) { + PAPRestConfig.dbDriver = dbDriver; + } + + public static String getDbUrl() { + return dbUrl; + } + + public static void setDbUrl(String dbUrl) { + PAPRestConfig.dbUrl = dbUrl; + } + + public static String getDbUserName() { + return dbUserName; + } + + public static void setDbUserName(String dbUserName) { + PAPRestConfig.dbUserName = dbUserName; + } + public static String getDbPassword() { + return dbPassword; + } + public static void setDbPassword(String dbPassword) { + PAPRestConfig.dbPassword = dbPassword; + } + } diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/CommonClassDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/CommonClassDaoImpl.java index 63c71e98f..c624012f1 100644 --- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/CommonClassDaoImpl.java +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/CommonClassDaoImpl.java @@ -27,18 +27,19 @@ import org.apache.commons.logging.LogFactory; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.Session; +import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.criterion.Conjunction; import org.hibernate.criterion.Criterion; import org.hibernate.criterion.Disjunction; import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; -import org.openecomp.policy.pap.xacml.rest.HibernateSession; import org.openecomp.policy.rest.dao.CommonClassDao; import org.openecomp.policy.rest.jpa.ClosedLoops; import org.openecomp.policy.rest.jpa.GroupPolicyScopeList; import org.openecomp.policy.rest.jpa.PolicyRoles; import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service("CommonClassDao") @@ -46,12 +47,22 @@ public class CommonClassDaoImpl implements CommonClassDao{ private static final Log LOGGER = LogFactory.getLog(CommonClassDaoImpl.class); - + + private static SessionFactory sessionFactory; + + @Autowired + private CommonClassDaoImpl(SessionFactory sessionFactory){ + CommonClassDaoImpl.sessionFactory = sessionFactory; + } + + public CommonClassDaoImpl(){ + //Default Constructor + } @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public List<Object> getData(Class className) { - Session session = HibernateSession.getSessionFactory(); + Session session = sessionFactory.openSession(); List<Object> data = null; try{ Criteria cr = session.createCriteria(className); @@ -72,7 +83,7 @@ public class CommonClassDaoImpl implements CommonClassDao{ @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public List<Object> getDataById(Class className, String columnName, String key) { - Session session = HibernateSession.getSessionFactory(); + Session session = sessionFactory.openSession(); List<Object> data = null; try { Criteria cr = session.createCriteria(className); @@ -101,7 +112,7 @@ public class CommonClassDaoImpl implements CommonClassDao{ @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public List<String> getDataByColumn(Class className, String columnName) { - Session session = HibernateSession.getSessionFactory(); + Session session = sessionFactory.openSession(); List<String> data = null; try{ Criteria cr = session.createCriteria(className); @@ -121,7 +132,7 @@ public class CommonClassDaoImpl implements CommonClassDao{ @Override public void save(Object entity) { - Session session = HibernateSession.getSessionFactory(); + Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); try { session.persist(entity); @@ -140,7 +151,7 @@ public class CommonClassDaoImpl implements CommonClassDao{ @Override public void delete(Object entity) { - Session session = HibernateSession.getSessionFactory(); + Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); try { session.delete(entity); @@ -160,7 +171,7 @@ public class CommonClassDaoImpl implements CommonClassDao{ @Override public void update(Object entity) { - Session session = HibernateSession.getSessionFactory(); + Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); try { session.update(entity); @@ -181,7 +192,7 @@ public class CommonClassDaoImpl implements CommonClassDao{ @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public List<Object> checkDuplicateEntry(String value, String columnName, Class className) { - Session session = HibernateSession.getSessionFactory(); + Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); List<Object> data = null; @@ -221,7 +232,7 @@ public class CommonClassDaoImpl implements CommonClassDao{ @SuppressWarnings("unchecked") @Override public List<Object> getDataByQuery(String query) { - Session session = HibernateSession.getSessionFactory(); + Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); List<Object> data = null; try { @@ -243,7 +254,7 @@ public class CommonClassDaoImpl implements CommonClassDao{ @Override public void updateQuery(String query) { - Session session = HibernateSession.getSessionFactory(); + Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); try { Query hbquery = session.createQuery(query); @@ -264,7 +275,7 @@ public class CommonClassDaoImpl implements CommonClassDao{ @SuppressWarnings("rawtypes") @Override public Object getEntityItem(Class className, String columnName, String key) { - Session session = HibernateSession.getSessionFactory(); + Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); Object data = null; try { @@ -296,7 +307,7 @@ public class CommonClassDaoImpl implements CommonClassDao{ @SuppressWarnings("unchecked") @Override public List<PolicyRoles> getUserRoles() { - Session session = HibernateSession.getSessionFactory(); + Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); List<PolicyRoles> rolesData = null; try { @@ -329,7 +340,7 @@ public class CommonClassDaoImpl implements CommonClassDao{ @SuppressWarnings("unchecked") @Override public void updateClAlarms(String clName, String alarms) { - Session session = HibernateSession.getSessionFactory(); + Session session = sessionFactory.openSession(); List<ClosedLoops> closedloopsdata = null; Transaction tx = session.beginTransaction(); try { @@ -351,7 +362,7 @@ public class CommonClassDaoImpl implements CommonClassDao{ @SuppressWarnings("unchecked") @Override public void updateClYaml(String clName, String yaml) { - Session session = HibernateSession.getSessionFactory(); + Session session = sessionFactory.openSession(); List<ClosedLoops> closedloopsdata = null; Transaction tx = session.beginTransaction(); try { @@ -373,7 +384,7 @@ public class CommonClassDaoImpl implements CommonClassDao{ @SuppressWarnings("unchecked") @Override public void deleteAll() { - Session session = HibernateSession.getSessionFactory(); + Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); List<ClosedLoops> closedloopsdata = null; try { @@ -401,7 +412,7 @@ public class CommonClassDaoImpl implements CommonClassDao{ @SuppressWarnings({ "unchecked"}) @Override public List<Object> checkExistingGroupListforUpdate(String groupListValue, String groupNameValue) { - Session session = HibernateSession.getSessionFactory(); + Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); List<Object> data = null; try { |