Search in sources :

Example 26 with PredicateBuilder

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

the class IndexesTest method testAndWithSingleEntry.

@Test
public void testAndWithSingleEntry() throws Exception {
    Indexes indexes = new Indexes(serializationService, Extractors.empty());
    indexes.addOrGetIndex("name", false);
    indexes.addOrGetIndex("age", true);
    indexes.addOrGetIndex("salary", true);
    for (int i = 0; i < 100; i++) {
        Employee employee = new Employee(i + "Name", i % 80, (i % 2 == 0), 100 + (i % 1000));
        indexes.saveEntryIndex(new QueryEntry(serializationService, toData(i), employee, Extractors.empty()), null);
    }
    int count = 10;
    Set<String> ages = new HashSet<String>(count);
    for (int i = 0; i < count; i++) {
        ages.add(String.valueOf(i));
    }
    EntryObject entryObject = new PredicateBuilder().getEntryObject();
    PredicateBuilder predicate = entryObject.get("name").equal("0Name").and(entryObject.get("age").in(ages.toArray(new String[count])));
    Set<QueryableEntry> results = indexes.query(predicate);
    assertEquals(1, results.size());
}
Also used : Employee(com.hazelcast.query.SampleObjects.Employee) EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) HashSet(java.util.HashSet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 27 with PredicateBuilder

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

the class PredicatesTest method testCriteriaAPI.

@Test
public void testCriteriaAPI() {
    Object value = new Employee(12, "abc-123-xvz", 34, true, 10D);
    EntryObject e = new PredicateBuilder().getEntryObject();
    EntryObject e2 = e.get("age");
    Predicate predicate = e2.greaterEqual(29).and(e2.lessEqual(36));
    assertTrue(predicate.apply(createEntry("1", value)));
    e = new PredicateBuilder().getEntryObject();
    assertTrue(e.get("id").equal(12).apply(createEntry("1", value)));
}
Also used : Employee(com.hazelcast.query.SampleObjects.Employee) EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) EntryObject(com.hazelcast.query.EntryObject) Predicate(com.hazelcast.query.Predicate) IndexAwarePredicate(com.hazelcast.query.IndexAwarePredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 28 with PredicateBuilder

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

the class NestedPredicateVersionedPortablesTest method singleAttributeQuery_versionedProtables_predicates.

@Test
public void singleAttributeQuery_versionedProtables_predicates() throws Exception {
    // GIVEN
    map.put(1, new NestedPredicateVersionedPortablesTest.Body("body1", new NestedPredicateVersionedPortablesTest.Limb("hand")));
    map.put(2, new NestedPredicateVersionedPortablesTest.Body("body2", new NestedPredicateVersionedPortablesTest.Limb("leg")));
    // WHEN
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate predicate = e.get("limb.name").equal("hand");
    Collection<NestedPredicateVersionedPortablesTest.Body> values = map.values(predicate);
    // THEN
    assertEquals(1, values.size());
    assertEquals("body1", values.toArray(new NestedPredicateVersionedPortablesTest.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 29 with PredicateBuilder

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

the class NestedPredicateWithExtractorTest 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("limbname").equal("leg");
    Collection<Body> values = map.values(predicate);
    // THEN
    assertEquals(1, values.size());
    assertEquals("body2", values.toArray(new Body[values.size()])[0].getName());
    assertEquals(0, bodyExtractorExecutions);
    assertEquals(2 + 1, 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

PredicateBuilder (com.hazelcast.query.PredicateBuilder)29 Test (org.junit.Test)20 Predicate (com.hazelcast.query.Predicate)19 SqlPredicate (com.hazelcast.query.SqlPredicate)19 QuickTest (com.hazelcast.test.annotation.QuickTest)19 EntryObject (com.hazelcast.query.EntryObject)18 HazelcastInstance (com.hazelcast.core.HazelcastInstance)14 ParallelTest (com.hazelcast.test.annotation.ParallelTest)12 Config (com.hazelcast.config.Config)6 Employee (com.hazelcast.query.SampleObjects.Employee)6 Value (com.hazelcast.query.SampleObjects.Value)6 MapConfig (com.hazelcast.config.MapConfig)4 MapIndexConfig (com.hazelcast.config.MapIndexConfig)3 IMap (com.hazelcast.core.IMap)3 ValueType (com.hazelcast.query.SampleObjects.ValueType)3 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 IndexAwarePredicate (com.hazelcast.query.IndexAwarePredicate)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2