Example usage for org.hibernate Criteria setResultTransformer

List of usage examples for org.hibernate Criteria setResultTransformer

Introduction

In this page you can find the example usage for org.hibernate Criteria setResultTransformer.

Prototype

public Criteria setResultTransformer(ResultTransformer resultTransformer);

Source Link

Document

Set a strategy for handling the query results.

Usage

From source file:at.ac.tuwien.ifs.tita.dao.user.UserDAO.java

License:Apache License

/** {@inheritDoc} **/
@Override/*  w w w .j ava  2  s . c  o  m*/
@SuppressWarnings("unchecked")
public List<TiTAUser> findUsersOrdered(int maxResult) throws PersistenceException {
    Criteria crit = getSession().createCriteria(TiTAUser.class);

    if (maxResult > 0) {
        crit.setMaxResults(maxResult);
    }

    crit.addOrder(Order.asc("userName"));
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    return crit.list();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.pages.UsersPage.java

License:Open Source License

/**
 * Gets a list of users with a specific search term. The users may be 
 * excluded from a specific class. //from w  w  w  .  j a  v  a 2s  . c o  m
 * 
 * @param request
 * @return response
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public JSONArray list(HttpServletRequest request) throws JSONException {
    JSONArray arr = new JSONArray();

    Criteria qu = this.db.createCriteria(User.class);

    String search = request.getParameter("search");
    if (search != null) {
        /* Search filter. */
        qu.add(Restrictions.disjunction().add(Restrictions.like("name", search, MatchMode.ANYWHERE))
                .add(Restrictions.like("firstName", search, MatchMode.ANYWHERE))
                .add(Restrictions.like("lastName", search, MatchMode.ANYWHERE)));
    }

    if (request.getParameter("max") != null) {
        /* Max results. */
        qu.setMaxResults(Integer.parseInt(request.getParameter("max")));
    }

    if (request.getParameter("in") != null) {
        /* Users in class. */
        UserClass inClass = new UserClassDao(this.db).findByName(request.getParameter("in"));
        if (inClass == null) {
            this.logger.warn("Not going to add in class as a user list restriction because the class '"
                    + request.getParameter("in") + "' was not found.");
        } else {
            qu.createCriteria("userAssociations").add(Restrictions.eq("userClass", inClass));
        }
    }

    if (request.getParameter("notIn") != null) {
        /* Users not in class. */
        UserClass notInClass = new UserClassDao(this.db).findByName(request.getParameter("notIn"));
        if (notInClass == null) {
            this.logger.warn("Not going to add not in class as a user list restriction because the class '"
                    + request.getParameter("notIn") + "' was not found.");
        } else {
            DetachedCriteria subQu = DetachedCriteria.forClass(User.class)
                    .setProjection(Property.forName("name")).createCriteria("userAssociations")
                    .add(Restrictions.eq("userClass", notInClass));

            List<String> names = subQu.getExecutableCriteria(this.db).list();
            if (names.size() > 0) {
                qu.add(Restrictions.not(Restrictions.in("name", names)));
            }
        }
    }

    qu.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    qu.addOrder(Order.asc("lastName"));
    qu.addOrder(Order.asc("name"));

    for (User user : (List<User>) qu.list()) {
        JSONObject uo = new JSONObject();
        uo.put("name", user.getNamespace() + "-_-" + user.getName());

        if (user.getFirstName() == null || user.getLastName() == null) {
            uo.put("display", user.getName());
        } else {
            uo.put("display", user.getLastName() + ", " + user.getFirstName());
        }

        arr.put(uo);
    }

    return arr;
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

protected Criteria buildArkRoleModuleFunctionVoCriteria(
        ArkRoleModuleFunctionVO arkRoleModuleFunctionVoCriteria) {
    Criteria criteria = getSession().createCriteria(ArkRolePolicyTemplate.class, "arpt");

    if (arkRoleModuleFunctionVoCriteria.getArkRole() != null) {
        criteria.add(Restrictions.eq("arpt.arkRole", arkRoleModuleFunctionVoCriteria.getArkRole()));
    }// w w  w.java  2s  .c o  m

    if (arkRoleModuleFunctionVoCriteria.getArkModule() != null) {
        criteria.add(Restrictions.eq("arpt.arkModule", arkRoleModuleFunctionVoCriteria.getArkModule()));
    }

    if (arkRoleModuleFunctionVoCriteria.getArkFunction() != null) {
        criteria.add(Restrictions.eq("arpt.arkFunction", arkRoleModuleFunctionVoCriteria.getArkFunction()));
    }

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("arpt.arkRole"), "arkRole");
    projectionList.add(Projections.groupProperty("arpt.arkModule"), "arkModule");
    projectionList.add(Projections.groupProperty("arpt.arkFunction"), "arkFunction");

    criteria.setProjection(projectionList);

    ResultTransformer resultTransformer = Transformers.aliasToBean(ArkRoleModuleFunctionVO.class);
    criteria.setResultTransformer(resultTransformer);

    return criteria;
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public List<ArkRoleModuleFunctionVO> getArkRoleModuleFunctionVoList(ArkRole arkRole) {
    Criteria criteria = getSession().createCriteria(ArkRolePolicyTemplate.class, "arpt");
    criteria.add(Restrictions.eq("arpt.arkRole", arkRole));

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("arpt.arkRole"), "arkRole");
    projectionList.add(Projections.groupProperty("arpt.arkModule"), "arkModule");
    projectionList.add(Projections.groupProperty("arpt.arkFunction"), "arkFunction");

    criteria.setProjection(projectionList);

    ResultTransformer resultTransformer = Transformers.aliasToBean(ArkRoleModuleFunctionVO.class);
    criteria.setResultTransformer(resultTransformer);

    return criteria.list();
}

From source file:au.org.theark.core.dao.ArkAuthorisationDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<ArkUser> getArkUserListByStudy(ArkUser arkUser, Study study) {
    Criteria criteria = getSession().createCriteria(ArkUserRole.class);
    // Restrict by user if NOT Super Administrator
    try {/*w  w w .  j  av  a 2 s  .  com*/
        if (!isUserAdminHelper(arkUser.getLdapUserName(), RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)) {
            criteria.add(Restrictions.eq("study", study));
        }
    } catch (EntityNotFoundException e) {
        log.info("User Name doen not exsists");
    }
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("arkUser"), "arkUser");
    criteria.setProjection(projectionList);
    criteria.setResultTransformer(Transformers.aliasToBean(ArkUserRole.class));
    List<ArkUserRole> arkUserRoles = (List<ArkUserRole>) criteria.list();
    List<ArkUser> arkUserLst = new ArrayList<ArkUser>();
    for (ArkUserRole arkRolePol : arkUserRoles) {
        arkUserLst.add(arkRolePol.getArkUser());
    }
    //Added on 2015-12-10 filter study wise users.
    //changed on 2016-04-28.
    return arkUserLst;
}

From source file:au.org.theark.core.dao.ArkAuthorisationDao.java

License:Open Source License

/**
 * List of Permission for function. /*from  ww  w. jav  a 2 s  .c o  m*/
 *
 * Just I need the list of permission list for a particular function I manage to use the hibernate projectionList property.
 * Group by Permission.
 * But still used setResultTransformer to transform the list which include the permission list.
 * @return
 */
public List<ArkPermission> getArkPremissionListForRoleAndModule(ArkRolePolicyTemplate arkRolePolicyTemplate) {
    Criteria criteria = getSession().createCriteria(ArkRolePolicyTemplate.class);
    criteria.add(Restrictions.eq("arkRole", arkRolePolicyTemplate.getArkRole()));
    criteria.add(Restrictions.eq("arkModule", arkRolePolicyTemplate.getArkModule()));
    criteria.add(Restrictions.eq("arkFunction", arkRolePolicyTemplate.getArkFunction()));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("arkPermission"), "arkPermission");
    criteria.setProjection(projectionList);
    criteria.setResultTransformer(Transformers.aliasToBean(ArkRolePolicyTemplate.class));
    List<ArkRolePolicyTemplate> arkRolePolicyTemplatesLst = (List<ArkRolePolicyTemplate>) criteria.list();
    List<ArkPermission> arkPermissionLst = new ArrayList<ArkPermission>();
    for (ArkRolePolicyTemplate arkRolePol : arkRolePolicyTemplatesLst) {
        arkPermissionLst.add(arkRolePol.getArkPermission());
    }
    return arkPermissionLst;
}

From source file:au.org.theark.core.dao.AuditDao.java

License:Open Source License

@Override
public List<AuditPackage> getAuditPackageList() {
    Criteria criteria = getSession().createCriteria(AuditPackage.class);
    //      criteria.setProjection(Projections.distinct(Projections.id()));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria.list();
}

From source file:au.org.theark.core.dao.AuditDao.java

License:Open Source License

@Override
public String getFieldName(Class<?> cls, String field) {
    Criteria criteria = getSession().createCriteria(AuditField.class);
    criteria.add(Restrictions.eq("fieldName", field));
    criteria.createAlias("auditEntity", "ae");
    criteria.add(Restrictions.eq("ae.classIdentifier", cls.getCanonicalName()));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return ((AuditField) criteria.uniqueResult()).getName();
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

public List<PhenoDataSetGroup> getPhenoDataSetGroupsByLinkSubjectStudy(LinkSubjectStudy linkSubjectStudy) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetCollection.class);
    criteria.add(Restrictions.eq("linkSubjectStudy", linkSubjectStudy));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("questionnaire"), "questionnaire");
    criteria.setProjection(projectionList);
    criteria.setResultTransformer(Transformers.aliasToBean(PhenoDataSetCollection.class));
    List<PhenoDataSetCollection> phenoDataSetCollections = (List<PhenoDataSetCollection>) criteria.list();
    List<PhenoDataSetGroup> phenoDataSetGroups = new ArrayList<PhenoDataSetGroup>();
    for (PhenoDataSetCollection phenoDataSetCollection : phenoDataSetCollections) {
        phenoDataSetGroups.add(phenoDataSetCollection.getQuestionnaire());
    }//w  ww .  j a v a 2 s . com
    return phenoDataSetGroups;
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

@Override
public List<PhenoDataSetFieldDisplay> getPhenoDataSetFieldDisplayForPhenoDataSetFieldGroupOrderByPhenoDataSetCategory(
        PhenoDataSetGroup phenoDataSetGroup) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class);
    criteria.add(Restrictions.eq("phenoDataSetGroup", phenoDataSetGroup));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("phenoDataSetGroup"), "phenoDataSetGroup");
    projectionList.add(Projections.groupProperty("phenoDataSetCategory"), "phenoDataSetCategory");
    projectionList.add(Projections.groupProperty("parentPhenoDataSetCategory"), "parentPhenoDataSetCategory");
    projectionList.add(Projections.groupProperty("phenoDataSetCategoryOrderNumber"),
            "phenoDataSetCategoryOrderNumber");
    criteria.setProjection(projectionList);
    criteria.addOrder(Order.asc("phenoDataSetCategoryOrderNumber"));
    criteria.setResultTransformer(Transformers.aliasToBean(PhenoDataSetFieldDisplay.class));
    return (List<PhenoDataSetFieldDisplay>) criteria.list();
}