private void processHints(ExecutionHints hints) { if (hints != null) { setHints(hints); } }
@Override public String toString() { return "Results(size=" + size() + ", hasKeys=" + hasKeys() + ", hasValues=" + hasValues() + ", hasAttributes=" + hasAttributes() + ", hasAggregators=" + hasAggregators() + ")"; }
@Override public int compareTo(ResultHolder other) { return comp.compare(this.result, other.result); } }
all(); } else if (criteria instanceof And) { and(And.class.cast(criteria)); } else if (criteria instanceof Or) { or(Or.class.cast(criteria)); } else if (criteria instanceof Not) { processNotCriteria(Not.class.cast(criteria)); } else if (criteria instanceof NotEqualTo) { notEqualTerm(NotEqualTo.class.cast(criteria)); } else if (criteria instanceof NotILike) { notIlike(NotILike.class.cast(criteria)); } else if (criteria instanceof NotNull) { notNull(NotNull.class.cast(criteria)); } else if (criteria instanceof Between) { between(Between.class.cast(criteria)); } else if (criteria instanceof EqualTo) { equalTo(EqualTo.class.cast(criteria)); } else if (criteria instanceof IsNull) { isNull(IsNull.class.cast(criteria)); } else if (criteria instanceof ILike) { ilike(ILike.class.cast(criteria)); } else if (criteria instanceof GreaterThan) { greaterThan(GreaterThan.class.cast(criteria)); } else if (criteria instanceof GreaterThanOrEqual) { greaterThanEqual(GreaterThanOrEqual.class.cast(criteria)); } else if (criteria instanceof InCollection) { in(InCollection.class.cast(criteria)); } else if (criteria instanceof LessThan) { lessThan(LessThan.class.cast(criteria));
/** * Interpret this query * * @param query */ public void process(StoreQuery query) { includeKeys(query.requestsKeys()); includeValues(query.requestsValues()); maxResults(query.maxResults()); processCriteria(query.getCriteria()); processAttributes(query.requestedAttributes()); processOrdering(query.getOrdering()); processGroupBy(query.groupByAttributes()); processAggregators(query.getAggregatorInstances()); processHints(query.getExecutionHints()); }
private void processAggregators(List<AggregatorInstance<?>> aggregatorInstances) { for (AggregatorInstance aggregatorInstance : aggregatorInstances) { if (aggregatorInstance instanceof Count) { count(); } else if (aggregatorInstance instanceof Average) { average(aggregatorInstance.getAttribute().getAttributeName()); } else if (aggregatorInstance instanceof Sum) { sum(aggregatorInstance.getAttribute().getAttributeName()); } else if (aggregatorInstance instanceof Min) { min(aggregatorInstance.getAttribute().getAttributeName()); } else if (aggregatorInstance instanceof Max) { max(aggregatorInstance.getAttribute().getAttributeName()); } else { throw new SearchException("unknown aggregator type: " + aggregatorInstance.getClass().getName()); } } }
private void processNotCriteria(Not not) { Criteria negated = not.getCriteria(); processCriteria(notOf(negated)); }
/** * Constructor * * @param orderings */ public OrderComparator(List<Ordering> orderings) { comparators = new ArrayList<Comparator<T>>(); int pos = 0; for (Ordering ordering : orderings) { switch (ordering.getDirection()) { case ASCENDING: { comparators.add(new AscendingComparator(pos)); break; } case DESCENDING: { comparators.add(new DescendingComparator(pos)); break; } default: { throw new AssertionError(ordering.getDirection()); } } pos++; } }
private void processOrdering(List<Ordering> orderings) { for (Ordering ordering : orderings) { String attributeName = ordering.getAttribute().getAttributeName(); if (Direction.DESCENDING.equals(ordering.getDirection())) { attributeDescending(attributeName); } else { attributeAscending(attributeName); } } }
/** * Constructor * * @param query * @param attributes * @param sortAttributes * @param aggregatorResults * @param groupBy */ public GroupedResultImpl(StoreQuery query, Map<String, Object> attributes, Object[] sortAttributes, List<Object> aggregatorResults, Map<String, Object> groupBy) { super(query); this.attributes = attributes; this.sortAttributes = sortAttributes; this.groupByValues = groupBy; setAggregateResults(aggregatorResults); }
private void processAttributes(Set<Attribute<?>> attributes) { for (Attribute<?> attr : attributes) { attribute(attr.getAttributeName()); } }
private void processGroupBy(Set<Attribute<?>> attributes) { for (Attribute attr : attributes) { groupBy(attr.getAttributeName()); } }
private void setResultAggregators(List<AggregatorInstance<?>> aggregators, BaseResult result) { List<Object> aggregateResults = new ArrayList<Object>(); for (AggregatorInstance<?> aggregator : aggregators) { aggregateResults.add(aggregator.aggregateResult()); } if (!aggregateResults.isEmpty()) { result.setAggregateResults(aggregateResults); } }
/** * {@inheritDoc} */ public Object getValue() throws SearchException { if (query.requestsValues()) { return basicGetValue(); } throw new SearchException("values not included in query. Use includeValues() to add values to results."); }
/** * {@inheritDoc} */ public Object getKey() { if (query.requestsKeys()) { return basicGetKey(); } throw new SearchException("keys not included in query. Use includeKeys() to add keys to results."); }
/** * {@inheritDoc} */ public <T> T getAttribute(Attribute<T> attribute) { String name = attribute.getAttributeName(); if (!query.requestedAttributes().contains(attribute)) { throw new SearchException("Attribute [" + name + "] not included in query"); } return (T) basicGetAttribute(name); }
/** * {@inheritDoc} */ public Results executeQuery(StoreQuery query) { if (searchManager == null) { throw new UnsupportedOperationException("Query execution not supported by this store type: " + getClass().getName()); } DynamicAttributesExtractor dynExtractor = query.getCache().getCacheConfiguration().getDynamicExtractor(); return searchManager.executeQuery(query, attributeExtractors, dynExtractor); }
/** * {@inheritDoc} */ @Override public Set<Attribute> getSearchAttributes() { if (searchManager == null) { throw new InvalidConfigurationException("Search attributes not supported by this store type: " + getClass().getName()); } return new HashSet<Attribute>(searchManager.getSearchAttributes(cacheName)); }
private Map<String, AttributeExtractor> getCombinedExtractors(Map<String, AttributeExtractor> configExtractors, DynamicAttributesExtractor dynIndexer, Element element) { if (dynIndexer != null) { Map<String, AttributeExtractor> combinedExtractors = new HashMap<String, AttributeExtractor>(); combinedExtractors.putAll(configExtractors); Map<String, ?> dynamic = DynamicSearchChecker.getSearchAttributes(element, configExtractors.keySet(), dynIndexer); for (final Map.Entry<String, ?> entry: dynamic.entrySet()) { AttributeExtractor old = combinedExtractors.put(entry.getKey(), new AttributeExtractor() { @Override public Object attributeFor(Element element, String attributeName) throws AttributeExtractorException { if (!attributeName.equals(entry.getKey())) { throw new AttributeExtractorException(String.format("Expected attribute name %s but got %s", entry.getKey(), attributeName)); } return entry.getValue(); } }); if (old != null) { throw new AttributeExtractorException(String.format("Attribute name %s already used by configured extractors", entry.getKey())); } } return combinedExtractors; } else { return configExtractors; } }
/** * {@inheritDoc} */ public Element putIfAbsent(Element element) throws NullPointerException { if (element == null) { return null; } if (searchManager != null) { searchManager.put(cache.getName(), -1, element, null, attributeExtractors, cache.getCacheConfiguration().getDynamicExtractor()); } long delta = poolAccessor.add(element.getObjectKey(), element.getObjectValue(), map.storedObject(element), storePinned); if (delta > -1) { Element old = map.putIfAbsent(element.getObjectKey(), element, delta); if (old == null) { checkCapacity(element); } else { poolAccessor.delete(delta); } return old; } else { notifyDirectEviction(element); return null; } }