@Test public void testUpdateQuery() { UserInfo userInfo = new UserInfo(); userInfo.setUserLoginId("TestID"); userInfo.setUserName("Test"); commonClassDao.save(userInfo); commonClassDao.updateQuery("SELECT * FROM userLoginId"); List<Object> data = commonClassDao.getDataById(UserInfo.class, "userLoginId:userName", "TestID:Test"); assertTrue(data.size() == 1); String query = "DELETE FROM org.onap.policy.rest.jpa.FunctionDefinition"; commonClassDao.updateQuery(query); data = commonClassDao.getDataById(UserInfo.class, "userLoginId:userName", "TestID:Test"); assertTrue(data.size() == 1); commonClassDao.delete(data); }
@Override public void updateQuery(String query) { Session session = sessionfactory.openSession(); Transaction tx = session.beginTransaction(); try { Query hbquery = session.createQuery(query); hbquery.executeUpdate(); tx.commit(); } catch (Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Database Table" + e); } finally { try { session.close(); } catch (Exception e1) { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1); } } }
PolicyValidationDaoImpl implements CommonClassDao { @Override public void updateQuery(String query) { Session session = sessionfactory.openSession(); Transaction tx = session.beginTransaction(); try { Query hbquery = session.createQuery(query); hbquery.executeUpdate(); tx.commit(); } catch (Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Database Table" + e); } finally { try { session.close(); } catch (Exception e1) { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1); } } } }
PolicyValidationDaoImpl implements CommonClassDao { @Override public void updateQuery(String query) { Session session = sessionfactory.openSession(); Transaction tx = session.beginTransaction(); try { Query hbquery = session.createQuery(query); hbquery.executeUpdate(); tx.commit(); } catch (Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Database Table" + e); } finally { try { session.close(); } catch (Exception e1) { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1); } } } @Autowired private  PolicyValidationDaoImpl(SessionFactory sessionfactory);  PolicyValidationDaoImpl(); }
PolicyValidationDaoImpl implements CommonClassDao { @Override public void updateQuery(String query) { Session session = sessionfactory.openSession(); Transaction tx = session.beginTransaction(); try { Query hbquery = session.createQuery(query); hbquery.executeUpdate(); tx.commit(); } catch (Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Database Table" + e); } finally { try { session.close(); } catch (Exception e1) { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1); } } } @Autowired private  PolicyValidationDaoImpl(SessionFactory sessionfactory);  PolicyValidationDaoImpl(); static SessionFactory getSessionfactory(); static void setSessionfactory(SessionFactory sessionfactory); @SuppressWarnings({ "unchecked", "rawtypes" }) @Override List<Object> getData(Class className); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override List<Object> getDataById(Class className, String columnName, String key); @Override void save(Object entity); @Override void delete(Object entity); @Override void update(Object entity); @SuppressWarnings({ "unchecked", "rawtypes" }) @Override List<Object> checkDuplicateEntry(String value, String columnName, Class className); @SuppressWarnings("unchecked") @Override List<PolicyRoles> getUserRoles(); @Override List<Object> checkExistingGroupListforUpdate(String arg0, String arg1); @Override void deleteAll(); @SuppressWarnings("unchecked") @Override List<Object> getDataByQuery(String query, SimpleBindings params); @SuppressWarnings("rawtypes") @Override Object getEntityItem(Class className, String columnName, String key); @Override void updateClAlarms(String arg0, String arg1); @Override void updateClYaml(String arg0, String arg1); @Override void updateQuery(String query); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override List<String> getDataByColumn(Class className, String columnName); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override List<Object> getMultipleDataOnAddingConjunction(Class className, String columnName, List<String> data); }
PolicyValidationDaoImpl implements CommonClassDao { @Override public void updateQuery(String query) { Session session = sessionfactory.openSession(); Transaction tx = session.beginTransaction(); try { Query hbquery = session.createQuery(query); hbquery.executeUpdate(); tx.commit(); } catch (Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Database Table" + e); } finally { try { session.close(); } catch (Exception e1) { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1); } } } @Autowired private  PolicyValidationDaoImpl(SessionFactory sessionfactory);  PolicyValidationDaoImpl(); static SessionFactory getSessionfactory(); static void setSessionfactory(SessionFactory sessionfactory); @SuppressWarnings({ "unchecked", "rawtypes" }) @Override List<Object> getData(Class className); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override List<Object> getDataById(Class className, String columnName, String key); @Override void save(Object entity); @Override void delete(Object entity); @Override void update(Object entity); @SuppressWarnings({ "unchecked", "rawtypes" }) @Override List<Object> checkDuplicateEntry(String value, String columnName, Class className); @SuppressWarnings("unchecked") @Override List<PolicyRoles> getUserRoles(); @Override List<Object> checkExistingGroupListforUpdate(String arg0, String arg1); @Override void deleteAll(); @SuppressWarnings("unchecked") @Override List<Object> getDataByQuery(String query, SimpleBindings params); @SuppressWarnings("rawtypes") @Override Object getEntityItem(Class className, String columnName, String key); @Override void updateClAlarms(String arg0, String arg1); @Override void updateClYaml(String arg0, String arg1); @Override void updateQuery(String query); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override List<String> getDataByColumn(Class className, String columnName); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override List<Object> getMultipleDataOnAddingConjunction(Class className, String columnName, List<String> data);  }