List of usage examples for org.hibernate Query setProperties
Query<R> setProperties(Map bean);
From source file:com.square.core.dao.implementations.RelationDaoImplementation.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public List<Relation> rechercherRelationsParCriteres( RemotePagingCriteriasDto<RelationCriteresRechercheDto> remotePagingCriterias) { final RelationCriteresRechercheDto criteres = remotePagingCriterias.getCriterias(); final Map<String, Object> parameters = new HashMap<String, Object>(); final StringBuffer requete = new StringBuffer("from Relation"); requete.append(" where 1=1"); completerQuery(requete, criteres, parameters); if (remotePagingCriterias.getListeSorts() == null || remotePagingCriterias.getListeSorts().size() == 0) { requete.append(" order by type.relationGroupement.ordre, type.ordre"); } else {//from w w w.j av a2s .c o m requete.append(" order by"); int countOrder = 0; for (RemotePagingSort order : remotePagingCriterias.getListeSorts()) { requete.append(countOrder > 0 ? ", " : " ").append(order.getSortField()); requete.append(order.getSortAsc() == RemotePagingSort.REMOTE_PAGING_SORT_ASC ? " asc" : " desc"); countOrder++; } } // on rajoute toujours un tri sur les ids de personne cible et source, pour assurer un tri identique chaque fois requete.append(", personneCible.id, personneSource.id"); final Query query = createQuery(requete.toString()); query.setProperties(parameters); query.setFirstResult(remotePagingCriterias.getFirstResult()); query.setMaxResults(remotePagingCriterias.getMaxResult()); final List<Relation> resultat = query.list(); return resultat; }
From source file:com.square.core.dao.implementations.RelationDaoImplementation.java
License:Open Source License
@Override public int countRelationsParCriteres(RelationCriteresRechercheDto criteres) { final Map<String, Object> parameters = new HashMap<String, Object>(); final StringBuffer requete = new StringBuffer("select count(id) from Relation rel"); requete.append(" where 1=1"); completerQuery(requete, criteres, parameters); final Query query = createQuery(requete.toString()); query.setProperties(parameters); final Object count = query.uniqueResult(); return count instanceof Integer ? ((Integer) count).intValue() : ((Long) count).intValue(); }
From source file:com.square.core.dao.implementations.RelationDaoImplementation.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public List<Long> rechercherIdsRelationsADesactiver(Calendar date, int pagination) { final Map<String, Object> parameters = new HashMap<String, Object>(); final StringBuffer requete = new StringBuffer("select id from Relation"); requete.append(" where topActif = :topActif"); parameters.put("topActif", true); requete.append(" and dateFin is not null and dateFin <= :dateFinMax"); parameters.put("dateFinMax", date); requete.append(" order by id"); final Query query = createQuery(requete.toString()); query.setProperties(parameters); query.setFirstResult(0);// w w w . j a v a2s . c om query.setMaxResults(pagination); return query.list(); }
From source file:com.square.core.dao.implementations.TelephoneDaoImplementation.java
License:Open Source License
/** * Former une requte pour la recherche de tlphone. * @param select la projection./*from w w w .j av a2 s .com*/ * @param criteres les criteres de la recherche. * @return la requte. */ private Query creerQuery(final String select, CritereRechercheTelephone criteres) { final StringBuffer requete = new StringBuffer(select); requete.append(" from Telephone as telephone"); requete.append(" inner join telephone.personnes as personne"); requete.append(" where 1 = 1"); final Map<String, Object> parameters = new HashMap<String, Object>(); if (criteres.getIdsPersonnes() != null && !criteres.getIdsPersonnes().isEmpty()) { final String param = "idsPersonnes"; requete.append(" and personne.id in (:" + param + ")"); parameters.put(param, criteres.getIdsPersonnes()); } if (criteres.getIdNature() != null) { requete.append(" and telephone.natureTelephone.id=:idNature"); parameters.put("idNature", criteres.getIdNature()); } if (criteres.getNumeroTelephone() != null && !"".equals(criteres.getNumeroTelephone())) { requete.append(" and telephone.numTelephone=:numTel"); parameters.put("numTel", criteres.getNumeroTelephone()); } if (criteres.getIsSupprime() != null) { requete.append(" and telephone.supprime=:isSupprime"); parameters.put("isSupprime", criteres.getIsSupprime()); } if (!criteres.getIdsTelExclus().isEmpty()) { requete.append(" and telephone.id not in (:idsTelExclus)"); parameters.put("idsTelExclus", criteres.getIdsTelExclus()); } final Query query = createQuery(requete.toString()); query.setProperties(parameters); return query; }
From source file:com.wwinsoft.modules.orm.hibernate.SimpleHibernateDao.java
License:Apache License
public Query createSQLQuery(final String queryString, final Map<String, ?> values) { Assert.hasText(queryString, "queryString?"); Query query = getSession().createSQLQuery(queryString); if (values != null) { query.setProperties(values); }/*from www . j av a2s. c o m*/ return query; }
From source file:com.xbwl.common.orm.hibernate.SimpleHibernateDao.java
License:Apache License
/** * HQLQuery.//from w ww.jav a 2 s.co m * * @param values ,. */ public Query createSQLQuery(final String queryString, final Map<String, ?> values) { Assert.hasText(queryString, "queryString"); Query query = getSession().createSQLQuery(queryString) .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); if (values != null) { query.setProperties(values); } return query; }
From source file:com.xbwl.common.orm.hibernate.SimpleHibernateDao.java
License:Apache License
/** * HQLQuery.// w w w . j a va 2 s . co m * * @param values ,. */ public Query createQuery(final String queryString, final Map<String, ?> values) { Assert.hasText(queryString, "queryString"); Query query = getSession().createQuery(queryString); if (values != null) { query.setProperties(values); } return query; }
From source file:com.xdtech.core.orm.hibernate.SimpleHibernateDao.java
License:Apache License
/** * HQLQuery.//from ww w . j a v a2 s . c om * find(). * * @param values ,. */ public Query createQuery(final String queryString, final Map<String, ?> values) { AssertUtils.hasText(queryString, "queryString"); Query query = getSession().createQuery(queryString); if (values != null) { query.setProperties(values); } return query; }
From source file:jp.ac.tokushima_u.is.ll.common.orm.hibernate.SimpleHibernateDao.java
License:Apache License
/** * HQL??Query?/* w w w . j av a 2s .c om*/ * * @param values ??,????. */ public Query createQuery(final String queryString, final Map<String, Object> values) { Assert.hasText(queryString, "queryString should not be null"); Query query = getSession().createQuery(queryString); if (values != null) { query.setProperties(values); } return query; }
From source file:net.firejack.platform.core.store.BaseStore.java
License:Apache License
@Transactional(readOnly = true) protected List<E> findByQuery(final Integer offset, final Integer limit, final String queryStr, final Map queryParams, final ResultTransformer transformer) { return getHibernateTemplate().execute(new HibernateCallback<List<E>>() { public List<E> doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery(queryStr); if (offset != null && offset > -1) { query.setFirstResult(offset); }//from w w w.j a va 2 s.c om if (limit != null && limit > -1) { query.setMaxResults(limit); } query.setProperties(queryParams); query.setResultTransformer(transformer); return query.list(); } }); }