List of usage examples for org.hibernate.criterion Restrictions ne
public static SimpleExpression ne(String propertyName, Object value)
From source file:com.xbwl.common.orm.hibernate.HibernateDao.java
License:Apache License
/** * Criterion,.//from ww w . ja v a2 s . c o m */ protected Criterion buildPropertyFilterCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) { Assert.hasText(propertyName, "propertyName"); Criterion criterion = null; try { //MatchTypecriterion if (MatchType.EQ.equals(matchType)) { criterion = Restrictions.eq(propertyName, propertyValue); } else if (MatchType.LIKE.equals(matchType)) { criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE); } else if (MatchType.LE.equals(matchType)) { criterion = Restrictions.le(propertyName, propertyValue); } else if (MatchType.LT.equals(matchType)) { criterion = Restrictions.lt(propertyName, propertyValue); } else if (MatchType.GE.equals(matchType)) { criterion = Restrictions.ge(propertyName, propertyValue); } else if (MatchType.GT.equals(matchType)) { criterion = Restrictions.gt(propertyName, propertyValue); } else if (MatchType.NE.equals(matchType)) { criterion = Restrictions.ne(propertyName, propertyValue); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return criterion; }
From source file:com.yougou.api.service.impl.ApiServiceImpl.java
@Override @Transactional/*from w w w .java2s . com*/ public void updateApi(Api api) throws Exception { ApiVersion apiVersion = apiVersionDao.getById(api.getApiVersion().getId()); if (apiVersion == null) { throw new UnsupportedOperationException("API!"); } ApiCategory apiCategory = apiCategoryDao.getById(api.getApiCategory().getId()); if (apiCategory == null) { throw new UnsupportedOperationException("API!"); } ApiImplementor apiImplementor = apiImplementorDao.getById(api.getApiImplementor().getId()); if (apiImplementor == null) { throw new UnsupportedOperationException("API!"); } Session session = null; try { session = apiDao.getHibernateSession(); // API?? Criteria criteria = session.createCriteria(Api.class); criteria.setProjection(Projections.rowCount()); criteria.add(Restrictions.eq("apiVersion.id", apiVersion.getId())); criteria.add(Restrictions.eq("apiCode", api.getApiCode())); criteria.add(Restrictions.ne("id", api.getId())); if (((Number) criteria.uniqueResult()).intValue() == 1) { throw new UnsupportedOperationException("API[" + apiVersion.getVersionNo() + "][" + api.getApiCode() + "]?!"); } // API? criteria = session.createCriteria(Api.class); criteria.setProjection(Projections.rowCount()); criteria.add(Restrictions.eq("apiImplementor.id", apiImplementor.getId())); criteria.add(Restrictions.eq("apiMethod", api.getApiMethod())); criteria.add(Restrictions.ne("id", api.getId())); if (((Number) criteria.uniqueResult()).intValue() == 1) { throw new UnsupportedOperationException("API[" + apiImplementor.getIdentifier() + "][" + api.getApiMethod() + "]!"); } // API Api another = (Api) session.load(Api.class, api.getId(), LockMode.UPGRADE); another.setApiVersion(apiVersion); another.setApiCategory(apiCategory); another.setApiImplementor(apiImplementor); another.setModifier(api.getModifier()); another.setModified(api.getModified()); another.setApiDescription(api.getApiDescription()); another.setApiName(api.getApiName()); another.setApiMethod(api.getApiMethod()); another.setApiMethodParamTypes(api.getApiMethodParamTypes()); another.setApiWeight(api.getApiWeight()); another.setIsEnable(api.getIsEnable()); another.setIsSaveResult(api.getIsSaveResult()); checkApiMethod(another); session.update(another); } finally { apiDao.releaseHibernateSession(session); } }
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;//from w w w .j a va2s. c o m 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;/*from w w w. j a v a 2 s . com*/ 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.zapangtrainer.model.dao.ClientDAOImpl.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = true) public Long getProm() { Long val = null; session = getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(Reply.class, "reply"); criteria.setReadOnly(true);/*from w w w . j a va2 s. com*/ criteria.add(Restrictions.like("reply.type", "rating")); criteria.add(Restrictions.ne("reply.answer", "0")); criteria.add(Restrictions.or(Restrictions.like("reply.answer", "4", MatchMode.START), Restrictions.like("reply.answer", "5", MatchMode.START))); criteria.setProjection(Projections.rowCount()); val = (Long) criteria.uniqueResult(); return val; }
From source file:com.zapangtrainer.model.dao.ClientDAOImpl.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = true) public Long getPass() { Long val = null; session = getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(Reply.class, "reply"); criteria.setReadOnly(true);// w w w . j a va2 s . co m criteria.add(Restrictions.like("reply.type", "rating")); criteria.add(Restrictions.ne("reply.answer", "0")); criteria.add(Restrictions.or(Restrictions.like("reply.answer", "2", MatchMode.START), Restrictions.like("reply.answer", "3", MatchMode.START))); criteria.setProjection(Projections.rowCount()); val = (Long) criteria.uniqueResult(); return val; }
From source file:com.zapangtrainer.model.dao.ClientDAOImpl.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = true) public Long getDet() { Long val = null; session = getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(Reply.class, "reply"); criteria.setReadOnly(true);//from w ww. j a v a 2 s . c o m criteria.add(Restrictions.like("reply.type", "rating")); criteria.add(Restrictions.ne("reply.answer", "0")); criteria.add(Restrictions.or(Restrictions.like("reply.answer", "0", MatchMode.START), Restrictions.like("reply.answer", "1", MatchMode.START))); criteria.setProjection(Projections.rowCount()); val = (Long) criteria.uniqueResult(); return val; }
From source file:com.zhima.base.dao.BaseDao.java
License:Open Source License
/** * ?criteriaeq,gt,ge,lt,le?//from ww w . j ava 2 s. c o m * * @param criteria * @param list * ?? */ @SuppressWarnings("rawtypes") private void setExpression(Criteria criteria, String[] list, String expression, Object dto) { Class dtoClass = dto.getClass(); try { for (String str : list) { if (str != null && !"".equals(str.trim())) { Field dtoField = dtoClass.getDeclaredField(str); dtoField.setAccessible(true); if (dtoField != null) { if (HibernateConstrant.HIBERNATE_CRITERIA_EQ.equals(expression)) { criteria.add(Restrictions.eq(str, dtoField.get(dto))); } else if (HibernateConstrant.HIBERNATE_CRITERIA_GE.equals(expression)) { criteria.add(Restrictions.gt(str, dtoField.get(dto))); } else if (HibernateConstrant.HIBERNATE_CRITERIA_GT.equals(expression)) { criteria.add(Restrictions.ge(str, dtoField.get(dto))); } else if (HibernateConstrant.HIBERNATE_CRITERIA_LT.equals(expression)) { criteria.add(Restrictions.lt(str, dtoField.get(dto))); } else if (HibernateConstrant.HIBERNATE_CRITERIA_LE.equals(expression)) { criteria.add(Restrictions.le(str, dtoField.get(dto))); } else if (HibernateConstrant.HIBERNATE_CRITERIA_NE.equals(expression)) { criteria.add(Restrictions.ne(str, dtoField.get(dto))); } else if (HibernateConstrant.HIBERNATE_CRITERIA_LIKE.equals(expression)) { criteria.add(Restrictions.like(str, "%" + dtoField.get(dto) + "%")); } } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.zl.bgec.basicapi.shop.service.impl.ShopServiceImpl.java
@Override @Transactional(readOnly = true)/*from w w w . j a v a 2 s. co m*/ public Map<String, Object> getShopIndexInfo(String memberNo) throws Exception { String sql = "select tsi.shop_name shopName," + "tsi.shop_address shopAddress," + "tsi.shop_logo shopLogo," + "tsi.status status, " + "tsi.shop_no shopNo " + "from tbl_shop_info tsi where tsi.merch_no=:shopNo and tsi.status!='3'"; Query query = shopDao.createSQLQuery(sql); query.setParameter("shopNo", memberNo); query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); List<Map<String, Object>> results = query.list(); Map<String, Object> result = new HashMap<String, Object>(); if (results != null && !results.isEmpty()) { result = results.get(0); } else { return null; } String shopNo = String.valueOf(result.get("shopNo")); Criteria criteria = commodityDao.createCriteria(Restrictions.eq("sellerNo", shopNo)); criteria.add(Restrictions.eq("deleteFlag", (byte) 0));// criteria.add(Restrictions.eq("publishState", "1"));// int commodityCount = commodityDao.getRowCount(criteria);// ?? result.put("commodityCount", String.valueOf(commodityCount)); criteria = shopCollectDao.createCriteria(Restrictions.eq("shopNo", shopNo)); int collectCount = shopCollectDao.getRowCount(criteria); result.put("collectCount", String.valueOf(collectCount)); Criteria promotionCriteria = promotionDao.createCriteria(Restrictions.eq("shopNo", shopNo)); promotionCriteria.add(Restrictions.ge("endTime", new Date()));// promotionCriteria.add(Restrictions.eq("status", "2"));// promotionCriteria.add(Restrictions.eq("lockFlag", "0"));//? promotionCriteria.add(Restrictions.ne("promotionType", "2"));//? int count = promotionDao.getRowCount(promotionCriteria); result.put("promotionCount", count); List<String> values = new ArrayList<String>(); // values.add(OrderConstants.BASIC_STATE_REFUND); // values.add(OrderConstants.BASIC_STATE_ALREADY_RECEIVE); // values.add(OrderConstants.BASIC_STATE_REFUND_APPLY); values.add(OrderConstants.BASIC_STATE_WAITING_DELIVERY); // values.add(OrderConstants.BASIC_STATE_WAITING_RETURN); // values.add(OrderConstants.BASIC_STATE_WAITING_PAY); // values.add(OrderConstants.BASIC_STATE_ALREADY_DELIVERY); Criteria criteriaOrder = orderDao.createCriteria(Restrictions.in("basicState", values)); criteriaOrder.add(Restrictions.eq("deleteFlag", (byte) 0)); criteriaOrder.add(Restrictions.eq("shopNo", shopNo)); String sqlGroupBuy = "select count(*) " + " from tbl_promotion tp " + " left join tbl_product tpr on tp.ref_commo_no = tpr.commo_no" + " where tp.promotion_type='2' and tp.delete_flag='0' and tp.shop_no=:shopNo and :curentTime between tp.start_time and tp.end_time "; Query groupBuyQuery = promotionDao.createSQLQuery(sqlGroupBuy); groupBuyQuery.setParameter("shopNo", shopNo); groupBuyQuery.setParameter("curentTime", new Date()); BigInteger totalRows = (BigInteger) groupBuyQuery.uniqueResult(); result.put("groupBuyCount", totalRows.intValue()); result.put("orderCount", orderDao.getRowCount(criteriaOrder)); String gradeSql = "select avg(tcc.service_grade) serviceGrade," + " avg(tcc.delivery_grade) deliveryGrade" + " from tbl_commodity_comment tcc " + " where tcc.shop_no = :shopNo " + " group by(tcc.shop_no) "; Query queryGrade = shopDao.createSQLQuery(gradeSql); queryGrade.setParameter("shopNo", shopNo); queryGrade.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); List<Map<String, Object>> list = queryGrade.list(); if (list != null && !list.isEmpty()) { Double servGrade = list.get(0).get("serviceGrade") == null ? 0 : Double.valueOf(list.get(0).get("serviceGrade").toString()); BigDecimal serviceGrade = new BigDecimal(servGrade); serviceGrade = serviceGrade.setScale(1, BigDecimal.ROUND_HALF_EVEN); result.put("serviceGrade", serviceGrade.doubleValue()); Double delGrade = list.get(0).get("deliveryGrade") == null ? 0 : Double.valueOf(list.get(0).get("deliveryGrade").toString()); BigDecimal deliveryGrade = new BigDecimal(delGrade); deliveryGrade = deliveryGrade.setScale(1, BigDecimal.ROUND_HALF_EVEN); result.put("deliveryGrade", deliveryGrade.doubleValue()); } else { result.put("serviceGrade", "0"); result.put("deliveryGrade", "0"); } return result; }
From source file:com.zl.bgec.basicapi.shop.service.impl.ShopServiceImpl.java
private Order getOrderByBuyer(String promotionNo, String buyerNo) { Criteria criteria = orderDao.createCriteria(Restrictions.eq("orderCouponsNo", promotionNo)); criteria.add(Restrictions.eq("buyerNo", buyerNo)); criteria.add(Restrictions.ne("deleteFlag", (byte) 1)); criteria.add(Restrictions.ne("basicState", OrderConstants.BASIC_STATE_CLOSED)); List<Order> orders = criteria.list(); if (orders != null && !orders.isEmpty()) return orders.get(0); return null;//from www . ja va 2 s. co m }