Java Code Examples for org.hibernate.criterion.DetachedCriteria#forClass()

The following examples show how to use org.hibernate.criterion.DetachedCriteria#forClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: K8sApiStatusDaoImpl.java    From kardio with Apache License 2.0 6 votes vote down vote up
@Override
public long getCurrentNumberOfApis(int envId,String componentIdsStrg) throws ParseException {
	
	List<Integer> comIdList = DaoUtil.convertCSVToList(componentIdsStrg);
	
	Session session = sessionFactory.openSession();
	DetachedCriteria subMaxDate = DetachedCriteria.forClass(K8sApiStatusEntity.class);
	subMaxDate.setProjection(Projections.max("statusDate"));
	Criteria crtCurrenrApi = session.createCriteria(K8sApiStatusEntity.class);
	crtCurrenrApi.add(Property.forName("statusDate").eq(subMaxDate));
	DaoUtil.addEnvironmentToCriteria(envId, comIdList, crtCurrenrApi);
	crtCurrenrApi.setProjection(Projections.sum("totalApi"));
	long currentNumberOfApi = (long) (crtCurrenrApi.uniqueResult() == null ? (long)0 : crtCurrenrApi.uniqueResult());
	session.close();
	return currentNumberOfApi;
}
 
Example 2
Source File: DHuSFtpUserManager.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public String[] getAllUserNames() throws FtpException
{
   DetachedCriteria criteria = DetachedCriteria.forClass (
         fr.gael.dhus.database.object.User.class);
   criteria.add (Restrictions.eq ("deleted", false));

   List<fr.gael.dhus.database.object.User> users = userService.getUsers (
         criteria, 0, 0);
   List<String> names = new LinkedList<> ();
   for (fr.gael.dhus.database.object.User user : users)
   {
      names.add (user.getUsername ());
   }
   return names.toArray(new String[names.size()]);
}
 
Example 3
Source File: CriteriaQuery.java    From jeecg with Apache License 2.0 6 votes vote down vote up
public CriteriaQuery(Class entityClass,DataTables dataTables) {
	this.curPage = dataTables.getDisplayStart();
	String[] fieldstring=dataTables.getsColumns().split(",");

	this.detachedCriteria = DetachedCriteria.forClass(entityClass);
	//this.detachedCriteria = DetachedCriteriaUtil.createDetachedCriteria(entityClass, "start", "_table",fieldstring);

	
	this.field=dataTables.getsColumns();
	this.entityClass=entityClass;
	this.dataTables=dataTables;
	this.pageSize=dataTables.getDisplayLength();
	this.map = new HashMap<String, Object>();

	this.ordermap = new LinkedHashMap<String, Object>();

	addJqCriteria(dataTables);
}
 
Example 4
Source File: ECRFFieldValueDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static DetachedCriteria createEcrfFieldValueDetachedCriteria(org.hibernate.Criteria ecrfFieldValueCriteria, org.hibernate.Criteria ecrfFieldCriteria,
		org.hibernate.Criteria probandListEntryCriteria,
		Long probandListEntryId, Long ecrfFieldId) {
	DetachedCriteria subQuery = DetachedCriteria.forClass(ECRFFieldValueImpl.class, "ecrfFieldValue1"); // IMPL!!!!
	if (probandListEntryId == null) {
		if (probandListEntryCriteria == null) {
			probandListEntryCriteria = ecrfFieldValueCriteria.createCriteria("listEntry", "probandListEntry0");
		}
		subQuery.add(Restrictions.eqProperty("listEntry.id", probandListEntryCriteria.getAlias() + ".id"));
	} else {
		subQuery.add(Restrictions.eq("listEntry.id", probandListEntryId.longValue()));
	}
	if (ecrfFieldId == null) {
		if (ecrfFieldCriteria == null) {
			ecrfFieldCriteria = ecrfFieldValueCriteria.createCriteria("ecrfField", "ecrfField0");
		}
		subQuery.add(Restrictions.eqProperty("ecrfField.id", ecrfFieldCriteria.getAlias() + ".id"));
	} else {
		subQuery.add(Restrictions.eq("ecrfField.id", ecrfFieldId.longValue()));
	}
	return subQuery;
}
 
Example 5
Source File: HomePageController.java    From TinyMooc with Apache License 2.0 6 votes vote down vote up
@RequestMapping("goPersonalTeam.htm")
public ModelAndView goPersonalTeam(HttpServletRequest request) {
    String userId = request.getParameter("userId");
    User user1 = userService.findById(User.class, userId);
    DetachedCriteria dCriteria = DetachedCriteria.forClass(UserTeam.class);
    dCriteria.add(Restrictions.eq("user", user1));

    List<UserTeam> userTeam = userService.queryAllOfCondition(UserTeam.class, dCriteria);
    DetachedCriteria dCriteria2 = DetachedCriteria.forClass(Discuss.class);
    dCriteria2.add(Restrictions.eq("user", user1));
    List<Discuss> discussList = userService.queryAllOfCondition(Discuss.class, dCriteria2);

    request.setAttribute("user1", user1);
    request.setAttribute("userTeam", userTeam);
    request.setAttribute("discussList", discussList);
    return new ModelAndView("/userPage/userGroup");
}
 
Example 6
Source File: GoodsCommentDaoImpl.java    From Mall-Server with MIT License 5 votes vote down vote up
@Override
public int getCountByCommentLevel(int commentLevel) {
    DetachedCriteria criteria = DetachedCriteria.forClass(GoodsComment.class);

    criteria.add(Restrictions.eq("commentLevel", commentLevel));
    criteria.setProjection(Projections.rowCount());

    Object obj  = template.findByCriteria(criteria).get(0);
    Long longObj = (Long) obj;
    int count = longObj.intValue();
    return count;
}
 
Example 7
Source File: UserDaoImpl.java    From Mall-Server with MIT License 5 votes vote down vote up
@Override
public List<User> getUserByPhone(String phone) {
    DetachedCriteria criteria=DetachedCriteria.forClass(User.class);
    criteria.add(Restrictions.eq("phone", phone));
    List<User> list = (List<User>) template.findByCriteria(criteria, 0, 1);
    return list;
}
 
Example 8
Source File: GoodsCatDaoImpl.java    From Mall-Server with MIT License 5 votes vote down vote up
@Override
public GoodsCat findById(int id) {
    DetachedCriteria criteria = DetachedCriteria.forClass(GoodsCat.class);
    criteria.add(Restrictions.eq("id", id));
    List<GoodsCat> resultList = (List<GoodsCat>) template.findByCriteria(criteria);
    if (resultList.size() == 0) {
        return null;
    }
    return resultList.get(0);
}
 
Example 9
Source File: CriteriaQuery.java    From jeewx with Apache License 2.0 5 votes vote down vote up
public CriteriaQuery(Class c, int pageSize, int curPage,
		String myAction, String myForm) {
	this.pageSize = pageSize;
	this.curPage = curPage;
	this.myAction = myAction;
	this.myForm = myForm;
	this.detachedCriteria = DetachedCriteria.forClass(c);
}
 
Example 10
Source File: NoteController.java    From TinyMooc with Apache License 2.0 5 votes vote down vote up
@RequestMapping("goNote.htm")
public ModelAndView goNote(HttpServletRequest request) {
    User user = (User) request.getSession().getAttribute("user");
    if (user == null) {
        return new ModelAndView("/login/login");
    } else {
        DetachedCriteria dCriteria = DetachedCriteria.forClass(UserCourse.class);
        dCriteria.add(Restrictions.eq("user", user));
        List<UserCourse> notelist = noteService.queryAllOfCondition(UserCourse.class, dCriteria);
        int credit = user.getCredit();
        Level level = userService.getUserLevel(credit);
        request.setAttribute("level", level);
        return new ModelAndView("/note/myNote", "notelist", notelist);
    }
}
 
Example 11
Source File: MerchantDaoImpl.java    From Mall-Server with MIT License 5 votes vote down vote up
@Override
public List<Merchant> getMerchantByMerchantName(String merchantName) {
    DetachedCriteria criteria=DetachedCriteria.forClass(Merchant.class);
    criteria.add(Restrictions.eq("merchantName", merchantName));
    List<Merchant> list = (List<Merchant>) template.findByCriteria(criteria, 0, 1);
    return list;
}
 
Example 12
Source File: GenericDaoTester.java    From framework with Apache License 2.0 5 votes vote down vote up
/**
 * Description: <br>
 * 
 * @author 王伟<br>
 * @taskId <br>
 *         <br>
 */
@Test
public void getListByCriteriaQuery() {
    DetachedCriteria criteria = DetachedCriteria.forClass(StudentEntity.class);
    criteria.add(Restrictions.eq(StudentEntity.AGE, NUM_18));
    List<StudentEntity> es1 = studentDao.getListByCriteriaQuery(criteria);

    List<StudentEntity> es2 = studentDao.findByProperty(StudentEntity.class, StudentEntity.AGE, NUM_18);
    Assert.isTrue(es1.size() == es2.size(), ErrorCodeDef.SYSTEM_ERROR_10001);
}
 
Example 13
Source File: CriteriaQuery.java    From jeewx with Apache License 2.0 5 votes vote down vote up
public CriteriaQuery(Class entityClass,DataGrid dg) {
	this.curPage = dg.getPage();
	//String[] fieldstring=dg.getField().split(",");
	//this.detachedCriteria = DetachedCriteriaUtil
	//.createDetachedCriteria(c, "start", "_table",fieldstring);
	this.detachedCriteria = DetachedCriteria.forClass(entityClass);
	//Criteria criteria = null;

	this.field=dg.getField();
	this.entityClass=entityClass;
	this.dataGrid=dg;
	this.pageSize=dg.getRows();
	this.map = new HashMap<String, Object>();
	this.ordermap = new HashMap<String, Object>();
}
 
Example 14
Source File: UserService.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Counts corresponding users at the given criteria.
 *
 * @param criteria criteria contains filter of required collection.
 * @return number of corresponding users.
 */
@Transactional(readOnly = true)
public int countUsers (DetachedCriteria criteria)
{
   if (criteria == null)
   {
      criteria = DetachedCriteria.forClass (User.class);
   }
   criteria.setResultTransformer (Criteria.DISTINCT_ROOT_ENTITY);
   criteria.setProjection (Projections.rowCount ());
   return userDao.count (criteria);
}
 
Example 15
Source File: GoodsCommentDaoImpl.java    From Mall-Server with MIT License 5 votes vote down vote up
@Override
public int getCount() {
    DetachedCriteria criteria = DetachedCriteria.forClass(GoodsComment.class);
    criteria.setProjection(Projections.rowCount());
    Object obj  = template.findByCriteria(criteria).get(0);
    Long longObj = (Long) obj;
    int count = longObj.intValue();
    return count;
}
 
Example 16
Source File: PasswordDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Collection<Password> handleFindExpiring(Date today,
		Long departmentId, AuthenticationType authMethod, VariablePeriod reminderPeriod,
		Long reminderPeriodDays, Boolean notify, boolean includeAlreadyPassed, PSFVO psf) throws Exception {
	org.hibernate.Criteria passwordCriteria = createPasswordCriteria("password0");
	SubCriteriaMap criteriaMap = new SubCriteriaMap(Password.class, passwordCriteria);
	if (departmentId != null) {
		criteriaMap.createCriteria("user").add(Restrictions.eq("department.id", departmentId.longValue()));
	}
	if (authMethod != null) {
		criteriaMap.createCriteria("user").add(Restrictions.eq("authMethod", authMethod));
	}
	DetachedCriteria subQuery = DetachedCriteria.forClass(PasswordImpl.class, "password1"); // IMPL!!!!
	subQuery.add(Restrictions.eqProperty("password1.user", "password0.user"));
	subQuery.setProjection(Projections.max("id"));
	passwordCriteria.add(Subqueries.propertyEq("id", subQuery));
	passwordCriteria.add(Restrictions.eq("expires", true)); // performance only...
	if (notify != null) {
		passwordCriteria.add(Restrictions.eq("prolongable", notify.booleanValue())); // performance only...
	}
	if (psf != null) {
		PSFVO sorterFilter = new PSFVO();
		sorterFilter.setFilters(psf.getFilters());
		sorterFilter.setSortField(psf.getSortField());
		sorterFilter.setSortOrder(psf.getSortOrder());
		CriteriaUtil.applyPSFVO(criteriaMap, sorterFilter);
	}
	ArrayList<Password> resultSet = CriteriaUtil.listExpirations(passwordCriteria, today, notify, includeAlreadyPassed, null, null, reminderPeriod, reminderPeriodDays);
	return CriteriaUtil.applyPVO(resultSet, psf, false); // no dupes by default
}
 
Example 17
Source File: CriteriaQuery.java    From jeewx with Apache License 2.0 4 votes vote down vote up
public CriteriaQuery(Class c) {
	this.detachedCriteria = DetachedCriteria.forClass(c);
	this.map = new HashMap<String, Object>();
	this.ordermap = new HashMap<String, Object>();
}
 
Example 18
Source File: GoodsCatDaoImpl.java    From Mall-Server with MIT License 4 votes vote down vote up
@Override
public List<GoodsCat> findAll() {
    DetachedCriteria criteria = DetachedCriteria.forClass(GoodsCat.class);
    return (List<GoodsCat>) template.findByCriteria(criteria);
}
 
Example 19
Source File: HomeExtendDaoImpl.java    From Mall-Server with MIT License 4 votes vote down vote up
@Override
public List<HomeExtend> findAll() {
    DetachedCriteria criteria = DetachedCriteria.forClass(HomeExtend.class);
    return (List<HomeExtend>) template.findByCriteria(criteria);
}
 
Example 20
Source File: HomePageController.java    From TinyMooc with Apache License 2.0 4 votes vote down vote up
/**
 * 我的萌课
 *
 * @param request
 * @return ModelAndView
 * @Date 2015年12月2日15:16:07
 */
@RequestMapping("myTinyMooc.htm")
public ModelAndView myTinyMooc(HttpServletRequest request) {
    User user = (User) request.getSession().getAttribute("user");

    String message = "";
    if (user == null) {
        message = "请先登录啊( ̄▽ ̄)";
        return new ModelAndView("/login/login", "message", message);
    } else {
        int credit = user.getCredit();
        Level level = userService.getUserLevel(credit);
        String sessionId = (String) request.getSession().getAttribute("userId");
        //热门标签
        DetachedCriteria dCriteriaLabel = DetachedCriteria.forClass(Label.class);
        dCriteriaLabel.addOrder(Order.desc("frequency"));
        List<Label> labelList = userService.queryMaxNumOfCondition(Label.class, dCriteriaLabel, 8);
        //课程推荐
        DetachedCriteria dCriteriaCourse = DetachedCriteria.forClass(Course.class);
        dCriteriaCourse.addOrder(Order.desc("scanNum"));
        dCriteriaCourse.add(Restrictions.eq("courseState", "批准"));
        // TODO 是否取消课程的自关联
        dCriteriaCourse.add(Restrictions.isNull("course"));
        List<Course> courseList1 = userService.queryMaxNumOfCondition(Course.class, dCriteriaCourse, 6);

        List<UserCourse> hotCourseList = new ArrayList<>();
        for (int i = 0; i < courseList1.size(); i++) {
            Course course = courseList1.get(i);
            DetachedCriteria dCriteriaUserCourse = DetachedCriteria.forClass(UserCourse.class);
            dCriteriaUserCourse.add(Restrictions.eq("course", course));
            List<UserCourse> userCourseList = userService.queryAllOfCondition(UserCourse.class, dCriteriaUserCourse);
            // UserCourse中以创建者作为标识
            for (int j = 0; j < userCourseList.size(); j++) {
                if (userCourseList.get(j).getUserPosition().equals("创建者")) {
                    hotCourseList.add(userCourseList.get(j));
                    break;
                }
            }
        }
        //达人推荐
        DetachedCriteria dCriteria2 = DetachedCriteria.forClass(User.class)
                .addOrder(Order.desc("credit"))
                .add(Restrictions.ne("userId", user.getUserId()));
        List<User> expertList = userService.queryMaxNumOfCondition(User.class, dCriteria2, 4);
        // 封装数据
        request.setAttribute("hotCourseList", hotCourseList);
        request.setAttribute("labelList", labelList);
        request.setAttribute("expertList", expertList);
        return new ModelAndView("/homePage/myTinyMooc", "level", level);
    }
}