List of usage examples for org.hibernate.criterion Restrictions in
public static Criterion in(String propertyName, Collection values)
From source file:com.abiquo.server.core.cloud.VirtualMachineDAO.java
License:Open Source License
public List<VirtualMachine> findVirtualMachinesNotAllocatedCompatibleHypervisor(final Hypervisor hypervisor) { Criteria criteria = createCriteria(); criteria.createAlias(VirtualMachine.VIRTUAL_MACHINE_TEMPLATE_PROPERTY, "template"); Restrictions.and(Restrictions.eq(VirtualMachine.HYPERVISOR_PROPERTY, null), Restrictions.in("template." + VirtualMachineTemplate.DISKFORMAT_TYPE_PROPERTY, Arrays.asList(hypervisor.getType().compatibleFormats))); criteria.addOrder(Order.asc(VirtualMachine.NAME_PROPERTY)); List<VirtualMachine> result = getResultList(criteria); return result; }
From source file:com.abiquo.server.core.infrastructure.DatastoreDAO.java
License:Open Source License
private Criteria inMachine(final Machine machine) { return createCriteria().createCriteria(Datastore.MACHINES_PROPERTY) .add(Restrictions.in(PersistentEntity.ID_PROPERTY, new Integer[] { machine.getId() })); }
From source file:com.abiquo.server.core.infrastructure.DatastoreDAO.java
License:Open Source License
private Criteria inMachine(final Machine machine, final String uuid) { return createCriteria(sharedUuid(uuid)).createCriteria(Datastore.MACHINES_PROPERTY) .add(Restrictions.in(PersistentEntity.ID_PROPERTY, new Integer[] { machine.getId() })); }
From source file:com.abiquo.server.core.infrastructure.management.RasdManagementDAO.java
License:Open Source License
public List<RasdManagement> findDisksAndVolumesByVirtualMachine(final VirtualMachine virtualMachine) { Criteria crit = createCriteria();// w w w. j a v a2s. c om crit.createAlias(RasdManagement.RASD_PROPERTY, "rasd"); // Add disk resource type filter crit.add(Restrictions.in(RasdManagement.ID_RESOURCE_TYPE_PROPERTY, new String[] { VolumeManagement.DISCRIMINATOR, DiskManagement.DISCRIMINATOR })); // Add virtual machine filter crit.add(sameVirtualMachine(virtualMachine)); // Order by generation (attachment order) crit.addOrder(Order.asc("sequence")); return getResultList(crit); }
From source file:com.abssh.util.GenericDao.java
License:Apache License
/** * ??Criterion,./*from ww w .j a v a2 s . com*/ */ protected Criterion buildPropertyFilterCriterion(final String propertyName, final Object[] propertyValue, final MatchType matchType) { Assert.hasText(propertyName, "propertyName should not be null!"); Criterion criterion = null; try { // ?MatchTypecriterion if (MatchType.EQ.equals(matchType)) { criterion = Restrictions.eq(propertyName, propertyValue[0]); } else if (MatchType.LIKE.equals(matchType)) { criterion = Restrictions.like(propertyName, (String) propertyValue[0], MatchMode.ANYWHERE); } else if (MatchType.ELIKE.equals(matchType)) { criterion = Restrictions.like(propertyName, (String) propertyValue[0], MatchMode.END); } else if (MatchType.SLIKE.equals(matchType)) { criterion = Restrictions.like(propertyName, (String) propertyValue[0], MatchMode.START); } else if (MatchType.LE.equals(matchType)) { criterion = Restrictions.le(propertyName, propertyValue[0]); } else if (MatchType.LT.equals(matchType)) { criterion = Restrictions.lt(propertyName, propertyValue[0]); } else if (MatchType.GE.equals(matchType)) { criterion = Restrictions.ge(propertyName, propertyValue[0]); } else if (MatchType.GT.equals(matchType)) { criterion = Restrictions.gt(propertyName, propertyValue[0]); } else if (MatchType.NE.equals(matchType)) { criterion = Restrictions.ne(propertyName, propertyValue[0]); } else if (MatchType.ISNULL.equals(matchType)) { criterion = Restrictions.isNull(propertyName); } else if (MatchType.ISNOTNULL.equals(matchType)) { criterion = Restrictions.isNotNull(propertyName); } else if (MatchType.ISEMPTY.equals(matchType)) { criterion = Restrictions.isEmpty(propertyName); } else if (MatchType.ISNOTEMPTY.equals(matchType)) { criterion = Restrictions.isNotEmpty(propertyName); } else if (MatchType.IN.equals(matchType)) { criterion = Restrictions.in(propertyName, propertyValue); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return criterion; }
From source file:com.abssh.util.GenericDao.java
License:Apache License
/** * ??//from ww w . j a va 2 s . com */ private Criterion getCriterion(String propertyName, Object[] propertyValue, MatchType matchType) { Criterion criterion = null; try { // ?MatchTypecriterion if (MatchType.EQ.equals(matchType)) { criterion = Restrictions.eq(propertyName, propertyValue[0]); } else if (MatchType.LIKE.equals(matchType)) { criterion = RestrictionsUtils.ilike(propertyName, String.valueOf(propertyValue[0]), MatchMode.ANYWHERE); } else if (MatchType.ELIKE.equals(matchType)) { criterion = RestrictionsUtils.ilike(propertyName, (String) propertyValue[0], MatchMode.END); } else if (MatchType.SLIKE.equals(matchType)) { criterion = RestrictionsUtils.ilike(propertyName, (String) propertyValue[0], MatchMode.START); } else if (MatchType.LE.equals(matchType)) { criterion = Restrictions.le(propertyName, propertyValue[0]); } else if (MatchType.LT.equals(matchType)) { criterion = Restrictions.lt(propertyName, propertyValue[0]); } else if (MatchType.GE.equals(matchType)) { criterion = Restrictions.ge(propertyName, propertyValue[0]); } else if (MatchType.GT.equals(matchType)) { criterion = Restrictions.gt(propertyName, propertyValue[0]); } else if (MatchType.NE.equals(matchType)) { criterion = Restrictions.ne(propertyName, propertyValue[0]); } else if (MatchType.ISNULL.equals(matchType)) { criterion = Restrictions.isNull(propertyName); } else if (MatchType.ISNOTNULL.equals(matchType)) { criterion = Restrictions.isNotNull(propertyName); } else if (MatchType.ISEMPTY.equals(matchType)) { criterion = Restrictions.isEmpty(propertyName); } else if (MatchType.ISNOTEMPTY.equals(matchType)) { criterion = Restrictions.isNotEmpty(propertyName); } else if (MatchType.IN.equals(matchType)) { criterion = Restrictions.in(propertyName, propertyValue); } else if (MatchType.LEN.equals(matchType)) { criterion = Restrictions.le(propertyName, propertyValue[0]); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return criterion; }
From source file:com.algoTrader.CriteriaSearch.java
/** * Adds an <code>Restrictions</code> to a <code>Criteria</code>. * * @param criteria//from www .ja v a 2 s. com * @param parameterName * @param parameterValue * @param comparator * @param matchMode */ private void addExpression(Criteria criteria, String parameterName, Object parameterValue, int comparator, MatchMode matchMode) { switch (comparator) { case SearchParameter.NOT_NULL_COMPARATOR: { criteria.add(Restrictions.isNotNull(parameterName)); break; } case SearchParameter.NULL_COMPARATOR: { criteria.add(Restrictions.isNull(parameterName)); break; } case SearchParameter.EMPTY_COMPARATOR: { criteria.add(Restrictions.isEmpty(parameterName)); break; } case SearchParameter.NOT_EMPTY_COMPARATOR: { criteria.add(Restrictions.isNotEmpty(parameterName)); break; } default: { if (parameterValue != null) { switch (comparator) { case SearchParameter.LIKE_COMPARATOR: { if ((matchMode != null) && (parameterValue instanceof String)) { criteria.add(Restrictions.like(parameterName, (String) parameterValue, matchMode)); } else { criteria.add(Restrictions.like(parameterName, parameterValue)); } break; } case SearchParameter.NOT_LIKE_COMPARATOR: { SimpleExpression expression; if ((matchMode != null) && (parameterValue instanceof String)) { expression = Restrictions.like(parameterName, (String) parameterValue, matchMode); } else { expression = Restrictions.like(parameterName, parameterValue); } criteria.add(Restrictions.not(expression)); break; } case SearchParameter.INSENSITIVE_LIKE_COMPARATOR: { if ((matchMode != null) && (parameterValue instanceof String)) { criteria.add(Restrictions.ilike(parameterName, (String) parameterValue, matchMode)); } else { criteria.add(Restrictions.ilike(parameterName, parameterValue)); } break; } case SearchParameter.NOT_INSENSITIVE_LIKE_COMPARATOR: { Criterion criterion; if ((matchMode != null) && (parameterValue instanceof String)) { criterion = Restrictions.ilike(parameterName, (String) parameterValue, matchMode); } else { criterion = Restrictions.ilike(parameterName, parameterValue); } criteria.add(Restrictions.not(criterion)); break; } case SearchParameter.EQUAL_COMPARATOR: { criteria.add(Restrictions.eq(parameterName, parameterValue)); break; } case SearchParameter.GREATER_THAN_OR_EQUAL_COMPARATOR: { criteria.add(Restrictions.ge(parameterName, parameterValue)); break; } case SearchParameter.GREATER_THAN_COMPARATOR: { criteria.add(Restrictions.gt(parameterName, parameterValue)); break; } case SearchParameter.LESS_THAN_OR_EQUAL_COMPARATOR: { criteria.add(Restrictions.le(parameterName, parameterValue)); break; } case SearchParameter.LESS_THAN_COMPARATOR: { criteria.add(Restrictions.lt(parameterName, parameterValue)); break; } case SearchParameter.IN_COMPARATOR: { if (parameterValue instanceof Collection) { criteria.add(Restrictions.in(parameterName, (Collection) parameterValue)); } break; } case SearchParameter.NOT_IN_COMPARATOR: { if (parameterValue instanceof Collection) { criteria.add(Restrictions.not(Restrictions.in(parameterName, (Collection) parameterValue))); } break; } case SearchParameter.NOT_EQUAL_COMPARATOR: { criteria.add(Restrictions.ne(parameterName, parameterValue)); break; } } } else { criteria.add(Restrictions.isNull(parameterName)); } } } }
From source file:com.algoTrader.CriteriaSearch.java
/** * Adds an <code>Restrictions</code> to a <code>Criteria</code>. The given <code>parameterValues</code> * represents either an array of <code>String</code> or another object. The different values in the * array are added to a disjunction or conjunction which is connected with logical and to the other criteria of the * search.//from w ww . j a va 2 s .co m * * @param criteria * @param parameterName * @param parameterValues * @param searchIfNull * @param comparator * @param matchMode */ private void addExpression(Criteria criteria, String parameterName, Object[] parameterValues, int comparator, MatchMode matchMode) { if (parameterValues != null) { Disjunction disjunction = null; Conjunction conjunction = null; switch (comparator) { case SearchParameter.LIKE_COMPARATOR: { disjunction = Restrictions.disjunction(); if ((matchMode != null) && (parameterValues instanceof String[])) { String[] stringParameterValues = (String[]) parameterValues; for (int index = 0; index < parameterValues.length; index++) { if (stringParameterValues[index] != null) { disjunction .add(Restrictions.like(parameterName, stringParameterValues[index], matchMode)); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } else { for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.like(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } break; } case SearchParameter.INSENSITIVE_LIKE_COMPARATOR: { disjunction = Restrictions.disjunction(); if ((matchMode != null) && (parameterValues instanceof String[])) { String[] stringParameterValues = (String[]) parameterValues; for (int index = 0; index < parameterValues.length; index++) { if (stringParameterValues[index] != null) { disjunction.add( Restrictions.ilike(parameterName, stringParameterValues[index], matchMode)); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } else { for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.ilike(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } break; } case SearchParameter.EQUAL_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.eq(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.GREATER_THAN_OR_EQUAL_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.ge(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.GREATER_THAN_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.gt(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.LESS_THAN_OR_EQUAL_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.le(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.LESS_THAN_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.lt(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.IN_COMPARATOR: { criteria.add(Restrictions.in(parameterName, parameterValues)); break; } case SearchParameter.NOT_IN_COMPARATOR: { criteria.add(Restrictions.not(Restrictions.in(parameterName, parameterValues))); break; } case SearchParameter.NOT_EQUAL_COMPARATOR: { conjunction = Restrictions.conjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { conjunction.add(Restrictions.ne(parameterName, parameterValues[index])); } else { conjunction.add(Restrictions.isNotNull(parameterName)); } } break; } } if (disjunction != null) { criteria.add(disjunction); } if (conjunction != null) { criteria.add(conjunction); } } else { switch (comparator) { case SearchParameter.EMPTY_COMPARATOR: { criteria.add(Restrictions.isEmpty(parameterName)); break; } case SearchParameter.NOT_EMPTY_COMPARATOR: { criteria.add(Restrictions.isNotEmpty(parameterName)); break; } default: { criteria.add(Restrictions.isNull(parameterName)); } } } }
From source file:com.all.client.model.LocalModelDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<Track> findTracks(final List<String> hashcodes) { return hibernateTemplate.executeFind(new HibernateCallback<List<LocalTrack>>() { @Override// w w w. j a v a 2 s . c o m public List<LocalTrack> doInHibernate(Session session) throws SQLException { Criteria criteria = session.createCriteria(LocalTrack.class); criteria.add(Restrictions.in("hashcode", hashcodes)); return criteria.list(); } }); }
From source file:com.all.rds.service.impl.TrackServiceImpl.java
License:Apache License
@SuppressWarnings("unchecked") @Override//from w w w .j a v a2 s . co m public List<String> filterTracksByAvailability(final List<String> trackIds) { return ht.executeFind(new HibernateCallback<List<String>>() { @Override public List<String> doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(TrackUploadStatus.class); criteria.setProjection(Projections.property("trackId")); criteria.add(Restrictions.in("trackId", trackIds)); criteria.add(Restrictions.eq("trackStatus", TrackStatus.Status.UPLOADED)); return criteria.list(); } }); }