Java Code Examples for com.hazelcast.query.impl.predicates.SqlPredicate

The following examples show how to use com.hazelcast.query.impl.predicates.SqlPredicate. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hazelcast-simulator   Source File: MapPredicateTest.java    License: Apache License 2.0 6 votes vote down vote up
@TimeStep(prob = 0.2)
public void sqlString(ThreadState state) {
    long startMs = System.currentTimeMillis();
    boolean active = state.randomBoolean();
    int age = state.randomInt(Employee.MAX_AGE);

    SqlPredicate predicate = new SqlPredicate("active=" + active + " AND age >" + age);
    Collection<Employee> employees = map.values(predicate);

    for (Employee emp : employees) {
        String assertMessage = format(baseAssertMessage, emp, predicate);
        assertTrue(assertMessage, emp.isActive() == active);
        assertTrue(assertMessage, emp.getAge() > age);
    }
    state.operationCounter.sqlStringCount++;
    updateStats(state, startMs);
}
 
Example 2
@Test
public void testQuery() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.start();
    try {
        String sql = "bar > 1000";
        Mockito.when(map.values(Mockito.any(SqlPredicate.class))).thenReturn(Arrays.<Object>asList(new Dummy("beta", 2000), new Dummy("gamma", 3000)));

        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBodyAndHeader("direct:queue", null, HazelcastConstants.QUERY, sql);
        Mockito.verify(map).values(Mockito.any(SqlPredicate.class));

        ConsumerTemplate consumer = camelctx.createConsumerTemplate();
        Collection<?> b1 = consumer.receiveBody("seda:out", 5000, Collection.class);

        Assert.assertNotNull(b1);
        Assert.assertEquals(2, b1.size());
    } finally {
        camelctx.close();
    }
}
 
Example 3
@Override
public Object execute(Object[] parameters) {
    String queryStringTemplate = queryMethod.getAnnotatedQuery();
    String queryString = String.format(queryStringTemplate, formatParameters(parameters));
    SqlPredicate sqlPredicate = new SqlPredicate(queryString);
    return getMap(keySpace).values(sqlPredicate);
}
 
Example 4
@SuppressWarnings("unchecked")
@BeforeRun
public void beforeRun(ThreadState state) {
    state.predicate = new SqlPredicate(query.getSql());
}
 
Example 5
Source Project: hazelcast-simulator   Source File: MapGetVsQueryTest.java    License: Apache License 2.0 4 votes vote down vote up
@TimeStep(prob = 0)
public void sqlString(ThreadState state) {
    int id = state.randomInt(itemCount);
    SqlPredicate predicate = new SqlPredicate("id=" + id);
    map.values(predicate);
}
 
Example 6
Source Project: hazelcast-simulator   Source File: PagingPredicateTest.java    License: Apache License 2.0 4 votes vote down vote up
@Setup
public void setUp() {
    map = targetInstance.getMap(name);
    innerPredicate = new SqlPredicate(innerPredicateQuery);
}