Search in sources :

Example 56 with Indexes

use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.

the class Accessors method getAllIndexes.

/**
 * Obtains a list of {@link Indexes} for the given map local to the node
 * associated with it.
 * <p>
 * There may be more than one indexes instance associated with a map if its
 * indexes are partitioned.
 *
 * @param map the map to obtain the indexes for.
 * @return the obtained indexes list.
 */
public static List<Indexes> getAllIndexes(IMap map) {
    MapProxyImpl mapProxy = (MapProxyImpl) map;
    String mapName = mapProxy.getName();
    NodeEngine nodeEngine = mapProxy.getNodeEngine();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    MapService mapService = nodeEngine.getService(MapService.SERVICE_NAME);
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    MapContainer mapContainer = mapServiceContext.getMapContainer(mapName);
    Indexes maybeGlobalIndexes = mapContainer.getIndexes();
    if (maybeGlobalIndexes != null) {
        return Collections.singletonList(maybeGlobalIndexes);
    }
    PartitionContainer[] partitionContainers = mapServiceContext.getPartitionContainers();
    List<Indexes> allIndexes = new ArrayList<>();
    for (PartitionContainer partitionContainer : partitionContainers) {
        IPartition partition = partitionService.getPartition(partitionContainer.getPartitionId());
        if (!partition.isLocal()) {
            continue;
        }
        Indexes partitionIndexes = partitionContainer.getIndexes().get(mapName);
        if (partitionIndexes == null) {
            continue;
        }
        assert !partitionIndexes.isGlobal();
        allIndexes.add(partitionIndexes);
    }
    return allIndexes;
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer) IPartitionService(com.hazelcast.internal.partition.IPartitionService) ArrayList(java.util.ArrayList) Indexes(com.hazelcast.query.impl.Indexes) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapContainer(com.hazelcast.map.impl.MapContainer) NodeEngine(com.hazelcast.spi.impl.NodeEngine) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) MapService(com.hazelcast.map.impl.MapService) IPartition(com.hazelcast.internal.partition.IPartition)

Aggregations

Indexes (com.hazelcast.query.impl.Indexes)56 MapContainer (com.hazelcast.map.impl.MapContainer)15 QuickTest (com.hazelcast.test.annotation.QuickTest)14 Test (org.junit.Test)14 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)13 Predicate (com.hazelcast.query.Predicate)11 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)11 InternalIndex (com.hazelcast.query.impl.InternalIndex)10 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)9 IndexConfig (com.hazelcast.config.IndexConfig)8 Record (com.hazelcast.map.impl.record.Record)8 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)7 MapService (com.hazelcast.map.impl.MapService)6 Data (com.hazelcast.nio.serialization.Data)6 ArrayList (java.util.ArrayList)6 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)5 PredicateTestUtils.createPassthroughVisitor (com.hazelcast.query.impl.predicates.PredicateTestUtils.createPassthroughVisitor)5 Index (com.hazelcast.query.impl.Index)4 Map (java.util.Map)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3