List of usage examples for org.hibernate Query setParameterList
Query<R> setParameterList(int position, Object[] values);
From source file:com.baomidou.hibernateplus.utils.HibernateUtils.java
License:Open Source License
/** * hibernate?/*from ww w. ja v a 2 s . com*/ * * @param query * @param key * @param obj * @return */ public static void setParams(Query query, String key, Object obj) { if (obj.getClass().isArray()) { query.setParameterList(key, (Object[]) obj); } else if (obj instanceof List) { query.setParameterList(key, (List) obj); } else { query.setParameter(key, obj); } }
From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMEngine.java
License:Open Source License
@SuppressWarnings({ "unchecked", "cast" }) private void cacheVariablesNoBatch(Session session, List<Long> contextInstanceIds, Map<Long, TokenVariableMap> variablesCache) { Query query = session.getNamedQuery("org.alfresco.repo.workflow.cacheInstanceVariables"); query.setParameterList("ids", contextInstanceIds); query.setCacheMode(CacheMode.PUT);/*from ww w .ja v a2 s . c om*/ query.setFlushMode(FlushMode.MANUAL); query.setCacheable(true); List<TokenVariableMap> results = (List<TokenVariableMap>) query.list(); for (TokenVariableMap tokenVariableMap : results) { variablesCache.put(tokenVariableMap.getContextInstance().getId(), tokenVariableMap); } }
From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMEngine.java
License:Open Source License
@SuppressWarnings({ "unchecked", "cast" }) private void cacheTasksNoBatch(Session session, List<Long> taskInstanceIds, Map<Long, TaskInstance> returnMap) { Query query = session.getNamedQuery("org.alfresco.repo.workflow.cacheTaskInstanceProperties"); query.setParameterList("ids", taskInstanceIds); query.setCacheMode(CacheMode.PUT);/*from www . j a v a2 s . c o m*/ query.setFlushMode(FlushMode.MANUAL); query.setCacheable(true); List<TaskInstance> results = (List<TaskInstance>) query.list(); for (TaskInstance taskInstance : results) { returnMap.put(taskInstance.getId(), taskInstance); } }
From source file:com.cms.utils.BaseFWDAOImpl.java
License:Open Source License
public void fillConditionQuery(Query query, List<ConditionBean> lstCondition) { int index = 0; for (ConditionBean con : lstCondition) { if (con.getType().equals(ParamUtils.TYPE_NUMBER)) { if (!con.getOperator().equals(ParamUtils.OP_IN)) { query.setParameter("idx" + String.valueOf(index++), Long.parseLong(con.getValue())); } else { query.setParameterList("idx" + String.valueOf(index++), DataUtil.parseInputListLong(con.getValue())); }//from www.j a v a 2s . co m } else if (con.getType().equals(ParamUtils.NUMBER_DOUBLE)) { if (!con.getOperator().equals(ParamUtils.OP_IN)) { query.setParameter("idx" + String.valueOf(index++), Double.parseDouble(con.getValue())); } else { query.setParameterList("idx" + String.valueOf(index++), DataUtil.parseInputListDouble(con.getValue())); } } else if (con.getType().equals(ParamUtils.TYPE_STRING)) { if (con.getOperator().equals(ParamUtils.OP_IN)) { query.setParameterList("idx" + String.valueOf(index++), DataUtil.parseInputListString(con.getValue())); } else { query.setParameter("idx" + String.valueOf(index++), con.getValue()); } } else { query.setParameter("idx" + String.valueOf(index++), con.getValue()); } } }
From source file:com.dell.asm.asmcore.asmmanager.db.DeviceGroupDAO.java
License:Open Source License
/** * Helper method for deleting Group Users Association * /*from w w w .j a va 2 s . c om*/ * @param userSeqIds - user's id to be deleted * * @throws AsmManagerCheckedException * */ // If there is a change in groups_users table structure, then this method should be updated accordingly public void deleteGroupUsersAssociation(Set<Long> userSeqIds) throws AsmManagerCheckedException { if (userSeqIds == null || userSeqIds.size() <= 0) return; // Initialize locals. Session session = null; Transaction tx = null; List<BigInteger> userIds = new ArrayList<>(); for (Long id : userSeqIds) { userIds.add(new BigInteger(String.valueOf(id))); } // Save the job history in the db. try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); // delete the Group Users Association. String sql = "delete from groups_users WHERE user_seq_id IN (:userSeqIds)"; Query query = session.createSQLQuery(sql); query.setParameterList("userSeqIds", userIds); query.executeUpdate(); tx.commit(); } catch (Exception e) { logger.warn("Caught exception during deleting Group Users association: " + e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during deleting Group Users association: " + ex); } } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during deleting Group Users association: " + ex); } } }
From source file:com.dell.asm.asmcore.asmmanager.db.ServiceTemplateDAO.java
License:Open Source License
public List<ServiceTemplateEntity> getTemplatesForUserIds(Set<String> userIdsSet) { Session session = null;/* ww w . j av a 2s .co m*/ Transaction tx = null; List<ServiceTemplateEntity> entityList = new ArrayList<ServiceTemplateEntity>(); try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); // Create and execute command. String hql = "from ServiceTemplateEntity where id in (select templateId from TemplateUserRefEntity where user_id in ( :userIdsSet ))"; Query query = session.createQuery(hql); query.setParameterList("userIdsSet", userIdsSet); for (Object result : query.list()) { entityList.add((ServiceTemplateEntity) result); } // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during get all deployments: " + e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during get all deployments: " + ex); } throw new AsmManagerInternalErrorException("Retrieve all deployments for userIds", "DeviceInventoryDAO", e); } finally { try { if (session != null) session.close(); } catch (Exception e2) { logger.warn("Error during session close", e2); } } return entityList; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateStatisticsCounterDao.java
License:Mozilla Public License
private void addParameterLists(List<Integer> filteredSeverities, List<Integer> filteredVulnerabilities, Scan scan, Query query) { if (!filteredSeverities.isEmpty()) { query.setParameterList("filteredSeverities", filteredSeverities); }//from w w w . j av a2s .c o m if (!filteredVulnerabilities.isEmpty()) { query.setParameterList("filteredVulnerabilities", filteredVulnerabilities); } if (scan != null) { query.setParameter("scanId", scan.getId()); } }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateVulnerabilityFilterDao.java
License:Mozilla Public License
private List<Map<String, Object>> runInnerMapQuery(List<Integer> filteredSeverities, List<Integer> filteredVulnerabilities, Class<?> targetClass) { String className = targetClass.getName(); String hql = "select new map (" + "count(*) as total, " + "closeMap.scan.id as scanId) " + "from " + className + " closeMap "; String filteredIDClause = getIgnoredIdHQL(filteredSeverities, filteredVulnerabilities); if (filteredIDClause != null) { hql += "where vulnerability.id not in " + filteredIDClause; }//from w w w. j a v a 2 s . c o m hql += "group by closeMap.scan.id"; Query query = sessionFactory.getCurrentSession().createQuery(hql); if (!filteredSeverities.isEmpty()) { query.setParameterList("filteredSeverities", filteredSeverities); } if (!filteredVulnerabilities.isEmpty()) { query.setParameterList("filteredVulnerabilities", filteredVulnerabilities); } Object idsMap = query.list(); return (List<Map<String, Object>>) idsMap; }
From source file:com.dgc.DAO.GenericDao.java
public List<E> executeNamedQuery(String namedQuery, HashMap<String, Object> parameters) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*w ww .j ava2s .co m*/ Query query = session.getNamedQuery(namedQuery); for (String parameter : parameters.keySet()) { if (parameters.get(parameter) instanceof List<?>) { query.setParameterList(parameter, (Collection<?>) parameters.get(parameter)); } else { query.setParameter(parameter, parameters.get(parameter)); } } @SuppressWarnings("unchecked") ArrayList<E> result = new ArrayList<E>((List<E>) query.list()); session.getTransaction().commit(); return result; }
From source file:com.dungnv.vfw5.base.dao.BaseFWDAOImpl.java
License:Open Source License
public void fillConditionQuery(Query query, List<ConditionBean> lstCondition) { int index = 0; for (ConditionBean con : lstCondition) { if (con.getType().equals(ParamUtils.TYPE_NUMBER)) { if (con.getOperator().equals(ParamUtils.OP_IN)) { query.setParameterList("idx" + String.valueOf(index++), DataUtil.parseInputListLong(con.getValue())); } else { query.setParameter("idx" + String.valueOf(index++), Long.parseLong(con.getValue())); }// ww w .j a va 2 s. co m } else if (con.getType().equals(ParamUtils.NUMBER_DOUBLE)) { if (con.getOperator().equals(ParamUtils.OP_IN)) { query.setParameterList("idx" + String.valueOf(index++), DataUtil.parseInputListDouble(con.getValue())); } else { query.setParameter("idx" + String.valueOf(index++), Double.parseDouble(con.getValue())); } } else if (con.getType().equals(ParamUtils.TYPE_STRING)) { if (con.getOperator().equals(ParamUtils.OP_IN)) { query.setParameterList("idx" + String.valueOf(index++), DataUtil.parseInputListString(con.getValue())); } else { query.setParameter("idx" + String.valueOf(index++), con.getValue()); } } else { query.setParameter("idx" + String.valueOf(index++), con.getValue()); } } }