List of usage examples for org.hibernate.criterion Restrictions ge
public static SimpleExpression ge(String propertyName, Object value)
From source file:com.google.api.ads.adwords.jaxws.extensions.report.model.persistence.sql.SqlReportEntitiesPersister.java
License:Open Source License
/** * Gets the entity list for the given report class and with the given date range. *///from w w w.j av a 2s .c o m @Override @Transactional(readOnly = true) @SuppressWarnings("unchecked") public <T> List<T> get(Class<T> clazz, String key, Object value, String dateKey, Date dateStart, Date dateEnd) { Criteria criteria = this.createCriteria(clazz); if (key != null) { criteria.add(Restrictions.eq(key, value)); } criteria.add(Restrictions.ge(dateKey, dateStart)); criteria.add(Restrictions.le(dateKey, dateEnd)); return criteria.list(); }
From source file:com.google.api.ads.adwords.jaxws.extensions.report.model.persistence.sql.SqlReportEntitiesPersister.java
License:Open Source License
/** * Gets the entity list for the given report class and key the given range. *///w ww. jav a 2s . c om @Override @Transactional(readOnly = true) @SuppressWarnings("unchecked") public <T> List<T> get(Class<T> clazz, String key, Object value, String dateKey, String dateStart, String dateEnd) { Criteria criteria = this.createCriteria(clazz); if (key != null) { criteria.add(Restrictions.eq(key, value)); } criteria.add(Restrictions.ge(dateKey, dateStart)); criteria.add(Restrictions.le(dateKey, dateEnd)); return criteria.list(); }
From source file:com.google.api.ads.adwords.jaxws.extensions.report.model.persistence.sql.SqlReportEntitiesPersister.java
License:Open Source License
/** * Gets the entity list for the given report class and with the given date range. *//* www .j av a 2 s . c om*/ @Override @Transactional(readOnly = true) @SuppressWarnings("unchecked") public <T> List<T> get(Class<T> clazz, String key, Object value, String dateKey, Date dateStart, Date dateEnd, int numToSkip, int limit) { Criteria criteria = this.createPaginatedCriteria(clazz, numToSkip, limit); criteria.add(Restrictions.eq(key, value)); criteria.add(Restrictions.ge(dateKey, dateStart)); criteria.add(Restrictions.le(dateKey, dateEnd)); return criteria.list(); }
From source file:com.google.api.ads.adwords.jaxws.extensions.report.model.persistence.sql.SqlReportEntitiesPersister.java
License:Open Source License
/** * @param startDate the start date// w ww .j a v a 2 s .com * @param endDate the end date * @param criteria the criteria * @return the list of reports grouped by month */ @SuppressWarnings("unchecked") private List<? extends Report> listMonthReportsForCriteria(long accountId, DateTime startDate, DateTime endDate, Criteria criteria) { criteria.add(Restrictions.isNull("day")); criteria.add(Restrictions.isNotNull("month")); criteria.add(Restrictions.eq("accountId", accountId)); criteria.addOrder(Order.asc("month")); if (startDate != null) { criteria.add(Restrictions.ge("month", startDate.toDate())); } if (endDate != null) { criteria.add(Restrictions.le("month", endDate.toDate())); } return criteria.list(); }
From source file:com.gps.rptbean.DataSourceFactory.java
public static JRDataSource buildYearlyDataSource(Vehicle v, String year, String measureName) { assert (v != null); assert (year != null); Date startDate = null;//from w w w .j av a2s . co m try { startDate = (new SimpleDateFormat("yyyy")).parse(year); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } Calendar cal = Calendar.getInstance(); cal.setTime(startDate); cal.add(Calendar.YEAR, 1); Date endDate = cal.getTime(); Session session = HibernateUtil.getSession(); List results = session.createCriteria(FRuningLog.class) .setProjection(Projections.projectionList().add(Projections.rowCount(), "rowCount") .add(Projections.sum(measureName), "total") .add(Projections.groupProperty("yearMonth"), "yearMonth")) .add(Restrictions.eq("vehicle.vehicleId", v.getVehicleId())) .add(Restrictions.le("startDate", endDate)).add(Restrictions.ge("startDate", startDate)) .addOrder(Order.asc("yearMonth")).list(); // // FRuningLogBean fruningLogBean = new FRuningLogBean(); // // fruningLogBean.setVehicleId(v.getVehicleId()); // fruningLogBean.setStartDateStart(startDate); // fruningLogBean.setStartDateEnd(endDate); // // fruningLogBean.getList(); YearlyDataSource ds = null; ds = new YearlyDataSource(); Iterator iter = results.iterator(); while (iter.hasNext()) { Object[] row = (Object[]) iter.next(); Integer count = (Integer) row[0]; Double total = (Double) row[1]; String yearMonth = (String) row[2]; int idx = getIndex(yearMonth); YearlyBean bean = new YearlyBean(idx); bean.setVehicleId(v.getVehicleId()); bean.setLicensePad(v.getLicensPadNumber()); bean.setMeasure1(total); ds.addRecord(idx, bean); } return ds; }
From source file:com.gps.rptbean.DataSourceFactory.java
public static JRDataSource buildMonthlyCostDataSource(Vehicle v, Date start, Date end) { CostAnalysisDataSource result = new CostAnalysisDataSource(); assert (v != null); assert (start != null); assert (end != null); int index = 1; Session session = HibernateUtil.getSession(); List results = session.createCriteria(FRuningLog.class) .setProjection(Projections.projectionList().add(Projections.rowCount(), "runCount") .add(Projections.sum("totalCost"), "total").add(Projections.sum("actualGas"), "totalGas") .add(Projections.sum("gasByCashCost"), "totalGasCash") .add(Projections.sum("gasByCardCost"), "totalGasCard") .add(Projections.sum("actualDistance"), "totalDistance") .add(Projections.sum("actualRoadFee"), "totalRoadFee") .add(Projections.sum("overLimitFee"), "totalOverLimitFee") .add(Projections.groupProperty("vehicle.vehicleId"), "vehicleId")) .add(Restrictions.eq("vehicle.vehicleId", v.getVehicleId())).add(Restrictions.le("startDate", end)) .add(Restrictions.ge("startDate", start)).list(); Double gas = (Double) ((Object[]) results.get(0))[2]; Double gasByCash = (Double) ((Object[]) results.get(0))[3]; Double gasByCard = (Double) ((Object[]) results.get(0))[4]; Double gasFee = gasByCash + gasByCard; Double roadFee = (Double) ((Object[]) results.get(0))[6]; Double limitFee = (Double) ((Object[]) results.get(0))[7]; CostAnalysisBean bean1 = new CostAnalysisBean(); bean1.setCategoryName(""); bean1.setIndex(index);/*w ww . java 2 s . co m*/ bean1.setLicensePad(v.getLicensPadNumber()); bean1.setMeasure1(gasFee); bean1.setVehicleId(v.getVehicleId()); result.addRecord(index - 1, bean1); index++; CostAnalysisBean bean2 = new CostAnalysisBean(); bean2.setCategoryName(""); bean2.setIndex(index); bean2.setLicensePad(v.getLicensPadNumber()); bean2.setMeasure1(roadFee); bean2.setVehicleId(v.getVehicleId()); result.addRecord(index - 1, bean2); index++; CostAnalysisBean bean3 = new CostAnalysisBean(); bean3.setCategoryName("?"); bean3.setIndex(index); bean3.setLicensePad(v.getLicensPadNumber()); bean3.setMeasure1(limitFee); bean3.setVehicleId(v.getVehicleId()); result.addRecord(index - 1, bean3); index++; results = null; results = session.createCriteria(FMaintain.class) .setProjection(Projections.projectionList().add(Projections.rowCount(), "runCount") .add(Projections.sum("cost"), "total") .add(Projections.groupProperty("vehicle.vehicleId"), "vehicleId")) .add(Restrictions.eq("vehicle.vehicleId", v.getVehicleId())) .add(Restrictions.le("maintainDate", end)).add(Restrictions.ge("maintainDate", start)).list(); if (results.size() > 0) { Double maitainFee = (Double) ((Object[]) results.get(0))[1]; CostAnalysisBean bean4 = new CostAnalysisBean(); bean4.setCategoryName("?"); bean4.setIndex(index); bean4.setLicensePad(v.getLicensPadNumber()); bean4.setMeasure1(maitainFee); bean4.setVehicleId(v.getVehicleId()); result.addRecord(index - 1, bean4); index++; } String yearMonth = new SimpleDateFormat("yyyyMM").format(start); results = null; results = session.createCriteria(FExpenseLog.class) .setProjection(Projections.projectionList().add(Projections.rowCount(), "runCount") .add(Projections.sum("amount"), "total") .add(Projections.groupProperty("category1"), "category1")) .add(Restrictions.eq("vehicle.vehicleId", v.getVehicleId())) .add(Restrictions.eq("yearMonth", yearMonth)).list(); Iterator iter = results.iterator(); while (iter.hasNext()) { Object[] row = (Object[]) iter.next(); Integer count = (Integer) row[0]; Double total = (Double) row[1]; String category = (String) row[2]; CostAnalysisBean bean = new CostAnalysisBean(); bean.setIndex(index); bean.setCategoryName(category); bean.setVehicleId(v.getVehicleId()); bean.setLicensePad(v.getLicensPadNumber()); bean.setMeasure1(total); result.addRecord(index - 1, bean); index++; } return result; }
From source file:com.heliosapm.aa4h.parser.XMLQueryParser.java
License:Apache License
/** * Element Start SAX ContentHandler Method. * @param uri/* ww w . ja v a 2 s .co m*/ * @param localName * @param qName * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) * @throws SAXException * TODO: Document supported tags in javadoc. */ @SuppressWarnings({ "unchecked" }) public void startElement(String uri, String localNameX, String qName, Attributes attrs) throws SAXException { if ("Query".equalsIgnoreCase(qName)) { queryName = attrs.getValue("name"); rootElementName = queryName; } else if ("Class".equalsIgnoreCase(qName)) { processCriteria(attrs); } else if ("Union".equalsIgnoreCase(qName)) { inDetached = true; DetachedCriteria dc = DetachedCriteria.forEntityName(className); criteriaStack.push(dc); } else if ("NamedQuery".equalsIgnoreCase(qName)) { isNamedQuery = true; namedQuery = attrs.getValue("name"); rootElementName = namedQuery; try { query = session.getNamedQuery(namedQuery); } catch (HibernateException he) { throw new SAXException("Failed to retrieve named query[" + namedQuery + "]", he); } } else if ("qparam".equalsIgnoreCase(qName)) { processQueryBind(attrs); } else if ("Join".equalsIgnoreCase(qName)) { processCriteria(attrs); } else if ("Projections".equalsIgnoreCase(qName)) { startProjection(attrs); } else if ("Projection".equalsIgnoreCase(qName)) { addProjection(attrs); } else if ("Order".equalsIgnoreCase(qName)) { if (isRowCountOnly() == false) { try { String name = attrs.getValue("name"); String type = attrs.getValue("type"); ((Criteria) criteriaStack.peek()) .addOrder(type.equalsIgnoreCase("asc") ? Order.asc(name) : Order.desc(name)); } catch (Exception e) { throw new SAXException("Unable To Parse GreaterThan:" + attrs.getValue("name"), e); } } } else if ("GreaterThan".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.gt(operator.getName(), operator.getNativeValue())); } catch (Exception e) { throw new SAXException("Unable To Parse GreaterThan:" + attrs.getValue("name"), e); } } else if ("GreaterThanOrEqual".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.ge(operator.getName(), operator.getNativeValue())); } catch (Exception e) { throw new SAXException("Unable To Parse GreaterThanOrEqual:" + attrs.getValue("name"), e); } } else if ("LessThan".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.lt(operator.getName(), operator.getNativeValue())); } catch (Exception e) { throw new SAXException("Unable To Parse LessThan:" + attrs.getValue("name"), e); } } else if ("LessThanOrEqual".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.le(operator.getName(), operator.getNativeValue())); } catch (Exception e) { throw new SAXException("Unable To Parse LessThanOrEqual:" + attrs.getValue("name"), e); } } else if ("Equals".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); if ("true".equalsIgnoreCase(attrs.getValue("not"))) { addCriterion(Restrictions.not(Restrictions.eq(operator.getName(), operator.getNativeValue()))); } else { addCriterion(Restrictions.eq(operator.getName(), operator.getNativeValue())); } } catch (Exception e) { throw new SAXException("Unable To Parse Equals:" + attrs.getValue("name"), e); } } else if ("Alias".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); ((Criteria) criteriaStack.peek()).createAlias(operator.getName(), operator.getValue()); } catch (Exception e) { throw new SAXException("Unable To Create Alias:" + attrs.getValue("name"), e); } } else if ("GreaterThanProperty".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.gtProperty(operator.getName(), operator.getName2())); } catch (Exception e) { throw new SAXException("Unable To Parse GreaterThanProperty:" + attrs.getValue("name"), e); } } else if ("GreaterThanOrEqualProperty".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.geProperty(operator.getName(), operator.getName2())); } catch (Exception e) { throw new SAXException("Unable To Parse GreaterThanOrEqualProperty:" + attrs.getValue("name"), e); } } else if ("LessThanProperty".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.ltProperty(operator.getName(), operator.getName2())); } catch (Exception e) { throw new SAXException("Unable To Parse LessThanProperty:" + attrs.getValue("name"), e); } } else if ("LessThanOrEqualProperty".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.leProperty(operator.getName(), operator.getName2())); } catch (Exception e) { throw new SAXException("Unable To Parse LessThanOrEqualProperty:" + attrs.getValue("name"), e); } } else if ("EqualsProperty".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); if ("true".equalsIgnoreCase(attrs.getValue("not"))) { addCriterion( Restrictions.not(Restrictions.eqProperty(operator.getName(), operator.getName2()))); } else { addCriterion(Restrictions.eqProperty(operator.getName(), operator.getName2())); } } catch (Exception e) { throw new SAXException("Unable To Parse EqualsProperty:" + attrs.getValue("name"), e); } } else if ("Like".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.like(operator.getName(), operator.getNativeValue())); } catch (Exception e) { throw new SAXException("Unable To Parse Like:" + attrs.getValue("name"), e); } } else if ("Between".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.between(operator.getName(), operator.getNativeValue(), operator.getNativeValue2())); } catch (Exception e) { throw new SAXException("Unable To Parse Between:" + attrs.getValue("name"), e); } } else if ("IsEmpty".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.isEmpty(operator.getName())); } catch (Exception e) { throw new SAXException("Unable To Parse IsEmpty:" + attrs.getValue("name"), e); } } else if ("IsNotEmpty".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.isNotEmpty(operator.getName())); } catch (Exception e) { throw new SAXException("Unable To Parse IsNotEmpty:" + attrs.getValue("name"), e); } } else if ("IsNull".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.isNull(operator.getName())); } catch (Exception e) { throw new SAXException("Unable To Parse IsNull:" + attrs.getValue("name"), e); } } else if ("IsNotNull".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.isNotNull(operator.getName())); } catch (Exception e) { throw new SAXException("Unable To Parse IsNotNull:" + attrs.getValue("name"), e); } } else if ("In".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); if (operator.isLiteral()) { addCriterion(new LiteralInExpression(operator.getName(), (String) operator.getNativeValue())); } else { addCriterion(Restrictions.in(operator.getName(), (Collection) operator.getNativeValue())); } } catch (Exception e) { throw new SAXException("Unable To Parse In:" + attrs.getValue("name"), e); } } else if ("SizeEquals".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); int i = ((Integer) operator.getNativeValue()).intValue(); addCriterion(Restrictions.sizeEq(operator.getName(), i)); } catch (Exception e) { throw new SAXException("Unable To Parse SizeEquals:" + attrs.getValue("name"), e); } } else if ("Not".equalsIgnoreCase(qName)) { notStack.push(new Object()); } else if ("Or".equalsIgnoreCase(qName)) { opStack.push(Restrictions.disjunction()); } else if ("And".equalsIgnoreCase(qName)) { opStack.push(Restrictions.conjunction()); } else { throw new SAXException("Element Name[" + qName + "] Not Recognized."); } }
From source file:com.hp.dao.CalendarDAOImpl.java
@Override public List<Calendar> getCalendarList(String pManagerID, String pStaff, Date pFromDate, Date pToDate) { Session session = HibernateSessionFactory.getSessionFactory().openSession(); Transaction transaction = session.beginTransaction(); try {/*from w ww . ja v a2 s . c o m*/ Criteria criteria = session.createCriteria(Calendar.class); Criteria criteriaInner = criteria.createCriteria("staff"); if (pStaff != null && !pStaff.equals("")) { criteriaInner.add(Restrictions.eq("id", pStaff)); } else if (pManagerID != null && !pManagerID.equals("")) { criteriaInner.add(Restrictions.eq("manager", pManagerID)); } if (pFromDate != null) { criteria.add(Restrictions.ge("calendarDate", pFromDate)); } if (pToDate != null) { criteria.add(Restrictions.le("calendarDate", pToDate)); } criteria.addOrder(Order.asc("calendarDate")); System.err.println(criteria.toString()); return criteria.list(); } catch (Exception e) { e.printStackTrace(); return null; } finally { session.close(); } }
From source file:com.hp.dao.ForLeaveDAOImpl.java
@Override public List<ForLeave> getForLeaveList(String pManagerID, String pStaff, Date pFromDate, Date pToDate) { Session session = HibernateSessionFactory.getSessionFactory().openSession(); Transaction transaction = session.beginTransaction(); try {// w w w . j a v a 2s . com Criteria criteria = session.createCriteria(ForLeave.class); Criteria criteriaInner = criteria.createCriteria("staff"); if (pStaff != null && !pStaff.equals("")) { criteriaInner.add(Restrictions.eq("id", pStaff)); } else if (pManagerID != null && !pManagerID.equals("")) { criteriaInner.add(Restrictions.eq("manager", pManagerID)); } if (pFromDate != null) { criteria.add(Restrictions.ge("timeAt", pFromDate)); } if (pToDate != null) { criteria.add(Restrictions.le("timeAt", pToDate)); } criteria.addOrder(Order.asc("timeAt")); System.err.println(criteria.toString()); return criteria.list(); } catch (Exception e) { e.printStackTrace(); return null; } finally { session.close(); } }
From source file:com.hp.dao.SetLunchDAOImpl.java
@Override public List<SetLunch> getSetLunchList(String pManagerID, String pStaff, Date pFromDate, Date pToDate) { Session session = HibernateSessionFactory.getSessionFactory().openSession(); Transaction transaction = session.beginTransaction(); try {/*w w w . j a va 2 s . c om*/ Criteria criteria = session.createCriteria(SetLunch.class); Criteria criteriaInner = criteria.createCriteria("staff"); if (pStaff != null && !pStaff.equals("")) { criteriaInner.add(Restrictions.eq("id", pStaff)); } else if (pManagerID != null && !pManagerID.equals("")) { criteriaInner.add(Restrictions.eq("manager", pManagerID)); } if (pFromDate != null) { criteria.add(Restrictions.ge("timeAt", pFromDate)); } if (pToDate != null) { criteria.add(Restrictions.le("timeAt", pToDate)); } criteria.addOrder(Order.asc("timeAt")); System.err.println(criteria.toString()); return criteria.list(); } catch (Exception e) { e.printStackTrace(); return null; } finally { session.close(); } }