Search in sources :

Example 6 with EntryObject

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

the class QueryIndexTest method testResultsReturned_whenCustomAttributeIndexed.

@Test
public void testResultsReturned_whenCustomAttributeIndexed() {
    HazelcastInstance h1 = createHazelcastInstance();
    IMap<String, CustomObject> imap = h1.getMap("objects");
    imap.addIndex("attribute", true);
    for (int i = 0; i < 10; i++) {
        CustomAttribute attr = new CustomAttribute(i, 200);
        CustomObject object = new CustomObject("o" + i, randomUUID(), attr);
        imap.put(object.getName(), object);
    }
    EntryObject entry = new PredicateBuilder().getEntryObject();
    Predicate predicate = entry.get("attribute").greaterEqual(new CustomAttribute(5, 200));
    Collection<CustomObject> values = imap.values(predicate);
    assertEquals(5, values.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with EntryObject

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

the class QueryIndexingTest method setUp.

@Before
public void setUp() {
    employees = newEmployees(count);
    nodeFactory = createHazelcastInstanceFactory(2);
    Config config = newConfig();
    h1 = nodeFactory.newHazelcastInstance(config);
    h2 = nodeFactory.newHazelcastInstance(config);
    EntryObject entryObject = new PredicateBuilder().getEntryObject();
    predicate = entryObject.get("name").equal(null).and(entryObject.get("city").isNull());
    assertClusterSizeEventually(2, h1);
}
Also used : EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) Config(com.hazelcast.config.Config) Before(org.junit.Before)

Example 8 with EntryObject

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

the class NestedPredicateTest method nestedAttributeQuery_predicates.

@Test
public void nestedAttributeQuery_predicates() throws Exception {
    // GIVEN
    map.put(1, new Body("body1", new Limb("hand")));
    map.put(2, new Body("body2", new Limb("leg")));
    // WHEN
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate predicate = e.get("limb.name").equal("leg");
    Collection<Body> values = map.values(predicate);
    // THEN
    assertEquals(1, values.size());
    assertEquals("body2", values.toArray(new Body[values.size()])[0].getName());
}
Also used : EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with EntryObject

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

the class NestedPredicateTest method singleAttributeQuery_predicates.

@Test
public void singleAttributeQuery_predicates() throws Exception {
    // GIVEN
    map.put(1, new Body("body1", new Limb("hand")));
    map.put(2, new Body("body2", new Limb("leg")));
    // WHEN
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate predicate = e.get("name").equal("body1");
    Collection<Body> values = map.values(predicate);
    // THEN
    assertEquals(1, values.size());
    assertEquals("body1", values.toArray(new Body[values.size()])[0].getName());
}
Also used : EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with EntryObject

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

the class NestedPredicateWithExtractorTest method singleAttributeQuery_predicates.

@Test
public void singleAttributeQuery_predicates() throws Exception {
    // GIVEN
    map.put(1, new Body("body1", new Limb("hand")));
    map.put(2, new Body("body2", new Limb("leg")));
    // WHEN
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate predicate = e.get("name").equal("body1");
    Collection<Body> values = map.values(predicate);
    // THEN
    assertEquals(1, values.size());
    assertEquals("body1", values.toArray(new Body[values.size()])[0].getName());
    assertEquals(2 + 1, bodyExtractorExecutions);
    assertEquals(0, limbExtractorExecutions);
}
Also used : EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

EntryObject (com.hazelcast.query.EntryObject)18 PredicateBuilder (com.hazelcast.query.PredicateBuilder)18 Predicate (com.hazelcast.query.Predicate)13 Test (org.junit.Test)13 QuickTest (com.hazelcast.test.annotation.QuickTest)12 SqlPredicate (com.hazelcast.query.SqlPredicate)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 Employee (com.hazelcast.query.SampleObjects.Employee)6 Config (com.hazelcast.config.Config)5 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 MapConfig (com.hazelcast.config.MapConfig)3 IMap (com.hazelcast.core.IMap)3 MapIndexConfig (com.hazelcast.config.MapIndexConfig)2 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 IndexAwarePredicate (com.hazelcast.query.IndexAwarePredicate)2 Collection (java.util.Collection)2 Map (java.util.Map)2 EvictionConfig (com.hazelcast.config.EvictionConfig)1 MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)1 NearCacheConfig (com.hazelcast.config.NearCacheConfig)1