Example usage for org.hibernate FlushMode ALWAYS

List of usage examples for org.hibernate FlushMode ALWAYS

Introduction

In this page you can find the example usage for org.hibernate FlushMode ALWAYS.

Prototype

FlushMode ALWAYS

To view the source code for org.hibernate FlushMode ALWAYS.

Click Source Link

Document

The Session is flushed before every query.

Usage

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

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

    List<Integer> teamIds = this.getTeamIdsForRoadOp(roadOperationId);

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

    criteriaAssignedPersons.setProjection(Projections.rowCount());
    criteriaAssignedPersons.setFetchMode("a", FetchMode.LAZY);
    Iterator iterator = criteriaAssignedPersons.list().iterator();

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

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

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

private Integer teamMemberPersonTeamCount(Integer teamId) {
    /* Get Count of Absent Persons */
    Criteria criteriaAssignedPersons = this.hibernateTemplate.getSessionFactory().getCurrentSession()
            .createCriteria(AssignedPersonDO.class, "a");
    criteriaAssignedPersons.add(Restrictions.eq("a.assignedPersonKey.team.teamId", teamId));

    criteriaAssignedPersons.setProjection(Projections.rowCount());
    criteriaAssignedPersons.setFetchMode("a", FetchMode.LAZY);
    Iterator iterator = criteriaAssignedPersons.list().iterator();

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

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

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

private Integer summonsTeamCount(Integer roadOperationId, Integer teamId) {
    /* Get Count of Summons For Road Operation */
    Criteria criteriaSummons = this.hibernateTemplate.getSessionFactory().getCurrentSession()
            .createCriteria(SummonsDO.class, "s");

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

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

    /* Get list of ta staff ids which are on a team. */
    Criteria criteria = this.hibernateTemplate.getSessionFactory().getCurrentSession()
            .createCriteria(SummonsDO.class, "team");

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

        criteriaSummons.setProjection(Projections.rowCount());

        criteriaSummons.setFetchMode("s", FetchMode.LAZY);
        criteriaSummons.setFlushMode(FlushMode.ALWAYS);

        Iterator iterator = criteriaSummons.list().iterator();

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

        return summonsCount;
    } else/* w w w . ja  v a 2s.  com*/
        return 0;
}

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

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

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

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

    criteriaWarningNotice.setProjection(Projections.rowCount());

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

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

    return warningNoticeCount;
}

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

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

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

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

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

        criteriaWarningNotice.setProjection(Projections.rowCount());

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

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

        return warningNoticeCount;
    } else/*w ww.j a v a 2 s.c  o m*/
        return 0;
}

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

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

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

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

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

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

    criteriaWarningNotice.setProjection(Projections.rowCount());

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

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

    return warningNoticeCount;
}

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/*  w  w  w .j a v  a2 s  .co 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 {// w ww . j  ava 2  s .  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;
}