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:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java

private Integer warningNoProsecutionCount(Integer roadOperationId) {
    /* Get Count of Summons For Road Operation */
    Criteria criteriaWarningNoProsecution = this.hibernateTemplate.getSessionFactory().getCurrentSession()
            .createCriteria(WarningNoProsecutionDO.class, "w");

    criteriaWarningNoProsecution.createAlias("w.roadCheckOffenceOutcome", "rout", Criteria.LEFT_JOIN);
    criteriaWarningNoProsecution.createAlias("rout.roadCheckOffence", "roff", Criteria.LEFT_JOIN);
    criteriaWarningNoProsecution.createAlias("roff.roadCheck", "rchk", Criteria.LEFT_JOIN);
    criteriaWarningNoProsecution.createAlias("rchk.compliance", "comp", Criteria.LEFT_JOIN);
    criteriaWarningNoProsecution.createAlias("comp.roadOperation", "rop", Criteria.LEFT_JOIN);

    criteriaWarningNoProsecution.add(Restrictions.eq("rop.roadOperationId", roadOperationId));

    criteriaWarningNoProsecution.setProjection(Projections.rowCount());

    criteriaWarningNoProsecution.setFetchMode("w", FetchMode.LAZY);
    criteriaWarningNoProsecution.setFlushMode(FlushMode.ALWAYS);
    Iterator iterator = criteriaWarningNoProsecution.list().iterator();

    Integer warningNoProsecutionCount = (Integer) iterator.next();

    return warningNoProsecutionCount;
}

From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java

private Integer warningNoProsecutionTeamCount(Integer roadOperationId, Integer teamId) {
    /* Get Count of Summons For Road Operation */
    Criteria criteriaWarningNoProsecution = this.hibernateTemplate.getSessionFactory().getCurrentSession()
            .createCriteria(WarningNoProsecutionDO.class, "w");

    criteriaWarningNoProsecution.createAlias("w.roadCheckOffenceOutcome", "rout", Criteria.LEFT_JOIN);
    criteriaWarningNoProsecution.createAlias("rout.roadCheckOffence", "roff", Criteria.LEFT_JOIN);
    criteriaWarningNoProsecution.createAlias("roff.roadCheck", "rchk", Criteria.LEFT_JOIN);
    criteriaWarningNoProsecution.createAlias("rchk.compliance", "comp", Criteria.LEFT_JOIN);
    criteriaWarningNoProsecution.createAlias("comp.roadOperation", "rop", Criteria.LEFT_JOIN);

    criteriaWarningNoProsecution.add(Restrictions.eq("rop.roadOperationId", roadOperationId));

    if (this.getStaffIdForTeam(teamId) != null) {
        criteriaWarningNoProsecution.add(Restrictions.in("w.taStaff.staffId", this.getStaffIdForTeam(teamId)));

        criteriaWarningNoProsecution.setProjection(Projections.rowCount());

        criteriaWarningNoProsecution.setFetchMode("w", FetchMode.LAZY);
        criteriaWarningNoProsecution.setFlushMode(FlushMode.ALWAYS);
        Iterator iterator = criteriaWarningNoProsecution.list().iterator();

        Integer warningNoProsecutionCount = (Integer) iterator.next();

        return warningNoProsecutionCount;
    } else//from  w w  w .j  a  v a2 s  . c  o  m
        return 0;
}

From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java

private Integer warningNoProsecutionCount(Integer roadOperationId, Integer personId, String personType) {
    /* Get Count of Summons For Road Operation */
    Criteria criteriaWarningNoProsecution = this.hibernateTemplate.getSessionFactory().getCurrentSession()
            .createCriteria(WarningNoticeDO.class, "w");

    criteriaWarningNoProsecution.createAlias("w.roadCheckOffenceOutcome", "rout", Criteria.LEFT_JOIN);
    criteriaWarningNoProsecution.createAlias("rout.roadCheckOffence", "roff", Criteria.LEFT_JOIN);
    criteriaWarningNoProsecution.createAlias("roff.roadCheck", "rchk", Criteria.LEFT_JOIN);
    criteriaWarningNoProsecution.createAlias("rchk.compliance", "comp", Criteria.LEFT_JOIN);
    criteriaWarningNoProsecution.createAlias("comp.roadOperation", "rop", Criteria.LEFT_JOIN);

    criteriaWarningNoProsecution.add(Restrictions.eq("rop.roadOperationId", roadOperationId));

    if (personType.equalsIgnoreCase(Constants.PersonType.TA_STAFF)) {
        criteriaWarningNoProsecution.createAlias("w.taStaff", "ta");
        criteriaWarningNoProsecution.createAlias("ta.person", "p");
    } else {// ww w.ja  v a 2s . c o m
        return -1;
    }

    criteriaWarningNoProsecution.add(Restrictions.eq("p.personId", personId));

    criteriaWarningNoProsecution.setProjection(Projections.rowCount());

    criteriaWarningNoProsecution.setFetchMode("w", FetchMode.LAZY);
    criteriaWarningNoProsecution.setFlushMode(FlushMode.ALWAYS);
    Iterator iterator = criteriaWarningNoProsecution.list().iterator();

    Integer warningNoProsecutionCount = (Integer) iterator.next();

    return warningNoProsecutionCount;
}

From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java

private Integer complianceCount(Integer roadOperationId) {
    /* Get Count of Summons For Road Operation */
    Criteria criteriaCompliance = this.hibernateTemplate.getSessionFactory().getCurrentSession()
            .createCriteria(ComplianceDO.class, "c");
    criteriaCompliance.add(Restrictions.eq("c.roadOperation.roadOperationId", roadOperationId));

    criteriaCompliance.setProjection(Projections.rowCount());

    criteriaCompliance.setFetchMode("c", FetchMode.LAZY);
    criteriaCompliance.setFlushMode(FlushMode.ALWAYS);
    Iterator iterator = criteriaCompliance.list().iterator();

    Integer complainceCount = (Integer) iterator.next();

    return complainceCount;
}

From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java

private Integer complianceTeamCount(Integer roadOperationId, Integer teamId) {
    /* Get Count of Summons For Road Operation */
    Criteria criteriaCompliance = this.hibernateTemplate.getSessionFactory().getCurrentSession()
            .createCriteria(ComplianceDO.class, "c");
    criteriaCompliance.add(Restrictions.eq("c.roadOperation.roadOperationId", roadOperationId));

    if (this.getStaffIdForTeam(teamId) != null) {
        criteriaCompliance.add(Restrictions.in("c.taStaff.staffId", this.getStaffIdForTeam(teamId)));

        criteriaCompliance.setProjection(Projections.rowCount());

        criteriaCompliance.setFetchMode("c", FetchMode.LAZY);
        criteriaCompliance.setFlushMode(FlushMode.ALWAYS);
        Iterator iterator = criteriaCompliance.list().iterator();

        Integer complainceCount = (Integer) iterator.next();

        return complainceCount;
    } else// ww w . j a va2 s  . c  om
        return 0;
}

From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java

private Integer complianceCount(Integer roadOperationId, Integer personId, String personType) {
    /* Get Count of Summons For Road Operation */
    Criteria criteriaCompliance = this.hibernateTemplate.getSessionFactory().getCurrentSession()
            .createCriteria(ComplianceDO.class, "c");
    criteriaCompliance.add(Restrictions.eq("c.roadOperation.roadOperationId", roadOperationId));

    if (personType.equalsIgnoreCase(Constants.PersonType.TA_STAFF)) {
        criteriaCompliance.createAlias("c.taStaff", "ta");
        criteriaCompliance.createAlias("ta.person", "p");
    } else {/*from ww  w.  j  a v  a  2 s . co m*/
        return -1;
    }

    criteriaCompliance.add(Restrictions.eq("p.personId", personId));

    criteriaCompliance.setProjection(Projections.rowCount());

    criteriaCompliance.setFetchMode("c", FetchMode.LAZY);
    criteriaCompliance.setFlushMode(FlushMode.ALWAYS);
    Iterator iterator = criteriaCompliance.list().iterator();

    Integer complainceCount = (Integer) iterator.next();

    return complainceCount;
}

From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java

/***************************
 * UR-057 /* w w w.j  a  v  a  2  s.  c om*/
 *********************/

private Integer absentPersonTypeCount(Integer roadOperationId, String personType) {
    /* Get Count of Absent Persons */
    Criteria criteriaAssignedPersons = this.hibernateTemplate.getSessionFactory().getCurrentSession()
            .createCriteria(AssignedPersonDO.class, "a");

    List<Integer> teamIds = getTeamIdsForRoadOp(roadOperationId);

    if (teamIds != null && teamIds.size() > 0) {
        criteriaAssignedPersons.add(Restrictions.in("a.assignedPersonKey.team.teamId", teamIds));

        criteriaAssignedPersons.add(Restrictions.eq("a.assignedPersonKey.personType.personTypeId", personType));

    }

    criteriaAssignedPersons.add(Restrictions.eq("a.attended", "n").ignoreCase());
    criteriaAssignedPersons.setProjection(Projections.count("a.attended"));
    criteriaAssignedPersons.setFetchMode("a", FetchMode.LAZY);
    Iterator iterator = criteriaAssignedPersons.list().iterator();

    Integer AbsentPersonTypeCount = (Integer) iterator.next();

    criteriaAssignedPersons.setFlushMode(FlushMode.ALWAYS);
    return AbsentPersonTypeCount;
}

From source file:gcom.atendimentopublico.RepositorioAtendimentoPublicoHBM.java

License:Open Source License

/**
 * [UC1186] Gerar Relatrio Ordem de Servio Cobrana p/Resultado
 * //from  w w w  .  j av  a  2s  .c o m
 * Pesquisar as Ordens de servios a partir de seu imvel e tipo de servio
 * 
 * @author Hugo Azevedo
 * @data 02/07/2011
 */

public Collection obterOSImovelTipoServico(Integer id, Integer tipoServico) throws ErroRepositorioException {

    Session session = HibernateUtil.getSession();
    Collection<OrdemServico> retorno = new ArrayList();

    try {

        Criteria crit = session.createCriteria(OrdemServico.class);
        crit.setFetchMode("imovel", FetchMode.JOIN);
        crit.setFetchMode("servicoTipo", FetchMode.JOIN);
        crit.setFetchMode("atendimentoMotivoEncerramento", FetchMode.JOIN);
        crit.add(Restrictions.eq("imovel.id", id));
        if (tipoServico != null && tipoServico.intValue() != -1) {
            crit.add(Restrictions.eq("servicoTipo.id", tipoServico.intValue()));
        }
        retorno = (Collection<OrdemServico>) crit.list();

    } catch (HibernateException e) {
        throw new ErroRepositorioException(e, "Erro no Hibernate");
    } finally {
        HibernateUtil.closeSession(session);
    }
    return retorno;
}

From source file:gr.abiss.calipso.hibernate.HibernateDao.java

License:Open Source License

@Override
public List<AbstractItem> findAllItems() {
    // return getHibernateTemplate().loadAll(AbstractItem.class);
    return (List<AbstractItem>) getHibernateTemplate().execute(new HibernateCallback() {
        @Override//from   w  w  w . j ava  2 s  . c  om
        public Object doInHibernate(Session session) {
            Criteria criteria = session.createCriteria(AbstractItem.class);
            criteria.setFetchMode("space", FetchMode.JOIN);
            return criteria.list();
        }
    });
}

From source file:id.co.sambaltomat.core.dao.hibernate.GenericDaoHibernate.java

protected void processJoinPath(Criteria criteria, List<JoinPath> joinPaths, ProjectionList projectionList) {
    boolean isDistinctRoot = true;
    if (joinPaths != null && !joinPaths.isEmpty()) {
        for (JoinPath joinPath : joinPaths) {
            if (joinPath.joinType == JoinType.INNER_JOIN)
                criteria.createCriteria(joinPath.path, joinPath.alias, CriteriaSpecification.INNER_JOIN);
            else if (joinPath.joinType == JoinType.LEFT_JOIN)
                criteria.createCriteria(joinPath.path, joinPath.alias, CriteriaSpecification.LEFT_JOIN);
            else if (joinPath.joinType == JoinType.NON_DISTINCT_ROOT_ENTITY)
                isDistinctRoot = false;/*  w  w w  . java 2  s .co  m*/
            else if (joinPath.joinType == JoinType.GROUPING_FIELD) {
                if (projectionList == null) {
                    projectionList = Projections.projectionList();
                }
                projectionList.add(Projections.groupProperty(joinPath.alias));
            } else
                criteria.setFetchMode(joinPath.path, FetchMode.SELECT);

        }
    }
    if (isDistinctRoot)
        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
}