use of org.apache.geode.cache.query.SelectResults in project geode by apache.
the class PDXPostProcessorDUnitTest method testQuery.
@Test
public void testQuery() {
client2.invoke(() -> {
ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
// put in a value that's a domain object
region.put("key1", new SimpleClass(1, (byte) 1));
region.put("key2", BYTES);
});
client1.invoke(() -> {
ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
// post process for query
String query = "select * from /AuthRegion";
SelectResults result = region.query(query);
Iterator itr = result.iterator();
while (itr.hasNext()) {
Object obj = itr.next();
if (obj instanceof byte[]) {
assertTrue(Arrays.equals(BYTES, (byte[]) obj));
} else {
assertTrue(obj instanceof SimpleClass);
}
}
});
// this makes sure PostProcessor is getting called
PDXPostProcessor pp = (PDXPostProcessor) SecurityService.getSecurityService().getPostProcessor();
assertEquals(pp.getCount(), 2);
}
use of org.apache.geode.cache.query.SelectResults in project geode by apache.
the class PostProcessorDUnitTest method testPostProcessQuery.
@Test
public void testPostProcessQuery() {
client1.invoke(() -> {
ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
// post process for query
String query = "select * from /AuthRegion";
SelectResults result = region.query(query);
assertEquals(5, result.size());
assertTrue(result.contains("super-user/null/null/value0"));
assertTrue(result.contains("super-user/null/null/value1"));
assertTrue(result.contains("super-user/null/null/value2"));
assertTrue(result.contains("super-user/null/null/value3"));
assertTrue(result.contains("super-user/null/null/value4"));
Pool pool = PoolManager.find(region);
result = (SelectResults) pool.getQueryService().newQuery(query).execute();
assertTrue(result.contains("super-user/null/null/value0"));
assertTrue(result.contains("super-user/null/null/value1"));
assertTrue(result.contains("super-user/null/null/value2"));
assertTrue(result.contains("super-user/null/null/value3"));
assertTrue(result.contains("super-user/null/null/value4"));
});
}
use of org.apache.geode.cache.query.SelectResults in project geode by apache.
the class SecurityTestUtils method doQueryExecuteP.
private static void doQueryExecuteP(final int multiUserIndex, final int expectedResult, final int expectedValue) {
Region region = null;
try {
if (multiUserAuthMode) {
region = proxyCaches[multiUserIndex].getRegion(REGION_NAME);
} else {
region = getCache().getRegion(REGION_NAME);
}
assertNotNull(region);
} catch (Exception ex) {
if (expectedResult == OTHER_EXCEPTION) {
getLogWriter().info("Got expected exception when executing query: " + ex);
} else {
fail("Got unexpected exception when executing query", ex);
}
}
try {
String queryString = "SELECT DISTINCT * FROM " + region.getFullPath();
Query query = null;
if (multiUserAuthMode) {
query = proxyCaches[multiUserIndex].getQueryService().newQuery(queryString);
} else {
region.getCache().getQueryService().newQuery(queryString);
}
SelectResults result = (SelectResults) query.execute();
if (expectedResult != NO_EXCEPTION) {
fail("Expected a NotAuthorizedException while executing function");
}
assertEquals(expectedValue, result.asList().size());
} catch (NoAvailableServersException ex) {
if (expectedResult == NO_AVAILABLE_SERVERS) {
getLogWriter().info("Got expected NoAvailableServers when executing query: " + ex.getCause());
} else {
fail("Got unexpected exception when executing query", ex);
}
} catch (ServerConnectivityException ex) {
if ((expectedResult == NOTAUTHZ_EXCEPTION) && (ex.getCause() instanceof NotAuthorizedException)) {
getLogWriter().info("Got expected NotAuthorizedException when executing query: " + ex.getCause());
} else if (expectedResult == OTHER_EXCEPTION) {
getLogWriter().info("Got expected exception when executing query: " + ex);
} else {
fail("Got unexpected exception when executing query", ex);
}
} catch (Exception ex) {
if (expectedResult == OTHER_EXCEPTION) {
getLogWriter().info("Got expected exception when executing query: " + ex);
} else {
fail("Got unexpected exception when executing query", ex);
}
}
}
use of org.apache.geode.cache.query.SelectResults in project geode by apache.
the class ZRangeByScoreExecutor method getKeys.
private Collection<?> getKeys(ByteArrayWrapper key, Region<ByteArrayWrapper, DoubleWrapper> keyRegion, ExecutionHandlerContext context, double start, double stop, boolean startInclusive, boolean stopInclusive, int offset, int limit) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
if (start == Double.POSITIVE_INFINITY || stop == Double.NEGATIVE_INFINITY || start > stop || (start == stop && (!startInclusive || !stopInclusive)))
return null;
if (start == Double.NEGATIVE_INFINITY && stop == Double.POSITIVE_INFINITY)
return new HashSet(keyRegion.entrySet());
Query query;
Object[] params;
if (isReverse()) {
if (startInclusive) {
if (stopInclusive) {
query = getQuery(key, SortedSetQuery.ZREVRBSSTISI, context);
} else {
query = getQuery(key, SortedSetQuery.ZREVRBSSTI, context);
}
} else {
if (stopInclusive) {
query = getQuery(key, SortedSetQuery.ZREVRBSSI, context);
} else {
query = getQuery(key, SortedSetQuery.ZREVRBS, context);
}
}
params = new Object[] { start, stop, INFINITY_LIMIT };
} else {
if (startInclusive) {
if (stopInclusive) {
query = getQuery(key, SortedSetQuery.ZRBSSTISI, context);
} else {
query = getQuery(key, SortedSetQuery.ZRBSSTI, context);
}
} else {
if (stopInclusive) {
query = getQuery(key, SortedSetQuery.ZRBSSI, context);
} else {
query = getQuery(key, SortedSetQuery.ZRBS, context);
}
}
params = new Object[] { start, stop, INFINITY_LIMIT };
}
if (limit > 0)
params[params.length - 1] = (limit + offset);
SelectResults<?> results = (SelectResults<?>) query.execute(params);
if (offset < results.size())
return (Collection<Struct>) results.asList().subList(offset, results.size());
else
return null;
}
use of org.apache.geode.cache.query.SelectResults in project geode by apache.
the class ZRemRangeByLexExecutor method getRange.
private Collection<ByteArrayWrapper> getRange(ByteArrayWrapper key, Region<ByteArrayWrapper, DoubleWrapper> keyRegion, ExecutionHandlerContext context, ByteArrayWrapper start, ByteArrayWrapper stop, boolean startInclusive, boolean stopInclusive) throws Exception {
if (start.equals("-") && stop.equals("+"))
return new ArrayList<ByteArrayWrapper>(keyRegion.keySet());
else if (start.equals("+") || stop.equals("-"))
return null;
Query query;
Object[] params;
if (start.equals("-")) {
if (stopInclusive) {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEXNINFI, context);
} else {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEXNINF, context);
}
params = new Object[] { stop, INFINITY_LIMIT };
} else if (stop.equals("+")) {
if (startInclusive) {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEXPINFI, context);
} else {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEXPINF, context);
}
params = new Object[] { start, INFINITY_LIMIT };
} else {
if (startInclusive) {
if (stopInclusive) {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEXSTISI, context);
} else {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEXSTI, context);
}
} else {
if (stopInclusive) {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEXSI, context);
} else {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEX, context);
}
}
params = new Object[] { start, stop, INFINITY_LIMIT };
}
@SuppressWarnings("unchecked") SelectResults<ByteArrayWrapper> results = (SelectResults<ByteArrayWrapper>) query.execute(params);
return results.asList();
}
Aggregations