Search in sources :

Example 21 with PredicateBuilder

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

the class QueryBasicTest method testPredicateCustomAttribute.

@Test(timeout = 1000 * 60)
public void testPredicateCustomAttribute() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<Integer, CustomObject> map = instance.getMap("testPredicateCustomAttribute");
    CustomAttribute attribute = new CustomAttribute(78, 145);
    CustomObject customObject = new CustomObject("name1", UuidUtil.newUnsecureUUID(), attribute);
    map.put(1, customObject);
    CustomObject object2 = new CustomObject("name2", UuidUtil.newUnsecureUUID(), attribute);
    map.put(2, object2);
    assertEquals(customObject, map.values(new PredicateBuilder().getEntryObject().get("uuid").equal(customObject.getUuid())).iterator().next());
    assertEquals(2, map.values(new PredicateBuilder().getEntryObject().get("attribute").equal(attribute)).size());
    assertEquals(object2, map.values(new PredicateBuilder().getEntryObject().get("uuid").in(object2.getUuid())).iterator().next());
    assertEquals(2, map.values(new PredicateBuilder().getEntryObject().get("attribute").in(attribute)).size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PredicateBuilder(com.hazelcast.query.PredicateBuilder) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with PredicateBuilder

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

the class QueryBasicTest method testPredicateEnumAttribute.

private void testPredicateEnumAttribute(IMap<Integer, NodeType> map) {
    map.put(1, NodeType.MEMBER);
    map.put(2, NodeType.LITE_MEMBER);
    map.put(3, NodeType.JAVA_CLIENT);
    assertEquals(NodeType.MEMBER, map.values(new SqlPredicate("this=MEMBER")).iterator().next());
    assertEquals(2, map.values(new SqlPredicate("this in (MEMBER, LITE_MEMBER)")).size());
    assertEquals(NodeType.JAVA_CLIENT, map.values(new PredicateBuilder().getEntryObject().get("this").equal(NodeType.JAVA_CLIENT)).iterator().next());
    assertEquals(0, map.values(new PredicateBuilder().getEntryObject().get("this").equal(NodeType.CSHARP_CLIENT)).size());
    assertEquals(2, map.values(new PredicateBuilder().getEntryObject().get("this").in(NodeType.LITE_MEMBER, NodeType.MEMBER)).size());
}
Also used : PredicateBuilder(com.hazelcast.query.PredicateBuilder) SqlPredicate(com.hazelcast.query.SqlPredicate)

Example 23 with PredicateBuilder

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

the class QueryBasicTest method queryWithThis.

@Test(timeout = 1000 * 60)
public void queryWithThis() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, String> map = instance.getMap("queryWithThis");
    map.addIndex("this", false);
    for (int i = 0; i < 1000; i++) {
        map.put("" + i, "" + i);
    }
    Predicate predicate = new PredicateBuilder().getEntryObject().get("this").equal("10");
    Collection<String> set = map.values(predicate);
    assertEquals(1, set.size());
    assertEquals(1, map.values(new SqlPredicate("this=15")).size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PredicateBuilder(com.hazelcast.query.PredicateBuilder) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 24 with PredicateBuilder

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

the class MapLiteMemberTest method testMapKeysQuery.

public static void testMapKeysQuery(final IMap<Integer, Object> map) {
    map.put(1, 2);
    EntryObject entryObject = new PredicateBuilder().getEntryObject();
    PredicateBuilder predicateBuilder = entryObject.key().equal(1);
    Collection values = map.keySet(predicateBuilder);
    assertEquals(1, values.size());
    assertEquals(1, values.iterator().next());
}
Also used : EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) Collection(java.util.Collection)

Example 25 with PredicateBuilder

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

the class IndexIntegrationTest method putRemove_withIndex_whereAttributeIsNull.

@Test
public void putRemove_withIndex_whereAttributeIsNull() {
    // GIVEN
    MapIndexConfig mapIndexConfig = new MapIndexConfig();
    mapIndexConfig.setAttribute("amount");
    mapIndexConfig.setOrdered(false);
    MapConfig mapConfig = new MapConfig().setName("map");
    mapConfig.addMapIndexConfig(mapIndexConfig);
    Config config = new Config();
    config.addMapConfig(mapConfig);
    Trade trade = new Trade();
    trade.setCurrency("EUR");
    trade.setAmount(null);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Integer, Trade> map = instance.getMap("map");
    // WHEN
    map.put(1, trade);
    map.remove(1);
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate predicate = e.get("amount").isNull();
    Collection<Trade> values = map.values(predicate);
    // THEN
    assertEquals(0, values.size());
    assertNull(map.get(1));
}
Also used : MapIndexConfig(com.hazelcast.config.MapIndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapConfig(com.hazelcast.config.MapConfig) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

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