Example usage for org.hibernate StatelessSession createCriteria

List of usage examples for org.hibernate StatelessSession createCriteria

Introduction

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

Prototype

@Deprecated
Criteria createCriteria(Class persistentClass, String alias);

Source Link

Document

Create Criteria instance for the given class (entity or subclasses/implementors), using a specific alias.

Usage

From source file:au.org.theark.lims.model.dao.BioCollectionDao.java

License:Open Source License

public Boolean hasBioCollections(LinkSubjectStudy linkSubjectStudy) {
    // Use WHERE EXIST to optimise query even further
    StatelessSession session = getStatelessSession();
    Criteria criteria = session.createCriteria(LinkSubjectStudy.class, "lss");
    DetachedCriteria sizeCriteria = DetachedCriteria.forClass(BioCollection.class, "bc");
    criteria.add(Restrictions.eq("lss.id", linkSubjectStudy.getId()));
    sizeCriteria.add(Property.forName("lss.id").eqProperty("bc.linkSubjectStudy.id"));
    criteria.add(Subqueries.exists(sizeCriteria.setProjection(Projections.property("bc.id"))));
    criteria.setProjection(Projections.rowCount());
    Boolean result = ((Long) criteria.uniqueResult()) > 0L;
    session.close();/*  www.  j  a v a 2s  .c  o m*/

    return result;
}

From source file:au.org.theark.lims.model.dao.BioCollectionDao.java

License:Open Source License

public Boolean hasBiospecimens(BioCollection bioCollection) {
    // Use WHERE EXIST to optimise query even further
    StatelessSession session = getStatelessSession();
    Criteria criteria = session.createCriteria(BioCollection.class, "bc");
    DetachedCriteria sizeCriteria = DetachedCriteria.forClass(Biospecimen.class, "b");
    criteria.add(Restrictions.eq("bc.id", bioCollection.getId()));
    sizeCriteria.add(Property.forName("bc.id").eqProperty("b.bioCollection.id"));
    criteria.add(Subqueries.exists(sizeCriteria.setProjection(Projections.property("b.id"))));
    criteria.setProjection(Projections.rowCount());
    Boolean result = ((Long) criteria.uniqueResult()) > 0L;
    session.close();/*from   ww w.j ava 2 s . co  m*/

    return result;
}

From source file:monasca.thresh.infrastructure.persistence.hibernate.AlarmSqlImpl.java

License:Apache License

@SuppressWarnings("unchecked")
private List<Alarm> findAlarms(@Nonnull final LookupHelper lookupHelper) {
    StatelessSession session = null;

    try {// w w  w.j a  va  2s  .com
        session = sessionFactory.openStatelessSession();
        final Criteria criteria = lookupHelper.apply(session.createCriteria(AlarmDb.class, "a")
                .createAlias("a.subAlarms", "sa").createAlias("a.alarmDefinition", "ad")
                .add(Restrictions.isNull("ad.deletedAt")).addOrder(Order.asc("a.id"))
                .setProjection(Projections.projectionList().add(Projections.property("a.id"))
                        .add(Projections.property("a.alarmDefinition.id")).add(Projections.property("a.state"))
                        .add(Projections.alias(Projections.property("sa.id"), "sub_alarm_id"))
                        .add(Projections.property("sa.expression"))
                        .add(Projections.property("sa.subExpression.id"))
                        .add(Projections.property("ad.tenantId")))
                .setReadOnly(true));
        assert criteria != null;
        return this.createAlarms(session, (List<Object[]>) criteria.list(), lookupHelper);
    } finally {
        if (session != null) {
            session.close();
        }
    }
}