List of usage examples for org.hibernate Query setResultTransformer
@Deprecated Query<R> setResultTransformer(ResultTransformer transformer);
From source file:com.age.core.orm.hibernate.HibernateDao.java
License:Apache License
/** * HQL./* ww w. j ava 2 s . c o m*/ * * @param page ?. * @param hql hql?. * @param values ???,??. * * @return , ??. */ public <X> Page<X> findPageSQL(final PageRequest pageRequest, String sql, final Map<String, ?> values, Class<X> clasz) { AssertUtils.notNull(pageRequest, "page?"); Page<X> page = new Page<X>(pageRequest); if (pageRequest.isCountTotal()) { long totalCount = countSqlResult(sql, values); page.setTotalItems(totalCount); } Query q = createSQLQuery(sql, values); q.setResultTransformer(new AliasToBeanResultTransformer(clasz)); setPageParameterToQuery(q, pageRequest); List result = q.list(); page.setResult(result); return page; }
From source file:com.asecurity.eventslogdb.AccessEvents.java
private List<ApacseventsCha> getApacseventsCha(String hql, int resCnt, boolean useNativeSQL) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); List<ApacseventsCha> aeCha = null; Transaction tx = null;/*from w ww .ja v a 2s.c o m*/ try { tx = session.beginTransaction(); Query q; if (useNativeSQL) { q = session.createSQLQuery(hql); q.setResultTransformer(Transformers.aliasToBean(ApacseventsCha.class)); } else { q = session.createQuery(hql); } q.setMaxResults(resCnt); aeCha = (List<ApacseventsCha>) q.list(); } catch (Exception e) { System.out.println(e.toString()); } finally { if (tx != null) { tx.rollback(); } if (session.isOpen()) { session.close(); } } return aeCha; }
From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateDao.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public <T> List<T> find(final String queryString, final int firstResult, final int maxResults, final List values, final Class<T> transformerClass) { final List<T> list = getHibernateTemplate().executeFind(new HibernateCallback() { @Override/* www . j a va2s . c om*/ public Object doInHibernate(Session session) throws HibernateException { final Query query = session.createQuery(queryString); setPagination(query, firstResult, maxResults); setPositionalParameters(values, query); query.setResultTransformer(Transformers.aliasToBean(transformerClass)); return query.list(); } }); traceResults(list); return list; }
From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateDao.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public <T> List<T> find(final String queryString, final int firstResult, final int maxResults, final Map values, final Class<T> transformerClass) { final List<T> list = getHibernateTemplate().executeFind(new HibernateCallback() { @Override/*from www . ja v a 2 s.co m*/ public Object doInHibernate(Session session) throws HibernateException { final Query query = session.createQuery(queryString); setPagination(query, firstResult, maxResults); setNamedParameters(values, query); query.setResultTransformer(Transformers.aliasToBean(transformerClass)); return query.list(); } }); traceResults(list); return list; }
From source file:com.blazebit.persistence.impl.hibernate.HibernateQueryTransformer.java
License:Apache License
@Override public <X> TypedQuery<X> transformQuery(TypedQuery<?> query, ObjectBuilder<X> objectBuilder) { Query hQuery = query.unwrap(Query.class); hQuery.setResultTransformer(new ObjectBuilderResultTransformerAdapter(objectBuilder)); return (TypedQuery<X>) query; }
From source file:com.cmweb.orm.hibernate.SimpleHibernateDao.java
License:Apache License
public Query distinct(Query query) { query.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return query; }
From source file:com.ejushang.steward.common.genericdao.search.hibernate.HibernateSearchProcessor.java
License:Apache License
private void addResultMode(Query query, ISearch search) { int resultMode = search.getResultMode(); if (resultMode == ISearch.RESULT_AUTO) { int count = 0; Iterator<Field> fieldItr = search.getFields().iterator(); while (fieldItr.hasNext()) { Field field = fieldItr.next(); if (field.getKey() != null && !field.getKey().equals("")) { resultMode = ISearch.RESULT_MAP; break; }/*from w w w. jav a2 s .c o m*/ count++; } if (resultMode == ISearch.RESULT_AUTO) { if (count > 1) resultMode = ISearch.RESULT_ARRAY; else resultMode = ISearch.RESULT_SINGLE; } } switch (resultMode) { case ISearch.RESULT_ARRAY: query.setResultTransformer(ARRAY_RESULT_TRANSFORMER); break; case ISearch.RESULT_LIST: query.setResultTransformer(Transformers.TO_LIST); break; case ISearch.RESULT_MAP: List<String> keyList = new ArrayList<String>(); Iterator<Field> fieldItr = search.getFields().iterator(); while (fieldItr.hasNext()) { Field field = fieldItr.next(); if (field.getKey() != null && !field.getKey().equals("")) { keyList.add(field.getKey()); } else { keyList.add(field.getProperty()); } } query.setResultTransformer(new MapResultTransformer(keyList.toArray(new String[0]))); break; default: // ISearch.RESULT_SINGLE break; } }
From source file:com.ephesoft.dcma.performance.reporting.service.ReportDataServiceImpl.java
License:Open Source License
/** * Method to get Reports Per page for a WorkflowType for a specified time. * /*from w w w . j a va 2 s . com*/ * @param batchClassIds List<{@link String}> Batch Class Ids for which the report data needs to be fetched * @param workflowType {@link WorkflowType}, One of Module , Plugin or Workflow specifying the type of filter * @param endTime {@link Date} upto which the reporting data needs to be fetched * @param startTime {@link Date} Starting Date from which the reporting data needs to be fetched * @param StartIndex int, Start Index for pagination * @param range int Number of records per page * @param order {@link Order} By field * @return List<{@link ReportDisplayData}> List of RepoertDisplayData DTOs * @throws DCMAException if error occurs in database creation */ @SuppressWarnings("unchecked") public List<ReportDisplayData> getReportByWorkflow(List<String> batchClassIds, WorkflowType workflowType, Date endTime, Date startTime, int StartIndex, int range, Order order) throws DCMAException { Connection connection = null; Query qry = null; List<ReportDisplayData> displayDatas = null; try { connection = dynamicHibernateDao.getConnectionProvider().getConnection(); StatelessSession session = dynamicHibernateDao.getStatelessSession(connection); qry = session.getNamedQuery(ReportingConstants.GET_REPORT_BY_WORKFLOW); qry.setResultTransformer(Transformers.aliasToBean(ReportDisplayData.class)); // Adding 1 Day in the End Time to show all the records for that Day Calendar calendar = Calendar.getInstance(); calendar.setTime(endTime); calendar.add(Calendar.DATE, 1); qry.setParameter(ReportingConstants.END_TIME, new java.sql.Date(calendar.getTimeInMillis())); qry.setParameter(ReportingConstants.START_TIME, new java.sql.Date(startTime.getTime())); qry.setParameter(ReportingConstants.START_INDEX, StartIndex); qry.setParameter(ReportingConstants.RANGE, range); qry.setParameter(ReportingConstants.WORK_FLOW_TYPE, workflowType.name()); qry.setParameterList(ReportingConstants.BATCH_CLASS_ID_LIST, batchClassIds); displayDatas = qry.list(); } catch (SQLException e) { LOGGER.error(ERROR_CREATING_DATABASE_CONNECTION + e.getMessage(), e); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { LOGGER.error(ERROR_CLOSING_DATABASE_CONNECTION + e.getMessage(), e); } } } return displayDatas; }
From source file:com.ephesoft.dcma.performance.reporting.service.ReportDataServiceImpl.java
License:Open Source License
/** * Method to get Reports Per page for a User for a specified time. * /*from w ww. j a v a2 s . co m*/ * @param batchClassIds List<{@link String}>, Batch Class Ids for which the report data needs to be fetched * @param userName {@link String}, User name for which the report are to be fetched * @param endTime {@link Date}, Date upto which the reporting data needs to be fetched * @param startTime {@link Date}, Starting Date from which the reporting data needs to be fetched * @param StartIndex int, Start Index for pagination * @param range int, Number of records per page * @param order {@link Order}, By field * @return List<{@link ReportDisplayData}>, List of RepoertDisplayData DTOs * @throws DCMAException if error occurs in database creation */ @SuppressWarnings("unchecked") public List<ReportDisplayData> getReportByUser(List<String> batchClassIds, String userName, Date endTime, Date startTime, int StartIndex, int range, Order order) throws DCMAException { Connection connection = null; Query qry = null; List<ReportDisplayData> resultList = null; try { connection = dynamicHibernateDao.getConnectionProvider().getConnection(); StatelessSession session = dynamicHibernateDao.getStatelessSession(connection); if (userName.equalsIgnoreCase(ReportingConstants.ALL)) { qry = session.getNamedQuery(ReportingConstants.GET_REPORT_FOR_ALL_USERS); } else { qry = session.getNamedQuery(ReportingConstants.GET_REPORT_BY_USER_NAME); qry.setParameter(ReportingConstants.USER_NAME, userName); } qry.setResultTransformer(Transformers.aliasToBean(ReportDisplayData.class)); qry.setParameterList(ReportingConstants.BATCH_CLASS_ID_LIST, batchClassIds); // Adding 1 Day in the End Time to show all the records for that Day Calendar calendar = Calendar.getInstance(); calendar.setTime(endTime); calendar.add(Calendar.DATE, 1); qry.setParameter(ReportingConstants.END_TIME, new java.sql.Date(calendar.getTimeInMillis())); qry.setParameter(ReportingConstants.START_TIME, new java.sql.Date(startTime.getTime())); qry.setParameter(ReportingConstants.START_INDEX, StartIndex); qry.setParameter(ReportingConstants.RANGE, range); resultList = qry.list(); } catch (SQLException e) { LOGGER.error(ERROR_CREATING_DATABASE_CONNECTION + e.getMessage(), e); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { LOGGER.error(ERROR_CLOSING_DATABASE_CONNECTION + e.getMessage(), e); } } } return resultList; }
From source file:com.eryansky.common.orm.core.hibernate.support.BasicHibernateDao.java
License:Apache License
/** * Querydistinct transformer,????distinct? * /*from w w w . j av a 2 s. c o m*/ * @param queryOrNamedQuery hql HibernateNamedQuery * @param values * * @return List */ public <X> List<X> distinct(String queryOrNamedQuery, Object... values) { Query query = createQuery(queryOrNamedQuery, values); query.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<X> result = query.list(); if (CollectionUtils.isEmpty(result) || result.get(0) == null) { return Lists.newArrayList(); } return result; }