/** * Get the defined search attributes indexed by attribute name *excluding* any search attributes that are automatically/implicitly * defined (eg. key and value attributes) * * @return search attributes */ public Map<String, SearchAttribute> getUserDefinedSearchAttributes() { Map<String, SearchAttribute> copy = new HashMap<String, SearchAttribute>(searchAttributes); copy.remove(Query.KEY.getAttributeName()); copy.remove(Query.VALUE.getAttributeName()); return copy; }
private void disallowBuiltins(String attributeName) { if (Query.KEY.getAttributeName().equals(attributeName) || Query.VALUE.getAttributeName().equals(attributeName)) { throw new InvalidConfigurationException("\"" + attributeName + "\" is a reserved attribute name"); } }
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 Map<String, Object> getAttributeValues(Set<Attribute<?>> attributes, Map<String, AttributeExtractor> extractors, Element element) { final Map<String, Object> values; if (attributes.isEmpty()) { values = Collections.emptyMap(); } else { values = new HashMap<String, Object>(); for (Attribute attribute : attributes) { String name = attribute.getAttributeName(); values.put(name, getExtractor(name, extractors).attributeFor(element, name)); } } return values; }
/** * As ehcache attribute string. * * @return the string */ public String asEhcacheAttributeString() { if (isKey() || isStar()) { return Query.KEY.getAttributeName(); } else if (isValue()) { return Query.VALUE.getAttributeName(); } else { return name; } }
/** * Extracts dynamically indexed search attributes from cache element using provided extractor, * validating against reserved set of attribute names (provided by Ehcache search config) * * @param e cache element for which to get dynamically extracted attribute values * @param reservedAttrs disallowed attribute names * @param extractor dynamic attributes extractor * @return map of dynamically extracted search attribute names to their values. If passed in extractor is null, map will be empty. * @throws SearchException */ public static Map<String, ? extends Object> getSearchAttributes(Element e, Set<String> reservedAttrs, DynamicAttributesExtractor extractor) throws SearchException { if (extractor == null) { return Collections.emptyMap(); } Map<String, ? extends Object> dynamic = extractor.attributesFor(e); Set<String> copy = new HashSet<String>(reservedAttrs); copy.add(Query.KEY.getAttributeName()); copy.add(Query.VALUE.getAttributeName()); if (copy.removeAll(dynamic.keySet())) { throw new SearchException("Dynamic extractor produced attributes already used in static search config"); } return dynamic; } }
/** * Toggle searchable keys * * @param keys */ public void setKeys(boolean keys) { checkDynamicChange(); this.keys = keys; if (!keys) { searchAttributes.remove(Query.KEY.getAttributeName()); } else { String keyAttr = Query.KEY.getAttributeName(); searchAttributes.put(keyAttr, new SearchAttribute().name(keyAttr).className(KeyObjectAttributeExtractor.class.getName())); } }
/** * Toggle searchable values * * @param values */ public void setValues(boolean values) { checkDynamicChange(); this.values = values; if (!values) { searchAttributes.remove(Query.VALUE.getAttributeName()); } else { String valueAttr = Query.VALUE.getAttributeName(); searchAttributes.put(valueAttr, new SearchAttribute().name(valueAttr).className(ValueObjectAttributeExtractor.class.getName())); } }
/** * {@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); }
private Object[] getSortAttributes(StoreQuery query, Map<String, AttributeExtractor> extractors, Element element) { Object[] sortAttributes; List<StoreQuery.Ordering> orderings = query.getOrdering(); if (orderings.isEmpty()) { sortAttributes = BruteForceSearchManager.EMPTY_OBJECT_ARRAY; } else { sortAttributes = new Object[orderings.size()]; for (int i = 0; i < sortAttributes.length; i++) { String name = orderings.get(i).getAttribute().getAttributeName(); sortAttributes[i] = getExtractor(name, extractors).attributeFor(element, name); } } return sortAttributes; }
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()); } } }
Map<String, String> attrs = new HashMap<String, String>(); for (Attribute a : query.requestedAttributes()) { attrs.put(a.getAttributeName(), String.valueOf(getAttribute(a)));
/** * {@inheritDoc} */ public <T> Attribute<T> getSearchAttribute(String attributeName) throws CacheException { // We don't trust config here since the store is the real authority checkStatus(); Attribute<T> searchAttribute = compoundStore.getSearchAttribute(attributeName); if (searchAttribute == null) { final String msg; if (attributeName.equals(Query.KEY.getAttributeName())) { msg = "Key search attribute is disabled for cache [" + getName() + "]. It can be enabled with <searchable keys=\"true\"..."; } else if (attributeName.equals(Query.VALUE.getAttributeName())) { msg = "Value search attribute is disabled for cache [" + getName() + "]. It can be enabled with <searchable values=\"true\"..."; } else { msg = "No such search attribute [" + attributeName + "] defined for this cache [" + getName() + "]"; } throw new CacheException(msg); } return searchAttribute; }
@Override public Map<String, String> getSearchAttributes() { Map<String, String> result = new HashMap<String, String>(); if (cache != null && cache.getCacheConfiguration().getSearchable() != null) { Map<String, Attribute> attrMap = new HashMap<String, Attribute>(); for (Attribute attr : cache.getSearchAttributes()) { attrMap.put(attr.getAttributeName(), attr); } for (SearchAttribute sa : cache.getCacheConfiguration().getSearchAttributes().values()) { String saName = sa.getName(); String typeName = sa.getTypeName(); if (attrMap.containsKey(saName) && typeName != null) { result.put(saName, typeName); } } } return result; }
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); } } }
String attrName = attr.getAttributeName(); attrMap.put(attrName, attr);
getExtractor(aggrAttr.getAttributeName(), extractorSuperset).attributeFor(element, aggrAttr.getAttributeName()) : null; resultAggs.add(val);
private void processGroupBy(Set<Attribute<?>> attributes) { for (Attribute attr : attributes) { groupBy(attr.getAttributeName()); } }
for (Attribute attr : getAttributesImpliedByStar(ehcache)) { if (Query.KEY.equals(attr) || Query.VALUE.equals(attr)) continue; // TODO targetList.add(attr.getAttributeName());