Search in sources :

Example 11 with EntryObject

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

the class QueryIndexTest method testOneIndexedFieldsWithTwoCriteriaField.

@Test(timeout = 1000 * 60)
public void testOneIndexedFieldsWithTwoCriteriaField() {
    HazelcastInstance h1 = createHazelcastInstance();
    IMap<String, Employee> map = h1.getMap("employees");
    map.addIndex("name", false);
    map.put("1", new Employee(1L, "joe", 30, true, 100D));
    EntryObject e = new PredicateBuilder().getEntryObject();
    PredicateBuilder a = e.get("name").equal("joe");
    Predicate b = e.get("age").equal("30");
    Collection<Employee> actual = map.values(a.and(b));
    assertEquals(1, actual.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) 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 12 with EntryObject

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

the class QueryBasicTest method doFunctionalQueryTest.

public static void doFunctionalQueryTest(IMap<String, Employee> map) {
    map.put("1", new Employee("joe", 33, false, 14.56));
    map.put("2", new Employee("ali", 23, true, 15.00));
    for (int i = 3; i < 103; i++) {
        map.put(String.valueOf(i), new Employee("name" + i, i % 60, ((i & 1) == 1), i));
    }
    Set<Map.Entry<String, Employee>> entries = map.entrySet();
    assertEquals(102, entries.size());
    int entryCount = 0;
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertNotNull(employee);
        entryCount++;
    }
    assertEquals(102, entryCount);
    EntryObject entryObject = new PredicateBuilder().getEntryObject();
    Predicate predicate = entryObject.is("active").and(entryObject.get("age").equal(23));
    entries = map.entrySet(predicate);
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertEquals(employee.getAge(), 23);
        assertTrue(employee.isActive());
    }
    map.remove("2");
    entries = map.entrySet(predicate);
    assertEquals(2, entries.size());
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertEquals(employee.getAge(), 23);
        assertTrue(employee.isActive());
    }
    entries = map.entrySet(new SqlPredicate(" (age >= " + 30 + ") AND (age <= " + 40 + ")"));
    assertEquals(23, entries.size());
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertTrue(employee.getAge() >= 30);
        assertTrue(employee.getAge() <= 40);
    }
}
Also used : Employee(com.hazelcast.query.SampleObjects.Employee) EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) SqlPredicate(com.hazelcast.query.SqlPredicate) Map(java.util.Map) IMap(com.hazelcast.core.IMap) Predicate(com.hazelcast.query.Predicate) SqlPredicate(com.hazelcast.query.SqlPredicate)

Example 13 with EntryObject

use of com.hazelcast.query.EntryObject 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 14 with EntryObject

use of com.hazelcast.query.EntryObject 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)

Example 15 with EntryObject

use of com.hazelcast.query.EntryObject 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)

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