Search in sources :

Example 56 with SqlPredicate

use of com.hazelcast.query.SqlPredicate in project ddf by codice.

the class HazelcastNotificationStore method getNotifications.

@Override
public List<Map<String, String>> getNotifications(String userId) {
    List<Map<String, String>> notificationsList = new ArrayList<Map<String, String>>();
    if (StringUtils.isNotBlank(userId)) {
        Collection<Object> notifications = notificationsCache.values(new SqlPredicate("userId = '" + userId + "'"));
        for (Object notificationObj : notifications) {
            @SuppressWarnings("unchecked") Map<String, String> notificationMap = (Map<String, String>) notificationObj;
            notificationsList.add(notificationMap);
        }
    }
    return notificationsList;
}
Also used : ArrayList(java.util.ArrayList) SqlPredicate(com.hazelcast.query.SqlPredicate) IMap(com.hazelcast.core.IMap) Map(java.util.Map)

Example 57 with SqlPredicate

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

the class QueryCacheMethodsWithPredicateTest method testKeySet_onIndexedField_afterRemovalOfSomeIndexes.

@Test
public void testKeySet_onIndexedField_afterRemovalOfSomeIndexes() {
    int count = 111;
    String cacheName = randomString();
    populateMap(map, count);
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
    cache.addIndex("id", true);
    populateMap(map, 17, count);
    // just choose arbitrary numbers to prove whether #keySet with predicate is working
    int smallerThan = 17;
    int expectedSize = 17;
    assertKeySetSizeEventually(expectedSize, new SqlPredicate("id < " + smallerThan), cache);
}
Also used : Employee(com.hazelcast.mapreduce.helpers.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 58 with SqlPredicate

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

the class QueryCacheMethodsWithPredicateTest method testValues_withoutIndex_whenIncludeValueFalse.

@Test
public void testValues_withoutIndex_whenIncludeValueFalse() {
    int count = 111;
    String cacheName = randomString();
    populateMap(map, count);
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
    removeEntriesFromMap(map, 17, count);
    // just choose arbitrary numbers to prove whether #entrySet with predicate is working
    int smallerThan = 17;
    int expectedSize = 0;
    assertValuesSizeEventually(expectedSize, new SqlPredicate("__key < " + smallerThan), cache);
}
Also used : Employee(com.hazelcast.mapreduce.helpers.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 59 with SqlPredicate

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

the class MapTransactionRegressionTest method test_Issue615_ValuesWithPredicate.

@Test
public void test_Issue615_ValuesWithPredicate() throws TransactionException {
    Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance h1 = factory.newHazelcastInstance(config);
    final HazelcastInstance h2 = factory.newHazelcastInstance(config);
    final IMap map2 = h2.getMap("default");
    final SampleObjects.Employee emp1 = new SampleObjects.Employee("abc-123-xvz", 34, true, 10D);
    map2.put(1, emp1);
    final SampleObjects.Employee emp2 = new SampleObjects.Employee("xvz", 4, true, 10D);
    boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {

        public Boolean execute(TransactionalTaskContext context) throws TransactionException {
            final TransactionalMap<Object, Object> txMap = context.getMap("default");
            assertEquals(0, txMap.values(new SqlPredicate("age <= 10")).size());
            txMap.put(2, emp2);
            Collection coll = txMap.values(new SqlPredicate("age <= 10"));
            Iterator<Object> iterator = coll.iterator();
            while (iterator.hasNext()) {
                final SampleObjects.Employee e = (SampleObjects.Employee) iterator.next();
                assertEquals(emp2, e);
            }
            coll = txMap.values(new SqlPredicate("age > 30 "));
            iterator = coll.iterator();
            while (iterator.hasNext()) {
                final SampleObjects.Employee e = (SampleObjects.Employee) iterator.next();
                assertEquals(emp1, e);
            }
            txMap.remove(2);
            coll = txMap.values(new SqlPredicate("age <= 10 "));
            assertEquals(0, coll.size());
            return true;
        }
    });
    assertEquals(0, map2.values(new SqlPredicate("age <= 10")).size());
    assertEquals(1, map2.values(new SqlPredicate("age = 34")).size());
    h1.shutdown();
    h2.shutdown();
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) SampleObjects(com.hazelcast.query.SampleObjects) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) SqlPredicate(com.hazelcast.query.SqlPredicate) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) Iterator(java.util.Iterator) Collection(java.util.Collection) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 60 with SqlPredicate

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

the class MapTransactionTest method testValuesWithPredicate_removingExistentEntry.

@Test
public void testValuesWithPredicate_removingExistentEntry() throws TransactionException {
    final int nodeCount = 1;
    final String mapName = randomMapName("_testValuesWithPredicate_removingExistentEntry_");
    final Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    final HazelcastInstance node = factory.newHazelcastInstance(config);
    final IMap map = node.getMap(mapName);
    final Employee emp = new Employee("name", 77, true, 10D);
    map.put(1, emp);
    node.executeTransaction(options, new TransactionalTask<Boolean>() {

        public Boolean execute(TransactionalTaskContext context) throws TransactionException {
            final TransactionalMap<Object, Object> txMap = context.getMap(mapName);
            txMap.remove(1);
            Collection<Object> coll = txMap.values(new SqlPredicate("age > 70 "));
            assertEquals(0, coll.size());
            return true;
        }
    });
    node.shutdown();
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) SqlPredicate(com.hazelcast.query.SqlPredicate) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) TransactionException(com.hazelcast.transaction.TransactionException) Collection(java.util.Collection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

SqlPredicate (com.hazelcast.query.SqlPredicate)111 Test (org.junit.Test)93 QuickTest (com.hazelcast.test.annotation.QuickTest)87 ParallelTest (com.hazelcast.test.annotation.ParallelTest)83 HazelcastInstance (com.hazelcast.core.HazelcastInstance)73 Config (com.hazelcast.config.Config)36 Employee (com.hazelcast.mapreduce.helpers.Employee)28 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)24 MapIndexConfig (com.hazelcast.config.MapIndexConfig)22 IMap (com.hazelcast.core.IMap)21 Employee (com.hazelcast.query.SampleObjects.Employee)21 MapStoreConfig (com.hazelcast.config.MapStoreConfig)18 Collection (java.util.Collection)14 MapConfig (com.hazelcast.config.MapConfig)13 Predicate (com.hazelcast.query.Predicate)12 Map (java.util.Map)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 PortableEmployee (com.hazelcast.query.SampleObjects.PortableEmployee)10 AssertTask (com.hazelcast.test.AssertTask)10 Value (com.hazelcast.query.SampleObjects.Value)9