Example usage for org.hibernate.criterion Projections id

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

Introduction

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

Prototype

public static IdentifierProjection id() 

Source Link

Document

An identifier value projection.

Usage

From source file:ubc.pavlab.aspiredb.server.dao.CriteriaBuilder.java

License:Apache License

private static Criterion processRestrictionExpression(PhenotypeRestriction restriction, EntityType target) {
    DetachedCriteria subquery = DetachedCriteria.forClass(target.clazz);

    addPhenotypeAlias(subquery, target);

    subquery.add(Restrictions.conjunction().add(Restrictions.eq("phenotype.name", restriction.getName()))
            .add(Restrictions.eq("phenotype.value", restriction.getValue())));

    subquery.setProjection(Projections.distinct(Projections.id()));

    return Subqueries.propertyIn("id", subquery);
}

From source file:ubc.pavlab.aspiredb.server.dao.CriteriaBuilder.java

License:Apache License

private static Criterion processRestrictionExpression(SetRestriction setRestriction, EntityType target) {
    Property property = setRestriction.getProperty();
    Operator operator = setRestriction.getOperator();
    Set<Object> values = setRestriction.getValues();

    log.debug("Property=" + property + "; operator=" + operator + "; values="
            + StringUtils.collectionToCommaDelimitedString(values));

    DetachedCriteria subquery = DetachedCriteria.forClass(target.clazz);

    Junction criteriaDisjunction = Restrictions.disjunction();

    if (property instanceof CharacteristicProperty) {
        for (Object value : values) {
            criteriaDisjunction.add(createCharacteristicCriterion((CharacteristicProperty) property,
                    Operator.TEXT_EQUAL, (TextValue) value, target));
        }//from   ww w  .jav  a 2s .com
    } else if (property instanceof LabelProperty) {
        for (Object value : values) {
            criteriaDisjunction.add(createLabelCriterion((LabelProperty) property, Operator.TEXT_EQUAL,
                    (LabelValueObject) value, target));
        }
    } else if (property instanceof CNVTypeProperty) {
        EntityType propertyOf = EntityType.VARIANT;
        for (Object value : values) {
            criteriaDisjunction.add(createCNVTypeCriterion(Operator.TEXT_EQUAL,
                    fullEntityPropertyName(target, propertyOf, property), (TextValue) value));
        }
    } else if (property instanceof VariantTypeProperty) {
        for (Object value : values) {
            criteriaDisjunction.add(createVariantTypeCriterion(target, (TextValue) value));
        }
    } else if (property instanceof ExternalSubjectIdProperty) {
        EntityType propertyOf = EntityType.SUBJECT;
        for (Object value : values) {
            criteriaDisjunction.add(createTextCriterion(Operator.TEXT_EQUAL,
                    fullEntityPropertyName(target, propertyOf, property), ((TextValue) value).getValue()));
        }
    } else if (property instanceof TextProperty) {
        EntityType propertyOf = EntityType.VARIANT;
        for (Object value : values) {
            criteriaDisjunction.add(createTextCriterion(Operator.TEXT_EQUAL,
                    fullEntityPropertyName(target, propertyOf, property), ((TextValue) value).getValue()));
        }
    } else if (property instanceof GenomicLocationProperty) {
        for (Object value : values) {
            criteriaDisjunction.add(overlapsGenomicRegionCriterion((GenomicRange) value));
        }
    } else if (property instanceof GeneProperty) {
        for (Object value : values) {
            GeneValueObject gene = (GeneValueObject) value;
            criteriaDisjunction.add(overlapsGenomicRegionCriterion(gene.getGenomicRange()));
        }
    } else if (property instanceof NeurocartaPhenotypeProperty) {
        for (Object value : values) {
            NeurocartaPhenotypeValueObject neurocartaPhenotype = (NeurocartaPhenotypeValueObject) value;
            for (GeneValueObject gene : neurocartaPhenotype.getGenes()) {
                criteriaDisjunction.add(overlapsGenomicRegionCriterion(gene.getGenomicRange()));
            }
        }
    } else {
        throw new IllegalArgumentException("Not supported!");
    }

    subquery.add(criteriaDisjunction);
    subquery.setProjection(Projections.distinct(Projections.id()));
    log.debug("subquery = " + subquery);

    switch (operator) {
    case IS_IN_SET:
        return Subqueries.propertyIn("id", subquery);
    case IS_NOT_IN_SET:
        return Subqueries.propertyNotIn("id", subquery);
    default:
        throw new IllegalArgumentException("Operator not supported.");
    }
}

From source file:ubc.pavlab.aspiredb.server.dao.PhenotypeDaoImpl.java

License:Apache License

@Override
@Transactional(readOnly = true)/*from  ww  w . ja va 2s  .com*/
public Integer findPhenotypeCountBySubjectId(Long id) {

    Criteria criteria = currentSession().createCriteria(Phenotype.class).createAlias("subject", "subject")
            .add(Restrictions.eq("subject.id", id));
    criteria.setProjection(Projections.distinct(Projections.id()));
    List<Long> ids = criteria.list();

    return ids.size();
}

From source file:ubc.pavlab.aspiredb.server.dao.PhenotypeDaoImpl.java

License:Apache License

@Override
@Transactional(readOnly = true)/*from  w  w w.  j a  v  a  2 s.  co m*/
public Collection<Phenotype> loadAllByProjectIds(Collection<Long> projectIds) {
    Session session = currentSession();

    Criteria criteria = session.createCriteria(Phenotype.class).createAlias("subject", "subject");
    criteria.createCriteria("subject.project").add(Restrictions.in("id", projectIds));
    criteria.setProjection(Projections.distinct(Projections.id()));

    List<Long> ids = criteria.list();

    return this.load(ids);
}

From source file:ubc.pavlab.aspiredb.server.dao.SubjectDaoImpl.java

License:Apache License

private List<Long> findIds(AspireDbFilterConfig filter)
        throws BioMartServiceException, NeurocartaServiceException {

    if (filter instanceof ProjectOverlapFilterConfig) {

        List<Long> variantIds = variantDao.getProjectOverlapVariantIds((ProjectOverlapFilterConfig) filter);

        Collection<Subject> subjects = this.loadByVariantIds(variantIds);

        ArrayList<Long> subjectIds = new ArrayList<Long>();

        for (Subject s : subjects) {
            subjectIds.add(s.getId());//from  ww w  .ja v a2  s.  com
        }

        return subjectIds;

    } else if (filter instanceof PhenotypeFilterConfig) {
        Collection<Subject> subjects = findByPhenotype((PhenotypeFilterConfig) filter);

        ArrayList<Long> subjectIds = new ArrayList<Long>();

        for (Subject s : subjects) {
            subjectIds.add(s.getId());
        }

        return subjectIds;
    }

    Session session = this.getSessionFactory().getCurrentSession();
    Criteria criteria = session.createCriteria(Subject.class);
    addSingleFilter(filter, criteria);
    criteria.setProjection(Projections.distinct(Projections.id()));
    return criteria.list();
}

From source file:ubc.pavlab.aspiredb.server.dao.VariantDaoBaseImpl.java

License:Apache License

private List<Long> findIds(AspireDbFilterConfig filter) {

    // for performance reasons as Criteria can be slow
    if (filter instanceof ProjectFilterConfig) {

        return this.getVariantIdsByProject((ProjectFilterConfig) filter);

        // Project overlap filter requires a little more data processing than the other filters and uses
        // precalculated database table as it doesn't quite fit the same paradigm as the other filters I am breaking
        // it off into its own method
    } else if (filter instanceof ProjectOverlapFilterConfig) {

        return this.getProjectOverlapVariantIds((ProjectOverlapFilterConfig) filter);

    } else if (filter instanceof PhenotypeFilterConfig) {
        List<Variant> variants = findByPhenotype((PhenotypeFilterConfig) filter);

        ArrayList<Long> variantIds = new ArrayList<Long>();

        for (Variant v : variants) {
            variantIds.add(v.getId());/*from   ww  w .ja v  a  2 s. com*/
        }

        return variantIds;
    }

    Session session = this.getSessionFactory().getCurrentSession();
    Criteria criteria = session.createCriteria(this.elementClass);

    addSingleFilter(filter, criteria);

    criteria.setProjection(Projections.distinct(Projections.id()));

    return criteria.list();
}