public void testJunctionNotExpressionQBE() throws Exception { deleteData(); initData(); Session s = openSession(); Transaction t = s.beginTransaction(); Componentizable master = getMaster("hibernate", null, "ope%"); Criteria crit = s.createCriteria(Componentizable.class); Example ex = Example.create(master).enableLike(); crit.add(Expression.or(Expression.not(ex), ex)); List result = crit.list(); assertNotNull(result); assertEquals(2, result.size()); t.commit(); s.close(); }
/** * Gets a list of all calendars not subscribed to sorted by primary key. * * @return List of Calendar * @throws Exception */ public Set getUnsubscribedCalendarList(String email, Session session) throws Exception { List result = null; Set subscriptions = SubscriptionController.getController().getSubscriberList(email, session); List subscriptionsList = new ArrayList(); Iterator i = subscriptions.iterator(); while (i.hasNext()) { Subscriber subscriber = (Subscriber) i.next(); subscriptionsList.add(subscriber.getCalendar().getId()); } Criteria criteria = session.createCriteria(Calendar.class); if (subscriptionsList.size() > 0) criteria.add(Expression.not(Expression.in("id", subscriptionsList.toArray()))); criteria.addOrder(Order.asc("name")); Set set = new LinkedHashSet(); set.addAll(criteria.list()); return set; }
/** * 参与的项目 * * @param id * @return */ @SuppressWarnings("unchecked") public List getProjectAboutSelf(Integer id) { Session session = this.getDBDao().getDBSession(); List<EpMemberInfo> list = new ArrayList<EpMemberInfo>(); List<EpProject> list1 = new ArrayList<EpProject>(); List<EpProRelational> list2 = new ArrayList<EpProRelational>(); try { Criteria cri = session.createCriteria(EpMemberInfo.class); cri.add(Expression.eq("id", id)); cri.add(Expression.eq("type", 0)); list = cri.list(); // 如果是项目经理 if (list.size() == 1) { // System.out.println("项目经理"); Hibernate.initialize(list.get(0).getEpPosition()); if (list.get(0).getEpPosition().getId() == 1) { Criteria c = session.createCriteria(EpProject.class); c.add(Expression.not(Expression.eq("proStartType", 1))); c.add(Expression.eq("epMemberInfo.id", id)); c.addOrder(Order.desc("id")); c.setMaxResults(6); list1 = c.list(); if (list1.size() > 0) { return list1; } else { Criteria cri1 = session.createCriteria(EpProRelational.class); cri1.add(Expression.eq("delId", 0)); cri1.add(Expression.eq("epMemberInfo.id", id)); cri1.setMaxResults(6); list2 = cri1.list(); if (list2.size() > 0) { // System.out.println("wwwww"); // System.out.println("size:"+list2.size()); for (int i = 0; i < list2.size(); i++) { Hibernate.initialize(list2.get(i).getEpProject()); EpProject epProject = list2.get(i).getEpProject(); Criteria cri2 = session.createCriteria(EpProject.class); cri2.add(Expression.not(Expression.eq("projectLxId", 1))); // System.out.println("epProject.getId():"+epProject.getId()); cri2.add(Expression.eq("id", epProject.getId())); List<EpProject> list4 = cri2.list(); if (list4.size() == 1) { list1.add(list4.get(0)); } } } } } // 如果是销售或者销售经理 if (list.get(0).getEpPosition().getId() == 2 || list.get(0).getEpPosition().getId() == 4) { // System.out.println("负责人或者销售经理"); // System.out.println("dsadsadsadsadsadsadas"); Criteria cri1 = session.createCriteria(EpProRelational.class); cri1.add(Expression.eq("delId", 0)); cri1.add(Expression.eq("epMemberInfo.id", id)); cri1.setMaxResults(6); list2 = cri1.list(); if (list2.size() > 0) { // System.out.println("wwwww"); // System.out.println("size:"+list2.size()); for (int i = 0; i < list2.size(); i++) { Hibernate.initialize(list2.get(i).getEpProject()); EpProject epProject = list2.get(i).getEpProject(); Criteria cri2 = session.createCriteria(EpProject.class); cri2.add(Expression.not(Expression.eq("projectLxId", 1))); // System.out.println("epProject.getId():"+epProject.getId()); cri2.add(Expression.eq("id", epProject.getId())); List<EpProject> list4 = cri2.list(); if (list4.size() == 1) { list1.add(list4.get(0)); } } } } } } catch (Exception e) { e.printStackTrace(); } return list1; }