Example usage for org.hibernate.criterion Restrictions and

List of usage examples for org.hibernate.criterion Restrictions and

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions and.

Prototype

public static LogicalExpression and(Criterion lhs, Criterion rhs) 

Source Link

Document

Return the conjuction of two expressions

Usage

From source file:eu.optimis.common.trec.db.ip.TrecSnRelationshipTrustDAO.java

License:Apache License

@SuppressWarnings("unchecked")
public SnTrustRelationship getSnRelationshipByOrigin(String origin, String originType) throws Exception {
    Session session = null;//from www.j a v  a  2  s. c om
    List<SnTrustRelationship> results = null;
    SessionFactory sf = HibernateUtil.getSessionFactory();
    try {
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        tx.begin();
        // Search by IP Name
        Criteria criteria = session.createCriteria(SnTrustRelationship.class);
        //         criteria.add(Restrictions.like("origin", origin));
        //         criteria.add(Restrictions.like("originType", originType));
        criteria.add(Restrictions.and(Restrictions.like("origin", origin),
                Restrictions.like("originType", originType)));
        results = (List<SnTrustRelationship>) criteria.list();
        tx.commit();
        return results.get(results.size() - 1);
    } catch (Exception e) {
        logger.error("ERROR " + e.getMessage());
        throw new Exception(e.toString());
    }

}

From source file:eu.optimis.common.trec.db.ip.TrecSnRelationshipTrustDAO.java

License:Apache License

@SuppressWarnings("unchecked")
public List<SnTrustRelationship> getSnRelationshipsByOrigin(String origin, String originType) throws Exception {
    Session session = null;//from w w w .  j  a v  a  2  s.c om
    List<SnTrustRelationship> results = null;
    SessionFactory sf = HibernateUtil.getSessionFactory();
    try {
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        tx.begin();
        // Search by IP Name
        Criteria criteria = session.createCriteria(SnTrustRelationship.class);
        //         criteria.add(Restrictions.like("origin", origin));
        //         criteria.add(Restrictions.like("originType", originType));
        criteria.add(Restrictions.and(Restrictions.like("origin", origin),
                Restrictions.like("originType", originType)));
        results = (List<SnTrustRelationship>) criteria.list();
        tx.commit();
        return results;
    } catch (Exception e) {
        logger.error("ERROR " + e.getMessage());
        throw new Exception(e.toString());
    }

}

From source file:eu.optimis.common.trec.db.ip.TrecSnRelationshipTrustDAO.java

License:Apache License

@SuppressWarnings("unchecked")
public SnTrustRelationship getSnRelationshipByDestiny(String destiny, String destinyType) throws Exception {
    Session session = null;//from  w ww .j  a v  a2s.  c  om
    List<SnTrustRelationship> results = null;
    SessionFactory sf = HibernateUtil.getSessionFactory();
    try {
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        tx.begin();
        // Search by IP Name
        Criteria criteria = session.createCriteria(SnTrustRelationship.class);
        //         criteria.add(Restrictions.like("origin", origin));
        //         criteria.add(Restrictions.like("originType", originType));
        criteria.add(Restrictions.and(Restrictions.like("destiny", destiny),
                Restrictions.like("destinyType", destinyType)));
        results = (List<SnTrustRelationship>) criteria.list();
        tx.commit();
        return results.get(results.size() - 1);
    } catch (Exception e) {
        logger.error("ERROR " + e.getMessage());
        throw new Exception(e.toString());
    }

}

From source file:eu.optimis.common.trec.db.ip.TrecSnRelationshipTrustDAO.java

License:Apache License

@SuppressWarnings("unchecked")
public List<SnTrustRelationship> getSnRelationshipsByDestiny(String destiny, String destinyType)
        throws Exception {
    Session session = null;/* w w w  . ja v a  2s  .c  o  m*/
    List<SnTrustRelationship> results = null;
    SessionFactory sf = HibernateUtil.getSessionFactory();
    try {
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        tx.begin();
        // Search by IP Name
        Criteria criteria = session.createCriteria(SnTrustRelationship.class);
        //         criteria.add(Restrictions.like("origin", origin));
        //         criteria.add(Restrictions.like("originType", originType));
        criteria.add(Restrictions.and(Restrictions.like("destiny", destiny),
                Restrictions.like("destinyType", destinyType)));
        results = (List<SnTrustRelationship>) criteria.list();
        tx.commit();
        return results;
    } catch (Exception e) {
        logger.error("ERROR " + e.getMessage());
        throw new Exception(e.toString());
    }

}

From source file:eu.optimis.common.trec.db.ip.TrecSnRelationshipTrustDAO.java

License:Apache License

@SuppressWarnings("unchecked")
public SnTrustRelationship getSnRelationshipByOriginAndDestiny(String origin, String originType, String destiny,
        String destinyType) throws Exception {
    Session session = null;/*from   w  ww .j  a v a  2s.c o m*/
    List<SnTrustRelationship> results = null;
    SessionFactory sf = HibernateUtil.getSessionFactory();
    try {
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        tx.begin();
        // Search by IP Name
        Criteria criteria = session.createCriteria(SnTrustRelationship.class);
        //         criteria.add(Restrictions.like("origin", origin));
        //         criteria.add(Restrictions.like("originType", originType));
        criteria.add(Restrictions.and(Restrictions.like("origin", origin),
                Restrictions.like("originType", originType)));
        criteria.add(Restrictions.and(Restrictions.like("destiny", destiny),
                Restrictions.like("destinyType", destinyType)));
        results = (List<SnTrustRelationship>) criteria.list();
        tx.commit();
        return results.get(results.size() - 1);
    } catch (Exception e) {
        logger.error("ERROR " + e.getMessage());
        throw new Exception(e.toString());
    }

}

From source file:eu.optimis.common.trec.db.ip.TrecSnRelationshipTrustDAO.java

License:Apache License

@SuppressWarnings("unchecked")
public List<SnTrustRelationship> getSnRelationshipsByOriginAndDestiny(String origin, String originType,
        String destiny, String destinyType) throws Exception {
    Session session = null;/*from   w  ww.  java 2  s. c  om*/
    List<SnTrustRelationship> results = null;
    SessionFactory sf = HibernateUtil.getSessionFactory();
    try {
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        tx.begin();
        // Search by IP Name
        Criteria criteria = session.createCriteria(SnTrustRelationship.class);
        //         criteria.add(Restrictions.like("origin", origin));
        //         criteria.add(Restrictions.like("originType", originType));
        criteria.add(Restrictions.and(Restrictions.like("origin", origin),
                Restrictions.like("originType", originType)));
        criteria.add(Restrictions.and(Restrictions.like("destiny", destiny),
                Restrictions.like("destinyType", destinyType)));
        results = (List<SnTrustRelationship>) criteria.list();
        tx.commit();
        return results;
    } catch (Exception e) {
        logger.error("ERROR " + e.getMessage());
        throw new Exception(e.toString());
    }

}

From source file:fr.gael.dhus.olingo.v1.SQLVisitor.java

License:Open Source License

private Criterion getCriterionLogical(BinaryOperator operator, Criterion left, Criterion right) {
    Criterion criterion;/*from w  ww.ja va2 s  .  c o  m*/
    if (left == null && right == null) {
        criterion = null;
    } else if (left != null && right != null) {
        switch (operator) {
        case AND: {
            criterion = Restrictions.and(left, right);
            break;
        }
        case OR: {
            criterion = Restrictions.or(left, right);
            break;
        }
        default: {
            throw new UnsupportedOperationException("Unsupported operator: " + operator.toUriLiteral());
        }
        }
    } else if (left == null) {
        criterion = right;
    } else {
        criterion = left;
    }
    return criterion;
}

From source file:fr.mcc.ginco.dao.hibernate.AssociativeRelationshipDAO.java

License:CeCILL license

@Override
public AssociativeRelationship getAssociativeRelationship(String id1, String id2) {
    Criteria criteria = getCurrentSession().createCriteria(AssociativeRelationship.class, "ar")
            .add(Restrictions.or(//  w w  w.  j  a v a2 s.com
                    Restrictions.and(Restrictions.eq("conceptLeft.identifier", id1),
                            Restrictions.eq("conceptRight.identifier", id2)),
                    Restrictions.and(Restrictions.eq("conceptRight.identifier", id1),
                            Restrictions.eq("conceptLeft.identifier", id2))));

    return (AssociativeRelationship) criteria.uniqueResult();
}

From source file:fr.mcc.ginco.dao.hibernate.ThesaurusConceptDAO.java

License:CeCILL license

@Override
public Long countConceptsAlignedToIntThes(String idThesaurus) throws BusinessException {
    DetachedCriteria alignmentCriteria = DetachedCriteria.forClass(Alignment.class, "al")
            .add(Restrictions.isNotNull("al.internalTargetThesaurus")).setProjection(
                    Projections.projectionList().add(Projections.property("al.sourceConcept.identifier")));

    DetachedCriteria conceptCriteria = DetachedCriteria.forClass(ThesaurusConcept.class, "stc")
            .add(Restrictions.eq("stc.thesaurus.identifier", idThesaurus))
            .setProjection(Projections.projectionList().add(Projections.property("stc.identifier")));

    Criteria criteria = getCurrentSession().createCriteria(ThesaurusConcept.class, "tc")
            .add(Restrictions.and(Subqueries.propertyIn("tc.identifier", alignmentCriteria),
                    Subqueries.propertyIn("tc.identifier", conceptCriteria)))
            .setProjection(Projections.rowCount());

    return (Long) criteria.list().get(0);
}

From source file:fr.mcc.ginco.dao.hibernate.ThesaurusConceptDAO.java

License:CeCILL license

@Override
public Long countConceptsAlignedToExtThes(String idThesaurus) throws BusinessException {
    DetachedCriteria alignmentCriteria = DetachedCriteria.forClass(Alignment.class, "al")
            .add(Restrictions.isNotNull("al.externalTargetThesaurus")).setProjection(
                    Projections.projectionList().add(Projections.property("al.sourceConcept.identifier")));

    DetachedCriteria conceptCriteria = DetachedCriteria.forClass(ThesaurusConcept.class, "stc")
            .add(Restrictions.eq("stc.thesaurus.identifier", idThesaurus))
            .setProjection(Projections.projectionList().add(Projections.property("stc.identifier")));

    Criteria criteria = getCurrentSession().createCriteria(ThesaurusConcept.class, "tc")
            .add(Restrictions.and(Subqueries.propertyIn("tc.identifier", alignmentCriteria),
                    Subqueries.propertyIn("tc.identifier", conceptCriteria)))
            .setProjection(Projections.rowCount());
    return (Long) criteria.list().get(0);
}