| | |
| | | package org.opends.server.backends.pluggable; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.Map; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.spi.IndexQueryFactory; |
| | | import org.forgerock.opendj.ldap.spi.IndexingOptions; |
| | | import org.opends.server.backends.pluggable.spi.ReadableStorage; |
| | | |
| | | import static org.opends.messages.JebMessages.*; |
| | | |
| | |
| | | * This class is an implementation of IndexQueryFactory which creates |
| | | * IndexQuery objects as part of the query of the JEB index. |
| | | */ |
| | | public final class IndexQueryFactoryImpl implements |
| | | IndexQueryFactory<IndexQuery> |
| | | public final class IndexQueryFactoryImpl implements IndexQueryFactory<IndexQuery> |
| | | { |
| | | |
| | | private static final String PRESENCE_INDEX_KEY = "presence"; |
| | | |
| | | /** |
| | | * The Map containing the string type identifier and the corresponding index. |
| | | */ |
| | | private final Map<String, Index> indexMap; |
| | | private final IndexingOptions indexingOptions; |
| | | private final ReadableStorage txn; |
| | | /** The Map containing the string type identifier and the corresponding index. */ |
| | | private final AttributeIndex attributeIndex; |
| | | |
| | | /** |
| | | * Creates a new IndexQueryFactoryImpl object. |
| | | * |
| | | * @param indexMap |
| | | * A map containing the index id and the corresponding index. |
| | | * @param indexingOptions |
| | | * The options to use for indexing |
| | | * @param txn |
| | | * The readable storage |
| | | * @param attributeIndex |
| | | * The targeted attribute index |
| | | */ |
| | | public IndexQueryFactoryImpl(Map<String, Index> indexMap, IndexingOptions indexingOptions) |
| | | public IndexQueryFactoryImpl(ReadableStorage txn, AttributeIndex attributeIndex) |
| | | { |
| | | this.indexMap = indexMap; |
| | | this.indexingOptions = indexingOptions; |
| | | this.txn = txn; |
| | | this.attributeIndex = attributeIndex; |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public IndexQuery createExactMatchQuery(final String indexID, final ByteSequence key) |
| | | { |
| | | return new IndexQuery() |
| | | { |
| | | |
| | | @Override |
| | | public EntryIDSet evaluate(LocalizableMessageBuilder debugMessage) |
| | | { |
| | | // Read the database and get Record for the key. |
| | | // Select the right index to be used. |
| | | Index index = indexMap.get(indexID); |
| | | final Index index = attributeIndex.getIndexById(indexID); |
| | | if (index == null) |
| | | { |
| | | if(debugMessage != null) |
| | |
| | | } |
| | | return createMatchAllQuery().evaluate(debugMessage); |
| | | } |
| | | EntryIDSet entrySet = index.readKey(key, null); |
| | | |
| | | final EntryIDSet entrySet = index.readKey(key, null); |
| | | if(debugMessage != null && !entrySet.isDefined()) |
| | | { |
| | | updateStatsUndefinedResults(debugMessage, index); |
| | |
| | | }; |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public IndexQuery createRangeMatchQuery(final String indexID, |
| | |
| | | { |
| | | return new IndexQuery() |
| | | { |
| | | |
| | | @Override |
| | | public EntryIDSet evaluate(LocalizableMessageBuilder debugMessage) |
| | | { |
| | | // Find the right index. |
| | | Index index = indexMap.get(indexID); |
| | | final Index index = attributeIndex.getIndexById(indexID); |
| | | if (index == null) |
| | | { |
| | | if(debugMessage != null) |
| | |
| | | } |
| | | return createMatchAllQuery().evaluate(debugMessage); |
| | | } |
| | | EntryIDSet entrySet = index.readRange(lowerBound, upperBound, |
| | | |
| | | final EntryIDSet entrySet = index.readRange(txn, lowerBound, upperBound, |
| | | includeLowerBound, includeUpperBound); |
| | | if(debugMessage != null && !entrySet.isDefined()) |
| | | { |
| | |
| | | }; |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public IndexQuery createIntersectionQuery(Collection<IndexQuery> subqueries) |
| | |
| | | return IndexQuery.createIntersectionIndexQuery(subqueries); |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public IndexQuery createUnionQuery(Collection<IndexQuery> subqueries) |
| | |
| | | return IndexQuery.createUnionIndexQuery(subqueries); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | * <p> |
| | |
| | | @Override |
| | | public EntryIDSet evaluate(LocalizableMessageBuilder debugMessage) |
| | | { |
| | | final String indexID = PRESENCE_INDEX_KEY; |
| | | final Index index = indexMap.get(indexID); |
| | | final String indexID = PRESENCE_INDEX_KEY; |
| | | final Index index = attributeIndex.getIndexById(indexID); |
| | | if (index == null) |
| | | { |
| | | if(debugMessage != null) |
| | |
| | | return new EntryIDSet(); |
| | | } |
| | | |
| | | EntryIDSet entrySet = index.readKey(PresenceIndexer.presenceKey, null); |
| | | final EntryIDSet entrySet = index.readKey(PresenceIndexer.presenceKey, null); |
| | | if (debugMessage != null && !entrySet.isDefined()) |
| | | { |
| | | updateStatsUndefinedResults(debugMessage, index); |
| | |
| | | @Override |
| | | public IndexingOptions getIndexingOptions() |
| | | { |
| | | return indexingOptions; |
| | | return attributeIndex.getIndexingOptions(); |
| | | } |
| | | } |