List of usage examples for org.hibernate Criteria createCriteria
@Deprecated public Criteria createCriteria(String associationPath, String alias, int joinType) throws HibernateException;
From source file:com.onecheckoutV1.sa.TransactionSandboxReportBean.java
public String getTransaction(int merchantCode, Date day) { Criteria criteria = getSession().createCriteria(Transactions.class); criteria.createCriteria("merchantPaymentChannel", "mpc", Criteria.INNER_JOIN); criteria.createCriteria("mpc.paymentChannel", "pc", Criteria.INNER_JOIN); criteria.add(Restrictions.eq("incMallid", merchantCode)); criteria.add(Restrictions.ge("transactionsDatetime", day)); List<Transactions> list = (List<Transactions>) criteria.list(); List<HashMap> listhashmap = new ArrayList<HashMap>(); System.out.println(list.size()); for (Transactions transactions : list) { HashMap<String, String> obj = new HashMap<String, String>(); obj.put("invoice", transactions.getIncTransidmerchant()); obj.put("amount", transactions.getIncAmount().toString()); obj.put("trans_date", transactions.getTransactionsDatetime().toString()); obj.put("status", transactions.getTransactionsStatus().toString()); obj.put("payment_channel", transactions.getMerchantPaymentChannel().getPaymentChannel().getPaymentChannelId()); listhashmap.add(obj);//from ww w.ja v a 2 s . c om } Gson gson = new Gson(); return gson.toJson(listhashmap); }
From source file:com.ponysdk.hibernate.query.decorator.AbstractCriteriaDecorator.java
License:Apache License
@SuppressWarnings("rawtypes") @Override// w w w .jav a2s. c om public void render(final CriteriaContext context) { final Criterion field = context.getCriterion(); Criteria criteria = context.getOrderingCriteria(); final List<String> propertyNamePath = Arrays.asList(field.getPojoProperty().split(REGEX_SPLIT)); final Iterator<String> iter = propertyNamePath.iterator(); String key = null; String associationPath = null; if (propertyNamePath.size() == 1) { associationPath = iter.next(); } else while (iter.hasNext()) { key = iter.next(); if (associationPath == null) { associationPath = new String(key); } else { associationPath += "." + key; } if (iter.hasNext()) { criteria = criteria.createCriteria(associationPath, key, CriteriaSpecification.INNER_JOIN); associationPath = new String(key); } } final T value = getObjectValue(field); ComparatorType comparator = field.getComparator(); if (value != null) { if (value.toString().contains("%")) { comparator = ComparatorType.LIKE; } } if (field.getValue() != null || field.getComparator() == ComparatorType.IS_NULL || field.getComparator() == ComparatorType.IS_NOT_NULL) { switch (comparator) { case EQ: criteria.add(Restrictions.eq(associationPath, value)); break; case GE: criteria.add(Restrictions.ge(associationPath, value)); break; case GT: criteria.add(Restrictions.gt(associationPath, value)); break; case LE: criteria.add(Restrictions.le(associationPath, value)); break; case LT: criteria.add(Restrictions.lt(associationPath, value)); break; case NE: criteria.add(Restrictions.ne(associationPath, value)); break; case LIKE: criteria.add(Restrictions.ilike(associationPath, value)); break; case IS_NULL: criteria.add(Restrictions.isNull(associationPath)); break; case IS_NOT_NULL: criteria.add(Restrictions.isNotNull(associationPath)); break; case IN: if (value instanceof Collection) { criteria.add(Restrictions.in(associationPath, (Collection) value)); } else if (value instanceof Object[]) { criteria.add(Restrictions.in(associationPath, (Object[]) value)); } else { log.warn("Type not allowed for IN clause: " + value.getClass() + ", value: " + value); } break; default: log.warn("Restriction not supported: " + comparator); break; } } switch (field.getSortingType()) { case ASCENDING: criteria.addOrder(Order.asc(associationPath)); break; case DESCENDING: criteria.addOrder(Order.desc(associationPath)); break; case NONE: break; } }
From source file:com.ponysdk.hibernate.query.decorator.DefaultSortCriteriaDecorator.java
License:Apache License
@Override public void render(final CriteriaContext context) { final Criterion field = context.getCriterion(); if (field.getSortingType() == SortingType.NONE) return;//from w w w .j a v a2 s. com Criteria criteria = context.getOrderingCriteria(); final List<String> propertyNamePath = Arrays.asList(field.getPojoProperty().split(REGEX_SPLIT)); final Iterator<String> iter = propertyNamePath.iterator(); String key = null; String associationPath = null; if (propertyNamePath.size() == 1) { associationPath = iter.next(); } else while (iter.hasNext()) { key = iter.next(); if (associationPath == null) { associationPath = new String(key); } else { associationPath += "." + key; } if (iter.hasNext()) { criteria = criteria.createCriteria(associationPath, key, CriteriaSpecification.LEFT_JOIN); associationPath = new String(key); } } criteria = context.getOrderingCriteria(); if (field.getSortingType() == SortingType.ASCENDING) { criteria.addOrder(Order.asc(associationPath)); } else if (field.getSortingType() == SortingType.DESCENDING) { criteria.addOrder(Order.desc(associationPath)); } }
From source file:dao.CondominioDAO.java
public static List<Condominio> findByFiltros(Integer idMorador, Date dtInicial, Date dtFinal, boolean emAberto) throws Exception { SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession();/*from w ww . ja v a 2 s . co m*/ Criteria crit = session.createCriteria(Condominio.class); Criteria subCrit = crit.createCriteria("pagamento", "pagamento", JoinType.INNER_JOIN); Criteria subCrit2 = crit.createCriteria("morador", "morador", JoinType.INNER_JOIN); if (emAberto) { subCrit.add(Restrictions.isNull("data")); crit.add(Restrictions.lt("data", new Date())); } if (idMorador != null && idMorador > 0) { subCrit2.add(Restrictions.eq("id", idMorador)); } if (dtInicial != null) { crit.add(Restrictions.ge("data", dtInicial)); } if (dtFinal != null) { crit.add(Restrictions.le("data", dtFinal)); } List<Condominio> list = crit.list(); session.flush(); session.close(); return list; }