/** * Selects the union of the current node sets child nodes. * * @return this query builder */ public QueryBuilder children() { return chain(Children.INSTANCE); }
/** * Selects the merged descendant set of the current node set. * <p> * More precisely this recursively merges the children of each member of the * node-set in to the output node set until the set ceases to grow. * * @return this query builder */ public QueryBuilder descendants() { return chain(Descendants.INSTANCE); }
/** * Asserts that the current node set is a singleton. * <p> * If the current node set is not of size 1 then the query will terminate with * an {@code IllegalStateException}. * * @return this query builder */ public QueryBuilder ensureUnique() { return chain(EnsureUnique.INSTANCE); }
@SuppressWarnings("unchecked") private static <T extends Enum<T>> OperationStatistic<T> findStat(Cache<?, ?> cache, final String statName, final String tag) { Query q = queryBuilder().chain(self()) .descendants().filter(context(identifier(subclassOf(OperationStatistic.class)))).build(); Set<TreeNode> operationStatisticNodes = q.execute(Collections.singleton(ContextManager.nodeFor(cache))); Set<TreeNode> result = queryBuilder() .filter( context(attributes(Matchers.<Map<String, Object>>allOf( hasAttribute("name", statName), hasAttribute("tags", new Matcher<Set<String>>() { @Override protected boolean matchesSafely(Set<String> object) { return object.contains(tag); } }))))).build().execute(operationStatisticNodes); switch (result.size()) { case 0: return null; case 1: { TreeNode node = result.iterator().next(); return (OperationStatistic<T>) node.getContext().attributes().get("this"); } default: throw new RuntimeException("query for unique stat '" + statName + "' with tag '" + tag + "' failed; found " + result.size() + " instance(s)"); } }
/** * Filters the current node set using the supplied {@code Matcher}. * <p> * Nodes in the current node set that are not selected by the supplied matcher * are removed. * * @param filter matcher to apply * @return this query builder */ public QueryBuilder filter(Matcher<? super TreeNode> filter) { return chain(new Filter(filter)); }
/** * Add the given nodes to the current node set * * @return merged node set */ EhcacheQuery add(final EhcacheQuery chain) { return new EhcacheQuery(queryBuilder().chain(query).chain(new Query() { @Override public Set<TreeNode> execute(Set<TreeNode> input) { Set<TreeNode> result = new HashSet<TreeNode>(); result.addAll(input); result.addAll(chain.execute(input)); return result; } }).build()); }
/** * Return the unique node selected by running this query against this * {@code ContextManager}'s root context. * <p> * If this query does not return a single unique result then an * {@code IllegalStateException} will be thrown. More details on the query * execution context can be found in {@link #query(Query)}. * * @see #query(Query) * @see QueryBuilder#ensureUnique() * @param query the query to execute * @return the node selected by the query * @throws IllegalStateException if the query does not select a unique node */ public TreeNode queryForSingleton(Query query) throws IllegalStateException { return query(queryBuilder().chain(query).ensureUnique().build()).iterator().next(); }
/** * Select the children of the current node set * * @return children */ EhcacheQuery children() { return new EhcacheQuery(queryBuilder().chain(query).children().build()); }
/** * Select the descendants of the current node set * * @return descendants */ EhcacheQuery descendants() { return new EhcacheQuery(queryBuilder().chain(query).descendants().build()); }
/** * Remove instances of the specified type from the node set * * @param klazz class to be excluded * @return current set minus the given type */ EhcacheQuery exclude(Class<?> klazz) { return new EhcacheQuery(queryBuilder().chain(query).filter(context(identifier(not(subclassOf(klazz))))).build()); }
/** * Select the children of the current node set that are subtypes of the specified class * * @param klazz class to be selected * @return children of the specified type */ EhcacheQuery children(Class<?> klazz) { return new EhcacheQuery(queryBuilder().chain(query).children().filter(context(identifier(subclassOf(klazz)))).build()); }
Set<TreeNode> passThroughStatisticNodes = manager.query(queryBuilder().chain(contextQuery).children() .filter(context(identifier(subclassOf(ValueStatistic.class)))).build()); Set<TreeNode> result = queryBuilder()
/** * Asserts that the current node set is a singleton. * <p> * If the current node set is not of size 1 then the query will terminate with * an {@code IllegalStateException}. * * @return this query builder */ public QueryBuilder ensureUnique() { return chain(EnsureUnique.INSTANCE); }
/** * Asserts that the current node set is a singleton. * <p> * If the current node set is not of size 1 then the query will terminate with * an {@code IllegalStateException}. * * @return this query builder */ public QueryBuilder ensureUnique() { return chain(EnsureUnique.INSTANCE); }
Set<TreeNode> operationStatisticNodes = manager.query(queryBuilder().chain(contextQuery).children() .filter(context(identifier(subclassOf(OperationStatistic.class)))).build()); Set<TreeNode> result = queryBuilder()
/** * Filters the current node set using the supplied {@code Matcher}. * <p> * Nodes in the current node set that are not selected by the supplied matcher * are removed. * * @param filter matcher to apply * @return this query builder */ public QueryBuilder filter(Matcher<? super TreeNode> filter) { return chain(new Filter(filter)); }
/** * Select the children of the current node set * * @return children */ EhcacheQuery children() { return new EhcacheQuery(queryBuilder().chain(query).children().build()); }
/** * Select the children of the current node set * * @return children */ EhcacheQuery children() { return new EhcacheQuery(queryBuilder().chain(query).children().build()); }
/** * Select the children of the current node set that are subtypes of the specified class * * @param klazz class to be selected * @return children of the specified type */ EhcacheQuery children(Class<?> klazz) { return new EhcacheQuery(queryBuilder().chain(query).children().filter(context(identifier(subclassOf(klazz)))).build()); }
/** * Remove instances of the specified type from the node set * * @param klazz class to be excluded * @return current set minus the given type */ EhcacheQuery exclude(Class<?> klazz) { return new EhcacheQuery(queryBuilder().chain(query).filter(context(identifier(not(subclassOf(klazz))))).build()); }