List of usage examples for org.hibernate.criterion Restrictions gt
public static SimpleExpression gt(String propertyName, Object value)
From source file:jp.ac.tokushima_u.is.ll.common.orm.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion?,.//from w w w. j a v a 2 s . c om */ protected Criterion buildPropertyFilterCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) { Assert.hasText(propertyName, "propertyName should not be null"); Criterion criterion = null; try { //MatchType?criterion? if (MatchType.EQ.equals(matchType)) { criterion = Restrictions.eq(propertyName, propertyValue); } else if (MatchType.LIKE.equals(matchType)) { criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE); } else if (MatchType.LE.equals(matchType)) { criterion = Restrictions.le(propertyName, propertyValue); } else if (MatchType.LT.equals(matchType)) { criterion = Restrictions.lt(propertyName, propertyValue); } else if (MatchType.GE.equals(matchType)) { criterion = Restrictions.ge(propertyName, propertyValue); } else if (MatchType.GT.equals(matchType)) { criterion = Restrictions.gt(propertyName, propertyValue); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return criterion; }
From source file:kr.debop4j.access.test.repository.CriteriaSampleTest.java
License:Apache License
@Test @Transactional(readOnly = true)/* w w w. j a v a2 s. co m*/ public void simpleWhere() { DetachedCriteria dc = DetachedCriteria.forClass(Employee.class); dc.add(Restrictions.eq("name", "Smith")); Employee employee = hibernateDao.findUnique(Employee.class, dc); log.info("Employee=[{}]", employee); dc.add(Restrictions.gt("age", 40)); employee = hibernateDao.findUnique(Employee.class, dc); log.info("Employee=[{}]", employee); }
From source file:main.java.info.jtrac.domain.ColumnHeading.java
License:Apache License
private Object process(Component c, DetachedCriteria criteria) { boolean forFragment = c != null; List<Expression> list = new ArrayList<Expression>(); Fragment fragment = null;//w ww. j av a 2s .c o m List values = filterCriteria.getValues(); Object value = filterCriteria.getValue(); Object value2 = filterCriteria.getValue2(); Expression expression = filterCriteria.getExpression(); if (isField()) { switch (field.getName().getType()) { case 1: case 2: case 3: list.add(Expression.IN); if (forFragment) { fragment = new Fragment("fragParent", "multiSelect"); final Map<String, String> options = field.getOptions(); JtracCheckBoxMultipleChoice choice = new JtracCheckBoxMultipleChoice("values", new ArrayList(options.keySet()), new IChoiceRenderer() { /** * */ private static final long serialVersionUID = 1L; public Object getDisplayValue(Object o) { return options.get(o); } public String getIdValue(Object o, int i) { return o.toString(); } }); fragment.add(choice); choice.setModel(new PropertyModel(this, "filterCriteria.values")); } if (filterHasValueList(criteria)) { List<Integer> keys = new ArrayList<Integer>(values.size()); for (Object o : values) { keys.add(new Integer(o.toString())); } criteria.add(Restrictions.in(name, keys)); } break; // drop down list case 4: // decimal number list.add(Expression.EQ); list.add(Expression.NOT_EQ); list.add(Expression.GT); list.add(Expression.LT); list.add(Expression.BETWEEN); if (forFragment) { fragment = new Fragment("fragParent", "textField"); TextField textField = new TextField("value", Double.class); textField.setModel(new PropertyModel(this, "filterCriteria.value")); fragment.add(textField); if (expression == Expression.BETWEEN) { TextField textField2 = new TextField("value2", Double.class); textField.setModel(new PropertyModel(this, "filterCriteria.value2")); fragment.add(textField2); } else { fragment.add(new WebMarkupContainer("value2").setVisible(false)); } } if (filterHasValue(criteria)) { switch (expression) { case EQ: criteria.add(Restrictions.eq(name, value)); break; case NOT_EQ: criteria.add(Restrictions.not(Restrictions.eq(name, value))); break; case GT: criteria.add(Restrictions.gt(name, value)); break; case LT: criteria.add(Restrictions.lt(name, value)); break; case BETWEEN: criteria.add(Restrictions.gt(name, value)); criteria.add(Restrictions.lt(name, value2)); break; default: } } break; case 6: // date list.add(Expression.EQ); list.add(Expression.NOT_EQ); list.add(Expression.GT); list.add(Expression.LT); list.add(Expression.BETWEEN); if (forFragment) { fragment = new Fragment("fragParent", "dateField"); YuiCalendar calendar = new YuiCalendar("value", new PropertyModel(this, "filterCriteria.value"), false); fragment.add(calendar); if (filterCriteria.getExpression() == Expression.BETWEEN) { YuiCalendar calendar2 = new YuiCalendar("value2", new PropertyModel(this, "filterCriteria.value2"), false); fragment.add(calendar2); } else { fragment.add(new WebMarkupContainer("value2").setVisible(false)); } } if (filterHasValue(criteria)) { switch (expression) { case EQ: criteria.add(Restrictions.eq(name, value)); break; case NOT_EQ: criteria.add(Restrictions.not(Restrictions.eq(name, value))); break; case GT: criteria.add(Restrictions.gt(name, value)); break; case LT: criteria.add(Restrictions.lt(name, value)); break; case BETWEEN: criteria.add(Restrictions.gt(name, value)); criteria.add(Restrictions.lt(name, value2)); break; default: } } break; case 5: // free text list.add(Expression.CONTAINS); if (forFragment) { fragment = new Fragment("fragParent", "textField"); TextField textField = new TextField("value", String.class); textField.setModel(new PropertyModel(this, "filterCriteria.value")); fragment.add(textField); fragment.add(new WebMarkupContainer("value2").setVisible(false)); } if (filterHasValue(criteria)) { criteria.add(Restrictions.ilike(name, (String) value, MatchMode.ANYWHERE)); } break; default: throw new RuntimeException("Unknown Column Heading " + name); } } else { if (name.equals(ID)) { list.add(Expression.EQ); if (forFragment) { fragment = new Fragment("fragParent", "textField"); TextField textField = new TextField("value", String.class); textField.setModel(new PropertyModel(this, "filterCriteria.value")); fragment.add(textField); fragment.add(new WebMarkupContainer("value2").setVisible(false)); } // should never come here for criteria: see ItemSearch#getRefId() } else if (name.equals(SUMMARY)) { list.add(Expression.CONTAINS); if (forFragment) { fragment = new Fragment("fragParent", "textField"); TextField textField = new TextField("value", String.class); textField.setModel(new PropertyModel(this, "filterCriteria.value")); fragment.add(textField); fragment.add(new WebMarkupContainer("value2").setVisible(false)); } if (filterHasValue(criteria)) { criteria.add(Restrictions.ilike(name, (String) value, MatchMode.ANYWHERE)); } } else if (name.equals(DETAIL)) { list.add(Expression.CONTAINS); if (forFragment) { fragment = new Fragment("fragParent", "textField"); TextField textField = new TextField("value", String.class); textField.setModel(new PropertyModel(this, "filterCriteria.value")); fragment.add(textField); fragment.add(new WebMarkupContainer("value2").setVisible(false)); } // should never come here for criteria: see ItemSearch#getSearchText() } else if (name.equals(STATUS)) { list.add(Expression.IN); if (forFragment) { fragment = new Fragment("fragParent", "multiSelect"); final Map<Integer, String> options = ComponentUtils.getCurrentSpace(c).getMetadata() .getStates(); options.remove(State.NEW); JtracCheckBoxMultipleChoice choice = new JtracCheckBoxMultipleChoice("values", new ArrayList(options.keySet()), new IChoiceRenderer() { /** * */ private static final long serialVersionUID = 1L; public Object getDisplayValue(Object o) { return options.get(o); } public String getIdValue(Object o, int i) { return o.toString(); } }); fragment.add(choice); choice.setModel(new PropertyModel(this, "filterCriteria.values")); } if (filterHasValueList(criteria)) { criteria.add(Restrictions.in(name, filterCriteria.getValues())); } } else if (name.equals(ASSIGNED_TO) || name.equals(LOGGED_BY)) { list.add(Expression.IN); if (forFragment) { fragment = new Fragment("fragParent", "multiSelect"); List<User> users = null; Space s = ComponentUtils.getCurrentSpace(c); if (s == null) { User u = ComponentUtils.getPrincipal(c); users = ComponentUtils.getJtrac(c).findUsersForUser(u); } else { users = ComponentUtils.getJtrac(c).findUsersForSpace(s.getId()); } JtracCheckBoxMultipleChoice choice = new JtracCheckBoxMultipleChoice("values", users, new IChoiceRenderer() { /** * */ private static final long serialVersionUID = 1L; public Object getDisplayValue(Object o) { return ((User) o).getName(); } public String getIdValue(Object o, int i) { return ((User) o).getId() + ""; } }); fragment.add(choice); choice.setModel(new PropertyModel(this, "filterCriteria.values")); } if (filterHasValueList(criteria)) { criteria.add(Restrictions.in(name, filterCriteria.getValues())); } } else if (name.equals(TIME_STAMP)) { list.add(Expression.BETWEEN); list.add(Expression.GT); list.add(Expression.LT); if (forFragment) { fragment = new Fragment("fragParent", "dateField"); YuiCalendar calendar = new YuiCalendar("value", new PropertyModel(this, "filterCriteria.value"), false); fragment.add(calendar); if (expression == Expression.BETWEEN) { YuiCalendar calendar2 = new YuiCalendar("value2", new PropertyModel(this, "filterCriteria.value2"), false); fragment.add(calendar2); } else { fragment.add(new WebMarkupContainer("value2").setVisible(false)); } } if (filterHasValue(criteria)) { switch (expression) { case GT: criteria.add(Restrictions.gt(name, value)); break; case LT: criteria.add(Restrictions.lt(name, value)); break; case BETWEEN: criteria.add(Restrictions.gt(name, value)); criteria.add(Restrictions.lt(name, value2)); break; default: } } } else if (name.equals(SPACE)) { list.add(Expression.IN); if (forFragment) { fragment = new Fragment("fragParent", "multiSelect"); List<Space> spaces = new ArrayList(ComponentUtils.getPrincipal(c).getSpaces()); JtracCheckBoxMultipleChoice choice = new JtracCheckBoxMultipleChoice("values", spaces, new IChoiceRenderer() { /** * */ private static final long serialVersionUID = 1L; public Object getDisplayValue(Object o) { return ((Space) o).getName(); } public String getIdValue(Object o, int i) { return ((Space) o).getId() + ""; } }); fragment.add(choice); choice.setModel(new PropertyModel(this, "filterCriteria.values")); } // should never come here for criteria: see ItemSearch#getSelectedSpaces() } else { throw new RuntimeException("Unknown Column Heading " + name); } } if (forFragment) { return fragment; } else { return list; } }
From source file:mitm.common.hibernate.HibernateDatabaseCriterion.java
License:Open Source License
private Criterion createGTCriterion() { return Restrictions.gt(property, value); }
From source file:mitm.common.security.certstore.dao.X509CertStoreDAOHibernate.java
License:Open Source License
/** * Helper function that returns the number of records that searchField would return. *///from www .j av a 2 s.c om private int getSearchFieldCount(Field field, String search, Expired expired, MissingKeyAlias missingKeyAlias, Date date) { Criteria criteria = createCriteria(entityName); criteria.setProjection(Projections.rowCount()); criteria.add(Restrictions.eq(getColumnName(Field.STORE_NAME), storeName)); criteria.add(Restrictions.ilike(getColumnName(field), search)); if (expired == Expired.NOT_ALLOWED) { criteria.add(Restrictions.lt(getColumnName(Field.NOT_BEFORE), date)); criteria.add(Restrictions.gt(getColumnName(Field.NOT_AFTER), date)); } if (missingKeyAlias == MissingKeyAlias.NOT_ALLOWED) { criteria.add(Restrictions.isNotNull(getColumnName(Field.KEY_ALIAS))); } return (Integer) criteria.uniqueResult(); }
From source file:mitm.common.security.certstore.dao.X509CertStoreDAOHibernate.java
License:Open Source License
@Override public int getRowCount(Expired expired, MissingKeyAlias missingKeyAlias, Date date) { Criteria criteria = createCriteria(entityName); criteria.setProjection(Projections.rowCount()); criteria.add(Restrictions.eq(getColumnName(Field.STORE_NAME), storeName)); if (expired == Expired.NOT_ALLOWED) { criteria.add(Restrictions.lt(getColumnName(Field.NOT_BEFORE), date)); criteria.add(Restrictions.gt(getColumnName(Field.NOT_AFTER), date)); }/* w w w. j ava 2 s . c o m*/ if (missingKeyAlias == MissingKeyAlias.NOT_ALLOWED) { criteria.add(Restrictions.isNotNull(getColumnName(Field.KEY_ALIAS))); } return (Integer) criteria.uniqueResult(); }
From source file:mitm.common.security.crlstore.dao.X509CRLStoreDAOHibernate.java
License:Open Source License
private void addSelectorCriterias(X509CRLSelector crlSelector, Criteria criteria) { Collection<X500Principal> crlSelectorIssuers = crlSelector.getIssuers(); if (crlSelectorIssuers != null && crlSelectorIssuers.size() > 0) { Disjunction issuerCriteria = Restrictions.disjunction(); for (X500Principal issuer : crlSelectorIssuers) { String issuerCanonical = X500PrincipalInspector.getCanonical(issuer); issuerCriteria.add(Restrictions.eq("crl.issuer", issuerCanonical)); }//from ww w. j a v a 2 s . c om criteria.add(issuerCriteria); } Date dateAndTime = crlSelector.getDateAndTime(); if (dateAndTime != null) { criteria.add(Restrictions.lt("crl.thisUpdate", dateAndTime)); criteria.add(Restrictions.gt("crl.nextUpdate", dateAndTime)); } }
From source file:models.Journal.java
public Journals getNextRow(Integer id) { Session session = DatabaseUtil.getSessionFactory().openSession(); Transaction tx = null;/*from w w w. ja v a 2 s . c o m*/ Journals jn = null; try { tx = (Transaction) session.getTransaction(); tx.begin(); Criteria criteria = session.createCriteria(Journals.class); criteria.add(Restrictions.gt("id", id)); criteria.addOrder(Order.asc("id")); criteria.setMaxResults(1); jn = (Journals) criteria.uniqueResult(); tx.commit(); } catch (HibernateException ex) { System.out.println(ex.getMessage()); if (tx != null) { tx.rollback(); } } finally { session.close(); } return jn; }
From source file:moos.ssds.dao.DataContainerDAO.java
License:LGPL
private Criteria formulatePropertyCriteria(boolean countQuery, Long id, String name, boolean exactNameMatch, String dataContainerType, Date startDate, boolean boundedByStartDate, Date endDate, boolean boundedByEndDate, String uriString, boolean exactUriMatch, String mimeType, boolean exactMimeTypeMatch, String dodsUrlString, boolean exactDodsUrlStringMatch, Double geospatialLatMin, boolean boundedByLatMin, Double geospatialLatMax, boolean boundedByLatMax, Double geospatialLonMin, boolean boundedByLonMin, Double geospatialLonMax, boolean boundedByLonMax, Float geospatialDepthMin, boolean boundedByDepthMin, Float geospatialDepthMax, boolean boundedByDepthMax, String orderByProperty, String ascendingOrDescending) throws MetadataAccessException { // The Criteria to return Criteria criteria = getSession().createCriteria(DataContainer.class); // Make the return distinct criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // Check for exceptional conditions on the query if ((dataContainerType != null) && (!DataContainer.isValidDataContainerType(dataContainerType))) throw new MetadataAccessException("The dataContainerType (" + dataContainerType + ") does not match a constant defined in the DataContainer class"); if ((geospatialLatMin != null) && (geospatialLatMax != null)) if (geospatialLatMax.doubleValue() < geospatialLatMin.doubleValue()) throw new MetadataAccessException("The maximum latitude specified was less than the minimum."); if ((geospatialLonMin != null) && (geospatialLonMax != null)) if (geospatialLonMax.doubleValue() < geospatialLonMin.doubleValue()) throw new MetadataAccessException("The maximum longitude specified was less than the minimum."); if ((geospatialDepthMin != null) && (geospatialDepthMax != null)) if (geospatialDepthMax.doubleValue() < geospatialDepthMin.doubleValue()) throw new MetadataAccessException("The depth maximum specified was less than the minimum."); if ((startDate != null) && (endDate != null) && (endDate.before(startDate))) throw new MetadataAccessException("The end date specified (" + endDate + ") is before the start date specified (" + startDate + ")"); if (id != null) { criteria.add(Restrictions.eq("id", id)); } else {/*w w w .j a v a2 s .co m*/ if ((name != null) && (!name.equals(""))) { if (exactNameMatch) { criteria.add(Restrictions.eq("name", name)); } else { criteria.add(Restrictions.like("name", "%" + name + "%")); } } if (dataContainerType != null) { criteria.add(Restrictions.eq("dataContainerType", dataContainerType)); } if (startDate != null) { criteria.add(Restrictions.gt("endDate", startDate)); if (boundedByStartDate) { criteria.add(Restrictions.gt("startDate", startDate)); } } if (endDate != null) { criteria.add(Restrictions.lt("startDate", endDate)); if (boundedByEndDate) { criteria.add(Restrictions.lt("endDate", endDate)); } } if (uriString != null) { if (exactUriMatch) { criteria.add(Restrictions.eq("uriString", uriString)); } else { criteria.add(Restrictions.like("uriString", "%" + uriString + "%")); } } if (mimeType != null) { if (exactMimeTypeMatch) { criteria.add(Restrictions.eq("mimeType", mimeType)); } else { criteria.add(Restrictions.like("mimdType", "%" + mimeType + "%")); } } if (dodsUrlString != null) { if (exactDodsUrlStringMatch) { criteria.add(Restrictions.eq("dodsUrlString", dodsUrlString)); } else { criteria.add(Restrictions.like("dodsUrlString", "%" + dodsUrlString + "%")); } } if (geospatialLatMin != null) { criteria.add(Restrictions.gt("maxLatitude", geospatialLatMin)); if (boundedByLatMin) { criteria.add(Restrictions.ge("minLatitude", geospatialLatMin)); } } if (geospatialLatMax != null) { criteria.add(Restrictions.lt("minLatitude", geospatialLatMax)); if (boundedByLatMax) { criteria.add(Restrictions.le("maxLatitude", geospatialLatMax)); } } if (geospatialLonMin != null) { criteria.add(Restrictions.gt("maxLongitude", geospatialLonMin)); if (boundedByLonMin) { criteria.add(Restrictions.ge("minLongitude", geospatialLonMin)); } } if (geospatialLonMax != null) { criteria.add(Restrictions.lt("minLongitude", geospatialLonMax)); if (boundedByLonMax) { criteria.add(Restrictions.le("maxLongitude", geospatialLonMax)); } } if (geospatialDepthMin != null) { criteria.add(Restrictions.gt("maxDepth", geospatialDepthMin)); if (boundedByDepthMin) { criteria.add(Restrictions.ge("minDepth", geospatialDepthMin)); } } if (geospatialDepthMax != null) { criteria.add(Restrictions.lt("minDepth", geospatialDepthMax)); if (boundedByDepthMax) { criteria.add(Restrictions.le("maxDepth", geospatialDepthMax)); } } } // Setup if a count query, if not add fetching and ordering if (countQuery) { criteria.setProjection(Projections.rowCount()); } else { addOrderByCriteria(criteria, orderByProperty, ascendingOrDescending); } // Now return the Criteria return criteria; }
From source file:moos.ssds.dao.DataProducerDAO.java
License:LGPL
/** * This method finds all the deployments of a <code>Device</code> that fall * within a certain time window. This is usually done when searching for * data from that device./* w w w. j a v a2 s . c om*/ * * @param device * @param startDate * @param endDate * @param orderByPropertyName * @param ascendingOrDescending * @param returnFullObjectGraph * @return * @throws MetadataAccessException */ public Collection findByDeviceAndTimeWindow(Device device, Date startDate, Date endDate, String orderByPropertyName, String ascendingOrDescending, boolean returnFullObjectGraph) throws MetadataAccessException { // The collection to return Collection dataProducersToReturn = new ArrayList(); // First make sure the device exists DeviceDAO deviceDAO = new DeviceDAO(getSession()); Device persistentDevice = null; persistentDevice = (Device) deviceDAO.findEquivalentPersistentObject(device, false); if (persistentDevice == null) return dataProducersToReturn; // Create the criteria try { Criteria criteria = getSession().createCriteria(DataProducer.class); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.eq("device", persistentDevice)); criteria.add(Restrictions.eq("dataProducerType", DataProducer.TYPE_DEPLOYMENT)); // Add the time criteria if (startDate != null) { criteria.add( Restrictions.or(Restrictions.gt("endDate", startDate), Restrictions.isNull("endDate"))); } if (endDate != null) { criteria.add( Restrictions.or(Restrictions.lt("startDate", endDate), Restrictions.isNull("startDate"))); } addOrderByCriteria(criteria, orderByPropertyName, ascendingOrDescending); dataProducersToReturn = criteria.list(); } catch (HibernateException e) { throw new MetadataAccessException(e.getMessage()); } // If the full object graphs are requested if (returnFullObjectGraph) dataProducersToReturn = getRealObjectsAndRelationships(dataProducersToReturn); return dataProducersToReturn; }