List of usage examples for org.hibernate Query setParameterList
Query<R> setParameterList(int position, Object[] values);
From source file:br.ufg.reqweb.dao.ReportDao.java
@Transactional(readOnly = true) public List<Map<String, ?>> listTotalRequerimento(PerfilEnum perfil, Curso curso, List<RequerimentoStatusEnum> statusList, List<TipoRequerimentoEnum> tipoRequerimentoList) { List<String> tipoRequerimentoNames = new ArrayList<>(); List<String> statusNames = new ArrayList<>(); for (TipoRequerimentoEnum tipoRequerimento : tipoRequerimentoList) { tipoRequerimentoNames.add(tipoRequerimento.name()); }// ww w. jav a 2 s . c o m for (RequerimentoStatusEnum status : statusList) { statusNames.add(status.name()); } Query query; if (perfil == null) { query = this.sessionFactory.getCurrentSession() .createSQLQuery("select c.nome as curso, r.tiporequerimento as requerimento,\n" + "r.status as status, count(r.tiporequerimento) as total\n" + "from requerimento r\n" + "join usuario u on u.id=r.usuario_id\n" + "join perfil p on p.usuario_id=u.id\n" + "join curso c on c.id=p.curso_id\n" + "group by c.id, c.nome, r.tiporequerimento, r.status\n" + "having r.status in :status\n" + "and r.tiporequerimento in :tipoRequerimento\n" + (curso == null ? "" : "and c.id = :cursoId\n") + "order by c.nome asc, r.tiporequerimento asc"); if (curso != null) { query.setLong("cursoId", curso.getId()); } } else { query = this.sessionFactory.getCurrentSession() .createSQLQuery("select coord.email, cdis.nome as curso,\n" + "r.tiporequerimento as requerimento,\n" + "r.status as status,\n" + "count(r.tiporequerimento) as total\n" + "from requerimento r\n" + "join usuario dis on dis.id=r.usuario_id\n" + "join perfil pdis on pdis.usuario_id=dis.id\n" + "join curso cdis on cdis.id=pdis.curso_id\n" + "join perfil pcoord on pcoord.curso_id=cdis.id\n" + "and pcoord.tipoperfil = :perfil\n" + "join usuario coord on pcoord.usuario_id=coord.id\n" + "group by coord.email, cdis.nome, r.tiporequerimento, r.status\n" + "having r.status in :status\n" + "and r.tiporequerimento in :tipoRequerimento\n" + "order by cdis.nome asc, r.tiporequerimento asc;\n"); query.setParameter("perfil", perfil.name()); } query.setParameterList("status", statusNames); query.setParameterList("tipoRequerimento", tipoRequerimentoNames); query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); return query.list(); }
From source file:ca.ualberta.physics.cssdp.catalogue.dao.UrlDataProductDao.java
License:Apache License
public void process(UrlDataProductUpdateMap urlDataProductUpdateMap) { if (urlDataProductUpdateMap.getUrls().size() == 0) { return;/*from w w w. ja v a 2s . c o m*/ } /* * The size of scannedUrlDataProducts should be <= jdbc batch size * configured. */ // we have to resort to hibernate directly because JPA does not have // scrolling capability Session session = emp.get().unwrap(Session.class).getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); // "in" clause limit is 2^16 on Postgresql, it might be different on // other dbs String hqlString = "from UrlDataProduct urldp where urldp.url in (:urls)"; // the fastest way to scroll through the existing data Query q = session.createQuery(hqlString); q.setParameterList("urls", urlDataProductUpdateMap.getUrls()); q.setCacheMode(CacheMode.IGNORE); ScrollableResults existingData = q.scroll(ScrollMode.FORWARD_ONLY); while (existingData.next()) { UrlDataProduct existing = (UrlDataProduct) existingData.get(0); UrlDataProduct updated = urlDataProductUpdateMap.get(existing.getUrl()); if (updated != null) { /* * Only bother to update the record if it's actually changed. * Note that the scan timestamp is ignored in the check because * that isn't something the provider changed. A change can also * mean the url was deleted, and now it's back. */ if (existing.hasChanged(updated)) { // existing.setDataProduct(updated.getDataProduct()); existing.setUrl(updated.getUrl()); existing.setStartTimestamp(updated.getStartTimestamp()); existing.setEndTimestamp(updated.getEndTimestamp()); existing.setScanTimestamp(updated.getScanTimestamp()); existing.setDeleted(false); urlDataProductUpdateMap.remove(updated.getUrl()); session.update(existing); } else { // remove it so it's not duplicated urlDataProductUpdateMap.remove(existing.getUrl()); } } else { // if we get here it means the existing url has been removed // from the server, set "delete" it from the catalogue existing.setDeleted(true); existing.setScanTimestamp(new LocalDateTime()); } } // persist the new url mappings for (String newUrl : urlDataProductUpdateMap.getUrls()) { UrlDataProduct newUrlDataProduct = urlDataProductUpdateMap.get(newUrl); session.save(newUrlDataProduct); logger.debug("saved a mapping: " + newUrlDataProduct.getUrl()); } session.flush(); session.clear(); tx.commit(); session.close(); }
From source file:ch.algotrader.dao.AbstractDao.java
License:Open Source License
private void applyParameters(final Query query, final NamedParam... params) { for (NamedParam param : params) { if (param.getValue() instanceof Collection) { query.setParameterList(param.getName(), (Collection<?>) param.getValue()); } else {/* www .j a v a 2s . c o m*/ query.setParameter(param.getName(), param.getValue()); } } }
From source file:com.abiquo.abiserver.persistence.dao.virtualappliance.hibernate.VirtualApplianceDAOHibernate.java
License:Open Source License
@Override public Collection<VirtualappHB> getVirtualAppliancesByEnterprise(final UserHB user, final Integer enterpriseId) { boolean isRestricted = !StringUtils.isEmpty(user.getAvailableVirtualDatacenters()); String queryName = isRestricted ? "VIRTUAL_APPLIANCE_BY_ENTERPRISE_TINY_WITH_RESTRICTIONS" : "VIRTUAL_APPLIANCE_BY_ENTERPRISE_TINY"; Query q = getSession().getNamedQuery(queryName); q.setParameter("enterpriseId", enterpriseId); if (isRestricted) { q.setParameterList("vdcs", getAvailableVdcs(user)); }/* w w w .ja v a 2s . c o m*/ List<Object[]> results = q.list(); return readVirtualApps(results); }
From source file:com.abiquo.abiserver.persistence.dao.virtualappliance.hibernate.VirtualApplianceDAOHibernate.java
License:Open Source License
@Override public Collection<VirtualappHB> getVirtualAppliancesByEnterpriseAndDatacenter(final UserHB user, final Integer enterpriseId, final Integer datacenterId) { boolean isRestricted = !StringUtils.isEmpty(user.getAvailableVirtualDatacenters()); String queryName = isRestricted ? "VIRTUAL_APPLIANCE_BY_ENTERPRISE_AND_DC_TINY_WITH_RESTRICTIONS" : "VIRTUAL_APPLIANCE_BY_ENTERPRISE_AND_DC_TINY"; Query q = getSession().getNamedQuery(queryName); q.setParameter("enterpriseId", enterpriseId); q.setParameter("datacenterId", datacenterId); if (isRestricted) { q.setParameterList("vdcs", getAvailableVdcs(user)); }// www .ja v a 2 s .c o m List<Object[]> results = q.list(); return readVirtualApps(results); }
From source file:com.abiquo.abiserver.persistence.dao.workload.hibernate.MachineLoadRuleDAOHibernate.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public List<MachineLoadRuleHB> findCandidateMachineRules( Collection<PhysicalmachineHB> firstPassCandidateMachines) { Query query = getSession().getNamedQuery(FIST_PASS_CANDIDATE_RULES); query.setParameterList("machines", firstPassCandidateMachines); List<MachineLoadRuleHB> candidateMachineLoadRules = query.list(); return candidateMachineLoadRules; }
From source file:com.abiquo.abiserver.persistence.hibernate.HibernateDAO.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w w w . ja v a2 s .co m*/ public List<T> findByNamedQuery(final String name, final Map<String, ?> params) { Query query = getSession().getNamedQuery(name); if (params != null) { for (Map.Entry<String, ?> param : params.entrySet()) { if (param.getValue() instanceof Collection) { query.setParameterList(param.getKey(), (Collection) param.getValue()); } else { query.setParameter(param.getKey(), param.getValue()); } } } return query.list(); }
From source file:com.abiquo.abiserver.persistence.hibernate.HibernateDAO.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from www . j ava 2s . co m*/ public T findUniqueByNamedQuery(final String name, final Map<String, ?> params) { Query query = getSession().getNamedQuery(name); if (params != null) { for (Map.Entry<String, ?> param : params.entrySet()) { if (param.getValue() instanceof Collection) { query.setParameterList(param.getKey(), (Collection) param.getValue()); } else { query.setParameter(param.getKey(), param.getValue()); } } } return (T) query.uniqueResult(); }
From source file:com.abiquo.server.core.cloud.VirtualApplianceDAO.java
License:Open Source License
/** * @param user, only users with restricted VDCs *//*from w ww . ja va2 s .c o m*/ public List<VirtualAppliance> findByEnterpriseAndDatacenter(final Integer entId, final Integer dcId, final User user) { Query query = getSession().createQuery(GET_VAPPS_BY_ENTERPRISE_AND_DATACENTER_AND_USER); query.setInteger("entId", entId); query.setInteger("dcId", dcId); query.setParameterList("allowedVDCs", availableVdsToUser(user)); return query.list(); }
From source file:com.abiquo.server.core.enterprise.UserDAO.java
License:Open Source License
@SuppressWarnings("rawtypes") public boolean isUserAllowedToUseVirtualDatacenter(final String username, final String authtype, final String[] privileges, final Integer idVdc) { Query query = getSession().createSQLQuery(USER_ALLOWED_VDC_SQL); query.setParameter("username", username); query.setParameter("authtype", authtype); query.setParameterList("privileges", privileges); query.setParameter("idvdc", idVdc); List result = query.list();//from ww w . ja v a 2 s . c om if (result == null || result.isEmpty()) { return false; } else { return true; } }