List of usage examples for org.hibernate Query setResultTransformer
@Deprecated Query<R> setResultTransformer(ResultTransformer transformer);
From source file:com.lzw.work.cms.services.AnjianDBMannager.java
public List getStationList() { Session session = this.getHibernateTemplate().getSessionFactory().openSession(); String sql = "select * from tm_StationInfo"; try {/*from w w w .j a va2 s . c o m*/ Query query = session.createSQLQuery(sql); query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); return query.list(); } finally { session.clear(); session.close(); } }
From source file:com.lzw.work.cms.services.AnjianDBMannager.java
public Integer userLogin(String userName, String password) { String sql = "select count(*) from t_user where userName = :userName and password = :password"; Session session = this.getHibernateTemplate().getSessionFactory().openSession(); try {/*from w w w. j a va2 s .c o m*/ Query query = session.createSQLQuery(sql); query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); Long c = (Long) query.uniqueResult(); return c.intValue(); } finally { session.clear(); session.close(); } }
From source file:com.mec.DAO.POF2.GeoDAO.java
public Geoposicion getByCueAnexo(int cue, int anexo) { Query query = getSessionPof2().createSQLQuery("exec [mapa].[paEntidadGetByCueAnexo] :CueAnexo"); //System.out.println("anexo: "+anexo); int aux;/*from ww w .j a va2s . co m*/ if (String.valueOf(anexo).length() == 1) { aux = Integer.parseInt(cue + "0" + anexo); } else if (String.valueOf(anexo).length() > 1) { aux = Integer.parseInt("" + cue + anexo + "0"); } else { aux = Integer.parseInt(cue + "00");//anexo null } //System.out.println("CueAnexo: "+aux); query.setParameter("CueAnexo", aux); query.setResultTransformer(Transformers.aliasToBean(Geoposicion.class)); List<Geoposicion> g = query.list(); return (g.isEmpty() ? null : g.get(0)); }
From source file:com.mg.framework.api.orm.OrmTemplate.java
License:Open Source License
private void setResultTransformer(final Query queryObject, final ResultTransformer resultTransformer) { if (resultTransformer != null) { queryObject.setResultTransformer(new org.hibernate.transform.ResultTransformer() { public List transformList(List collection) { return collection; }//from ww w . j a v a 2 s . co m public Object transformTuple(Object[] tuple, String[] aliases) { return resultTransformer.transformTuple(tuple, aliases); } }); } }
From source file:com.myapp.core.base.dao.impl.AbstractBaseDao.java
public List findByHQL(String hql, Object[] params) { Query query = createQuery(hql, params); if (hql.indexOf("select") >= 0) { query.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP); }// w ww . java 2s . co m if (query != null) return query.list(); return null; }
From source file:com.myapp.core.base.dao.impl.AbstractBaseDao.java
public List executeSQLQuery(String sql, Object[] params) { Query query = initHqlParams(getCurrentSession().createSQLQuery(sql), params); query.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP); return query.list(); }
From source file:com.myapp.core.base.dao.impl.AbstractBaseDao.java
public PageModel toPageQuery(Integer curPage, Integer pageSize, String hql, Object[] params) { if (curPage == null) curPage = SystemConstant.DEF_PAGE_BEG; if (pageSize == null) pageSize = SystemConstant.DEF_PAGE_SIZE; if (!BaseUtil.isEmpty(hql)) { Session session = getCurrentSession(); long rows = getCount(session, hql, params); System.out.println("rows := " + rows); PageModel pm = new PageModel(curPage, pageSize, rows); Query pageQuery = initHqlParams(session.createQuery(hql), params); pageQuery.setFirstResult(pm.getStartNum()); pageQuery.setMaxResults(pageSize); pageQuery.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP); pm.setDatas(pageQuery.list());//from ww w.j av a2 s.co m return pm; } return null; }
From source file:com.myapp.core.base.dao.impl.AbstractBaseDao.java
public PageModel toPageSqlQuery(Integer curPage, Integer pageSize, String sql, Object[] params) { if (curPage == null) curPage = SystemConstant.DEF_PAGE_BEG; if (pageSize == null) pageSize = SystemConstant.DEF_PAGE_SIZE; if (!BaseUtil.isEmpty(sql)) { Session session = getCurrentSession(); long rows = getSqlCount(session, sql, params); System.out.println("rows := " + rows); PageModel pm = new PageModel(curPage, pageSize, rows); Query pageQuery = initHqlParams(session.createSQLQuery(sql), params); pageQuery.setFirstResult(pm.getStartNum()); pageQuery.setMaxResults(pageSize); pageQuery.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP); pm.setDatas(pageQuery.list());/* w w w.j a va 2 s . co m*/ return pm; } return null; }
From source file:com.mysema.query.jpa.hibernate.AbstractHibernateQuery.java
License:Apache License
private Query createQuery(String queryString, @Nullable QueryModifiers modifiers, boolean forCount) { Query query = session.createQuery(queryString); HibernateUtil.setConstants(query, getConstants(), getMetadata().getParams()); if (fetchSize > 0) { query.setFetchSize(fetchSize);/*from ww w . j a v a2 s . c om*/ } if (timeout > 0) { query.setTimeout(timeout); } if (cacheable != null) { query.setCacheable(cacheable); } if (cacheRegion != null) { query.setCacheRegion(cacheRegion); } if (comment != null) { query.setComment(comment); } if (readOnly != null) { query.setReadOnly(readOnly); } for (Map.Entry<Path<?>, LockMode> entry : lockModes.entrySet()) { query.setLockMode(entry.getKey().toString(), entry.getValue()); } if (flushMode != null) { query.setFlushMode(flushMode); } if (modifiers != null && modifiers.isRestricting()) { if (modifiers.getLimit() != null) { query.setMaxResults(modifiers.getLimit().intValue()); } if (modifiers.getOffset() != null) { query.setFirstResult(modifiers.getOffset().intValue()); } } // set transformer, if necessary List<? extends Expression<?>> projection = getMetadata().getProjection(); if (projection.size() == 1 && !forCount) { Expression<?> expr = projection.get(0); if (expr instanceof FactoryExpression<?>) { query.setResultTransformer( new FactoryExpressionTransformer((FactoryExpression<?>) projection.get(0))); } } else if (!forCount) { FactoryExpression<?> proj = FactoryExpressionUtils.wrap(projection); if (proj != null) { query.setResultTransformer(new FactoryExpressionTransformer(proj)); } } return query; }
From source file:com.nec.harvest.service.impl.ActualViewServiceImpl.java
License:Open Source License
/** {@inheritDoc}*/ @Override/*from ww w. j a va 2s. co m*/ public List<VJiseki> findByOrgCodeAndMonthies(String orgCode, String... monthlies) throws ServiceException { if (StringUtils.isEmpty(orgCode)) { throw new IllegalArgumentException("Organization must not be null or empty"); } if (ArrayUtils.isEmpty(monthlies)) { throw new IllegalArgumentException("The monthlies must not be null"); } final Session session = HibernateSessionManager.getSession(); Transaction tx = null; List<VJiseki> jisekis = new ArrayList<>(); try { tx = session.beginTransaction(); Query query = repository.getSQLQuery(session, "SELECT UriSkKG as uriSkKG, KtSkKG as ktSkKG, IdoSkKGU as idoSkKGU, IdoSkKGH as idoSkKGH, UriKrKG as uriKrKG," + " KtKrKG as ktKrKG, KnSrKG as knSrKG, KtSrKG as ktSrKG, KgcSrKG as kgcSrKG, IdoSrKGU as idoSrKGU, IdoSrKGH as idoSrKGH, KtJkKG as ktJkKG, JkJkKG as jkJkKG, KgcJkKG as kgcJkKG, IdoJkKGU as idoJkKGU, IdoJkKGH as idoJkKGH, HelpJkKGU as helpJkKGU, " + " HelpJkKGH as helpJkKGH, KtKhKG as ktKhKG, KnKhKG as knKhKG, KgcKhKG as kgcKhKG, IdoKhKGU as idoKhKGU, IdoKhKGH as idoKhKGH, UriKhKG as uriKhKG FROM V_JISEKI WHERE StrCode = :strCode AND Getsudo in (:monthlies)"); query.setParameter("strCode", orgCode); query.setParameterList("monthlies", monthlies); query.setResultTransformer(Transformers.aliasToBean(VJiseki.class)); jisekis = repository.findByQuery(query); // Release transaction tx.commit(); if (CollectionUtils.isEmpty(jisekis)) { throw new ObjectNotFoundException("There is no actual view object"); } } catch (SQLGrammarException | GenericJDBCException ex) { if (tx != null) { tx.rollback(); } throw new ServiceException( "An exception occured while getting VJiseki data for the organization " + orgCode, ex); } finally { HibernateSessionManager.closeSession(session); } return jisekis; }