Adding PolicyType to getConfig Response
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / daoimpl / CommonClassDaoImpl.java
index 7b50397..c8b8c6a 100644 (file)
@@ -28,6 +28,7 @@ import javax.script.SimpleBindings;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hibernate.Criteria;
+import org.hibernate.HibernateException;
 import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
@@ -43,9 +44,11 @@ import org.onap.policy.rest.jpa.GroupPolicyScopeList;
 import org.onap.policy.rest.jpa.PolicyRoles;
 import org.onap.policy.xacml.api.XACMLErrorConstants;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Service;
 
 @Service("CommonClassDao")
+@Primary
 public class CommonClassDaoImpl implements CommonClassDao{
 
        private static final Log LOGGER = LogFactory.getLog(CommonClassDaoImpl.class);
@@ -53,6 +56,7 @@ public class CommonClassDaoImpl implements CommonClassDao{
        
        private static SessionFactory sessionFactory;
        
+       
        @Autowired
        private CommonClassDaoImpl(SessionFactory sessionFactory){
                CommonClassDaoImpl.sessionFactory = sessionFactory;
@@ -241,7 +245,12 @@ public class CommonClassDaoImpl implements CommonClassDao{
                try {
                        Query hbquery = session.createQuery(query);
                        for (Map.Entry<String, Object> paramPair : params.entrySet()) {
-                               hbquery.setParameter(paramPair.getKey(), paramPair.getValue());
+                               if(paramPair.getValue() instanceof java.lang.Long){
+                                       hbquery.setLong(paramPair.getKey(), (long) paramPair.getValue());
+                               }
+                               else{
+                                       hbquery.setParameter(paramPair.getKey(), paramPair.getValue());
+                               }
                        }
                        data = hbquery.list();
                        tx.commit();
@@ -251,9 +260,8 @@ public class CommonClassDaoImpl implements CommonClassDao{
                }finally{
                        try{
                                session.close();
-                       }catch(Exception e1){
-                               LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
-                               throw e1;
+                       }catch(HibernateException e1){
+                               LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement",e1);
                        }
                }
                return data;
@@ -448,4 +456,8 @@ public class CommonClassDaoImpl implements CommonClassDao{
                return null;
        }
 
+    public static void setSessionfactory(SessionFactory sessionfactory) {
+        sessionFactory = sessionfactory;
+    }
+
 }
\ No newline at end of file