Example usage for org.hibernate FetchMode JOIN

List of usage examples for org.hibernate FetchMode JOIN

Introduction

In this page you can find the example usage for org.hibernate FetchMode JOIN.

Prototype

FetchMode JOIN

To view the source code for org.hibernate FetchMode JOIN.

Click Source Link

Document

Fetch using an outer join.

Usage

From source file:ispyb.server.common.daos.shipping.Dewar3DAOBean.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Dewar3VO> findByDateWithHistory(java.sql.Date firstDate) {

    Session session = (Session) this.entityManager.getDelegate();
    Criteria criteria = session.createCriteria(Dewar3VO.class);
    Criteria shippingCriteria = criteria.createCriteria("shippingVO");

    if (firstDate != null)
        shippingCriteria.add(Restrictions.ge("creationDate", firstDate));

    criteria.addOrder(Order.desc("dewarId"));
    criteria.setFetchMode("dewarTransportHistoryVOs", FetchMode.JOIN);

    List<Dewar3VO> dewars = criteria.list();
    // dewars = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();

    return dewars;
}

From source file:ispyb.server.common.daos.shipping.Shipping3DAOBean.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from ww  w .  j  av a  2  s  . com
public List<Shipping3VO> findByStatus(String status, java.util.Date dateStart, boolean fetchDewars) {
    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 (fetchDewars) {
        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.daos.shipping.Shipping3DAOBean.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   ww  w . jav  a2 s  .  c o m*/
public List<Shipping3VO> findByBeamLineOperator(String operatorSiteNumber, boolean fetchDewars) {
    Session session = (Session) this.entityManager.getDelegate();
    Criteria criteria = session.createCriteria(Shipping3VO.class);

    if (operatorSiteNumber != null) {
        Criteria sessionCriteria = criteria.createCriteria("sessions")
                .add(Restrictions.eq("operatorSiteNumber", operatorSiteNumber));
        // .addOrder(Order.desc(propertyName))
        if (fetchDewars) {
            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.daos.shipping.Shipping3DAOBean.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*ww  w  . ja v  a  2  s.  c  om*/
public List<Shipping3VO> findFiltered(Integer proposalId, String shippingName, String proposalCode,
        Integer proposalNumber, String mainProposer, Date dateStart, Date dataEnd, String operatorSiteNumber,
        String type, boolean withDewars) {

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

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

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

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

    if (type != null) {
        criteria.add(Restrictions.like("shippingType", type));
    }

    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 (proposalId == null && proposalNumber != null)
            subCritProposal.add(Restrictions.like("number", proposalNumber).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.common.services.shipping.Dewar3ServiceBean.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/* ww  w  .  ja  va 2  s  .c  om*/
public List<Dewar3VO> findFiltered(final Integer proposalId, final Integer shippingId, final String type,
        final String code, final String barCode, final String comments, final Date date1, final Date date2,
        final String dewarStatus, final String storageLocation, final Integer dewarId,
        final Integer firstExperimentId, final boolean fetchSession, final boolean withDewarHistory,
        final boolean withContainer) throws Exception {

    try {
        Session session = (Session) this.entityManager.getDelegate();
        Criteria criteria = session.createCriteria(Dewar3VO.class);

        if (dewarId != null) {
            criteria.add(Restrictions.eq("dewarId", dewarId));
        }

        if (firstExperimentId != null) {
            Criteria sessionCriteria = criteria.createCriteria("sessionVO");
            sessionCriteria.add(Restrictions.eq("sessionId", firstExperimentId));
        }
        if (proposalId != null || shippingId != null || (date1 != null) || (date2 != null)) {

            Criteria shippingCriteria = criteria.createCriteria("shippingVO");
            if (proposalId != null) {

                Criteria proposalCriteria = shippingCriteria.createCriteria("proposalVO");
                proposalCriteria.add(Restrictions.eq("proposalId", proposalId));
            }

            if (shippingId != null) {
                shippingCriteria.add(Restrictions.eq("shippingId", shippingId));
            }

            if ((date1 != null) || (date2 != null)) {
                if (date1 != null)
                    shippingCriteria.add(Restrictions.ge("creationDate", date1));
                if (date2 != null)
                    shippingCriteria.add(Restrictions.le("creationDate", date2));
            }
        }

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

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

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

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

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

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

        if (fetchSession) {
            criteria.setFetchMode("sessionVO", FetchMode.JOIN);
            criteria.createCriteria("sessionVO");
        }

        if (withDewarHistory) {
            criteria.setFetchMode("dewarTransportHistoryVOs", FetchMode.JOIN);
        }

        if (withContainer) {
            criteria.setFetchMode("containerVOs", FetchMode.JOIN);
        }

        criteria.addOrder(Order.desc("dewarId"));

        return criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
    } catch (Exception exp) {
        exp.printStackTrace();
        return null;
    }

}

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

License:Open Source License

public List<Dewar3VO> findByDateWithHistory(final java.sql.Date firstDate) throws Exception {

    Session session = (Session) this.entityManager.getDelegate();
    Criteria criteria = session.createCriteria(Dewar3VO.class);
    Criteria shippingCriteria = criteria.createCriteria("shippingVO");

    if (firstDate != null)
        shippingCriteria.add(Restrictions.ge("creationDate", firstDate));

    criteria.addOrder(Order.desc("dewarId"));
    criteria.setFetchMode("dewarTransportHistoryVOs", FetchMode.JOIN);

    List<Dewar3VO> dewars = criteria.list();
    // dewars = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();

    return dewars;
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override/* ww  w  .  j a va2s . co  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/*  w  ww . j a  v  a  2s  . 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/*w w  w .j  ava 2 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();
}