Example usage for org.hibernate.criterion DetachedCriteria forClass

List of usage examples for org.hibernate.criterion DetachedCriteria forClass

Introduction

In this page you can find the example usage for org.hibernate.criterion DetachedCriteria forClass.

Prototype

public static DetachedCriteria forClass(Class clazz) 

Source Link

Document

Static builder to create a DetachedCriteria for the given entity, by its Class.

Usage

From source file:com.headstrong.teevra.services.useradmin.dao.impl.RoleDAOImpl.java

License:Open Source License

public void saveRole(RoleEO roleToSave) throws UserAdminServiceException {
    DetachedCriteria criteria = DetachedCriteria.forClass(RoleEO.class);
    criteria.add(Restrictions.eq("roleName", roleToSave.getRoleName()));
    if (roleToSave.getRoleId() != null) {
        criteria.add(Restrictions.ne("roleId", roleToSave.getRoleId()));
    }/*  w  w w. j  a va2  s .  c  om*/
    List<RoleEO> roleList = super.getByCriteria(criteria);

    if (!roleList.isEmpty()) {
        logger.error("Couldn't save role: " + roleToSave.getRoleName()
                + " A role with the same name already exists in the system");
        throw new UniqueRoleException("A role with the name " + "'" + roleToSave.getRoleName() + "'"
                + " already exists in the system");
    } else {
        super.saveOrUpdate(roleToSave);
    }

}

From source file:com.headstrong.teevra.services.useradmin.dao.impl.UserDAOImpl.java

License:Open Source License

public void saveUser(UserEO userToSave) throws UserAdminServiceException {

    DetachedCriteria criteria = DetachedCriteria.forClass(UserEO.class);
    criteria.add(Restrictions.eq("userName", userToSave.getUserName()));
    if (userToSave.getUserId() != null) {
        criteria.add(Restrictions.ne("userId", userToSave.getUserId()));
    }/* w  w w  .  j  a  va2 s  .c  o  m*/
    List<UserEO> userList = super.getByCriteria(criteria);

    if (!userList.isEmpty()) {
        logger.error("Couldn't register user: " + userToSave.getUserName()
                + "A user with the same name already exists in the system");
        throw new UniqueUserException("A user with the name " + "'" + userToSave.getUserName() + "'"
                + " already exists in the system");
    } else {
        super.saveOrUpdate(userToSave);
    }
}

From source file:com.headstrong.teevra.services.useradmin.dao.impl.UserDAOImpl.java

License:Open Source License

public UserEO getUser(String userName) throws UserAdminServiceException {
    DetachedCriteria criteria = DetachedCriteria.forClass(UserEO.class);
    criteria.add(Restrictions.eq("userName", userName));
    //criteria.add(Restrictions.eq("userStatus", UserEO.STATUS_ACTIVE));
    List<UserEO> userList = super.getByCriteria(criteria);
    if (!userList.isEmpty()) {
        return userList.get(0);
    }//from  w w w  .j  ava 2  s .  c  o m
    return null;
}

From source file:com.hod.pro.web.action.LoginAction.java

public String doLogin() {
    int usernumber = 0;
    request = ServletActionContext.getRequest();
    try {//w  ww.  ja va  2  s.co  m
        log.info("UserCounter.userSession.size=" + UserCounter.userSession.size());
        int onlinecount = 0;
        for (int i = 0; i < UserCounter.userSession.size(); i++) {
            UserSession obj = (UserSession) UserCounter.userSession.get(i);
            log.info("obj.sid=" + obj.sid);
            log.info("obj.lastonlinetime=" + obj.lastonlinetime);
            log.info("obj.lastonlinetime11=" + (System.currentTimeMillis() - obj.lastonlinetime));
            if (System.currentTimeMillis() - obj.lastonlinetime > UserCounter.offtime
                    && (!(request.getSession().getId()).equals(obj.sid))) {
                // UserCounter.userSession.remove(i);
                log.info("" + obj.sid);
                UserCounter.decrementUserCounter(obj.sid);
                i--;
            } else {
                onlinecount++;
            }
        }
        log.info("UserCounter.userSession.size=" + onlinecount);
        // todo code this
        //  onlinecount >= +1return message
        String file = InitServlet.localpath + "licenseFile1.a";

        String content = encryptData.decrypt(file);
        if (content != null && content.length() > 0) {
            String[] contents = content.split("\n");

            String sequence = contents[1];// 
            String dateuser = info.xuyj.util.License.decodeKey(sequence);// +_
            usernumber = Integer.parseInt(dateuser.substring(10).split("_")[1]);
            log.info("" + onlinecount + "" + usernumber);
            if (onlinecount > usernumber) {
                //throw new HodExecption("");
                msg.setError1("");
                msg.setLink(0, "<a href='" + request.getContextPath() + "/login.jsp'></a>");
                msg.setJump(false);
                request.setAttribute("message", msg);
                return "message";

            } else {
                this.checklicenseFile1(onlinecount);
            }
        }
        log.info("UserCounter.userSession.size=" + onlinecount);
        String userName = request.getParameter("username");
        String userPassWord = request.getParameter("userpassword");
        // 
        DetachedCriteria dc = DetachedCriteria.forClass(Hod2000Operator.class);
        dc.add(Restrictions.eq("loginName", userName));
        List list = hod2000OperatorService.findByCriteria(dc);
        if (list.size() > 0) {
            hod2000Operator = (Hod2000Operator) list.get(0);
            // 
            String pass = MD5.getMd5(userPassWord);
            if (pass.equals(hod2000Operator.getOperPassword())) {
                // 
                if (1 != hod2000Operator.getOperEnable()) {
                    //throw new HodExecption("");
                    msg.setError1("!");
                    msg.setLink(0, "<a href='" + request.getContextPath() + "/login.jsp'></a>");
                    msg.setJump(false);
                    request.setAttribute("message", msg);
                    return "message";
                }
            } else {
                //throw new HodExecption("");
                msg.setError1("!");
                msg.setLink(0, "<a href='" + request.getContextPath() + "/login.jsp'></a>");
                msg.setJump(false);
                request.setAttribute("message", msg);
                return "message";
            }
        } else {
            //throw new HodExecption("");
            msg.setError1("!");
            msg.setLink(0, "<a href='" + request.getContextPath() + "/login.jsp'></a>");
            msg.setJump(false);
            request.setAttribute("message", msg);
            return "message";
        }
        request.getSession().setAttribute("user", hod2000Operator);
        log.info(request.getSession().getId());
        UserCounter.updateUserCounter(request.getSession().getId(), Utils.dateToStrLong(new Date()),
                request.getRemoteHost(), hod2000Operator.getLoginName());
        request.getSession().setMaxInactiveInterval(-1);
        //1idid 2id
        String rolePermission = hod2000RoleService.findByOperatorId(hod2000Operator.getOperId());
        if (rolePermission != null && !"".equals(rolePermission)) {
            String permission = hod2000PermissionService.findByRolePermission(rolePermission);
            request.getSession().setAttribute("permission", permission);
        }
        OperatorLog.addOperatorLog("");
    } catch (Exception e) {
        // 
        msg.setError1("" + e.toString());
        msg.setLink(0, "<a href='" + request.getContextPath() + "/login.jsp'></a>");
        msg.setJump(false);
        log.error("LoginAction-->doLogin", e);
        request.setAttribute("message", msg);
        return "message";
    }
    return "login";
}

From source file:com.hypersocket.repository.AbstractRepositoryImpl.java

License:Open Source License

protected DetachedCriteria createDetachedCriteria(Class<?> entityClass) {
    return DetachedCriteria.forClass(entityClass);
}

From source file:com.ignou.aadhar.dao.hibernate.GenericDaoHibernate.java

License:Open Source License

/**
 * Fetch all the models available in the database.
 * @return All models in the database./* w ww.  ja va2 s  .c om*/
 */
public List<MODEL> list() {
    DetachedCriteria criteria = DetachedCriteria.forClass(type);
    return getHibernateTemplate().findByCriteria(criteria);
}

From source file:com.ihsolution.hqipo.dao.utils.QueryHelper.java

License:Open Source License

public QueryHelper(Class targetClass) {

    this.targetClass = targetClass;
    detCriteria = DetachedCriteria.forClass(targetClass);
}

From source file:com.ihsolution.hqipo.dao.utils.QueryHelper.java

License:Open Source License

public QueryHelper(String entName) throws Exception {
    Class cls = Class.forName(entName);
    this.targetClass = cls;
    detCriteria = DetachedCriteria.forClass(cls);
}

From source file:com.inkubator.hrm.dao.impl.EmpCareerHistoryDaoImpl.java

@Override
public EmpCareerHistory getByBioIdandStatus(long id, String status) {
    DetachedCriteria maxEvaluationScore = DetachedCriteria.forClass(getEntityClass())
            .setProjection(Property.forName("createdOn").max())
            .createAlias("bioData", "bio", JoinType.INNER_JOIN).add(Restrictions.eq("bio.id", id))
            .add(Restrictions.eq("status", status));

    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN);
    criteria.add(Restrictions.eq("bio.id", id));
    criteria.add(Restrictions.eq("status", status));
    criteria.add(Property.forName("createdOn").eq(maxEvaluationScore));
    return (EmpCareerHistory) criteria.uniqueResult();
}

From source file:com.inkubator.hrm.dao.impl.EmpCareerHistoryDaoImpl.java

@Override
public List<EmpCareerHistory> getByParamReport(ReportEmpMutationParameter searchParameter, int firstResult,
        int maxResults, Order order) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN);
    criteria.createAlias("jabatan", "jabatan", JoinType.INNER_JOIN);
    doSearchEmpRotasiByParamReport(searchParameter, criteria);

    DetachedCriteria maxTglPengangkatanQuery = DetachedCriteria.forClass(getEntityClass());
    ProjectionList proj = Projections.projectionList();
    proj.add(Projections.max("tglPenganngkatan"));
    proj.add(Projections.groupProperty("nik"));
    maxTglPengangkatanQuery.setProjection(proj);

    criteria.add(Subqueries.propertiesIn(new String[] { "tglPenganngkatan", "nik" }, maxTglPengangkatanQuery));
    criteria.addOrder(order);/*from   www . j  av a  2  s  .c  o  m*/
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);

    List<EmpCareerHistory> listEmpCareerHistorys = criteria.list();

    //Set Jabatan Lama/sebelumnya dari masing - masing record
    for (EmpCareerHistory ech : listEmpCareerHistorys) {
        Criteria criteriaOldPosition = getCurrentSession().createCriteria(getEntityClass());
        criteriaOldPosition.setFetchMode("jabatan", FetchMode.JOIN);
        criteriaOldPosition.add(Restrictions.eq("nik", ech.getNik()));
        criteriaOldPosition.add(Restrictions.lt("tglPenganngkatan", ech.getTglPenganngkatan()));
        criteriaOldPosition.addOrder(Order.desc("tglPenganngkatan"));
        criteriaOldPosition.setMaxResults(1);
        EmpCareerHistory prevPosition = (EmpCareerHistory) criteriaOldPosition.uniqueResult();

        //jika sebelumnya dia sudah pernah menjabat di posisi lain maka set oldJabatan dengan posisi tersebut
        if (null != prevPosition) {
            ech.setJabatanOldCode(prevPosition.getJabatan().getCode());
            ech.setJabatanOldName(prevPosition.getJabatan().getName());
        } else {
            ech.setJabatanOldCode("-");
        }
    }

    return listEmpCareerHistorys;
}