List of usage examples for org.hibernate Query setParameterList
Query<R> setParameterList(int position, Object[] values);
From source file:com.krawler.dao.BaseDAO.java
License:Open Source License
/** * Executes the provided HQL query after applying the provided collection parameter and * * returns the result//from ww w. j a v a2 s . c om * @param hql * The query to execute * @param paramnames * Collection Query Paramters names * @param params * Collection Query Paramters values * @return List */ public List executeCollectionQuery(final String hql, final List<String> paramnames, final List<List> params) { List results = null; results = getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery(hql); for (int i = 0; i < paramnames.size(); i++) { query.setParameterList(paramnames.get(i), params.get(i)); } return query.list(); } }); return results; }
From source file:com.krawler.dao.BaseDAO.java
License:Open Source License
public List executeQuery(final String hql, final Object[] params, final Map<String, Object> namedParams) { return getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery(hql); if (params != null) { for (int i = 0; i < params.length; i++) { query.setParameter(i, params[i]); }/*from w w w .j a v a2 s . c o m*/ } if (namedParams != null) { for (Map.Entry<String, Object> entry : namedParams.entrySet()) { Object value = entry.getValue(); if (value != null) { if (value instanceof Collection) query.setParameterList(entry.getKey(), (Collection) value); else if (entry.getValue().getClass().isArray()) query.setParameterList(entry.getKey(), (Object[]) value); else query.setParameter(entry.getKey(), entry.getValue()); } else query.setParameter(entry.getKey(), entry.getValue()); } } return query.list(); } }); }
From source file:com.krawler.dao.BaseDAO.java
License:Open Source License
public List executeQuery(final String hql, final Object[] params, final Map<String, Object> namedParams, final int[] pagingParams) { return getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery(hql); if (params != null) { for (int i = 0; i < params.length; i++) { query.setParameter(i, params[i]); }// w w w .j a v a2s . c o m } if (namedParams != null) { for (Map.Entry<String, Object> entry : namedParams.entrySet()) { Object value = entry.getValue(); if (value != null) { if (value instanceof Collection) query.setParameterList(entry.getKey(), (Collection) value); else if (entry.getValue().getClass().isArray()) query.setParameterList(entry.getKey(), (Object[]) value); else query.setParameter(entry.getKey(), entry.getValue()); } else query.setParameter(entry.getKey(), entry.getValue()); } } if (pagingParams != null) { query.setFirstResult(pagingParams[0]); query.setMaxResults(pagingParams[1]); } return query.list(); } }); }
From source file:com.krawler.dao.BaseDAO.java
License:Open Source License
/** * Executes an update query using the provided hql and query parameters * //www. j av a2 s. c o m * @param hql * Query to execute * @param params * the query paramters * @return List */ public int executeUpdate(final String hql, final Object[] params, final Map<String, Object> namedParams) { int numRow = 0; numRow = (Integer) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) { int numRows = 0; Query query = session.createQuery(hql); if (params != null) { for (int i = 0; i < params.length; i++) { query.setParameter(i, params[i]); } } if (namedParams != null) { for (Map.Entry<String, Object> entry : namedParams.entrySet()) { Object value = entry.getValue(); if (value != null) { if (value instanceof Collection) query.setParameterList(entry.getKey(), (Collection) value); else if (entry.getValue().getClass().isArray()) query.setParameterList(entry.getKey(), (Object[]) value); else query.setParameter(entry.getKey(), entry.getValue()); } else query.setParameter(entry.getKey(), entry.getValue()); } } numRows = query.executeUpdate(); return numRows; } }); return numRow; }
From source file:com.krawler.spring.hrms.common.hrmsCommonDAOImpl.java
License:Open Source License
public KwlReturnObject addAssignSalaryManager(final String[] managerIDs, final String[] availmanagerid) { boolean success = true; int numRow = 0; try {/*from w w w. j a v a 2 s . c o m*/ final String hql1 = "Update Useraccount set salarymanager= false where userid in (:managerids) "; numRow = (Integer) hibernateTemplate.execute(new HibernateCallback() { public Object doInHibernate(Session session) { int numRows = 0; Query query = session.createQuery(hql1); if (managerIDs != null) { query.setParameterList("managerids", availmanagerid); } numRows = query.executeUpdate(); return numRows; } }); final String hql = "Update Useraccount set salarymanager= true where userid in (:managerids) "; numRow = (Integer) hibernateTemplate.execute(new HibernateCallback() { public Object doInHibernate(Session session) { int numRows = 0; Query query = session.createQuery(hql); if (managerIDs != null) { query.setParameterList("managerids", managerIDs); } numRows = query.executeUpdate(); return numRows; } }); success = true; } catch (Exception ex) { success = false; ex.printStackTrace(); } finally { return new KwlReturnObject(success, "", "-1", null, numRow); } }
From source file:com.krawler.spring.hrms.employee.hrmsEmpDAOImpl.java
License:Open Source License
public KwlReturnObject generateApprovedSalary(final String[] historyIDs, int mode) { boolean success = true; int numRow = 0; try {/*from www . java2 s .co m*/ final String hql = "Update Payhistory set salarystatus=" + mode + " where historyid in (:historyids) "; numRow = (Integer) hibernateTemplate.execute(new HibernateCallback() { public Object doInHibernate(Session session) { int numRows = 0; Query query = session.createQuery(hql); if (historyIDs != null) { query.setParameterList("historyids", historyIDs); } numRows = query.executeUpdate(); return numRows; } }); success = true; } catch (Exception e) { success = false; logger.warn("Exception in hrmsEmpDAOImpl.generateApprovedSalary", e); } finally { return new KwlReturnObject(success, "", "-1", null, numRow); } }
From source file:com.krawler.spring.hrms.payroll.hrmsPayrollDAOImpl.java
License:Open Source License
@Override public boolean editAssignFrequency(final String[] empids, final int frequency) { boolean success = false; int numRow = 0; try {/*ww w . j av a 2 s . c o m*/ final String hql1 = "Update User set frequency= " + frequency + " where userID in (:userids) "; numRow = (Integer) hibernateTemplate.execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) { int numRows = 0; Query query = session.createQuery(hql1); if (empids != null) { query.setParameterList("userids", empids); } numRows = query.executeUpdate(); return numRows; } }); success = true; } catch (Exception ex) { success = false; ex.printStackTrace(); } finally { return success; } }
From source file:com.krawler.spring.hrms.payroll.hrmsPayrollDAOImpl.java
License:Open Source License
@Override public boolean editSalaryStatus(final String[] historyids, final int status, final String comment) { boolean success = false; int numRow = 0; try {// w w w. j a va 2 s . c om final String hql1 = "Update PayrollHistory set salarystatus= " + status + ", comment='" + comment + "' where historyid in (:ids) "; numRow = (Integer) hibernateTemplate.execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) { int numRows = 0; Query query = session.createQuery(hql1); if (historyids != null) { query.setParameterList("ids", historyids); } numRows = query.executeUpdate(); return numRows; } }); success = true; } catch (Exception ex) { success = false; ex.printStackTrace(); } finally { return success; } }
From source file:com.krawler.spring.hrms.payroll.statutoryform.MalaysianStatutoryFormDAOImpl.java
License:Open Source License
@Override public boolean authorizeStatutoryFormsData(final String[] empids, final int authorizeStatus, final String formID, final int month, final int year) { boolean success = false; int numRow = 0; try {/*ww w .j av a2 s.com*/ String tableName = ""; String users = ""; if (StringUtil.equal(formID, "1")) { tableName = MalaysianIncomeTaxConstants.STATUTORY_FORM_TABLE_POJO_NAME_AMANAH_SAHAM_NASIONAL; users = "user.userID"; } else if (StringUtil.equal(formID, "2")) { tableName = MalaysianIncomeTaxConstants.STATUTORY_FORM_TABLE_POJO_NAME_CP39; users = "useraccount.userID"; } else if (StringUtil.equal(formID, "3")) { tableName = MalaysianIncomeTaxConstants.STATUTORY_FORM_TABLE_POJO_NAME_CP39A; users = "useraccount.userID"; } else if (StringUtil.equal(formID, "4")) { tableName = MalaysianIncomeTaxConstants.STATUTORY_FORM_TABLE_POJO_NAME_CP21; users = "user.userID"; } else if (StringUtil.equal(formID, "5")) { tableName = MalaysianIncomeTaxConstants.STATUTORY_FORM_TABLE_POJO_NAME_HRD_LEVY; users = "user.userID"; } else if (StringUtil.equal(formID, "6")) { tableName = MalaysianIncomeTaxConstants.STATUTORY_FORM_TABLE_POJO_NAME_PCB2; users = "useraccount.userID"; } else if (StringUtil.equal(formID, "7")) { tableName = MalaysianIncomeTaxConstants.STATUTORY_FORM_TABLE_POJO_NAME_TABUNG_HAJI; users = "user.userID"; } else if (StringUtil.equal(formID, "8")) { tableName = MalaysianIncomeTaxConstants.STATUTORY_FORM_TABLE_POJO_NAME_TP1; users = "useraccount.userID"; } else if (StringUtil.equal(formID, "9")) { tableName = MalaysianIncomeTaxConstants.STATUTORY_FORM_TABLE_POJO_NAME_TP2; users = "useraccount.userID"; } else if (StringUtil.equal(formID, "10")) { tableName = MalaysianIncomeTaxConstants.STATUTORY_FORM_TABLE_POJO_NAME_TP3; users = "useraccount.userID"; } else if (StringUtil.equal(formID, "11")) { tableName = MalaysianIncomeTaxConstants.STATUTORY_FORM_TABLE_POJO_NAME_EA; users = "useraccount.userID"; } if (StringUtil.isNullOrEmpty(tableName)) { return success = false; } String hql = "Update " + tableName + " set authorizeStatus= " + authorizeStatus + " where month =" + month + " and year=" + year + " and " + users + " in (:userids) "; final String hql1 = hql; numRow = (Integer) hibernateTemplate.execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) { int numRows = 0; Query query = session.createQuery(hql1); if (empids != null) { query.setParameterList("userids", empids); } numRows = query.executeUpdate(); return numRows; } }); success = true; } catch (Exception ex) { success = false; ex.printStackTrace(); } finally { return success; } }
From source file:com.krawler.spring.organizationChart.organizationChartDAOImpl.java
License:Open Source License
@Override public boolean assignNewParent(final String[] empProfileIds, final User parentObj) throws ServiceException { boolean success = false; int numRow = 0; try {/*from w ww .ja v a 2 s .c o m*/ final String hql1 = "Update Empprofile set reportto= '" + parentObj.getUserID() + "' where userID in (:userids) "; numRow = (Integer) hibernateTemplate.execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) { int numRows = 0; Query query = session.createQuery(hql1); if (empProfileIds != null) { query.setParameterList("userids", empProfileIds); } numRows = query.executeUpdate(); return numRows; } }); success = true; } catch (Exception ex) { success = false; throw ServiceException.FAILURE("organizationChartDAOImpl.assignNewParent", ex); } finally { return success; } }