Example usage for org.hibernate Criteria setFetchMode

List of usage examples for org.hibernate Criteria setFetchMode

Introduction

In this page you can find the example usage for org.hibernate Criteria setFetchMode.

Prototype

public Criteria setFetchMode(String associationPath, FetchMode mode) throws HibernateException;

Source Link

Document

Specify an association fetching strategy for an association or a collection of values.

Usage

From source file:ispyb.server.common.services.shipping.Shipping3ServiceBean.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*w  w  w .  j av  a2  s . c o m*/
public List<Shipping3VO> findByStatus(final String status, final java.util.Date dateStart,
        final boolean withDewars) throws Exception {

    Session session = (Session) this.entityManager.getDelegate();
    Criteria criteria = session.createCriteria(Shipping3VO.class);
    if (status != null && !status.isEmpty()) {
        criteria.add(Restrictions.like("shippingStatus", status));
    }

    if (dateStart != null) {
        criteria.add(Restrictions.ge("creationDate", dateStart));
    }

    if (withDewars) {
        criteria.setFetchMode("dewarVOs", FetchMode.JOIN);
    }
    criteria.addOrder(Order.desc("shippingId")).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // DISTINCT
    // RESULTS !

    return criteria.list();
}

From source file:ispyb.server.common.services.shipping.Shipping3ServiceBean.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from w  ww  .  j  a v a  2 s . co  m*/
public List<Shipping3VO> findByProposal(final Integer userProposalId, final boolean withDewars)
        throws Exception {

    Session session = (Session) this.entityManager.getDelegate();
    Criteria criteria = session.createCriteria(Shipping3VO.class);

    if (userProposalId != null) {
        Criteria subCritProposal = criteria.createCriteria("proposalVO");
        subCritProposal.add(Restrictions.eq("proposalId", userProposalId));
    }

    if (withDewars) {
        criteria.setFetchMode("dewarVOs", FetchMode.JOIN);
    }
    criteria.addOrder(Order.desc("creationDate"));
    criteria.addOrder(Order.desc("shippingId"));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria.list();
}

From source file:ispyb.server.common.services.shipping.Shipping3ServiceBean.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from  ww  w  .  ja va2 s. co  m*/
public List<Shipping3VO> findByCreationDate(final Date firstDate, final boolean withDewars) throws Exception {

    Session session = (Session) this.entityManager.getDelegate();
    Criteria criteria = session.createCriteria(Shipping3VO.class);

    if (firstDate != null) {
        criteria.add(Restrictions.ge("creationDate", firstDate));
    }

    if (withDewars) {
        criteria.setFetchMode("dewarVOs", FetchMode.JOIN);
    }
    criteria.addOrder(Order.desc("creationDate"));
    criteria.addOrder(Order.desc("shippingId"));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria.list();
}

From source file:ispyb.server.common.services.shipping.Shipping3ServiceBean.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*www . j  a v  a2 s  .  c om*/
public List<Shipping3VO> findByBeamLineOperator(final String beamlineOperatorSiteNumber,
        final boolean withDewars) throws Exception {

    Session session = (Session) this.entityManager.getDelegate();
    Criteria criteria = session.createCriteria(Shipping3VO.class);

    if (beamlineOperatorSiteNumber != null) {
        Criteria sessionCriteria = criteria.createCriteria("sessions")
                .add(Restrictions.eq("operatorSiteNumber", beamlineOperatorSiteNumber));
        // .addOrder(Order.desc(propertyName))
        if (withDewars) {
            criteria.setFetchMode("dewarVOs", FetchMode.JOIN);
        }
        criteria.addOrder(Order.desc("creationDate"));
        criteria.addOrder(Order.desc("shippingId"));
        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        return criteria.list();
    } else
        return null;
}

From source file:ispyb.server.common.services.shipping.Shipping3ServiceBean.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//w w w  . ja  va2s . c  o  m
public List<Shipping3VO> findFiltered(final Integer proposalId, final String shippingName,
        final String proposalCode, final String proposalNumber, final String mainProposer, final Date date,
        final Date date2, final String operatorSiteNumber, final boolean withDewars) throws Exception {

    Session session = (Session) this.entityManager.getDelegate();
    Criteria criteria = session.createCriteria(Shipping3VO.class);

    if ((shippingName != null) && (!shippingName.isEmpty())) {
        criteria.add(Restrictions.like("shippingName", shippingName));
    }

    if (date != null) {
        criteria.add(Restrictions.ge("creationDate", date));
    }

    if (date2 != null) {
        criteria.add(Restrictions.le("creationDate", date2));
    }

    if (proposalId != null || proposalCode != null || mainProposer != null) {
        Criteria subCritProposal = criteria.createCriteria("proposalVO");
        if (proposalId != null) {
            subCritProposal.add(Restrictions.eq("proposalId", proposalId));
        }
        if (proposalId == null && proposalCode != null && !proposalCode.isEmpty()) {
            subCritProposal.add(Restrictions.like("code", proposalCode).ignoreCase());
        }
        if ((mainProposer != null) && (!mainProposer.isEmpty())) {
            Criteria subCritPerson = subCritProposal.createCriteria("personVO");
            subCritPerson.add(Restrictions.like("familyName", mainProposer).ignoreCase());
        }

    }

    if (operatorSiteNumber != null) {
        criteria.createAlias("sessions", "se");
        criteria.add(Restrictions.eq("se.operatorSiteNumber", operatorSiteNumber));
    }

    if (withDewars) {
        criteria.setFetchMode("dewarVOs", FetchMode.JOIN);
    }
    criteria.addOrder(Order.desc("creationDate"));
    criteria.addOrder(Order.desc("shippingId"));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria.list();
}

From source file:ispyb.server.mx.daos.collections.DataCollectionGroup3DAOBean.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<DataCollectionGroup3VO> findFiltered(Integer sessionId, boolean fetchDataCollection,
        boolean fetchScreening, Integer workflowId, Integer blSampleId) {

    List<DataCollectionGroup3VO> resultList;

    Session session = (Session) this.entityManager.getDelegate();
    Criteria crit = session.createCriteria(DataCollectionGroup3VO.class);
    crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // DISTINCT RESULTS !
    if (sessionId != null) {
        Criteria subCritSession = crit.createCriteria("sessionVO");
        subCritSession.add(Restrictions.eq("sessionId", sessionId));
    }//from  w  ww .ja  v a2  s.c o m
    if (fetchDataCollection) {
        crit.setFetchMode("dataCollectionVOs", FetchMode.JOIN);
    }
    if (fetchScreening) {
        crit.setFetchMode("screeningVOs", FetchMode.JOIN);
    }

    if (workflowId != null) {
        Criteria subCritWorkflow = crit.createCriteria("workflowVO");
        subCritWorkflow.add(Restrictions.eq("workflowId", workflowId));
    }
    if (blSampleId != null) {
        Criteria subCritSample = crit.createCriteria("blSampleVO");
        subCritSample.add(Restrictions.eq("blSampleId", blSampleId));
    }
    crit.addOrder(Order.desc("startTime"));

    resultList = crit.list();
    // TODO understand why crit.setMaxResults does not work ???

    return resultList;
}

From source file:ispyb.server.mx.daos.sample.Protein3DAOBean.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Protein3VO> findFiltered(Integer proposalId, String acronym, boolean fetchCrystal,
        boolean sortByAcronym) {

    Session session = (Session) this.entityManager.getDelegate();

    Criteria crit = session.createCriteria(Protein3VO.class);
    Criteria subCrit = crit.createCriteria("proposalVO");

    crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // DISTINCT RESULTS !

    if (proposalId != null) {
        subCrit.add(Restrictions.eq("proposalId", proposalId));
    }//w w w  .j  a  va  2  s .  c o m

    if (acronym != null && !acronym.isEmpty()) {
        crit.add(Restrictions.like("acronym", acronym.toUpperCase()));
    }

    if (fetchCrystal) {
        crit.setFetchMode("crystalVOs", FetchMode.JOIN);
    }
    if (sortByAcronym) {
        crit.addOrder(Order.asc("acronym"));
    } else
        crit.addOrder(Order.desc("proteinId"));

    return crit.list();
}

From source file:ispyb.server.mx.services.collections.DataCollectionGroup3ServiceBean.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<DataCollectionGroup3VO> findFiltered(final Integer sessionId, final boolean withDataCollection,
        final boolean withScreenings) throws Exception {

    List<DataCollectionGroup3VO> resultList;

    Session session = (Session) this.entityManager.getDelegate();
    Criteria crit = session.createCriteria(DataCollectionGroup3VO.class);
    crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // DISTINCT RESULTS !
    if (sessionId != null) {
        Criteria subCritSession = crit.createCriteria("sessionVO");
        subCritSession.add(Restrictions.eq("sessionId", sessionId));
    }/*  ww  w . j av a 2s.com*/
    if (withDataCollection) {
        crit.setFetchMode("dataCollectionVOs", FetchMode.JOIN);
    }
    if (withScreenings) {
        crit.setFetchMode("screeningVOs", FetchMode.JOIN);
    }

    crit.addOrder(Order.desc("startTime"));

    resultList = crit.list();
    // TODO understand why crit.setMaxResults does not work ???

    List<DataCollectionGroup3VO> foundEntities = crit.list();
    return foundEntities;
}

From source file:ispyb.server.mx.services.collections.DataCollectionGroup3ServiceBean.java

License:Open Source License

/**
 * find groups for a given blSampleId/*w ww  .j a  v a  2  s. c om*/
 * 
 * @param sampleId
 * @return
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public List<DataCollectionGroup3VO> findBySampleId(final Integer sampleId, final boolean withDataCollection,
        final boolean withScreenings) throws Exception {

    Session session = (Session) this.entityManager.getDelegate();
    Criteria crit = session.createCriteria(DataCollectionGroup3VO.class);
    crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // DISTINCT RESULTS !

    if (withDataCollection) {
        crit.setFetchMode("dataCollectionVOs", FetchMode.JOIN);
    }
    if (withScreenings) {
        crit.setFetchMode("screeningVOs", FetchMode.JOIN);
    }

    if (sampleId != null) {
        Criteria subCritSample = crit.createCriteria("blSampleVO");
        subCritSample.add(Restrictions.eq("blSampleId", sampleId));
    }
    crit.addOrder(Order.desc("startTime"));

    // TODO understand why crit.setMaxResults does not work ???

    List<DataCollectionGroup3VO> foundEntities = crit.list();
    return foundEntities;
}

From source file:ispyb.server.mx.services.sample.Protein3ServiceBean.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Protein3VO> findByAcronymAndProposalId(final Integer proposalId, final String acronym,
        final boolean withCrystal, final boolean sortByAcronym) throws Exception {

    Session session = (Session) this.entityManager.getDelegate();

    Criteria crit = session.createCriteria(Protein3VO.class);
    Criteria subCrit = crit.createCriteria("proposalVO");

    crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // DISTINCT RESULTS !

    if (proposalId != null) {
        subCrit.add(Restrictions.eq("proposalId", proposalId));
    }/*from  w  w  w .jav a  2s.  c  o  m*/

    if (acronym != null && !acronym.isEmpty()) {
        crit.add(Restrictions.like("acronym", acronym.toUpperCase()));
    }

    if (withCrystal) {
        crit.setFetchMode("crystalVOs", FetchMode.JOIN);
    }
    if (sortByAcronym) {
        crit.addOrder(Order.asc("acronym"));
    } else
        crit.addOrder(Order.desc("proteinId"));

    List<Protein3VO> foundEntities = crit.list();
    return foundEntities;
}