List of usage examples for org.hibernate Criteria setFlushMode
public Criteria setFlushMode(FlushMode flushMode);
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 a 2 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 {/*from ww w . j ava2 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; }
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 va 2 s .com 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 . jav a 2 s.c o 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 /*from w w w .j av a 2s. com*/ *********************/ 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:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsHibernateUtil.java
License:Apache License
/** * Populates criteria arguments for the given target class and arguments map * * @param grailsApplication the GrailsApplication instance * @param targetClass The target class//from w ww. ja v a 2 s . co m * @param c The criteria instance * @param argMap The arguments map * */ @SuppressWarnings("rawtypes") public static void populateArgumentsForCriteria(GrailsApplication grailsApplication, Class<?> targetClass, Criteria c, Map argMap) { Integer maxParam = null; Integer offsetParam = null; SimpleTypeConverter converter = new SimpleTypeConverter(); if (argMap.containsKey(ARGUMENT_MAX)) { maxParam = converter.convertIfNecessary(argMap.get(ARGUMENT_MAX), Integer.class); } if (argMap.containsKey(ARGUMENT_OFFSET)) { offsetParam = converter.convertIfNecessary(argMap.get(ARGUMENT_OFFSET), Integer.class); } if (argMap.containsKey(ARGUMENT_FETCH_SIZE)) { c.setFetchSize(converter.convertIfNecessary(argMap.get(ARGUMENT_FETCH_SIZE), Integer.class)); } if (argMap.containsKey(ARGUMENT_TIMEOUT)) { c.setTimeout(converter.convertIfNecessary(argMap.get(ARGUMENT_TIMEOUT), Integer.class)); } if (argMap.containsKey(ARGUMENT_FLUSH_MODE)) { c.setFlushMode(converter.convertIfNecessary(argMap.get(ARGUMENT_FLUSH_MODE), FlushMode.class)); } if (argMap.containsKey(ARGUMENT_READ_ONLY)) { c.setReadOnly(GrailsClassUtils.getBooleanFromMap(ARGUMENT_READ_ONLY, argMap)); } String orderParam = (String) argMap.get(ARGUMENT_ORDER); Object fetchObj = argMap.get(ARGUMENT_FETCH); if (fetchObj instanceof Map) { Map fetch = (Map) fetchObj; for (Object o : fetch.keySet()) { String associationName = (String) o; c.setFetchMode(associationName, getFetchMode(fetch.get(associationName))); } } final String sort = (String) argMap.get(ARGUMENT_SORT); final String order = ORDER_DESC.equalsIgnoreCase(orderParam) ? ORDER_DESC : ORDER_ASC; final int max = maxParam == null ? -1 : maxParam; final int offset = offsetParam == null ? -1 : offsetParam; if (max > -1) { c.setMaxResults(max); } if (offset > -1) { c.setFirstResult(offset); } if (GrailsClassUtils.getBooleanFromMap(ARGUMENT_CACHE, argMap)) { c.setCacheable(true); } if (GrailsClassUtils.getBooleanFromMap(ARGUMENT_LOCK, argMap)) { c.setLockMode(LockMode.PESSIMISTIC_WRITE); } else { if (argMap.get(ARGUMENT_CACHE) == null) { cacheCriteriaByMapping(targetClass, c); } } if (sort != null) { boolean ignoreCase = true; Object caseArg = argMap.get(ARGUMENT_IGNORE_CASE); if (caseArg instanceof Boolean) { ignoreCase = (Boolean) caseArg; } addOrderPossiblyNested(grailsApplication, c, targetClass, sort, order, ignoreCase); } else { Mapping m = GrailsDomainBinder.getMapping(targetClass); if (m != null && !StringUtils.isBlank(m.getSort())) { addOrderPossiblyNested(grailsApplication, c, targetClass, m.getSort(), m.getOrder(), true); } } }
From source file:org.grails.orm.hibernate.cfg.GrailsHibernateUtil.java
License:Apache License
/** * Populates criteria arguments for the given target class and arguments map * * @param datastore the GrailsApplication instance * @param targetClass The target class/*from w w w . ja va2 s.c o m*/ * @param c The criteria instance * @param argMap The arguments map */ @SuppressWarnings("rawtypes") public static void populateArgumentsForCriteria(AbstractHibernateDatastore datastore, Class<?> targetClass, Criteria c, Map argMap, ConversionService conversionService, boolean useDefaultMapping) { Integer maxParam = null; Integer offsetParam = null; if (argMap.containsKey(ARGUMENT_MAX)) { maxParam = conversionService.convert(argMap.get(ARGUMENT_MAX), Integer.class); } if (argMap.containsKey(ARGUMENT_OFFSET)) { offsetParam = conversionService.convert(argMap.get(ARGUMENT_OFFSET), Integer.class); } if (argMap.containsKey(ARGUMENT_FETCH_SIZE)) { c.setFetchSize(conversionService.convert(argMap.get(ARGUMENT_FETCH_SIZE), Integer.class)); } if (argMap.containsKey(ARGUMENT_TIMEOUT)) { c.setTimeout(conversionService.convert(argMap.get(ARGUMENT_TIMEOUT), Integer.class)); } if (argMap.containsKey(ARGUMENT_FLUSH_MODE)) { c.setFlushMode(convertFlushMode(argMap.get(ARGUMENT_FLUSH_MODE))); } if (argMap.containsKey(ARGUMENT_READ_ONLY)) { c.setReadOnly(ClassUtils.getBooleanFromMap(ARGUMENT_READ_ONLY, argMap)); } String orderParam = (String) argMap.get(ARGUMENT_ORDER); Object fetchObj = argMap.get(ARGUMENT_FETCH); if (fetchObj instanceof Map) { Map fetch = (Map) fetchObj; for (Object o : fetch.keySet()) { String associationName = (String) o; c.setFetchMode(associationName, getFetchMode(fetch.get(associationName))); } } final int max = maxParam == null ? -1 : maxParam; final int offset = offsetParam == null ? -1 : offsetParam; if (max > -1) { c.setMaxResults(max); } if (offset > -1) { c.setFirstResult(offset); } if (ClassUtils.getBooleanFromMap(ARGUMENT_LOCK, argMap)) { c.setLockMode(LockMode.PESSIMISTIC_WRITE); c.setCacheable(false); } else { if (argMap.containsKey(ARGUMENT_CACHE)) { c.setCacheable(ClassUtils.getBooleanFromMap(ARGUMENT_CACHE, argMap)); } else { cacheCriteriaByMapping(targetClass, c); } } final Object sortObj = argMap.get(ARGUMENT_SORT); if (sortObj != null) { boolean ignoreCase = true; Object caseArg = argMap.get(ARGUMENT_IGNORE_CASE); if (caseArg instanceof Boolean) { ignoreCase = (Boolean) caseArg; } if (sortObj instanceof Map) { Map sortMap = (Map) sortObj; for (Object sort : sortMap.keySet()) { final String order = ORDER_DESC.equalsIgnoreCase((String) sortMap.get(sort)) ? ORDER_DESC : ORDER_ASC; addOrderPossiblyNested(datastore, c, targetClass, (String) sort, order, ignoreCase); } } else { final String sort = (String) sortObj; final String order = ORDER_DESC.equalsIgnoreCase(orderParam) ? ORDER_DESC : ORDER_ASC; addOrderPossiblyNested(datastore, c, targetClass, sort, order, ignoreCase); } } else if (useDefaultMapping) { Mapping m = GrailsDomainBinder.getMapping(targetClass); if (m != null) { Map sortMap = m.getSort().getNamesAndDirections(); for (Object sort : sortMap.keySet()) { final String order = ORDER_DESC.equalsIgnoreCase((String) sortMap.get(sort)) ? ORDER_DESC : ORDER_ASC; addOrderPossiblyNested(datastore, c, targetClass, (String) sort, order, true); } } } }
From source file:org.openspaces.persistency.hibernate.iterator.DefaultCriteriaByExampleDataIterator.java
License:Open Source License
protected Iterator createIterator() { session = sessionFactory.openSession(); transaction = session.beginTransaction(); Example example = Example.create(template); Criteria criteria = session.createCriteria(template.getClass()).add(example); criteria.setCacheMode(CacheMode.IGNORE); criteria.setCacheable(false);// ww w. j ava2 s. co m criteria.setFlushMode(FlushMode.NEVER); return criteria.list().iterator(); }
From source file:org.openspaces.persistency.hibernate.iterator.DefaultListQueryDataIterator.java
License:Open Source License
protected Iterator createIterator() { session = sessionFactory.openSession(); transaction = session.beginTransaction(); if (entityName != null) { Criteria criteria = session.createCriteria(entityName); criteria.setCacheMode(CacheMode.IGNORE); criteria.setCacheable(false);//w w w . j a v a2 s. c o m criteria.setFlushMode(FlushMode.NEVER); if (from >= 0) { criteria.setFirstResult(from); criteria.setMaxResults(size); } return criteria.list().iterator(); } else if (sqlQuery != null) { Query query = HibernateIteratorUtils.createQueryFromSQLQuery(sqlQuery, session); if (from >= 0) { query.setFirstResult(from); query.setMaxResults(size); } return query.list().iterator(); } else if (dataSourceSQLQuery != null) { Query query = HibernateIteratorUtils.createQueryFromDataSourceSQLQuery(dataSourceSQLQuery, session); if (from >= 0) { query.setFirstResult(from); query.setMaxResults(size); } return query.list().iterator(); } else { throw new IllegalStateException("Either SQLQuery or entity must be provided"); } }