List of usage examples for org.hibernate Query setResultTransformer
@Deprecated Query<R> setResultTransformer(ResultTransformer transformer);
From source file:com.griffinslogistics.db.helpers.BookspackagesHelper.java
public BookspackageCMRModel totalWeightForBookspackage(Bookspackage bookspackage) { logger.log(Level.SEVERE, "{0}: totalWeightForBookspackage started", CLASS_NAME); BookspackageCMRModel result = null;/*w w w .j a v a2 s.co m*/ this.session = HibernateUtil.getSessionFactory().openSession(); Transaction transaction = this.session.beginTransaction(); try { Query query = this.session.createQuery(QUERY_TOTAL_WEIGHT_FOR_BOOKSPACKAGE); query.setResultTransformer(Transformers.aliasToBean(BookspackageCMRModel.class)); query.setParameter("bookspackage", bookspackage); result = (BookspackageCMRModel) query.uniqueResult(); } catch (HibernateException e) { transaction.rollback(); BookspackagesHelper.logger.log(Level.SEVERE, e.getMessage()); } finally { this.session.close(); logger.log(Level.SEVERE, "{0}: totalWeightForBookspackage finished", CLASS_NAME); } return result; }
From source file:com.heimaide.server.common.persistence.BaseDao.java
License:Open Source License
public <E> Page<E> findBySql(Page<E> page, String sqlString, Parameter parameter, Class<?> resultClass, ResultTransformer rtf) {/* w w w.j a v a 2s .c o m*/ // get count if (!page.isDisabled() && !page.isNotCount()) { String countSqlString = "select count(*) " + removeSelect(removeOrders(sqlString)); // page.setCount(Long.valueOf(createSqlQuery(countSqlString, // parameter).uniqueResult().toString())); Query query = createSqlQuery(countSqlString, parameter); List<Object> list = query.list(); if (list.size() > 0) { page.setCount(Long.valueOf(list.get(0).toString())); } else { page.setCount(list.size()); } if (page.getCount() < 1) { return page; } } // order by String sql = sqlString; if (StringUtils.isNotBlank(page.getOrderBy())) { sql += " order by " + page.getOrderBy(); } SQLQuery query = createSqlQuery(sql, parameter); // set page if (!page.isDisabled()) { query.setFirstResult(page.getFirstResult()); query.setMaxResults(page.getMaxResults()); } if (rtf != null) { query.setResultTransformer(rtf); } else { setResultTransformer(query, resultClass); } page.setList(query.list()); return page; }
From source file:com.heimaide.server.common.persistence.BaseDao.java
License:Open Source License
public <E> Page<E> queryBySqlFromDB(Page<E> page, String sqlString, Class<?> resultClass, List param) { // get count//from ww w.j a v a 2 s . c om if (!page.isDisabled() && !page.isNotCount()) { String countSqlString = "select count(*) from ( " + sqlString + ") k";// ????? // page.setCount(Long.valueOf(createSqlQuery(countSqlString, // parameter).uniqueResult().toString())); Query query = createSqlQuery(countSqlString, param); query.setCacheMode(CacheMode.REFRESH); List<Object> list = query.list(); if (list.size() > 0) { page.setCount(Long.valueOf(list.get(0).toString())); } else { page.setCount(list.size()); } if (page.getCount() < 1) { return page; } } // order by String sql = sqlString; if (StringUtils.isNotBlank(page.getOrderBy())) { sql += " order by " + page.getOrderBy(); } SQLQuery query = createSqlQuery(sql, param); query.setCacheMode(CacheMode.REFRESH); // set page if (!page.isDisabled()) { query.setFirstResult(page.getFirstResult()); query.setMaxResults(page.getMaxResults()); } /* * Field[] fields = resultClass.getFields(); for (Field f : fields) { * query.addScalar(f.getName());// } */ query.setResultTransformer(Transformers.aliasToBean(resultClass)); page.setList(query.list()); return page; }
From source file:com.heimaide.server.common.persistence.BaseDao.java
License:Open Source License
public <E> Page<E> queryBySql(Page<E> page, String sqlString, Class<?> resultClass, List param) { // get count//from w w w.j ava2 s . c om if (!page.isDisabled() && !page.isNotCount()) { String countSqlString = "select count(*) from ( " + sqlString + ") k";// ????? // page.setCount(Long.valueOf(createSqlQuery(countSqlString, // parameter).uniqueResult().toString())); Query query = createSqlQuery(countSqlString, param); List<Object> list = query.list(); if (list.size() > 0) { page.setCount(Long.valueOf(list.get(0).toString())); } else { page.setCount(list.size()); } if (page.getCount() < 1) { return page; } } // order by String sql = sqlString; if (StringUtils.isNotBlank(page.getOrderBy())) { sql += " order by " + page.getOrderBy(); } SQLQuery query = createSqlQuery(sql, param); // set page if (!page.isDisabled()) { query.setFirstResult(page.getFirstResult()); query.setMaxResults(page.getMaxResults()); } /* * Field[] fields = resultClass.getFields(); for (Field f : fields) { * query.addScalar(f.getName());// } */ query.setResultTransformer(Transformers.aliasToBean(resultClass)); page.setList(query.list()); return page; }
From source file:com.hyzy.core.orm.hibernate.HibernateDao.java
License:Apache License
/** * ???? // ww w . j a va 2s . c om *VO?? *VO?? ????? ?idsetId ?set SQL:SELSECT supplier_id ,SHIPPING_FEE ,REMIT_SHIPPING_MONEY FROM t_Supplier_Store supplier_id? SupplierStore?supplier_id? Supplier * @author: zhaozongzhan * @create: 201618 ?6:05:45 * * @param sql * @param vo * VO?? ????? * vo??VO ???? * @param queryParameterValues * @return */ public List<T> findBySQL(String sql, Class vo, final Object... queryParameterValues) { Query query = createCountSqlQuery(sql, queryParameterValues); if (vo == null) query.setResultTransformer(new SQLColumnToBean(entityClass));//supplier_idVO??supplierId else//vo??VO ???? query.setResultTransformer(new SQLColumnToBean(vo));//supplier_idVO??supplierId List entitys = query.list(); return entitys; }
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
@Override public List<SearchEmployeeCandidateViewModel> getAllDataEmpCandidateByParamWithDetail( SearchEmployeeCandidateParameter searchEmployeeCandidateParameter) { String listEducationId = Lambda.join(searchEmployeeCandidateParameter.getListEducationlevelId(), "','"); StringBuffer selectQuery = new StringBuffer(" SELECT empData.id AS empDataId, empData.nik AS nik, " + " bioData.first_name AS firstName, bioData.last_name AS lastName, " + " jabatan.id AS idJabatan, jabatan.name AS jabatanName, " + " ( SELECT educationLevelInner.id FROM bio_education_history bioEduInner " + " INNER JOIN education_level educationLevelInner ON bioEduInner.pendidikan_level_id = educationLevelInner.id " + " INNER JOIN bio_data bioDataInner ON bioEduInner.biodata_id = bioDataInner.id " + " WHERE bioDataInner.id = bioData.id " + " AND educationLevelInner.id IN ('" + listEducationId + "') " + " AND bioEduInner.score > " + searchEmployeeCandidateParameter.getGpa() + " LIMIT 1 " + " ) AS lastEducationLevelId, " + " religion.id AS idReligion, religion.name AS religionName " + " FROM emp_data empData " + " INNER JOIN jabatan jabatan ON empData.jabatan_id = jabatan.id " + " INNER JOIN department department ON jabatan.departement_id = department.id " + " INNER JOIN company company ON department.company_id = company.id " + " LEFT OUTER JOIN bio_data bioData ON empData.bio_data_id = bioData.id " + " INNER JOIN religion religion ON bioData.agama_id = religion.id " + " WHERE company.id = '" + HrmUserInfoUtil.getCompanyId() + "' "); selectQuery.append(setQueryParamForEmpCandidateSearchQuery(searchEmployeeCandidateParameter)); Query hbm = getCurrentSession().createSQLQuery(selectQuery.toString()); return hbm.setResultTransformer(Transformers.aliasToBean(SearchEmployeeCandidateViewModel.class)).list(); }
From source file:com.inkubator.hrm.dao.impl.WtPeriodeDaoImpl.java
@Override public List<WtPeriodEmpViewModel> getListWtPeriodEmpByParam(WtPeriodeEmpSearchParameter searchParameter, int firstResult, int maxResults, Order order) { final StringBuilder fromQuery = new StringBuilder(); fromQuery.append("select wtPeriode.id AS wtPeriodId, "); fromQuery.append("wtPeriode.from_periode AS fromPeriode,"); fromQuery.append("wtPeriode.until_periode AS untilPeriode,"); fromQuery.append(// ww w. j a va 2 s . com "SUM(CASE WHEN tempAttendanceRealization.id IS NOT NULL THEN 1 ELSE 0 END) AS totalEmpDataFromTemporary, "); fromQuery.append( "SUM(CASE WHEN logWtAttendanceRealization.id IS NOT NULL THEN 1 ELSE 0 END) AS totalEmpDataFromLogMonthEnd, "); fromQuery.append( "COUNT(DISTINCT (tempAttendanceRealization.wt_group_working_id)) AS totalWorkingGroupFromTemporary, "); fromQuery.append( "COUNT(DISTINCT (logWtAttendanceRealization.wt_group_working_id)) AS totalWorkingGroupFromLogMonthEnd, "); fromQuery.append("wtPeriode.absen as status "); fromQuery.append("FROM wt_periode wtPeriode "); fromQuery.append( "LEFT JOIN log_wt_attendance_realization logWtAttendanceRealization ON logWtAttendanceRealization.wt_periode_id=wtPeriode.id "); fromQuery.append( "LEFT JOIN temp_attendance_realization tempAttendanceRealization ON tempAttendanceRealization.wt_period_id=wtPeriode.id "); //filter by search param fromQuery.append(doSearchWtPeriodEmpByParam(searchParameter)); fromQuery.append("GROUP BY wtPeriode.id "); final StringBuilder query = new StringBuilder(); query.append("select wtPeriodId, "); query.append("fromPeriode, "); query.append("untilPeriode, "); query.append("status, "); query.append( "CASE WHEN totalEmpDataFromLogMonthEnd > 0 THEN totalEmpDataFromLogMonthEnd ELSE totalEmpDataFromTemporary END AS totalEmpData, "); query.append( "CASE WHEN totalWorkingGroupFromLogMonthEnd > 0 THEN totalWorkingGroupFromLogMonthEnd ELSE totalWorkingGroupFromTemporary END AS totalWorkingGroup "); query.append("FROM (" + fromQuery.toString() + ") AS xx "); query.append("ORDER BY " + order); Query hbm = getCurrentSession().createSQLQuery(query.toString()).setFirstResult(firstResult) .setMaxResults(maxResults); hbm = this.setValueQueryWtPeriodEmpByParam(hbm, searchParameter); return hbm.setResultTransformer(Transformers.aliasToBean(WtPeriodEmpViewModel.class)).list(); }
From source file:com.lighting.platform.base.dao.HibernateDao.java
License:Apache License
public <K> Page<K> findPage(PageConfig pageConfig, SqlEso eso, Class<K> clazz) { Page<K> page = new Page<K>(pageConfig); Query q = createQuery(eso.getSql(), eso.getParam()); long totalCount = countHqlResult(eso.getSql(), eso.getParam()); page.setTotal(totalCount);//from w w w . j a v a 2 s . c om setPageParameterToQuery(q, page); q.setResultTransformer(Transformers.aliasToBean(clazz)); List result = q.list(); page.setRows(result); return page; }
From source file:com.lighting.platform.base.dao.SimpleHibernateDao.java
License:Apache License
/** * Querydistinct transformer./* www . jav a2 s. c o m*/ * ?HQL??, ?distinct?. */ public Query distinct(Query query) { query.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return query.setCacheable(cacheable()); }
From source file:com.lzw.work.cms.services.AnjianDBMannager.java
public List getUserListBy(String stationCode) { Session session = this.getHibernateTemplate().getSessionFactory().openSession(); String sql = "select * from t_user where username<>'admin' and [check]=1 and StationCode=:StationCode"; try {/* ww w.j a v a 2 s .co m*/ Query query = session.createSQLQuery(sql); query.setParameter("StationCode", stationCode); query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); return query.list(); } finally { session.clear(); session.close(); } }