List of usage examples for org.hibernate Query setProperties
Query<R> setProperties(Map bean);
From source file:br.gov.jfrj.siga.hibernate.ExDao.java
License:Open Source License
public List consultarPorFiltro(final ExMobilDaoFiltro flt, final int offset, final int itemPagina, DpPessoa titular, DpLotacao lotaTitular) { Query query = getSessao().getNamedQuery("consultarPorFiltro"); if (offset > 0) { query.setFirstResult(offset);/* w w w . j a v a 2 s. c o m*/ } if (itemPagina > 0) { query.setMaxResults(itemPagina); } query.setProperties(flt); query.setLong("titular", titular.getIdPessoaIni() != null ? titular.getIdPessoaIni() : 0); query.setLong("lotaTitular", lotaTitular.getIdLotacaoIni() != null ? lotaTitular.getIdLotacaoIni() : 0); List l = query.list(); return l; }
From source file:br.gov.jfrj.siga.hibernate.ExDao.java
License:Open Source License
public List consultarPorFiltroOld(final ExMobilDaoFiltro flt, final int offset, final int itemPagina, DpPessoa titular, DpLotacao lotaTitular) { try {/* www.j av a2 s. c om*/ final Query query = getSessao().getNamedQuery("consultarPorFiltro"); if (offset > 0) { query.setFirstResult(offset); } if (itemPagina > 0) { query.setMaxResults(itemPagina); } query.setProperties(flt); if (titular.getIdPessoaIni() != null) query.setLong("titular", titular.getIdPessoaIni()); else query.setLong("titular", 0); if (lotaTitular.getIdLotacaoIni() != null) query.setLong("lotaTitular", lotaTitular.getIdLotacaoIni()); else query.setLong("lotaTitular", 0); if (flt.getDescrDocumento() != null) query.setString("descrDocumento", flt.getDescrDocumento().toUpperCase().replace(' ', '%')); return query.list(); } catch (final NullPointerException e) { return null; } }
From source file:br.gov.jfrj.siga.hibernate.ExDao.java
License:Open Source License
public Integer consultarQuantidadePorFiltro(final ExMobilDaoFiltro flt, DpPessoa titular, DpLotacao lotaTitular) {//from w w w . j a v a2 s . c o m Query query = getSessao().getNamedQuery("consultarQuantidadePorFiltro"); query.setProperties(flt); query.setLong("titular", titular.getIdPessoaIni()); query.setLong("lotaTitular", lotaTitular.getIdLotacaoIni()); long tempoIni = System.nanoTime(); Long l = (Long) query.uniqueResult(); long tempoTotal = System.nanoTime() - tempoIni; System.out.println("consultarQuantidadePorFiltro: " + tempoTotal / 1000000 + ", resultado: " + l); return l.intValue(); }
From source file:br.gov.jfrj.siga.hibernate.ExDao.java
License:Open Source License
public ExMobil consultarPorSigla(final ExMobilDaoFiltro flt) { try {// w ww .j av a2 s. c om if (flt.getIdDoc() != null && (flt.getIdTipoMobil() == null || flt.getIdTipoMobil() == ExTipoMobil.TIPO_MOBIL_GERAL)) { final ExDocumento d = consultar(flt.getIdDoc(), ExDocumento.class, false); return d.getMobilGeral(); } if (flt.getAnoEmissao() == null) flt.setAnoEmissao(Long.valueOf(new Date().getYear()) + 1900); if (flt.getNumSequencia() == null) { final Query query = getSessao().getNamedQuery("consultarPorSiglaDocumento"); query.setProperties(flt); final List<ExDocumento> l = query.list(); if (l.size() != 1) return null; return l.get(0).getMobilGeral(); } final Query query = getSessao().getNamedQuery("consultarPorSigla"); query.setProperties(flt); final List<ExMobil> l = query.list(); if (l.size() != 1) return null; final ExMobil retorno = new ExMobil(); return l.get(0); } catch (final NullPointerException e) { return null; } }
From source file:cc.cnfc.core.orm.hibernate.HibernateDao.java
License:Open Source License
/** * ?HQL?Query.//from ww w .j ava2 s . c o m * * @param values * ???,??. */ public Query createQuery(final String queryString, final Map<String, Object> values) { Assert.hasText(queryString, "queryString?"); Query query = getSession().createQuery(queryString); if (values != null) { query.setProperties(values); } return query; }
From source file:cn.dao.MedicineInfoDao.java
public int getPageCount(Session session, String hql, Map properties) { StringBuffer countHql = new StringBuffer(); countHql.append("select count(1) "); countHql.append(hql);/*from w w w . ja v a2 s . c o m*/ Query query = session.createQuery(countHql.toString()); if (properties != null) { query.setProperties(properties); } return Integer.parseInt(query.uniqueResult().toString()); }
From source file:cn.dao.MedicineInfoDao.java
@SuppressWarnings("unchecked") public List<MedicineInfo> query(MedicineInfo vo, PageResult page) { Session session = this.getSessionFactory().getCurrentSession(); Map<String, Object> properties = new HashMap<>(); StringBuffer hql = new StringBuffer(); hql.append("from MedicineInfo"); hql.append(" where 1=1"); if (vo.getMedicineName() != null && !"".equals(vo.getMedicineName())) { hql.append(" and medicineName like :medicineName"); properties.put("medicineName", "%" + vo.getMedicineName() + "%"); }//w w w. ja va2 s .c o m int items = getPageCount(session, hql.toString(), properties); page.setItems(items); Query query = session.createQuery(hql.toString()); query.setProperties(properties); if (page != null) { query.setFirstResult(page.getFirstResult()); query.setMaxResults(page.getMaxResult()); } return query.list(); }
From source file:cn.dao.MedicinePurchaseDao.java
public int getPageCount(Session session, String hql, Map properties) { StringBuffer countHql = new StringBuffer(); countHql.append("select count(1) from("); countHql.append(hql);/*from w w w.j a v a 2 s. c o m*/ countHql.append(") c"); Query query = session.createSQLQuery(countHql.toString()); if (properties != null) { query.setProperties(properties); } return Integer.parseInt(query.uniqueResult().toString()); }
From source file:cn.dao.MedicinePurchaseDao.java
@SuppressWarnings("unchecked") public List<Object> query(MedicinePurchase vo, PageResult page) { Session session = this.getSessionFactory().getCurrentSession(); Map<String, Object> properties = new HashMap<>(); StringBuffer hql = new StringBuffer(); hql.append("select t.batch_number,t.purchase_date,u.name"); hql.append(" from medicine_purchase t"); hql.append(" left join user_info u"); hql.append(" on t.user_id = u.id"); hql.append(" group by t.batch_number,t.purchase_date,u.name"); hql.append(" order by t.purchase_date desc"); Query query = session.createSQLQuery(hql.toString()); query.setProperties(properties); if (page != null) { int items = getPageCount(session, hql.toString(), properties); page.setItems(items);/* w w w . j a v a 2s. c om*/ query.setFirstResult(page.getFirstResult()); query.setMaxResults(page.getMaxResult()); } return query.list(); }
From source file:cn.dao.MedicinePurchaseDao.java
public List<Object> queryByBatchNumber(MedicinePurchase vo, PageResult page) { Session session = this.getSessionFactory().getCurrentSession(); Map<String, Object> properties = new HashMap<>(); StringBuffer hql = new StringBuffer(); hql.append("select u.license_number,u.medicine_name,t.cost_price,t.number"); hql.append(" from medicine_purchase t"); hql.append(" left join medicine_info u"); hql.append(" on t.medicine_id = u.id"); hql.append(" where t.batch_number = :batchNumber"); hql.append(" order by t.purchase_date desc"); Query query = session.createSQLQuery(hql.toString()); properties.put("batchNumber", vo.getBatchNumber()); query.setProperties(properties); if (page != null) { int items = getPageCount(session, hql.toString(), properties); page.setItems(items);// ww w .jav a2s .co m query.setFirstResult(page.getFirstResult()); query.setMaxResults(page.getMaxResult()); } return query.list(); }