List of usage examples for org.hibernate.criterion Restrictions lt
public static SimpleExpression lt(String propertyName, Object value)
From source file:com.hmsinc.epicenter.model.surveillance.impl.SurveillanceRepositoryImpl.java
License:Open Source License
/** * @param c/*from www .j ava 2 s .c om*/ * @param startDate * @param endDate * @param includeAll * @param includeFacilityLocation * @param filter * @return */ private Criteria applyAnomalyCriteria(final Criteria c, final DateTime startDate, final DateTime endDate, final boolean includeAll, final Geometry filter, final Geometry excludeFacilityEventsFilter) { if (startDate == null && endDate != null) { c.add(Restrictions.lt("analysisTimestamp", endDate)); } else if (startDate != null && endDate == null) { c.add(Restrictions.gt("analysisTimestamp", startDate)); } else if (startDate != null && endDate != null) { c.add(Restrictions.between("analysisTimestamp", startDate, endDate)); } if (!includeAll) { c.add(Restrictions.isEmpty("investigations")).createCriteria("disposition") .add(Restrictions.eq("type", WorkflowStateType.INITIAL)); } if (filter != null && excludeFacilityEventsFilter == null) { c.createCriteria("geography").add(SpatialRestrictions.withinOrFilter("geometry", filter, 1000, true)); } else if (filter == null && excludeFacilityEventsFilter != null) { final Conjunction conjunction = Restrictions.conjunction(); c.createAlias("geography", "eventGeography"); c.createAlias("task", "eventTask"); conjunction.add(Restrictions.eq("eventTask.location", AnalysisLocation.FACILITY)); conjunction.add(SpatialRestrictions.withinOrFilter("eventGeography.geometry", excludeFacilityEventsFilter, 1000, true)); c.add(Restrictions.not(conjunction)); } else if (filter != null && excludeFacilityEventsFilter != null) { final Conjunction conjunction = Restrictions.conjunction(); c.createAlias("geography", "eventGeography"); c.createAlias("task", "eventTask"); // Find events where we have unlimited access conjunction.add(SpatialRestrictions.withinOrFilter("eventGeography.geometry", filter, 1000, true)); // Filter events in the limited region final Conjunction facilityEventsConjunction = Restrictions.conjunction(); facilityEventsConjunction.add(Restrictions.eq("eventTask.location", AnalysisLocation.FACILITY)); facilityEventsConjunction.add(SpatialRestrictions.withinOrFilter("eventGeography.geometry", excludeFacilityEventsFilter, 1000, true)); conjunction.add(Restrictions.not(facilityEventsConjunction)); c.add(conjunction); } return c; }
From source file:com.hmsinc.epicenter.tools.reclassifier.Reclassifier.java
License:Open Source License
@Transactional public void run() { setup();/*from w ww . ja va 2 s .co m*/ final String destinationTable = (arguments.length > 4) ? arguments[4] : DEFAULT_TABLE_NAME; final String query = new StringBuilder("INSERT INTO ").append(destinationTable) .append(INSERT_CLASSIFICATION).toString(); final BatchSqlUpdate updater = new BatchSqlUpdate(modelDataSource, query); updater.declareParameter(new SqlParameter(Types.BIGINT)); updater.declareParameter(new SqlParameter(Types.BIGINT)); updater.setBatchSize(BATCH_SIZE); updater.compile(); final StatelessSession ss = ((Session) entityManager.getDelegate()).getSessionFactory() .openStatelessSession(); final Criteria c = ss.createCriteria(target.getInteractionClass()) .add(Restrictions.eq("patientClass", target.getPatientClass())).addOrder(Order.asc("id")) .setCacheable(false); if (arguments.length > 2) { c.add(Restrictions.gt("id", Long.valueOf(arguments[2]))); } if (arguments.length > 3) { c.add(Restrictions.lt("id", Long.valueOf(arguments[3]))); } final ScrollableResults sr = c.scroll(ScrollMode.FORWARD_ONLY); int i = 0; while (sr.next()) { final Interaction interaction = (Interaction) sr.get(0); final Set<Classification> classifications = classificationService.classify(interaction, target); save(interaction, classifications, updater); i++; if (i % BATCH_SIZE == 0) { logger.info("Processed {} interactions (current id: {})", i, interaction.getId()); } ((Session) entityManager.getDelegate()).evict(interaction); } sr.close(); updater.flush(); }
From source file:com.hypersocket.session.SessionRepositoryImpl.java
License:Open Source License
@Override public Map<String, Long> getBrowserCount(final Date startDate, final Date endDate) { List<?> ret = getCounts(Session.class, "userAgent", new CriteriaConfiguration() { @Override//ww w .j a v a 2 s . com public void configure(Criteria criteria) { criteria.add(Restrictions.ge("created", startDate)); criteria.add(Restrictions.lt("created", endDate)); criteria.add(Restrictions.eq("system", false)); } }); Map<String, Long> results = new HashMap<String, Long>(); for (Object obj : ret) { Object[] tmp = (Object[]) obj; results.put((String) tmp[0], (Long) tmp[1]); } return results; }
From source file:com.hypersocket.session.SessionRepositoryImpl.java
License:Open Source License
@Override public Map<String, Long> getIPCount(final Date startDate, final Date endDate) { List<?> ret = getCounts(Session.class, "remoteAddress", new CriteriaConfiguration() { @Override/* ww w . j a v a 2s .c om*/ public void configure(Criteria criteria) { criteria.add(Restrictions.ge("created", startDate)); criteria.add(Restrictions.lt("created", endDate)); criteria.add(Restrictions.eq("system", false)); } }); Map<String, Long> results = new HashMap<String, Long>(); for (Object obj : ret) { Object[] tmp = (Object[]) obj; results.put((String) tmp[0], (Long) tmp[1]); } return results; }
From source file:com.hypersocket.session.SessionRepositoryImpl.java
License:Open Source License
@Override public Map<String, Long> getOSCount(final Date startDate, final Date endDate) { List<?> ret = getCounts(Session.class, "os", new CriteriaConfiguration() { @Override//from w ww. j a v a 2 s . com public void configure(Criteria criteria) { criteria.add(Restrictions.ge("created", startDate)); criteria.add(Restrictions.lt("created", endDate)); criteria.add(Restrictions.eq("system", false)); } }); Map<String, Long> results = new HashMap<String, Long>(); for (Object obj : ret) { Object[] tmp = (Object[]) obj; results.put((String) tmp[0], (Long) tmp[1]); } return results; }
From source file:com.hypersocket.session.SessionRepositoryImpl.java
License:Open Source License
@Override public Long getSessionCount(final Date startDate, final Date endDate, final boolean distinctUsers) { Criteria criteria = createCriteria(Session.class); criteria.add(Restrictions.or(//w w w.j av a2 s .c o m Restrictions.and(Restrictions.ge("created", startDate), Restrictions.lt("created", endDate)), Restrictions.and(Restrictions.lt("created", startDate), Restrictions .or(Restrictions.ge("signedOut", startDate), Restrictions.isNull("signedOut"))))); criteria.add(Restrictions.eq("system", false)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); if (distinctUsers) { criteria.setProjection(Projections.countDistinct("principal")); } else { criteria.setProjection(Projections.rowCount()); } return (long) criteria.uniqueResult(); }
From source file:com.hyzy.core.orm.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion,./*from www .jav a 2 s . c o m*/ */ protected Criterion buildCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) { Assert.hasText(propertyName, "propertyName?"); Criterion criterion = null; //?MatchTypecriterion switch (matchType) { case EQ: criterion = Restrictions.eq(propertyName, propertyValue); break; case LIKE: criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE); break; case LIKEEXACT: criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.EXACT); break; case LIKESTART: criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.START); break; case LIKEEND: criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.END); break; case LE: criterion = Restrictions.le(propertyName, propertyValue); break; case LT: criterion = Restrictions.lt(propertyName, propertyValue); break; case GE: criterion = Restrictions.ge(propertyName, propertyValue); break; case GT: criterion = Restrictions.gt(propertyName, propertyValue); break; case NEQ: criterion = Restrictions.ne(propertyName, propertyValue); break; case ISN: criterion = Restrictions.isNull(propertyName); break; case ISNN: criterion = Restrictions.isNotNull(propertyName); break; case IN: criterion = Restrictions.in(propertyName, (Object[]) propertyValue); break; } return criterion; }
From source file:com.inkubator.hrm.dao.impl.EmpCareerHistoryDaoImpl.java
@Override public List<EmpCareerHistory> getByParamReport(ReportEmpMutationParameter searchParameter, int firstResult, int maxResults, Order order) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN); criteria.createAlias("jabatan", "jabatan", JoinType.INNER_JOIN); doSearchEmpRotasiByParamReport(searchParameter, criteria); DetachedCriteria maxTglPengangkatanQuery = DetachedCriteria.forClass(getEntityClass()); ProjectionList proj = Projections.projectionList(); proj.add(Projections.max("tglPenganngkatan")); proj.add(Projections.groupProperty("nik")); maxTglPengangkatanQuery.setProjection(proj); criteria.add(Subqueries.propertiesIn(new String[] { "tglPenganngkatan", "nik" }, maxTglPengangkatanQuery)); criteria.addOrder(order);/*from w w w. j a va 2 s. co m*/ criteria.setFirstResult(firstResult); criteria.setMaxResults(maxResults); List<EmpCareerHistory> listEmpCareerHistorys = criteria.list(); //Set Jabatan Lama/sebelumnya dari masing - masing record for (EmpCareerHistory ech : listEmpCareerHistorys) { Criteria criteriaOldPosition = getCurrentSession().createCriteria(getEntityClass()); criteriaOldPosition.setFetchMode("jabatan", FetchMode.JOIN); criteriaOldPosition.add(Restrictions.eq("nik", ech.getNik())); criteriaOldPosition.add(Restrictions.lt("tglPenganngkatan", ech.getTglPenganngkatan())); criteriaOldPosition.addOrder(Order.desc("tglPenganngkatan")); criteriaOldPosition.setMaxResults(1); EmpCareerHistory prevPosition = (EmpCareerHistory) criteriaOldPosition.uniqueResult(); //jika sebelumnya dia sudah pernah menjabat di posisi lain maka set oldJabatan dengan posisi tersebut if (null != prevPosition) { ech.setJabatanOldCode(prevPosition.getJabatan().getCode()); ech.setJabatanOldName(prevPosition.getJabatan().getName()); } else { ech.setJabatanOldCode("-"); } } return listEmpCareerHistorys; }
From source file:com.inkubator.hrm.dao.impl.EmpCareerHistoryDaoImpl.java
@Override public List<EmpCareerHistory> getPreviousEmpCareerByBioDataIdAndCurrentCreatedOn(Long bioDataId, Date currentCreatedOn) {/*from w w w. j ava 2 s .c o m*/ Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN); criteria.add(Restrictions.eq("bioData.id", bioDataId)); criteria.add(Restrictions.lt("createdOn", currentCreatedOn)); criteria.addOrder(Order.desc("createdOn")); criteria.setFetchMode("copyOfLetterTo", FetchMode.JOIN); criteria.setFetchMode("copyOfLetterTo.bioData", FetchMode.JOIN); criteria.setFetchMode("employeeType", FetchMode.JOIN); criteria.setFetchMode("jabatan", FetchMode.JOIN); criteria.setFetchMode("jabatan.department", FetchMode.JOIN); criteria.setFetchMode("jabatan.department.company", FetchMode.JOIN); criteria.setFetchMode("golonganJabatan", FetchMode.JOIN); criteria.setFetchMode("golonganJabatan.pangkat", FetchMode.JOIN); /*criteria.setMaxResults(1);*/ return criteria.list(); }
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
@Override public Long getTotalByAgeBetween(Date startDate, Date endDate) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); /**/* ww w . ja v a 2s .co m*/ * automatically get relations of jabatanByJabatanId, department, * company don't create alias for that entity, or will get error : * duplicate association path */ criteria = this.addJoinRelationsOfCompanyId(criteria, HrmUserInfoUtil.getCompanyId()); criteria.add(Restrictions.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN); criteria.add(Restrictions.gt("bioData.dateOfBirth", startDate)); criteria.add(Restrictions.lt("bioData.dateOfBirth", endDate)); return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); }