Search in sources :

Example 1 with PredicateBuilder

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

the class MapLiteMemberTest method testMapValuesQuery.

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

Example 2 with PredicateBuilder

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

the class QueryBasicTest method issue393.

@Test(timeout = 1000 * 60)
public void issue393() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Value> map = instance.getMap("default");
    map.addIndex("name", true);
    for (int i = 0; i < 4; i++) {
        Value v = new Value("name" + i);
        map.put("" + i, v);
    }
    Predicate predicate = new PredicateBuilder().getEntryObject().get("name").in("name0", "name2");
    Collection<Value> values = map.values(predicate);
    String[] expectedValues = new String[] { "name0", "name2" };
    assertEquals(expectedValues.length, values.size());
    List<String> names = new ArrayList<String>();
    for (Value configObject : values) {
        names.add(configObject.getName());
    }
    String[] array = names.toArray(new String[names.size()]);
    Arrays.sort(array);
    assertArrayEquals(names.toString(), expectedValues, array);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PredicateBuilder(com.hazelcast.query.PredicateBuilder) Value(com.hazelcast.query.SampleObjects.Value) ArrayList(java.util.ArrayList) 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 3 with PredicateBuilder

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

the class QueryBasicTest method testPredicateDateAttribute.

private void testPredicateDateAttribute(IMap<Integer, Date> map) {
    Calendar cal = Calendar.getInstance();
    cal.set(2012, Calendar.JUNE, 5);
    map.put(1, cal.getTime());
    cal.set(2011, Calendar.NOVEMBER, 10);
    map.put(2, cal.getTime());
    cal.set(2011, Calendar.FEBRUARY, 1);
    map.put(3, cal.getTime());
    cal.set(2010, Calendar.SEPTEMBER, 5);
    map.put(4, cal.getTime());
    cal.set(2000, Calendar.JUNE, 5);
    map.put(5, cal.getTime());
    cal.set(2011, Calendar.JANUARY, 1);
    assertEquals(3, map.values(new PredicateBuilder().getEntryObject().get("this").greaterThan(cal.getTime())).size());
    assertEquals(3, map.values(new SqlPredicate("this > 'Sat Jan 01 11:43:05 EET 2011'")).size());
    assertEquals(2, map.values(new PredicateBuilder().getEntryObject().get("this").lessThan(cal.getTime())).size());
    assertEquals(2, map.values(new SqlPredicate("this < 'Sat Jan 01 11:43:05 EET 2011'")).size());
    cal.set(2003, Calendar.NOVEMBER, 10);
    Date d1 = cal.getTime();
    cal.set(2012, Calendar.FEBRUARY, 10);
    Date d2 = cal.getTime();
    assertEquals(3, map.values(new PredicateBuilder().getEntryObject().get("this").between(d1, d2)).size());
    assertEquals(3, map.values(new SqlPredicate("this between 'Mon Nov 10 11:43:05 EET 2003'" + " and 'Fri Feb 10 11:43:05 EET 2012'")).size());
}
Also used : PredicateBuilder(com.hazelcast.query.PredicateBuilder) Calendar(java.util.Calendar) SqlPredicate(com.hazelcast.query.SqlPredicate) Date(java.util.Date)

Example 4 with PredicateBuilder

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

the class NearCacheTest method testAfterExecuteOnEntriesNearCacheIsInvalidated.

@Test
public void testAfterExecuteOnEntriesNearCacheIsInvalidated() {
    int mapSize = 10;
    String mapName = randomMapName();
    Config config = createNearCachedMapConfig(mapName);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Integer, Employee> map = instance.getMap(mapName);
    for (int i = 0; i < mapSize; i++) {
        map.put(i, new Employee(i, "", 0, true, 0D));
    }
    populateNearCache(map, mapSize);
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate predicate = e.get("salary").equal(0);
    map.executeOnEntries(new AbstractEntryProcessor<Integer, Employee>() {

        @Override
        public Object process(Map.Entry<Integer, Employee> entry) {
            Employee employee = entry.getValue();
            double currentSalary = employee.getSalary();
            double newSalary = currentSalary + 10;
            employee.setSalary(newSalary);
            return newSalary;
        }
    }, predicate);
    assertEquals(0, getNearCacheStats(map).getOwnedEntryCount());
}
Also used : EntryObject(com.hazelcast.query.EntryObject) MapConfig(com.hazelcast.config.MapConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) Predicate(com.hazelcast.query.Predicate) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) PredicateBuilder(com.hazelcast.query.PredicateBuilder) EntryObject(com.hazelcast.query.EntryObject) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with PredicateBuilder

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

the class MapTransactionRegressionTest method test_Issue1076.

@Test
public void test_Issue1076() {
    Config config = getConfig();
    final HazelcastInstance inst = createHazelcastInstance(config);
    IMap map = inst.getMap("default");
    EntryListener<String, Integer> l = new EntryAdapter<String, Integer>() {
    };
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate<String, Integer> p = e.equal(1);
    map.addEntryListener(l, p, null, false);
    for (Integer i = 0; i < 100; i++) {
        TransactionContext context = inst.newTransactionContext();
        context.beginTransaction();
        TransactionalMap<String, Integer> txnMap = context.getMap("default");
        txnMap.remove(i.toString());
        context.commitTransaction();
    }
    assertEquals(0, map.size());
    inst.shutdown();
}
Also used : IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) Config(com.hazelcast.config.Config) TransactionContext(com.hazelcast.transaction.TransactionContext) EntryAdapter(com.hazelcast.core.EntryAdapter) NightlyTest(com.hazelcast.test.annotation.NightlyTest) 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