List of usage examples for org.hibernate Criteria setFlushMode
public Criteria setFlushMode(FlushMode flushMode);
From source file:com.heliosapm.aa4h.parser.XMLQueryParser.java
License:Apache License
/** * Initializes a Criteria Query.//from w w w .j a v a2 s . c o m * Mandatory Attributes:<ul> * <li><b>name</b>: The unqualified class name driving the criteria query.</li> * </ul> * Optional Attributes:<ul> * <li><b>prefix</b>: The package name of the class driving the criteria query. If null, no package is assumed.</li> * <li><b>maxSize</b>: The maximum number of rows to return from the database.</li> * <li><b>fetchSize</b>: The number of rows to fetch when rows are requested. Usually not useful for AA4H.</li> * <li><b>cacheEnabled</b>: Enables or disables caching for the queried objects.</li> * <li><b>cacheMode</b>: The cache options for the queried objects.</li> * <li><b>flushMode</b>: The session flush options.</li> * <li><b>fetchMode</b>: The collection fetch options for the query.</li> * <li><b>lockMode</b>: The row lock options for the queried rows.</li> * <li><b>timeOut</b>: The query timeout option.</li> * <li><b>rowCountOnly</b>: Returns a count of the query rows only.</li> * </ul> * @param attrs The attributes of the processed node. * @return An appended or new CriteriaSpecification * @throws SAXException */ protected CriteriaSpecification processCriteria(Attributes attrs) throws SAXException { if (inDetached) { return criteriaStack.peek(); } String name = attrs.getValue("name"); String prefix = attrs.getValue("prefix"); if (prefix != null) { className = prefix + "." + name; } else { className = name; } String maxSize = attrs.getValue("maxSize"); String fetchSize = attrs.getValue("fetchSize"); String firstResult = attrs.getValue("firstResult"); String cacheEnabled = attrs.getValue("cacheEnabled"); String cacheMode = attrs.getValue("cacheMode"); String flushMode = attrs.getValue("flushMode"); String fetchMode = attrs.getValue("fetchMode"); String lockMode = attrs.getValue("lockMode"); String timeOut = attrs.getValue("timeOut"); String rowCountOnly = attrs.getValue("rowCountOnly"); Criteria newCriteria = null; try { if (criteriaStack.size() == 0) { newCriteria = session.createCriteria(className); } else { newCriteria = ((Criteria) criteriaStack.peek()).createCriteria(className); } criteriaStack.push(newCriteria); if ("true".equalsIgnoreCase(rowCountOnly)) { newCriteria.setProjection(Projections.projectionList().add(Projections.rowCount()) ); setRowCountOnly(true); } if (maxSize != null && isRowCountOnly() == false) { newCriteria.setMaxResults(Integer.parseInt(maxSize)); } if (fetchSize != null && isRowCountOnly() == false) { newCriteria.setFetchSize(Integer.parseInt(fetchSize)); } if (firstResult != null && isRowCountOnly() == false) { newCriteria.setFirstResult(Integer.parseInt(firstResult)); } if (timeOut != null) { newCriteria.setTimeout(Integer.parseInt(timeOut)); } if ("true".equalsIgnoreCase(cacheEnabled)) { newCriteria.setCacheable(true); } else if ("false".equalsIgnoreCase(cacheEnabled)) { newCriteria.setCacheable(false); } if (fetchMode != null && fetchMode.length() > 0) { if ("JOIN".equalsIgnoreCase(fetchMode)) { newCriteria.setFetchMode(name, FetchMode.JOIN); } else if ("SELECT".equalsIgnoreCase(fetchMode)) { newCriteria.setFetchMode(name, FetchMode.SELECT); } else { newCriteria.setFetchMode(name, FetchMode.DEFAULT); } } else { newCriteria.setFetchMode(name, FetchMode.DEFAULT); } if (cacheMode != null && cacheMode.length() > 0) { if ("GET".equalsIgnoreCase(cacheMode)) { newCriteria.setCacheMode(CacheMode.GET); } else if ("IGNORE".equalsIgnoreCase(cacheMode)) { newCriteria.setCacheMode(CacheMode.IGNORE); } else if ("NORMAL".equalsIgnoreCase(cacheMode)) { newCriteria.setCacheMode(CacheMode.NORMAL); } else if ("PUT".equalsIgnoreCase(cacheMode)) { newCriteria.setCacheMode(CacheMode.PUT); } else if ("REFRESH".equalsIgnoreCase(cacheMode)) { newCriteria.setCacheMode(CacheMode.REFRESH); } else { newCriteria.setCacheMode(CacheMode.NORMAL); } } if (lockMode != null && lockMode.length() > 0) { if ("NONE".equalsIgnoreCase(lockMode)) { newCriteria.setLockMode(LockMode.NONE); } else if ("READ".equalsIgnoreCase(lockMode)) { newCriteria.setLockMode(LockMode.READ); } else if ("UPGRADE".equalsIgnoreCase(lockMode)) { newCriteria.setLockMode(LockMode.UPGRADE); } else if ("UPGRADE_NOWAIT".equalsIgnoreCase(lockMode)) { newCriteria.setLockMode(LockMode.UPGRADE_NOWAIT); } else if ("WRITE".equalsIgnoreCase(lockMode)) { newCriteria.setLockMode(LockMode.WRITE); } else { throw new SAXException("lockMode[" + lockMode + "] Not Recognized"); } } if (flushMode != null && flushMode.length() > 0) { if ("ALWAYS".equalsIgnoreCase(flushMode)) { newCriteria.setFlushMode(FlushMode.ALWAYS); } else if ("AUTO".equalsIgnoreCase(flushMode)) { newCriteria.setFlushMode(FlushMode.AUTO); } else if ("COMMIT".equalsIgnoreCase(flushMode)) { newCriteria.setFlushMode(FlushMode.COMMIT); } else if ("NEVER".equalsIgnoreCase(flushMode)) { // NEVER is deprecated, so we won't throw an exception but we'll ignore it. } else { throw new SAXException("flushMode[" + flushMode + "] Not Recognized"); } } return newCriteria; } catch (Exception e) { throw new SAXException("Unable to configure class " + className, e); } }
From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java
private Integer absentPersonCount(Integer roadOperationId) { /* 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.attended", "n").ignoreCase()); criteriaAssignedPersons.setProjection(Projections.count("a.attended")); 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 absentPersonTeamCount(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.add(Restrictions.eq("a.attended", "n").ignoreCase()); criteriaAssignedPersons.setProjection(Projections.count("a.attended")); 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 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/*ww w. j ava 2 s. co m*/ 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//from ww w .java 2s . co 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 {// w ww . j a v a2 s . 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; }