List of usage examples for org.hibernate.criterion Restrictions in
public static Criterion in(String propertyName, Collection values)
From source file:com.eryansky.modules.sys.web.OrganController.java
License:Apache License
/** * combogrid//from w w w . j a v a 2s . c o m * * @return * @throws Exception */ @RequestMapping(value = { "combogrid" }) @ResponseBody public Datagrid<Organ> combogrid(String nameOrCode, @RequestParam(value = "ids", required = false) List<Long> ids, Integer rows) throws Exception { Criterion statusCriterion = Restrictions.eq("status", StatusState.normal.getValue()); Criterion[] criterions = new Criterion[0]; criterions = ArrayUtils.add(criterions, 0, statusCriterion); Criterion criterion = null; if (Collections3.isNotEmpty(ids)) { //in? Criterion inCriterion = Restrictions.in("id", ids); if (StringUtils.isNotBlank(nameOrCode)) { Criterion nameCriterion = Restrictions.like("name", nameOrCode, MatchMode.ANYWHERE); Criterion codeCriterion = Restrictions.like("code", nameOrCode, MatchMode.ANYWHERE); Criterion criterion1 = Restrictions.or(nameCriterion, codeCriterion); criterion = Restrictions.or(inCriterion, criterion1); } else { criterion = inCriterion; } //?? criterions = ArrayUtils.add(criterions, 0, criterion); } else { if (StringUtils.isNotBlank(nameOrCode)) { Criterion nameCriterion = Restrictions.like("name", nameOrCode, MatchMode.ANYWHERE); Criterion codeCriterion = Restrictions.like("code", nameOrCode, MatchMode.ANYWHERE); criterion = Restrictions.or(nameCriterion, codeCriterion); //?? criterions = ArrayUtils.add(criterions, 0, criterion); } } // Page<Organ> p = new Page<Organ>(rows);// p = organManager.findPageByCriteria(p, criterions); Datagrid<Organ> dg = new Datagrid<Organ>(p.getTotalCount(), p.getResult()); return dg; }
From source file:com.eryansky.modules.sys.web.UserController.java
License:Apache License
/** * * @param userIds ID/*w w w .j a v a 2s . c o m*/ * @param excludeUserIds ID * @param dataScope {@link DataScope} * @param multiple * @return */ @RequestMapping(value = { "select" }) public ModelAndView selectPage(@RequestParam(value = "userIds", required = false) List<String> userIds, @RequestParam(value = "excludeUserIds", required = false) List<String> excludeUserIds, String dataScope, Boolean multiple, @RequestParam(value = "cascade", required = false, defaultValue = "false") Boolean cascade) { ModelAndView modelAndView = new ModelAndView("modules/sys/user-select"); List<User> users = Lists.newArrayList(); if (Collections3.isNotEmpty(userIds)) { Criterion inUserCriterion = Restrictions.in("id", userIds); users = userManager.findByCriteria(inUserCriterion); } modelAndView.addObject("users", users); modelAndView.addObject("excludeUserIds", excludeUserIds); if (Collections3.isNotEmpty(excludeUserIds)) { modelAndView.addObject("excludeUserIdStrs", Collections3.convertToString(excludeUserIds, ",")); } modelAndView.addObject("dataScope", dataScope); modelAndView.addObject("multiple", multiple); modelAndView.addObject("cascade", cascade); modelAndView.addObject("userDatagridData", JsonMapper.getInstance().toJson(new Datagrid(users.size(), users), User.class, new String[] { "id", "name", "sexView", "defaultOrganName" })); return modelAndView; }
From source file:com.eryansky.web.base.OrganAction.java
License:Apache License
/** * combogrid//from w w w. ja va2 s. c o m * @return * @throws Exception */ public String combogrid() throws Exception { try { Criterion statusCriterion = Restrictions.eq("status", StatusState.normal.getValue()); Criterion[] criterions = new Criterion[0]; criterions = (Criterion[]) ArrayUtils.add(criterions, 0, statusCriterion); Criterion criterion = null; if (!Collections3.isEmpty(ids)) { //in? Criterion inCriterion = Restrictions.in("id", ids); if (StringUtils.isNotBlank(nameOrCode)) { Criterion nameCriterion = Restrictions.like("name", nameOrCode, MatchMode.ANYWHERE); Criterion codeCriterion = Restrictions.like("code", nameOrCode, MatchMode.ANYWHERE); Criterion criterion1 = Restrictions.or(nameCriterion, codeCriterion); criterion = Restrictions.or(inCriterion, criterion1); } else { criterion = inCriterion; } //?? criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion); } else { if (StringUtils.isNotBlank(nameOrCode)) { Criterion nameCriterion = Restrictions.like("name", nameOrCode, MatchMode.ANYWHERE); Criterion codeCriterion = Restrictions.like("code", nameOrCode, MatchMode.ANYWHERE); criterion = Restrictions.or(nameCriterion, codeCriterion); //?? criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion); } } // Page<Organ> p = new Page<Organ>(rows);// p = organManager.findByCriteria(p, criterions); Datagrid<Organ> dg = new Datagrid<Organ>(p.getTotalCount(), p.getResult()); Struts2Utils.renderJson(dg); } catch (Exception e) { throw e; } return null; }
From source file:com.eryansky.web.base.UserAction.java
License:Apache License
/** * combogrid//w w w . jav a 2s. c o m * @return * @throws Exception */ public String combogrid() throws Exception { try { Criterion statusCriterion = Restrictions.eq("status", StatusState.normal.getValue()); Criterion[] criterions = new Criterion[0]; criterions = (Criterion[]) ArrayUtils.add(criterions, 0, statusCriterion); Criterion criterion = null; if (!Collections3.isEmpty(ids)) { //in? Criterion inCriterion = Restrictions.in("id", ids); if (StringUtils.isNotBlank(loginNameOrName)) { Criterion loginNameCriterion = Restrictions.like("loginName", loginNameOrName, MatchMode.ANYWHERE); Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE); Criterion criterion1 = Restrictions.or(loginNameCriterion, nameCriterion); criterion = Restrictions.or(inCriterion, criterion1); } else { criterion = inCriterion; } //?? criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion); } else { if (StringUtils.isNotBlank(loginNameOrName)) { Criterion loginNameCriterion = Restrictions.like("loginName", loginNameOrName, MatchMode.ANYWHERE); Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE); criterion = Restrictions.or(loginNameCriterion, nameCriterion); //?? criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion); } } // Page<User> p = new Page<User>(rows);// p = userManager.findByCriteria(p, criterions); Datagrid<User> dg = new Datagrid<User>(p.getTotalCount(), p.getResult()); Struts2Utils.renderJson(dg); } catch (Exception e) { throw e; } return null; }
From source file:com.eucalyptus.auth.DatabaseRoleProxy.java
License:Open Source License
@Override public List<Authorization> lookupAuthorizations(final String resourceType) throws AuthException { if (resourceType == null) { throw new AuthException("Empty resource type"); }/*www .ja v a 2 s . c om*/ final EntityWrapper<AuthorizationEntity> db = EntityWrapper.get(AuthorizationEntity.class); try { @SuppressWarnings("unchecked") final List<AuthorizationEntity> authorizations = (List<AuthorizationEntity>) db .createCriteria(AuthorizationEntity.class) .add(Restrictions.and( Restrictions.or(Restrictions.eq("type", resourceType), Restrictions.eq("type", "*")), Restrictions.in("effect", EnumSet.of(Authorization.EffectType.Allow, Authorization.EffectType.Deny)))) .createCriteria("statement").createCriteria("policy").createCriteria("role") .add(Restrictions.eq("roleId", getRoleId())).setCacheable(true).list(); final List<Authorization> results = Lists.newArrayList(); for (final AuthorizationEntity auth : authorizations) { results.add(new DatabaseAuthorizationProxy(auth)); } return results; } catch (Exception e) { Debugging.logError(LOG, e, "Failed to lookup authorization for user with ID " + getRoleId() + ", type=" + resourceType); throw new AuthException("Failed to lookup auth", e); } finally { if (db.isActive()) db.rollback(); } }
From source file:com.eucalyptus.autoscaling.activities.PersistenceScalingActivities.java
License:Open Source License
@Override public <T> List<T> list(@Nullable final OwnerFullName ownerFullName, @Nullable final AutoScalingGroupMetadata group, @Nonnull final Collection<String> activityIds, @Nonnull final Predicate<? super ScalingActivity> filter, @Nonnull final Function<? super ScalingActivity, T> transform) throws AutoScalingMetadataException { final ScalingActivity example = ScalingActivity.withOwner(ownerFullName); final Conjunction conjunction = Restrictions.conjunction(); final Collection<Predicate<? super ScalingActivity>> predicates = Lists.newArrayList(); predicates.add(filter);// www. ja v a 2 s . c om if (group != null) { predicates.add(CollectionUtils.propertyPredicate(group.getArn(), Functions.compose(AutoScalingMetadatas.toArn(), ScalingActivities.group()))); conjunction.add(Restrictions.eq("autoScalingGroupName", group.getDisplayName())); } if (!activityIds.isEmpty()) { conjunction.add(Restrictions.in("displayName", activityIds)); } return persistenceSupport.listByExample(example, Predicates.and(predicates), conjunction, Collections.<String, String>emptyMap(), transform); }
From source file:com.eucalyptus.autoscaling.activities.PersistenceScalingActivities.java
License:Open Source License
@Override public <T> List<T> listByActivityStatusCode(@Nullable final OwnerFullName ownerFullName, @Nonnull final Collection<ActivityStatusCode> statusCodes, @Nonnull final Function<? super ScalingActivity, T> transform) throws AutoScalingMetadataException { final ScalingActivity example = ScalingActivity.withOwner(ownerFullName); final Conjunction conjunction = Restrictions.conjunction(); if (!statusCodes.isEmpty()) { conjunction.add(Restrictions.in("statusCode", statusCodes)); }/*from w ww.j a v a 2 s . c o m*/ return persistenceSupport.listByExample(example, Predicates.alwaysTrue(), conjunction, Collections.<String, String>emptyMap(), transform); }
From source file:com.eucalyptus.autoscaling.common.internal.tags.TagSupport.java
License:Open Source License
/** * Get the tags for the given resources, grouped by ID and ordered for display. * * @param owner The account for the tags * @param identifiers The resource identifiers for the tags * @param tagPredicate Predicate for filtering tags * @return The tag map with an entry for each requested resource *///from w ww . j a v a 2s . c o m public Map<String, List<Tag>> getResourceTagMap(final OwnerFullName owner, final Iterable<String> identifiers, final Predicate<? super Tag> tagPredicate) { final Map<String, List<Tag>> tagMap = Maps.newHashMap(); for (final String id : identifiers) { tagMap.put(id, Lists.<Tag>newArrayList()); } if (!tagMap.isEmpty()) { final Tag example = example(owner); final DetachedCriteria detachedCriteria = DetachedCriteria.forClass(resourceClass) .add(Restrictions.in(resourceClassIdField, Lists.newArrayList(identifiers))) .setProjection(Projections.id()); final Criterion idRestriction = Property.forName(tagClassResourceField).in(detachedCriteria); try { final List<Tag> tags = Tags.list(example, tagPredicate, idRestriction, Collections.<String, String>emptyMap()); for (final Tag tag : tags) { tagMap.get(tag.getResourceId()).add(tag); } } catch (AutoScalingMetadataNotFoundException e) { log.error(e, e); } Ordering<Tag> order = Ordering.natural().onResultOf(Tags.key()); for (final String id : identifiers) { Collections.sort(tagMap.get(id), order); } } return tagMap; }
From source file:com.eucalyptus.blockstorage.BlockStorageController.java
License:Open Source License
/** * Checks to see if a new snapshot of size volSize will exceed the quota * @param volSize/*from w ww. j av a 2s. co m*/ * @return */ private boolean totalSnapshotSizeLimitExceeded(String snapshotId, int volSize) throws EucalyptusCloudException { int totalSnapshotSize = 0; EntityTransaction dbTrans = Entities.get(SnapshotInfo.class); try { Criteria query = Entities.createCriteria(SnapshotInfo.class); query.setReadOnly(true); //Only look for snaps that are not failed and not error ImmutableSet<String> excludedStates = ImmutableSet.of(StorageProperties.Status.failed.toString(), StorageProperties.Status.error.toString(), StorageProperties.Status.deleted.toString()); query.add(Restrictions.not(Restrictions.in("status", excludedStates))); //The listing may include duplicates (for snapshots cached on multiple clusters), this set ensures each unique snap id is counted only once. HashSet<String> idSet = new HashSet<String>(); List<SnapshotInfo> snapshots = (List<SnapshotInfo>) query.list(); for (SnapshotInfo snap : snapshots) { totalSnapshotSize += (snap.getSizeGb() != null && idSet.add(snap.getSnapshotId()) ? snap.getSizeGb() : 0); } int sizeLimitGB = WalrusInfo.getWalrusInfo().getStorageMaxTotalSnapshotSizeInGb(); LOG.debug("Snapshot " + snapshotId + " checking snapshot total size of " + totalSnapshotSize + " against limit of " + sizeLimitGB); return (totalSnapshotSize + volSize) > sizeLimitGB; } catch (final Throwable e) { LOG.error("Error finding total snapshot used size " + e.getMessage()); throw new EucalyptusCloudException("Failed to check snapshot total size limit", e); } finally { if (dbTrans.isActive()) { dbTrans.rollback(); } } }
From source file:com.eucalyptus.blockstorage.StorageUtil.java
License:Open Source License
private static long getBlockStorageTotalSize(final String partition, final String partitionProperty, final String sizeProperty, final Class<? extends UserMetadata<State>> sizedType) { long size = -1; final EntityTransaction db = Entities.get(sizedType); try {//from w w w .j a v a 2s . co m size = Objects.firstNonNull((Number) Entities.createCriteria(sizedType) .add(Restrictions.in("state", EnumSet.of(State.EXTANT, State.BUSY))) .add(partition == null ? Restrictions.isNotNull(partitionProperty) : // Get size for all partitions. Restrictions.eq(partitionProperty, partition)) .setProjection(Projections.sum(sizeProperty)).setReadOnly(true).uniqueResult(), 0).longValue(); db.commit(); } catch (Exception e) { LOG.error(e); db.rollback(); } return size; }