List of usage examples for org.hibernate.criterion Restrictions lt
public static SimpleExpression lt(String propertyName, Object value)
From source file:com.ut.healthelink.dao.impl.transactionOutDAOImpl.java
/** * The 'findInboxBatches' will return a list of received batches for the logged in user. * * @param userId The id of the logged in user trying to view received batches * @param orgId The id of the organization the user belongs to * * @return The function will return a list of received batches */// w w w . j a v a2 s . c om @Transactional @SuppressWarnings("UnusedAssignment") public List<batchDownloads> findInboxBatches(int userId, int orgId, int fromOrgId, int messageTypeId, Date fromDate, Date toDate) throws Exception { int firstResult = 0; /* Get a list of connections the user has access to */ Criteria connections = sessionFactory.getCurrentSession() .createCriteria(configurationConnectionReceivers.class); connections.add(Restrictions.eq("userId", userId)); List<configurationConnectionReceivers> userConnections = connections.list(); List<Integer> messageTypeList = new ArrayList<Integer>(); List<Integer> sourceOrgList = new ArrayList<Integer>(); if (userConnections.isEmpty()) { messageTypeList.add(0); sourceOrgList.add(0); } else { for (configurationConnectionReceivers userConnection : userConnections) { Criteria connection = sessionFactory.getCurrentSession() .createCriteria(configurationConnection.class); connection.add(Restrictions.eq("id", userConnection.getconnectionId())); configurationConnection connectionInfo = (configurationConnection) connection.uniqueResult(); /* Get the message type for the configuration */ Criteria targetconfigurationQuery = sessionFactory.getCurrentSession() .createCriteria(configuration.class); targetconfigurationQuery.add(Restrictions.eq("id", connectionInfo.gettargetConfigId())); configuration configDetails = (configuration) targetconfigurationQuery.uniqueResult(); /* Add the message type to the message type list */ if (messageTypeId == 0) { messageTypeList.add(configDetails.getMessageTypeId()); } else { if (messageTypeId == configDetails.getMessageTypeId()) { messageTypeList.add(configDetails.getMessageTypeId()); } } /* Get the list of source orgs */ Criteria sourceconfigurationQuery = sessionFactory.getCurrentSession() .createCriteria(configuration.class); sourceconfigurationQuery.add(Restrictions.eq("id", connectionInfo.getsourceConfigId())); configuration sourceconfigDetails = (configuration) sourceconfigurationQuery.uniqueResult(); /* Add the target org to the target organization list */ if (fromOrgId == 0) { sourceOrgList.add(sourceconfigDetails.getorgId()); } else { if (fromOrgId == sourceconfigDetails.getorgId()) { sourceOrgList.add(sourceconfigDetails.getorgId()); } } } } if (messageTypeList.isEmpty()) { messageTypeList.add(0); } /* Get a list of available batches */ Criteria batchSummaries = sessionFactory.getCurrentSession().createCriteria(batchDownloadSummary.class); batchSummaries.add(Restrictions.eq("targetOrgId", orgId)); batchSummaries.add(Restrictions.in("messageTypeId", messageTypeList)); batchSummaries.add(Restrictions.in("sourceOrgId", sourceOrgList)); List<batchDownloadSummary> batchDownloadSummaryList = batchSummaries.list(); List<Integer> batchIdList = new ArrayList<Integer>(); if (batchDownloadSummaryList.isEmpty()) { batchIdList.add(0); } else { for (batchDownloadSummary summary : batchDownloadSummaryList) { batchIdList.add(summary.getbatchId()); } } Criteria findBatches = sessionFactory.getCurrentSession().createCriteria(batchDownloads.class); findBatches.add(Restrictions.in("id", batchIdList)); findBatches.add(Restrictions.eq("transportMethodId", 2)); findBatches.add(Restrictions.and(Restrictions.ne("statusId", 29), /* Submission Processed Errored */ Restrictions.ne("statusId", 30), /* Target Creation Errored */ Restrictions.ne("statusId", 32) /* Submission Cancelled */ )); if (!"".equals(fromDate) && fromDate != null) { findBatches.add(Restrictions.ge("dateCreated", fromDate)); } if (!"".equals(toDate) && toDate != null) { findBatches.add(Restrictions.lt("dateCreated", toDate)); } findBatches.addOrder(Order.desc("dateCreated")); return findBatches.list(); }
From source file:com.ut.healthelink.dao.impl.transactionOutDAOImpl.java
/** * The 'getAllBatches' function will return a list of batches for the admin in the processing activities section. * * @param fromDate/*from w w w. j a va 2 s. co m*/ * @param toDate * @return This function will return a list of batch uploads * @throws Exception */ @Override @Transactional public List<batchDownloads> getAllBatches(Date fromDate, Date toDate) throws Exception { int firstResult = 0; Criteria findBatches = sessionFactory.getCurrentSession().createCriteria(batchDownloads.class); if (!"".equals(fromDate)) { findBatches.add(Restrictions.ge("dateCreated", fromDate)); } if (!"".equals(toDate)) { findBatches.add(Restrictions.lt("dateCreated", toDate)); } findBatches.addOrder(Order.desc("dateCreated")); return findBatches.list(); }
From source file:com.ut.healthelink.dao.impl.transactionOutDAOImpl.java
/** * The 'getdownloadableBatches' will return a list of received batches for the logged in user that are ready to be downloaded * * @param userId The id of the logged in user trying to view downloadable batches * @param orgId The id of the organization the user belongs to * * @return The function will return a list of downloadable batches *//*from ww w . ja va 2 s . c om*/ @Override @Transactional @SuppressWarnings("UnusedAssignment") public List<batchDownloads> getdownloadableBatches(int userId, int orgId, Date fromDate, Date toDate) throws Exception { int firstResult = 0; /* Get a list of connections the user has access to */ Criteria connections = sessionFactory.getCurrentSession() .createCriteria(configurationConnectionReceivers.class); connections.add(Restrictions.eq("userId", userId)); List<configurationConnectionReceivers> userConnections = connections.list(); List<Integer> messageTypeList = new ArrayList<Integer>(); List<Integer> sourceOrgList = new ArrayList<Integer>(); if (userConnections.isEmpty()) { messageTypeList.add(0); sourceOrgList.add(0); } else { for (configurationConnectionReceivers userConnection : userConnections) { Criteria connection = sessionFactory.getCurrentSession() .createCriteria(configurationConnection.class); connection.add(Restrictions.eq("id", userConnection.getconnectionId())); configurationConnection connectionInfo = (configurationConnection) connection.uniqueResult(); /* Get the message type for the configuration */ Criteria targetconfigurationQuery = sessionFactory.getCurrentSession() .createCriteria(configuration.class); targetconfigurationQuery.add(Restrictions.eq("id", connectionInfo.gettargetConfigId())); configuration configDetails = (configuration) targetconfigurationQuery.uniqueResult(); /* Need to make sure only file download configurations are displayed */ Criteria transportDetailsQuery = sessionFactory.getCurrentSession() .createCriteria(configurationTransport.class); transportDetailsQuery.add(Restrictions.eq("configId", configDetails.getId())); configurationTransport transportDetails = (configurationTransport) transportDetailsQuery .uniqueResult(); if (transportDetails.gettransportMethodId() == 1) { /* Add the message type to the message type list */ messageTypeList.add(configDetails.getMessageTypeId()); } /* Get the list of source orgs */ Criteria sourceconfigurationQuery = sessionFactory.getCurrentSession() .createCriteria(configuration.class); sourceconfigurationQuery.add(Restrictions.eq("id", connectionInfo.getsourceConfigId())); configuration sourceconfigDetails = (configuration) sourceconfigurationQuery.uniqueResult(); /* Add the target org to the target organization list */ sourceOrgList.add(sourceconfigDetails.getorgId()); } } if (messageTypeList.isEmpty()) { messageTypeList.add(0); } /* Get a list of available batches */ Criteria batchSummaries = sessionFactory.getCurrentSession().createCriteria(batchDownloadSummary.class); batchSummaries.add(Restrictions.eq("targetOrgId", orgId)); batchSummaries.add(Restrictions.in("messageTypeId", messageTypeList)); batchSummaries.add(Restrictions.in("sourceOrgId", sourceOrgList)); List<batchDownloadSummary> batchDownloadSummaryList = batchSummaries.list(); List<Integer> batchIdList = new ArrayList<Integer>(); if (batchDownloadSummaryList.isEmpty()) { batchIdList.add(0); } else { for (batchDownloadSummary summary : batchDownloadSummaryList) { batchIdList.add(summary.getbatchId()); } } Criteria findBatches = sessionFactory.getCurrentSession().createCriteria(batchDownloads.class); findBatches.add(Restrictions.in("id", batchIdList)); findBatches.add(Restrictions.eq("transportMethodId", 1)); findBatches.add(Restrictions.or(Restrictions.eq("statusId", 22), Restrictions.eq("statusId", 23), Restrictions.eq("statusId", 28))); if (!"".equals(fromDate)) { findBatches.add(Restrictions.ge("dateCreated", fromDate)); } if (!"".equals(toDate)) { findBatches.add(Restrictions.lt("dateCreated", toDate)); } findBatches.addOrder(Order.desc("dateCreated")); return findBatches.list(); }
From source file:com.ut.healthelink.dao.impl.transactionOutDAOImpl.java
/** * The 'getPendingTransactions' method will return all pending target transactions based on the org and message type passed in. * * @param orgId The id of the organzition to return pending transactions * @param messageType The id of the message type to return pending transactions * * @return This function will return a list of transactionTargets *///from w w w. j a v a 2 s . c om @Override @Transactional public List<transactionTarget> getPendingDeliveryTransactions(int orgId, int messageType, Date fromDate, Date toDate) throws Exception { List<Integer> configIds = new ArrayList<Integer>(); Criteria listConfigs = sessionFactory.getCurrentSession().createCriteria(configuration.class); listConfigs.add(Restrictions.eq("orgId", orgId)); listConfigs.add(Restrictions.eq("messageTypeId", messageType)); List<configuration> configs = listConfigs.list(); for (configuration config : configs) { if (!configIds.contains(config.getId())) { configIds.add(config.getId()); } } Criteria transactions = sessionFactory.getCurrentSession().createCriteria(transactionTarget.class); transactions.add(Restrictions.in("configId", configIds)); transactions.add(Restrictions.eq("statusId", 9)); transactions.add(Restrictions.eq("batchDLId", 0)); if (!"".equals(fromDate)) { transactions.add(Restrictions.ge("dateCreated", fromDate)); } if (!"".equals(toDate)) { transactions.add(Restrictions.lt("dateCreated", toDate)); } return transactions.list(); }
From source file:com.ut.tekir.contact.ContactStatusBean.java
License:LGPL
/** * nce devir hesaplayalm.../*from ww w. j a v a 2 s . c o m*/ * */ @SuppressWarnings("unchecked") protected void calculateOffset() { HibernateSessionProxy session = (HibernateSessionProxy) entityManager.getDelegate(); Calendar cal = Calendar.getInstance(); cal.set(getYear(), 0, 1); Date beginDate = cal.getTime(); Criteria crit = session.createCriteria(FinanceTxn.class); crit.add(Restrictions.eq("contact", contact)).add(Restrictions.lt("date", beginDate)) .add(Restrictions.eq("active", true)); //Tarih kontrol yaplacak crit.setProjection(Projections.projectionList() .add(Projections.groupProperty("amount.currency"), "amountCurrency") .add(Projections.groupProperty("action"), "action").add(Projections.sum("amount.value"), "amount") .add(Projections.sum("localAmount.value"), "localAmount")); List ls = crit.list(); for (Iterator it = ls.iterator(); it.hasNext();) { Object obj[] = (Object[]) it.next(); dataTable.addRow("OPEN", (String) obj[0], (FinanceAction) obj[1], (Double) obj[2], (Double) obj[3]); } }
From source file:com.ut.tekir.contact.ContactStatusBean.java
License:LGPL
@SuppressWarnings("unchecked") private void calculateMonth(Integer month) { String rowKey = "MONTH" + (month < 10 ? "0" + month : month); Calendar cal = Calendar.getInstance(); cal.set(getYear(), month, 1);//from w w w . j ava2 s . c o m Date beginDate = cal.getTime(); if (month == 12) { cal.set(getYear() + 1, 1, 1); } else { cal.set(getYear(), month + 1, 1); } Date endDate = cal.getTime(); HibernateSessionProxy session = (HibernateSessionProxy) entityManager.getDelegate(); Criteria crit = session.createCriteria(FinanceTxn.class); crit.add(Restrictions.eq("contact", contact)).add(Restrictions.ge("date", beginDate)) .add(Restrictions.lt("date", endDate)).add(Restrictions.eq("active", true)); //Tarih kontrol yaplacak crit.setProjection(Projections.projectionList() .add(Projections.groupProperty("amount.currency"), "amountCurrency") .add(Projections.groupProperty("action"), "action").add(Projections.sum("amount.value"), "amount") .add(Projections.sum("localAmount.value"), "localAmount")); List ls = crit.list(); for (Iterator it = ls.iterator(); it.hasNext();) { Object obj[] = (Object[]) it.next(); dataTable.addRow(rowKey, (String) obj[0], (FinanceAction) obj[1], (Double) obj[2], (Double) obj[3]); } }
From source file:com.wdeanmedical.portal.persistence.AppDAO.java
License:LGPL
public List<Appointment> getAppointments(Patient patient, boolean isPast) throws Exception { Session session = this.getSession(); Criteria crit = session.createCriteria(Appointment.class); crit.add(Restrictions.eq("patient", patient)); if (isPast) { crit.add(Restrictions.lt("startTime", new Date())); } else {//from w w w. j ava 2 s . co m crit.add(Restrictions.ge("startTime", new Date())); } List<Appointment> list = crit.list(); return list; }
From source file:com.webbfontaine.valuewebb.search.custom.UserCriterion.java
License:Open Source License
public Criterion getCriterion() throws Exception { if (condition.equals(EQ)) { if (value == null || value.toString().trim().length() == 0) { return Restrictions.isNull(fullKey); } else {//from w ww . j av a 2s . c o m return Restrictions.eq(fullKey, value); } } if (condition.equals(NE)) { if (value == null || value.toString().trim().length() == 0) { return Restrictions.isNotNull(fullKey); } else { return Restrictions.ne(fullKey, value); } } if (condition.equals(GT)) { assertNonNullity(value); return Restrictions.gt(fullKey, value); } if (condition.equals(GE)) { assertNonNullity(value); return Restrictions.ge(fullKey, value); } if (condition.equals(LT)) { assertNonNullity(value); return Restrictions.lt(fullKey, value); } if (condition.equals(LE)) { assertNonNullity(value); return Restrictions.le(fullKey, value); } if (condition.equals(IN_A_RANGE)) { assertNonNullity(value); assertNonNullity(diff); return getPercentRange(); } if (condition.equals(ENDS_WITH)) { return Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString())); } if (condition.equals(STARTS_WITH)) { return Restrictions.like(fullKey, StringUtils.trim(value.toString()) + "%"); } if (condition.equals(CONTAINS)) { return Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString()) + '%'); } if (condition.equals(NOT_CONTAIN)) { return Restrictions.not(Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString()) + '%')); } LOGGER.error( "Undefined User Criteria [key:{0}, value:{1}, condition:{3}] couldn't be transformed to search criterion", fullKey, value, condition); throw new RuntimeException("Undefined User Criteria: " + name); }
From source file:com.wontheone.hiber01.DataProvider.java
public static List<Car> getCarsByLessThanPrice(double price) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null;/*from w w w. jav a 2 s. c o m*/ List<Car> listCar = null; try { tx = session.beginTransaction(); Criteria criteria = session.createCriteria(Car.class); criteria.add(Restrictions.lt("price", price)); listCar = (List<Car>) criteria.list(); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } e.printStackTrace(); } finally { session.close(); } return listCar; }
From source file:com.wwinsoft.modules.orm.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion,./*w w w . ja v a 2s . co m*/ */ protected Criterion buildCriterion(final String propertyName, final Object propertyValue, final PropertyFilter.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 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); } return criterion; }