List of usage examples for org.hibernate Criteria setResultTransformer
public Criteria setResultTransformer(ResultTransformer resultTransformer);
From source file:com.zanvork.guildhub.model.RaidTeam.java
public static RaidTeam getRaidTeam(int raid_team_id) { List<RaidTeam> list;/* ww w . j av a 2s .c o m*/ RaidTeam team = null; SessionFactory sessionFactory = HibernateMySQLDAO.getSessionFactory(); Session session = sessionFactory.openSession(); session.beginTransaction(); Criteria criteria = session.createCriteria(RaidTeam.class); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); list = criteria.add(Restrictions.eq("raid_team_id", raid_team_id)).list(); session.getTransaction().commit(); if (!list.isEmpty()) { team = list.get(0); } return team; }
From source file:com.zapangtrainer.model.dao.ClientDAOImpl.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = true) public Object readInnerProperty(String type, String paramId, String calType) { String average = null;//ww w . j ava 2 s. c om List<Reply> list = null; switch (type) { case "rating": session = getSessionFactory().openSession(); Criteria criteria = session.createCriteria(Reply.class, "reply"); criteria.createAlias("reply.client", "client"); criteria.setReadOnly(true); Calendar cal = Calendar.getInstance(); String date0 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.DATE, -1); String date1 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.DATE, -1); String date2 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.DATE, -1); String date3 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.DATE, -1); String date4 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.DATE, -1); String date5 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.DATE, -1); String date6 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); criteria.add(Restrictions.or(Restrictions.eq("client.date", date0), Restrictions.or(Restrictions.eq("client.date", date1), Restrictions.or(Restrictions.eq("client.date", date2), Restrictions.or(Restrictions.eq("client.date", date3), Restrictions.or(Restrictions.eq("client.date", date4), Restrictions.or( Restrictions.eq("client.date", date5), Restrictions.or(Restrictions.eq("client.date", date6))))))))); criteria.add(Restrictions.eq("reply.question", paramId)); criteria.add(Restrictions.eq("reply.type", type)); criteria.add(Restrictions.ne("reply.answer", "0")); criteria.setResultTransformer(criteria.DISTINCT_ROOT_ENTITY); list = (List<Reply>) criteria.list(); Float value = 0.0f; for (Reply val : list) { if (val.getAnswer() != null && !val.getAnswer().equals("")) { value += Float.parseFloat(val.getAnswer()); } } value /= list.size(); average = value.toString(); case "descriptive": case "options": case "binary": default: } return average; }
From source file:com.zapangtrainer.model.dao.ClientDAOImpl.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = true) public String fetchAvgByTypeAndDate(String type, String date) { String average = null;//ww w . jav a2 s . co m session = getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(Reply.class, "reply"); criteria.setReadOnly(true); criteria.createAlias("reply.client", "client"); criteria.add(Restrictions.like("client.date", date, MatchMode.START)); criteria.add(Restrictions.like("reply.question", type)); criteria.add(Restrictions.ne("reply.answer", "0")); criteria.setResultTransformer(criteria.DISTINCT_ROOT_ENTITY); List<Reply> list = criteria.list(); Float value = 0.0f; for (Reply val : list) { if (val.getAnswer() != null && !val.getAnswer().equals("")) { value += Float.parseFloat(val.getAnswer()); } } value /= list.size(); average = value.toString(); return average; }
From source file:com.zc.orm.hibernate.HibernateDao.java
License:Apache License
/** * countCriteria???//from w ww.j a v a 2s . c o m */ @SuppressWarnings("unchecked") protected long countCriteriaResult(final Criteria c) { CriteriaImpl impl = (CriteriaImpl) c; // Projection?ResultTransformer?OrderBy?????Count? Projection projection = impl.getProjection(); ResultTransformer transformer = impl.getResultTransformer(); List<CriteriaImpl.OrderEntry> orderEntries = null; try { orderEntries = (List) Reflector.getFieldValue(impl, "orderEntries"); Reflector.setFieldValue(impl, "orderEntries", new ArrayList()); } catch (Exception e) { logger.error("??:{}", e.getMessage()); } // Count Long totalCountObject = (Long) c.setProjection(Projections.rowCount()).uniqueResult(); long totalCount = (totalCountObject != null) ? totalCountObject : 0; // ?Projection,ResultTransformerOrderBy??? c.setProjection(projection); if (projection == null) { c.setResultTransformer(CriteriaSpecification.ROOT_ENTITY); } if (transformer != null) { c.setResultTransformer(transformer); } try { Reflector.setFieldValue(impl, "orderEntries", orderEntries); } catch (Exception e) { logger.error("??:{}", e.getMessage()); } return totalCount; }
From source file:com.zhima.base.dao.BaseDao.java
License:Open Source License
/** * /*from ww w .j a va2 s . c o m*/ * * @param detachedCriteria * @param resultTransformer * @return */ @Transactional(readOnly = true) @SuppressWarnings("unchecked") public List<T> find(DetachedCriteria detachedCriteria, ResultTransformer resultTransformer) { Criteria criteria = detachedCriteria.getExecutableCriteria(getSession()); criteria.setResultTransformer(resultTransformer); return criteria.list(); }
From source file:connectster.server.command.BuildProductMappingsCommand.java
License:Apache License
@Override @SuppressWarnings("unchecked") public IResponse<Integer> execute(Session session, Map<String, Object> parameters) { IUser user = (IUser) parameters.get(ICommand.PARAMETER_USER); IUserMapping userMapping = (IUserMapping) parameters.get(ICommand.PARAMETER_USER_MAPPING); int count = 0; try {//from w ww.ja va2 s . co m Criteria productCriteria = session.createCriteria(Product.class); productCriteria.add(Restrictions.eq("owner", user)); productCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Product> products = (List<Product>) productCriteria.list(); for (Product product : products) { ProductMapping mapping = new ProductMapping(); mapping.setUpdatedOn(null); mapping.setDestinationId("*PENDING*" + product.getId()); mapping.setDestinationUserId(userMapping.getTargetUserId()); mapping.setRetryCount(0); mapping.setAdapter(userMapping.getTargetAdapterId()); mapping.setProductId(product.getId()); session.save(mapping); session.flush(); count++; } return new Response<Integer>(count, IResponse.Status.Successful, "Product Mappings Created"); } catch (Exception x) { return new Response<Integer>(count, IResponse.Status.Failure, x.getMessage()); } }
From source file:dao.AlbumDaoImpl.java
@Override public List<Album> findAll() { Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates. List<Album> album = (List<Album>) criteria.list(); return album; }
From source file:dao.CabinetUserDao.java
public List<CabinetUser> getByUser(User user) { Criteria crit = getCurrentSession().createCriteria(CabinetUser.class); crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); crit.add(Restrictions.eq("user", user)); return crit.list(); }
From source file:dao.ClaseDaoImpl.java
@Override public List<Clase> findAll() { Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates. List<Clase> clase = (List<Clase>) criteria.list(); return clase; }
From source file:dao.ContactoDaoImpl.java
@Override public List<Contacto> findAll() { Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates. List<Contacto> contacto = (List<Contacto>) criteria.list(); return contacto; }