List of usage examples for org.hibernate.criterion DetachedCriteria add
public DetachedCriteria add(Criterion criterion)
From source file:com.ateam.hibernate.HibernateDAOImpl.java
public String checkRole(String strUserName, String password) throws DataAccessException, java.sql.SQLException { String obj = null;/*from www . ja v a 2s. co m*/ DetachedCriteria critthree = DetachedCriteria.forClass(UserAttr.class); ProjectionList pl = Projections.projectionList(); pl.add(Projections.groupProperty("userRole")); critthree.add(Restrictions.eq("userName", strUserName)); critthree.add(Restrictions.eq("userPassword", password)); critthree.setProjection(pl); List objs = getHibernateTemplate().findByCriteria(critthree); if ((objs != null) && (objs.size() > 0)) { obj = (String) objs.get(0); } return obj; }
From source file:com.ateam.hibernate.HibernateDAOImpl.java
public String checkFullName(String strUserName, String password) throws DataAccessException, java.sql.SQLException { String obj = null;//from ww w . j a v a 2 s.c o m DetachedCriteria critname = DetachedCriteria.forClass(UserAttr.class); ProjectionList pl = Projections.projectionList(); pl.add(Projections.groupProperty("userFullName")); critname.add(Restrictions.eq("userName", strUserName)); critname.add(Restrictions.eq("userPassword", password)); critname.setProjection(pl); List objs = getHibernateTemplate().findByCriteria(critname); if ((objs != null) && (objs.size() > 0)) { obj = (String) objs.get(0); } return obj; }
From source file:com.ateam.hibernate.HibernateDAOImpl.java
public List<Questions> generateQuestion(String skillId, String difficulty) throws DataAccessException, java.sql.SQLException { Questions obj = null;/* w w w. ja v a 2 s .c o m*/ DetachedCriteria criteria = DetachedCriteria.forClass(Questions.class); criteria.add(Restrictions.eq("skillId", skillId)); criteria.add(Restrictions.eq("difficulty", difficulty)); criteria.add(Restrictions.sqlRestriction("1=1 order by rand() LIMIT 1")); List objs = getHibernateTemplate().findByCriteria(criteria); if ((objs != null) && (objs.size() > 0)) { obj = (Questions) objs.get(0); } return objs; }
From source file:com.ateam.hibernate.HibernateDAOImpl.java
public void deleteUser(String userName) throws DataAccessException { UserAttr obj4 = null;//from ww w .ja v a 2 s . co m DetachedCriteria criteria4 = DetachedCriteria.forClass(UserAttr.class); criteria4.add(Restrictions.eq("userName", userName)); List objs = getHibernateTemplate().findByCriteria(criteria4); if ((objs != null) && (objs.size() > 0)) { obj4 = (UserAttr) objs.get(0); getHibernateTemplate().delete(obj4); } }
From source file:com.benfante.minimark.blo.AssessmentBo.java
License:Apache License
/** * Find assessments./*w w w . j a v a 2 s .c o m*/ * * @param active If true, map only active assessments. null, any value. * @param showInHomePage If true, map only assessments that must be shown in the home page. null, any value. * @param username map only the assessments of this user. null, any user. * * @return The map of courses on assessments */ public List<Assessment> searchAssessments(Boolean active, Boolean showInHomePage, String username) { DetachedCriteria crit = DetachedCriteria.forClass(Assessment.class); if (active != null) { crit.add(Restrictions.eq("active", active)); } if (showInHomePage != null) { crit.add(Restrictions.eq("showInHomePage", showInHomePage)); } if (username != null) { crit.createAlias("course.courseTeachers", "courseTeachers"); crit.createAlias("courseTeachers.userProfile.user", "user"); crit.add(Restrictions.eq("user.username", username)); } List<Assessment> assessments = assessmentDao.searchByCriteria(crit); return assessments; }
From source file:com.benfante.minimark.blo.AssessmentFillingBo.java
License:Apache License
/** * Retrieve all fillings of active assessments. * * @return The list of fillings of active assesments. *//*from w w w. j a v a 2s .c o m*/ public List<AssessmentFilling> searchActiveFillings() { DetachedCriteria crit = DetachedCriteria.forClass(AssessmentFilling.class); crit.createAlias("assessment", "assessment"); crit.add(Restrictions.eq("assessment.active", Boolean.TRUE)); List<AssessmentFilling> result = assessmentFillingDao.searchByCriteria(crit); Collections.sort(result, new AssessmentFillingStatusComparator()); return filterByAuthorization(result); }
From source file:com.benfante.minimark.blo.AssessmentFillingBo.java
License:Apache License
/** * Retrieve all fillings of active assessments. * * @return The list of fillings of active assesments. *///from ww w .j a va2s .c om public List<AssessmentFilling> searchActiveFillingsByCourse(Long courseId) { DetachedCriteria crit = DetachedCriteria.forClass(AssessmentFilling.class); crit.createAlias("assessment", "assessment"); crit.add(Restrictions.eq("assessment.active", Boolean.TRUE)); crit.createAlias("assessment.course", "course"); crit.add(Restrictions.eq("course.id", courseId)); List<AssessmentFilling> result = assessmentFillingDao.searchByCriteria(crit); Collections.sort(result, new AssessmentFillingStatusComparator()); return filterByAuthorization(result); }
From source file:com.benfante.minimark.blo.QuestionBo.java
License:Apache License
/** * Search questions by example./*from w w w .j av a 2s . c om*/ * * @param questionBean The values for searching questions. * @return The list of questions matching the questionBean values. */ public List<Question> search(QuestionBean questionBean) { DetachedCriteria crit = null; if (StringUtils.isBlank(questionBean.getType())) { crit = DetachedCriteria.forClass(Question.class); } else { if ("open".equals(questionBean.getType())) { crit = DetachedCriteria.forClass(OpenQuestion.class); if (StringUtils.isNotBlank(questionBean.getVisualization())) { crit.add(Restrictions.eq("visualization", questionBean.getVisualization())); } } else if ("closed".equals(questionBean.getType())) { crit = DetachedCriteria.forClass(ClosedQuestion.class); } else { throw new IllegalArgumentException("Unknown question type (" + questionBean.getType() + ")"); } } if (StringUtils.isNotBlank(questionBean.getTitle())) { crit.add(Restrictions.ilike("title", questionBean.getTitle(), MatchMode.ANYWHERE)); } if (questionBean.getWeight() != null) { crit.add(Restrictions.eq("weight", questionBean.getWeight())); } if (questionBean.getCourse() != null && questionBean.getCourse().getId() != null) { crit.add(Restrictions.eq("course.id", questionBean.getCourse().getId())); } crit.addOrder(Order.asc("title")); crit.addOrder(Order.asc("content")); if (StringUtils.isNotBlank(questionBean.getTags())) { crit.createAlias("tags", "tags"); crit.createAlias("tags.tag", "tag"); crit.add(Restrictions.in("tag.name", questionBean.getTagList())); } crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return questionDao.searchByCriteria(crit); }
From source file:com.benfante.minimark.blo.UserProfileBo.java
License:Apache License
/** * Search all users associated with at least one course. * * @return The list of all teachers/*from w w w. j a v a 2s . c o m*/ */ public List<UserProfile> searchAllTeachers() { DetachedCriteria crit = DetachedCriteria.forClass(UserProfile.class); crit.add(Restrictions.isNotEmpty("courseTeachers")); crit.addOrder(Order.asc("name")); return userProfileDao.searchByCriteria(crit); }
From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java
@Override public List<ChasePlan> getOutNumStopChasePlan(boolean outNumStop, I issueData) { DetachedCriteria criteria = DetachedCriteria.forClass(ChasePlan.class); if (outNumStop) { criteria.add(Restrictions.eq("outNumStop", outNumStop)); }//w ww . j a v a2 s. co m criteria.add(Restrictions.eq("lotteryType", this.getLottery())); // criteria.add(Restrictions.ge("curPeriodId", // Long.valueOf(issueData.getPeriodNumber()))); criteria.add(Restrictions.eq("state", ChaseState.RUNNING)); List<ChasePlan> list = queryService.findByDetachedCriteria(criteria); return list; }