use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class AddIndexOperation method run.
@Override
public void run() throws Exception {
Indexes indexes = mapContainer.getIndexes();
Index index = indexes.addOrGetIndex(attributeName, ordered);
final long now = getNow();
final Iterator<Record> iterator = recordStore.iterator(now, false);
SerializationService serializationService = getNodeEngine().getSerializationService();
while (iterator.hasNext()) {
final Record record = iterator.next();
Data key = record.getKey();
Object value = Records.getValueOrCachedValue(record, serializationService);
QueryableEntry queryEntry = mapContainer.newQueryEntry(key, value);
index.saveEntryIndex(queryEntry, null);
}
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class MapMigrationAwareService method migrateIndex.
private void migrateIndex(PartitionMigrationEvent event) {
final long now = getNow();
final PartitionContainer container = mapServiceContext.getPartitionContainer(event.getPartitionId());
for (RecordStore recordStore : container.getMaps().values()) {
final MapContainer mapContainer = mapServiceContext.getMapContainer(recordStore.getName());
final Indexes indexes = mapContainer.getIndexes();
if (!indexes.hasIndex()) {
continue;
}
final Iterator<Record> iterator = recordStore.iterator(now, false);
while (iterator.hasNext()) {
Record record = iterator.next();
Data key = record.getKey();
if (event.getMigrationEndpoint() == SOURCE) {
assert event.getNewReplicaIndex() != 0 : "Invalid migration event: " + event;
Object value = Records.getValueOrCachedValue(record, serializationService);
indexes.removeEntryIndex(key, value);
} else if (event.getNewReplicaIndex() == 0) {
Object value = Records.getValueOrCachedValue(record, serializationService);
if (value != null) {
QueryableEntry queryEntry = mapContainer.newQueryEntry(record.getKey(), value);
indexes.saveEntryIndex(queryEntry, null);
}
}
}
}
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class AbstractVisitorTest method testAllVisitMethodReturnTheOriginalPredicate.
@Test
public void testAllVisitMethodReturnTheOriginalPredicate() throws Exception {
// Contract of AbstractVisitor mandates to return original predicate
// for all methods on Visitor interface.
// This test makes sure if a new method is added into Visitor interface
// then it's added to AbstractVisitor and honour its contract
AbstractVisitor visitor = new AbstractVisitor() {
};
Method[] methods = Visitor.class.getMethods();
for (Method method : methods) {
Class<?> predicateType = method.getParameterTypes()[0];
Predicate predicate = (Predicate) predicateType.newInstance();
Indexes indexes = mock(Indexes.class);
Object result = method.invoke(visitor, predicate, indexes);
assertSame("Method " + method + " does not return identity of the original predicate. " + "See contract of " + AbstractVisitor.class.getSimpleName(), predicate, result);
}
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class AndPredicateTest method accept_whenInnerPredicateChangedOnAccept_thenReturnAndNewAndPredicate.
@Test
public void accept_whenInnerPredicateChangedOnAccept_thenReturnAndNewAndPredicate() {
Visitor mockVisitor = createPassthroughVisitor();
Indexes mockIndexes = mock(Indexes.class);
Predicate transformed = mock(Predicate.class);
Predicate innerPredicate = createMockVisitablePredicate(transformed);
Predicate[] innerPredicates = new Predicate[1];
innerPredicates[0] = innerPredicate;
AndPredicate andPredicate = new AndPredicate(innerPredicates);
AndPredicate result = (AndPredicate) andPredicate.accept(mockVisitor, mockIndexes);
assertThat(result, not(sameInstance(andPredicate)));
Predicate[] newInnerPredicates = result.predicates;
assertThat(newInnerPredicates, arrayWithSize(1));
assertThat(newInnerPredicates[0], equalTo(transformed));
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class EmptyOptimizerTest method optimize_returnsOriginalPredicate.
@Test
public void optimize_returnsOriginalPredicate() {
EmptyOptimizer emptyOptimizer = new EmptyOptimizer();
Predicate predicate = mock(Predicate.class);
Indexes indexes = mock(Indexes.class);
Predicate result = emptyOptimizer.optimize(predicate, indexes);
assertSame(predicate, result);
}
Aggregations