Example usage for org.hibernate.criterion Projections projectionList

List of usage examples for org.hibernate.criterion Projections projectionList

Introduction

In this page you can find the example usage for org.hibernate.criterion Projections projectionList.

Prototype

public static ProjectionList projectionList() 

Source Link

Document

Create a new projection list.

Usage

From source file:alpha.portal.dao.hibernate.AlphaCardDaoHibernate.java

License:Apache License

/**
 * List alpha cards by criterion.// w w w.j  a va 2  s. c om
 * 
 * @param caseId
 *            the case id
 * @param criteriaArray
 *            the criteria array
 * @return the list
 * @see alpha.portal.dao.AlphaCardDao#listAlphaCardsByCriterion(org.hibernate.criterion.Criterion)
 */
public List<AlphaCard> listAlphaCardsByCriterion(final String caseId, final Criterion... criteriaArray) {
    Session session;
    boolean sessionOwn = false;
    try {
        session = this.getSessionFactory().getCurrentSession();
    } catch (final Exception e) {
        session = this.getSessionFactory().openSession();
        sessionOwn = true;
    }

    // get newest sequenceNumber for each cardId
    final DetachedCriteria version = DetachedCriteria.forClass(AlphaCard.class, "cardVersion")
            .add(Property.forName("card.alphaCardIdentifier.cardId")
                    .eqProperty("cardVersion.alphaCardIdentifier.cardId"))
            .setProjection(
                    Projections.projectionList().add(Projections.max("alphaCardIdentifier.sequenceNumber")));

    final Criteria crit = session.createCriteria(AlphaCard.class, "card");
    for (final Criterion c : criteriaArray) {
        // Create the subquery (somehow we need to use the Descriptor or
        // else the subquery-JOIN is not done)
        final DetachedCriteria subcrit = DetachedCriteria.forClass(AlphaCardDescriptor.class, "crit");

        // Join the adornments
        subcrit.createAlias("crit.adornmentList", "ad");

        // Add adornment condition
        subcrit.add(c);

        // Map the subquery back to the outer query
        subcrit.add(Restrictions.eqProperty("card.alphaCardIdentifier", "crit.alphaCardIdentifier"));

        // Narrow down subquery or else we get a NullPointer-Exception
        subcrit.setProjection(Projections.property("crit.alphaCardIdentifier.cardId"));

        // Add this subquery to the outer query.
        crit.add(Subqueries.exists(subcrit));
    }
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
            .add(Property.forName("alphaCardIdentifier.sequenceNumber").eq(version))
            .createAlias("alphaCase", "case").add(Restrictions.eq("case.caseId", caseId));

    List<AlphaCard> list = crit.list();
    if (list.size() > 1) {
        final List<AlphaCard> order = (list.get(0)).getAlphaCase().getAlphaCards();
        final List<AlphaCard> orderedList = new LinkedList<AlphaCard>();
        for (final AlphaCard cc : order) {
            for (final AlphaCard c : list) {
                if (c.getAlphaCardIdentifier().equals(cc.getAlphaCardIdentifier())) {
                    orderedList.add(c);
                    break;
                }
            }
        }
        list = orderedList;
    }

    if (sessionOwn) {
        session.close();
    }

    return list;
}

From source file:ar.com.zauber.commons.repository.aggregate.ProjectionAggregateFunctionVisitor.java

License:Apache License

/** @see AggregateFunctionVisitor#visitCompositeAggregateFilter(
 * CompositeAggregateFunction) */
public final void visitCompositeAggregateFilter(final CompositeAggregateFunction caf) {

    final ProjectionList pj = Projections.projectionList();
    ProjectionList last = pj;/*from  w  w w  .j  a  v  a2  s  .co m*/
    for (final AggregateFunction function : caf.getFunctions()) {
        final Projection p = createProjection(function);
        last = last.add(p);
    }
    projection = pj;
}

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 .j a  v a  2  s  .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.admin.model.dao.AdminDao.java

License:Open Source License

public List<ArkModule> getArkModuleList(ArkRole arkRole) {
    Criteria criteria = getSession().createCriteria(ArkModuleRole.class);

    if (arkRole != null) {
        criteria.add(Restrictions.eq("arkRole", arkRole));
    }/*  w  w w .j  a va 2s  .  c o  m*/
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("arkModule"), "arkModule");
    criteria.setProjection(projectionList);

    return criteria.list();
}

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

License:Open Source License

public List<ArkFunction> getArkFunctionListByArkModule(ArkModule arkModule) {
    Criteria criteria = getSession().createCriteria(ArkModuleFunction.class);
    if (arkModule.getId() != null) {
        criteria.add(Restrictions.eq("arkModule", arkModule));
    }//  ww  w  . ja va2  s . c  o  m
    criteria.createAlias("arkModule", "module");
    criteria.addOrder(Order.asc("module.name"));
    criteria.addOrder(Order.asc("functionSequence"));

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("arkFunction"), "arkFunction");
    criteria.setProjection(projectionList);
    return criteria.list();
}

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

License:Open Source License

public List<ArkModule> getArkModuleListByArkRole(ArkRole arkRole) {
    Criteria criteria = getSession().createCriteria(ArkModuleRole.class);
    if (arkRole != null) {
        criteria.add(Restrictions.eq("arkRole", arkRole));
    }/*from w ww .  ja v a 2  s . c  o  m*/
    criteria.createAlias("arkModule", "module");
    criteria.addOrder(Order.asc("module.name"));

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("arkModule"), "arkModule");
    criteria.setProjection(projectionList);
    return criteria.list();
}

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

License:Open Source License

public List<ArkRole> getArkRoleListByArkModule(ArkModule arkModule) {
    Criteria criteria = getSession().createCriteria(ArkModuleRole.class);
    if (arkModule.getId() != null) {
        criteria.add(Restrictions.eq("arkModule", arkModule));
    }//ww w.ja  va 2 s  .  c om

    // Restrict searching/selecting of Super Administrator
    criteria.add(Restrictions.ne("arkModule",
            getArkRoleByName(au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)));

    criteria.createAlias("arkRole", "role");
    criteria.addOrder(Order.asc("role.name"));

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("arkRole"), "arkRole");
    criteria.setProjection(projectionList);
    return criteria.list();
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public Collection<String> getArkRolePermission(ArkFunction arkFunction, String userRole, ArkModule arkModule)
        throws EntityNotFoundException {

    Collection<String> stringPermissions = new ArrayList<String>();
    ArkRole arkRole = getArkRoleByName(userRole);
    Criteria criteria = getSession().createCriteria(ArkRolePolicyTemplate.class);

    if (arkModule != null) {
        criteria.add(Restrictions.eq("arkModule", arkModule));
    }//from   w  w  w  .  j av a2s .  c  o m

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

    if (arkRole != null) {
        criteria.add(Restrictions.eq("arkRole", arkRole));

        criteria.createAlias("arkPermission", "permission");
        ProjectionList projectionList = Projections.projectionList();
        projectionList.add(Projections.groupProperty("permission.name"));
        criteria.setProjection(projectionList);

        stringPermissions = criteria.list();
    }
    return stringPermissions;
}

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

License:Open Source License

/**
 * Returns a list of All Permissions in Ark System
 * /*from  w ww .j  av a 2 s .  com*/
 * @return
 */
@SuppressWarnings("unchecked")
public Collection<String> getArkPermission() {
    Collection<String> arkStringPermissions = new ArrayList<String>();
    Criteria criteria = getSession().createCriteria(ArkPermission.class);
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("name"));
    criteria.setProjection(projectionList);
    arkStringPermissions = criteria.list();
    return arkStringPermissions;
}