/** * Read this index. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public Object toIndex(JTransaction jtx) { return new ConvertedIndex(jtx.tx.queryIndex(this.storageId), this.getConverter(jtx), jtx.referenceConverter); }
/** * Get the index on a simple field. The simple field may be a sub-field of a complex field. * * @param targetType Java type containing the indexed field; may also be any super-type (e.g., an interface type), * as long as {@code fieldName} is not ambiguous among all sub-types * @param fieldName name of the indexed field; for complex fields, * must include the sub-field name (e.g., {@code "mylist.element"}, {@code "mymap.key"}) * @param valueType the Java type corresponding to the field value * @param <V> Java type corresponding to the indexed field * @param <T> Java type containing the field * @return read-only, real-time view of field values mapped to sets of objects having that value in the field * @throws IllegalArgumentException if any parameter is null, or invalid * @throws StaleTransactionException if this transaction is no longer usable */ @SuppressWarnings({ "rawtypes", "unchecked" }) public <V, T> Index<V, T> queryIndex(Class<T> targetType, String fieldName, Class<V> valueType) { final IndexQueryInfo info = this.jdb.getIndexQueryInfo(new IndexQueryInfoKey(fieldName, false, targetType, valueType)); assert info.indexInfo instanceof SimpleFieldIndexInfo; // otherwise getIndexQueryInfo() would have failed... final SimpleFieldIndexInfo indexInfo = (SimpleFieldIndexInfo)info.indexInfo; final CoreIndex<?, ObjId> index = info.applyFilters(this.tx.queryIndex(indexInfo.storageId)); final Converter<?, ?> valueConverter = indexInfo.getConverter(this).reverse(); final Converter<T, ObjId> targetConverter = new ReferenceConverter<T>(this, targetType); return new ConvertedIndex(index, valueConverter, targetConverter); }