/** * Get the composite index on a list field that includes list indicies. * * @param targetType 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; must include {@code "element"} sub-field name (e.g., {@code "mylist.element"}) * @param valueType the Java type corresponding to list elements * @param <V> Java type corresponding to the indexed list's element field * @param <T> Java type containing the field * @return read-only, real-time view of field values, objects having that value in the field, and corresponding list indicies * @throws IllegalArgumentException if any parameter is null, or invalid * @throws StaleTransactionException if this transaction is no longer usable */ @SuppressWarnings({ "rawtypes", "unchecked" }) public <V, T> Index2<V, T, Integer> queryListElementIndex(Class<T> targetType, String fieldName, Class<V> valueType) { final IndexQueryInfo info = this.jdb.getIndexQueryInfo(new IndexQueryInfoKey(fieldName, false, targetType, valueType)); if (!(info.indexInfo instanceof ListElementIndexInfo)) throw new IllegalArgumentException("field `" + fieldName + "' is not a list element sub-field"); final ListElementIndexInfo indexInfo = (ListElementIndexInfo)info.indexInfo; final CoreIndex2<?, ObjId, Integer> index = info.applyFilters(this.tx.queryListElementIndex(indexInfo.storageId)); final Converter<?, ?> valueConverter = indexInfo.getConverter(this).reverse(); final Converter<T, ObjId> targetConverter = new ReferenceConverter<T>(this, targetType); return new ConvertedIndex2(index, valueConverter, targetConverter, Converter.<Integer>identity()); }
final IndexQueryInfo info = this.jdb.getIndexQueryInfo(new IndexQueryInfoKey(jfield.name, false, jfield.getter.getDeclaringClass(), jfield.typeToken.wrap().getRawType())); final CoreIndex<?, ObjId> index = info.applyFilters(this.tx.queryIndex(jfield.storageId)); final IndexQueryInfo info = this.jdb.getIndexQueryInfo( new IndexQueryInfoKey(index.name, true, index.declaringType, index.getQueryInfoValueTypes())); final CompositeIndexInfo indexInfo = (CompositeIndexInfo)info.indexInfo;
/** * Get the composite index on a map value field that includes map keys. * * @param targetType 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; must include {@code "value"} sub-field name (e.g., {@code "mymap.value"}) * @param valueType the Java type corresponding to map values * @param keyType the Java type corresponding to map keys * @param <V> Java type corresponding to the indexed map's value field * @param <T> Java type containing the field * @param <K> Java type corresponding to the indexed map's key field * @return read-only, real-time view of map values, objects having that value in the map field, and corresponding map keys * @throws IllegalArgumentException if any parameter is null, or invalid * @throws StaleTransactionException if this transaction is no longer usable */ @SuppressWarnings({ "rawtypes", "unchecked" }) public <V, T, K> Index2<V, T, K> queryMapValueIndex(Class<T> targetType, String fieldName, Class<V> valueType, Class<K> keyType) { final IndexQueryInfo info = this.jdb.getIndexQueryInfo( new IndexQueryInfoKey(fieldName, false, targetType, valueType, keyType)); if (!(info.indexInfo instanceof MapValueIndexInfo)) throw new IllegalArgumentException("field `" + fieldName + "' is not a map value sub-field"); final MapValueIndexInfo indexInfo = (MapValueIndexInfo)info.indexInfo; final CoreIndex2<?, ObjId, ?> index = info.applyFilters(this.tx.queryMapValueIndex(indexInfo.storageId)); final Converter<?, ?> valueConverter = indexInfo.getConverter(this).reverse(); final Converter<?, ?> keyConverter = indexInfo.getKeyConverter(this).reverse(); final Converter<T, ObjId> targetConverter = new ReferenceConverter<T>(this, targetType); return new ConvertedIndex2(index, valueConverter, targetConverter, keyConverter); }
/** * 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); }
/** * Access a composite index on two fields. * * @param targetType type containing the indexed fields; may also be any super-type (e.g., an interface type) * @param indexName the name of the composite index * @param value1Type the Java type corresponding to the first field value * @param value2Type the Java type corresponding to the second field value * @param <V1> Java type corresponding to the first indexed field * @param <V2> Java type corresponding to the second indexed field * @param <T> Java type containing the field * @return read-only, real-time view of the fields' values and the objects having those values in the fields * @throws IllegalArgumentException if any parameter is null, or invalid * @throws StaleTransactionException if this transaction is no longer usable */ @SuppressWarnings({ "rawtypes", "unchecked" }) public <V1, V2, T> Index2<V1, V2, T> queryCompositeIndex(Class<T> targetType, String indexName, Class<V1> value1Type, Class<V2> value2Type) { final IndexQueryInfo info = this.jdb.getIndexQueryInfo( new IndexQueryInfoKey(indexName, true, targetType, value1Type, value2Type)); final CompositeIndexInfo indexInfo = (CompositeIndexInfo)info.indexInfo; final CoreIndex2<?, ?, ObjId> index = info.applyFilters(this.tx.queryCompositeIndex2(indexInfo.storageId)); final Converter<?, ?> value1Converter = indexInfo.getConverter(this, 0).reverse(); final Converter<?, ?> value2Converter = indexInfo.getConverter(this, 1).reverse(); final Converter<T, ObjId> targetConverter = new ReferenceConverter<T>(this, targetType); return new ConvertedIndex2(index, value1Converter, value2Converter, targetConverter); }
/** * Access a composite index on three fields. * * @param targetType type containing the indexed fields; may also be any super-type (e.g., an interface type) * @param indexName the name of the composite index * @param value1Type the Java type corresponding to the first field value * @param value2Type the Java type corresponding to the second field value * @param value3Type the Java type corresponding to the third field value * @param <V1> Java type corresponding to the first indexed field * @param <V2> Java type corresponding to the second indexed field * @param <V3> Java type corresponding to the third indexed field * @param <T> Java type containing the field * @return read-only, real-time view of the fields' values and the objects having those values in the fields * @throws IllegalArgumentException if any parameter is null, or invalid * @throws StaleTransactionException if this transaction is no longer usable */ @SuppressWarnings({ "rawtypes", "unchecked" }) public <V1, V2, V3, T> Index3<V1, V2, V3, T> queryCompositeIndex(Class<T> targetType, String indexName, Class<V1> value1Type, Class<V2> value2Type, Class<V3> value3Type) { final IndexQueryInfo info = this.jdb.getIndexQueryInfo( new IndexQueryInfoKey(indexName, true, targetType, value1Type, value2Type, value3Type)); final CompositeIndexInfo indexInfo = (CompositeIndexInfo)info.indexInfo; final CoreIndex3<?, ?, ?, ObjId> index = info.applyFilters(this.tx.queryCompositeIndex3(indexInfo.storageId)); final Converter<?, ?> value1Converter = indexInfo.getConverter(this, 0).reverse(); final Converter<?, ?> value2Converter = indexInfo.getConverter(this, 1).reverse(); final Converter<?, ?> value3Converter = indexInfo.getConverter(this, 2).reverse(); final Converter<T, ObjId> targetConverter = new ReferenceConverter<T>(this, targetType); return new ConvertedIndex3(index, value1Converter, value2Converter, value3Converter, targetConverter); }
public <V1, V2, V3, V4, T> Index4<V1, V2, V3, V4, T> queryCompositeIndex(Class<T> targetType, String indexName, Class<V1> value1Type, Class<V2> value2Type, Class<V3> value3Type, Class<V4> value4Type) { final IndexQueryInfo info = this.jdb.getIndexQueryInfo( new IndexQueryInfoKey(indexName, true, targetType, value1Type, value2Type, value3Type, value4Type)); final CompositeIndexInfo indexInfo = (CompositeIndexInfo)info.indexInfo;