项目还是一样,以一个reservation为例,一个reservation就是一个课程在实际中的体现,它有开始和终止时间还有状态等信息。timeslot就是定义了他的时间。
作者:中国IT实验室 来源:中国IT实验室 2007年9月26日
关键字:
2. 如果我要创建一个reservation,要判断的是当前这个创建的reservation是否与其它的reservation有交叉点的时间,那查询条件就这样修改
- broker = PersistenceBrokerFactory.defaultPersistenceBroker();
- broker.clearCache();
- //general criteria, with all the query condition
- Criteria crit = new Criteria();
- Criteria crit1 = null;
- List criteriaList = new Vector();
- if (this.selectType == Constants.TOUCHING_RESERVATIONS) {
- crit1 = new Criteria();
- /**
- * <p>the start time is in between <code>this.startTimeUTC</code> and <code>this.endTimeUTC</code>
- */
- crit1.addGreaterOrEqualThan("start", startTimeUTC);
- crit1.addLessOrEqualThan("start", endTimeUTC);
- /**
- * <p>the end time is in between <code>this.startTimeUTC</code> and <code>this.endTimeUTC</code>
- */
- Criteria crit2 = new Criteria();
- crit2.addGreaterOrEqualThan("end", startTimeUTC);
- crit2.addLessOrEqualThan("end", endTimeUTC);
-
- /**
- * <p>the start time is in less than <code>this.startTimeUTC</code> and
- * the end time is greater than <code>this.endTimeUTC</code>
- */
- Criteria crit3 = new Criteria();
- crit3.addLessOrEqualThan("start", startTimeUTC);
- crit3.addGreaterOrEqualThan("end", endTimeUTC);
- crit1.addOrCriteria(crit2);
- crit1.addOrCriteria(crit3);
- }
- criteriaList.add(crit1.copy(true, true, true));
- if (criteriaList.size() > 0) {
- crit1 = new Criteria();
- for (int i = 0; i < criteriaList.size(); i++) {
- crit1.addOrCriteria((Criteria) criteriaList.get(i));
- }
- crit.addAndCriteria(crit1);
- }
- QueryByCriteria tquery = QueryFactory.newQuery(Timeslot.class, crit);
- this.timeslots = broker.getCollectionByQuery(tquery);
- broker.clearCache();
- broker.close();
查看本文来源