Search in sources :

Example 6 with PredicateConfig

use of com.hazelcast.config.PredicateConfig in project hazelcast by hazelcast.

the class ClientQueryCacheBasicTest method setup.

// setup a map with 2 query caches, same predicate, one includes values, the other excludes values
@Before
public void setup() {
    Config config = new Config();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.addQueryCacheConfig(TEST_MAP_NAME, new QueryCacheConfig(QUERY_CACHE_NAME).setPredicateConfig(new PredicateConfig(predicate)).setIncludeValue(includeValues));
    if (useNearCache) {
        clientConfig.addNearCacheConfig(new NearCacheConfig().setName(TEST_MAP_NAME).setInvalidateOnChange(true));
    }
    clientConfig.setProperty(MapEventPublisherImpl.LISTENER_WITH_PREDICATE_PRODUCES_NATURAL_EVENT_TYPES.getName(), Boolean.toString(useQueryCacheNaturalFilteringStrategy));
    factory = new TestHazelcastFactory();
    factory.newHazelcastInstance(config);
    HazelcastInstance client = factory.newHazelcastClient(clientConfig);
    map = client.getMap(TEST_MAP_NAME);
    queryCache = map.getQueryCache(QUERY_CACHE_NAME);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Before(org.junit.Before)

Example 7 with PredicateConfig

use of com.hazelcast.config.PredicateConfig in project hazelcast by hazelcast.

the class QueryCacheYamlConfigBuilderHelper method queryCachePredicateHandler.

@Override
protected void queryCachePredicateHandler(Node childNode, QueryCacheConfig queryCacheConfig) {
    Node classNameNode = getNamedItemNode(childNode, "class-name");
    Node sqlNode = getNamedItemNode(childNode, "sql");
    if (classNameNode != null && sqlNode != null) {
        throw new InvalidConfigurationException("Both class-name and sql is defined for the predicate of map " + childNode.getParentNode().getParentNode().getNodeName());
    }
    if (classNameNode == null && sqlNode == null) {
        throw new InvalidConfigurationException("Either class-name and sql must be defined for the predicate of map " + childNode.getParentNode().getParentNode().getNodeName());
    }
    PredicateConfig predicateConfig = new PredicateConfig();
    if (classNameNode != null) {
        predicateConfig.setClassName(getTextContent(classNameNode));
    } else if (sqlNode != null) {
        predicateConfig.setSql(getTextContent(sqlNode));
    }
    queryCacheConfig.setPredicateConfig(predicateConfig);
}
Also used : PredicateConfig(com.hazelcast.config.PredicateConfig) Node(org.w3c.dom.Node) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 8 with PredicateConfig

use of com.hazelcast.config.PredicateConfig in project hazelcast by hazelcast.

the class AbstractQueryCacheConfigurator method setPredicateImpl.

protected void setPredicateImpl(QueryCacheConfig config) {
    PredicateConfig predicateConfig = config.getPredicateConfig();
    if (predicateConfig.getImplementation() != null) {
        return;
    }
    Predicate predicate = getPredicate(predicateConfig);
    if (predicate == null) {
        return;
    }
    predicateConfig.setImplementation(predicate);
}
Also used : PredicateConfig(com.hazelcast.config.PredicateConfig) Predicate(com.hazelcast.query.Predicate)

Example 9 with PredicateConfig

use of com.hazelcast.config.PredicateConfig in project hazelcast by hazelcast.

the class ClientQueryCacheListenerTest method listenerShouldBeRegistered_whenConfiguredProgrammatically.

@Test
public void listenerShouldBeRegistered_whenConfiguredProgrammatically() {
    final int valueCount = 100;
    String mapName = randomString();
    String qcName = randomString();
    final QueryCacheAdditionListener listener = new QueryCacheAdditionListener();
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(qcName).setPredicateConfig(new PredicateConfig(TRUE_PREDICATE)).addEntryListenerConfig(new EntryListenerConfig(listener, true, true));
    ClientConfig config = new ClientConfig().addQueryCacheConfig(mapName, queryCacheConfig);
    HazelcastInstance instance = factory.newHazelcastClient(config);
    IMap<Integer, Employee> map = instance.getMap(mapName);
    // trigger creation of the query cache
    map.getQueryCache(qcName);
    for (int i = 0; i < valueCount; i++) {
        map.put(i, new Employee(i));
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertEquals(valueCount, listener.getAddedEventCount());
        }
    });
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.map.impl.querycache.utils.Employee) PredicateConfig(com.hazelcast.config.PredicateConfig) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with PredicateConfig

use of com.hazelcast.config.PredicateConfig in project hazelcast by hazelcast.

the class ClientQueryCacheBasicTest method setup.

// setup a map with 2 query caches, same predicate, one includes values, the other excludes values
@Before
public void setup() {
    Config config = getConfig();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.addQueryCacheConfig(TEST_MAP_NAME, new QueryCacheConfig(QUERY_CACHE_NAME).setPredicateConfig(new PredicateConfig(predicate)).setIncludeValue(includeValues));
    clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
    if (useNearCache) {
        clientConfig.addNearCacheConfig(new NearCacheConfig().setName(TEST_MAP_NAME).setInvalidateOnChange(true));
    }
    clientConfig.setProperty(MapEventPublisherImpl.LISTENER_WITH_PREDICATE_PRODUCES_NATURAL_EVENT_TYPES.getName(), Boolean.toString(useQueryCacheNaturalFilteringStrategy));
    factory = new TestHazelcastFactory();
    factory.newHazelcastInstance(config);
    HazelcastInstance client = factory.newHazelcastClient(clientConfig);
    map = client.getMap(TEST_MAP_NAME);
    queryCache = map.getQueryCache(QUERY_CACHE_NAME);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Before(org.junit.Before)

Aggregations

PredicateConfig (com.hazelcast.config.PredicateConfig)21 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)14 Config (com.hazelcast.config.Config)11 MapConfig (com.hazelcast.config.MapConfig)9 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 Employee (com.hazelcast.map.impl.querycache.utils.Employee)6 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)5 NearCacheConfig (com.hazelcast.config.NearCacheConfig)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 AttributeConfig (com.hazelcast.config.AttributeConfig)3 IndexConfig (com.hazelcast.config.IndexConfig)3 Before (org.junit.Before)3 TestHazelcastFactory (com.hazelcast.client.test.TestHazelcastFactory)2 AwsConfig (com.hazelcast.config.AwsConfig)2 CachePartitionLostListenerConfig (com.hazelcast.config.CachePartitionLostListenerConfig)2 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)2