Example usage for org.hibernate.criterion DetachedCriteria createCriteria

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

Introduction

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

Prototype

@Deprecated
public DetachedCriteria createCriteria(String associationPath, String alias, int joinType) 

Source Link

Document

Deprecated!

Usage

From source file:com.evolveum.midpoint.repo.sql.query.custom.ShadowQueryWithDisjunction.java

License:Apache License

@Override
public RQuery createQuery(ObjectQuery objectQuery, Class<? extends ObjectType> type,
        Collection<SelectorOptions<GetOperationOptions>> options, boolean countingObjects, Session session) {

    DetachedCriteria c1 = DetachedCriteria.forClass(ClassMapper.getHQLTypeClass(ShadowType.class), "s");
    c1.createCriteria("strings", "s1", JoinType.LEFT_OUTER_JOIN);

    ParsedQuery parsedQuery = parse(objectQuery);
    Conjunction conjunction = Restrictions.conjunction();
    conjunction/*  w w  w  .  ja  va2  s  .  c om*/
            .add(Restrictions.eq("resourceRef.targetOid", parsedQuery.refFilter.getValues().get(0).getOid()));
    Disjunction disjunction = Restrictions.disjunction();
    disjunction.add(createAttributeEq(parsedQuery.eqUidFilter,
            parsedQuery.eqUidFilter.getPath().lastNamed().getName()));
    disjunction.add(createAttributeEq(parsedQuery.eqNameFilter, SchemaConstantsGenerated.ICF_S_NAME));
    conjunction.add(disjunction);
    c1.add(conjunction);

    if (countingObjects) {
        c1.setProjection(Projections.countDistinct("s.oid"));
        return new RQueryCriteriaImpl(c1.getExecutableCriteria(session));
    }

    c1.setProjection(Projections.distinct(Projections.property("s.oid")));

    Criteria cMain = session.createCriteria(ClassMapper.getHQLTypeClass(ShadowType.class), "o");
    cMain.add(Subqueries.propertyIn("oid", c1));

    if (objectQuery != null && objectQuery.getPaging() != null) {
        cMain = updatePagingAndSorting(cMain, type, objectQuery.getPaging());
    }

    ProjectionList projections = Projections.projectionList();
    projections.add(Projections.property("fullObject"));
    projections.add(Projections.property("stringsCount"));
    projections.add(Projections.property("longsCount"));
    projections.add(Projections.property("datesCount"));
    projections.add(Projections.property("referencesCount"));
    projections.add(Projections.property("polysCount"));
    projections.add(Projections.property("booleansCount"));

    cMain.setProjection(projections);

    cMain.setResultTransformer(GetObjectResult.RESULT_TRANSFORMER);
    return new RQueryCriteriaImpl(cMain);
}

From source file:org.jspresso.framework.model.persistence.hibernate.criterion.EnhancedDetachedCriteria.java

License:Open Source License

/**
 * Creates or gets a previously registered sub-criteria.
 *
 * @param masterCriteria//ww  w . j  ava  2s .c o  m
 *          the parent criteria holding the sub-criteria.
 * @param associationPath
 *          the association path.
 * @param alias
 *          the alias.
 * @param joinType
 *          the join type.
 * @return the new or previously registered sub-criteria.
 */
public DetachedCriteria getSubCriteriaFor(DetachedCriteria masterCriteria, String associationPath, String alias,
        JoinType joinType) {
    DetachedCriteria subCriteria = getRegisteredSubCriteria(masterCriteria, associationPath);
    if (subCriteria == null) {
        subCriteria = masterCriteria.createCriteria(associationPath, alias, joinType);
        registerSubCriteria(masterCriteria, associationPath, subCriteria);
    }
    return subCriteria;
}