Search in sources :

Example 21 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class IndexesTest method testAndWithSingleEntry.

@Test
public void testAndWithSingleEntry() {
    Indexes indexes = Indexes.newBuilder(serializationService, copyBehavior, DEFAULT_IN_MEMORY_FORMAT).build();
    indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "name"));
    indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.SORTED, "age"));
    indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.SORTED, "salary"));
    for (int i = 0; i < 100; i++) {
        Employee employee = new Employee(i + "Name", i % 80, (i % 2 == 0), 100 + (i % 1000));
        indexes.putEntry(new QueryEntry(serializationService, toData(i), employee, newExtractor()), null, Index.OperationSource.USER);
    }
    int count = 10;
    Set<String> ages = new HashSet<>(count);
    for (int i = 0; i < count; i++) {
        ages.add(String.valueOf(i));
    }
    EntryObject entryObject = Predicates.newPredicateBuilder().getEntryObject();
    PredicateBuilder predicate = entryObject.get("name").equal("0Name").and(entryObject.get("age").in(ages.toArray(new String[0])));
    assertEquals(1, size(indexes.query(predicate, SKIP_PARTITIONS_COUNT_CHECK)));
}
Also used : Employee(com.hazelcast.query.SampleTestObjects.Employee) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) IndexMatchHint(com.hazelcast.query.impl.QueryContext.IndexMatchHint) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class PredicateBuilderTest method get_key.

@Test
public void get_key() {
    HazelcastInstance hz = createHazelcastInstance();
    EntryObject entryObject = Predicates.newPredicateBuilder().getEntryObject();
    Predicate predicate = entryObject.key().equal(10L);
    IMap<Integer, Integer> hazelcastLookupMap = hz.getMap("someMap");
    hazelcastLookupMap.put(10, 1);
    hazelcastLookupMap.put(30, 2);
    Collection<Integer> result = hazelcastLookupMap.values(predicate);
    assertEquals(1, result.size());
    assertContains(result, 1);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class PredicateBuilderTest method get_keyAttribute.

@Test
public void get_keyAttribute() {
    HazelcastInstance hz = createHazelcastInstance();
    EntryObject entryObject = Predicates.newPredicateBuilder().getEntryObject();
    Predicate predicate = entryObject.key().get("id").equal("10").and(entryObject.get("name").equal("value1"));
    IMap<Id, Value> hazelcastLookupMap = hz.getMap("someMap");
    hazelcastLookupMap.put(new Id("10"), new Value("value1"));
    hazelcastLookupMap.put(new Id("20"), new Value("value2"));
    hazelcastLookupMap.put(new Id("30"), new Value("value3"));
    Collection<Value> result = hazelcastLookupMap.values(predicate);
    assertEquals(1, result.size());
    assertContains(result, new Value("value1"));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class PredicateBuilderTest method get_this.

@Test
public void get_this() {
    HazelcastInstance hz = createHazelcastInstance();
    EntryObject entryObject = Predicates.newPredicateBuilder().getEntryObject();
    Predicate predicate = entryObject.get("this").equal(1L);
    IMap<Integer, Integer> hazelcastLookupMap = hz.getMap("someMap");
    hazelcastLookupMap.put(10, 1);
    hazelcastLookupMap.put(30, 2);
    Collection<Integer> result = hazelcastLookupMap.values(predicate);
    assertEquals(1, result.size());
    assertContains(result, 1);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

EntryObject (com.hazelcast.query.PredicateBuilder.EntryObject)24 Test (org.junit.Test)18 QuickTest (com.hazelcast.test.annotation.QuickTest)16 Predicate (com.hazelcast.query.Predicate)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)12 Employee (com.hazelcast.query.SampleTestObjects.Employee)7 Config (com.hazelcast.config.Config)6 PredicateBuilder (com.hazelcast.query.PredicateBuilder)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 MapConfig (com.hazelcast.config.MapConfig)4 EvictionConfig (com.hazelcast.config.EvictionConfig)2 IndexConfig (com.hazelcast.config.IndexConfig)2 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 NearCacheConfig (com.hazelcast.config.NearCacheConfig)2 IMap (com.hazelcast.map.IMap)2 Collection (java.util.Collection)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)1 EntryAdapter (com.hazelcast.core.EntryAdapter)1 EntryView (com.hazelcast.core.EntryView)1