List of usage examples for org.hibernate.query Query setResultTransformer
@Deprecated Query<R> setResultTransformer(ResultTransformer transformer);
From source file:com.wso2telco.services.dep.sandbox.dao.hibernate.HibernateProvisioningDAO.java
License:Open Source License
public List<ListProvisionedDTO> getActiveProvisionedServices(String msisdn, String username, int offset, int limit) throws Exception { Session session = getSession();//from w w w . ja v a2 s. co m List<ListProvisionedDTO> resultSet = null; StringBuilder hql = new StringBuilder(); hql.append(" SELECT"); hql.append( " services.serviceCode AS serviceCode,services.description AS description,prservice.createdDate AS createdDate,services.tag AS tag,services.value AS value"); hql.append(" FROM"); hql.append(" ManageNumber AS num,"); hql.append(" ProvisionMSISDNServicesMap AS map,"); hql.append(" ProvisionedServices AS prservice,"); hql.append(" Status AS stat,"); hql.append(" ProvisionAllService AS services,"); hql.append(" User AS user"); hql.append(" WHERE num.Number = :number"); hql.append(" AND user.userName= :username"); hql.append(" AND user.id = num.user.id"); hql.append(" AND user.id = services.user.id"); hql.append(" AND map.msisdnId.id = num.id"); hql.append(" AND map.id = prservice.msisdnServiceMap.id"); hql.append(" AND map.servicesId.id = services.id"); hql.append(" AND stat.id = prservice.status.id"); hql.append(" AND stat.code= :status"); try { Query query = session.createQuery(hql.toString()); query.setParameter("status", ProvisioningStatusCodes.PRV_PROVISION_SUCCESS.toString()); query.setParameter("number", msisdn); query.setParameter("username", username); if (offset > 0) { query.setFirstResult(offset); } if (limit > 0) { query.setMaxResults(limit); } resultSet = query.setResultTransformer(Transformers.aliasToBean(ListProvisionedDTO.class)) .getResultList(); } catch (Exception ex) { LOG.error("###PROVISION### Error in getActiveProvisionedServices " + ex); throw ex; } return resultSet; }
From source file:se.backede.jeconomix.database.CategoryHandler.java
public Optional<List<CategoryDto>> getFilteredCategories(Integer year, CategoryTypeEnum... type) { try {//from w w w .j a va 2 s. c o m super.startTransaction(); Query query = super.getHibernateSession().getNamedQuery(EntityQueries.FILTERED_CATEGORIES_BY_YEAR); query.setParameter("year", year); query.setParameter("type", Arrays.asList(type)); query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Category> categories = (List<Category>) query.list(); return mapper.mapToDtoList(categories); } catch (NoResultException ex) { log.debug("No result for query when getting Category"); } finally { super.commitTransaction(); } return Optional.empty(); }
From source file:se.backede.jeconomix.database.CategoryHandler.java
public Optional<List<CategoryDto>> getFilteredCategories(CategoryTypeEnum... type) { try {//from www. j av a 2 s .com super.startTransaction(); Query query = super.getHibernateSession().getNamedQuery(EntityQueries.FILTERED_CATEGORIES); query.setParameter("type", Arrays.asList(type)); query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Category> categories = (List<Category>) query.list(); return mapper.mapToDtoList(categories); } catch (NoResultException ex) { log.debug("No result for query when getting Category"); } finally { super.commitTransaction(); } return Optional.empty(); }