List of usage examples for org.hibernate FetchMode LAZY
FetchMode LAZY
To view the source code for org.hibernate FetchMode LAZY.
Click Source Link
From source file:com.ihsolution.hqipo.dao.utils.QueryHelper.java
License:Open Source License
/** * convert the InputDTO to QueryHelper to get the count (omitting sort order) *///from ww w .ja v a2 s.c o m @SuppressWarnings("deprecation") public QueryHelper convertDtoToQhelperForCount(InputDTO dto) { if (dto == null) return this; this.dto = dto; int ind = 0; try { Junction j = null; Junction conj = Restrictions.conjunction(); Junction disj = Restrictions.disjunction(); String operator = ""; boolean disjB = false, conjB = false; if (dto.getFetchMode() != null) { for (Map.Entry<String, String> entry : dto.getFetchMode().entrySet()) { FetchMode fmode = null; logger.debug("FetchMode key=" + entry.getKey() + " val=" + entry.getValue()); if (entry.getValue().equals("join")) fmode = FetchMode.JOIN; else if (entry.getValue().equals("eager")) fmode = FetchMode.EAGER; else if (entry.getValue().equals("lazy")) fmode = FetchMode.LAZY; else fmode = FetchMode.LAZY; this.detCriteria.setFetchMode(entry.getKey(), fmode); } } for (String field : dto.getFields()) { operator = dto.getOperators().get(ind); if ("or".equals(operator)) { j = disj; disjB = true; } else { j = conj; conjB = true; } this.addFieldAndVal(createAliases(field), dto.getValues().get(ind), dto.getOperations().get(ind), j); ind++; } if (dto.getExpressions() != null) { for (String expr : dto.getExpressions()) { j.add(Expression.sql(expr)); } } if (dto.getFieldsToSelect() != null && dto.getFieldsToSelect().length > 0) { ProjectionList prList = Projections.projectionList(); Projection projection = null; for (String fld : dto.getFieldsToSelect()) { String als = this.createAliases(fld); prList.add(Projections.property(als)); } if (dto.isDistinct()) { projection = Projections.distinct(prList); } else { projection = prList; } this.detCriteria.setProjection(projection); } else { this.fldSelectedSet = false; } if (disjB) detCriteria.add(disj); if (conjB) detCriteria.add(conj); if (logger.isDebugEnabled()) { if (conjB) logger.debug("conjuction=" + conj.toString()); if (disjB) logger.debug("disjunction=" + disj.toString()); } if (dto.isDistinct()) detCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); } catch (Exception e) { e.printStackTrace(); logger.error(e); } return this; }
From source file:com.smartitengineering.dao.impl.hibernate.AbstractDAO.java
License:Open Source License
@SuppressWarnings("unchecked") private void processNestedParameter(Criteria criteria, String element, QueryParameter parameter) { FetchMode mode;//from w w w . j ava2 s .c o m CompositionQueryParameter queryParameter = QueryParameterCastHelper.COMPOSITION_PARAM_FOR_NESTED_TYPE .cast(parameter); switch (queryParameter.getFetchMode()) { case EAGER: mode = FetchMode.EAGER; break; case SELECT: mode = FetchMode.SELECT; break; case JOIN: mode = FetchMode.JOIN; break; case LAZY: mode = FetchMode.LAZY; break; default: case DEFAULT: mode = FetchMode.DEFAULT; break; } criteria.setFetchMode(element, ((mode == null) ? FetchMode.JOIN : mode)); Collection<QueryParameter> nestedParameters = queryParameter.getNestedParameters(); if (nestedParameters == null || nestedParameters.size() <= 0) { return; } Criteria nestedCriteria = criteria.createCriteria(element); for (QueryParameter nestedQueryParameter : nestedParameters) { if (!nestedQueryParameter.isInitialized()) { continue; } processCriteria(nestedCriteria, getPropertyName(nestedQueryParameter), nestedQueryParameter); } }
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//from w w w. j a va 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// w w w.j a v a2 s . c om 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 w w . j av a2s. 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; }