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);
}
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);
}
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);
}
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());
}
});
}
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);
}
Aggregations