Java Code Examples for com.gemstone.gemfire.cache.Region#query()
The following examples show how to use
com.gemstone.gemfire.cache.Region#query() .
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 File: I18nClient.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public static void main(String [] args) throws Exception { System.out.println("Connecting to the distributed system and creating the cache."); // Create the cache which causes the cache-xml-file to be parsed ClientCache cache = new ClientCacheFactory() .set("name", "I18nClient") .set("cache-xml-file", "xml/I18nClient.xml") .create(); // Get the exampleRegion Region<String, String> region = cache.getRegion("家具店"); System.out.println("Example region, " + region.getFullPath() + ", created in cache."); System.out.println(); System.out.println("Getting values from the server..."); String query = "SELECT DISTINCT * FROM " + region.getFullPath() + ".keys"; SelectResults<String> results = region.query(query); List<String> keys = results.asList(); for (String key : keys) { String value = region.get(key); System.out.println("item: " + key + " price: " + value); } System.out.println(); System.out.println("Closing the cache and disconnecting."); cache.close(); }
Example 2
Source File: ListIndexCommandDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
protected <T extends Comparable<T>, B extends AbstractBean<T>> B query(final Region<T, B> region, final String queryPredicate) { try { getLogWriter().info(String.format("Running Query (%1$s) on Region (%2$s)...", queryPredicate, region.getFullPath())); final SelectResults<B> results = region.query(queryPredicate); getLogWriter().info(String.format("Running Query (%1$s) on Region (%2$s) returned (%3$d) result(s).", queryPredicate, region.getFullPath(), results.size())); return (results.iterator().hasNext() ? results.iterator().next() : null); } catch (Exception e) { throw new RuntimeException(String.format("An error occurred running Query (%1$s) on Region (%2$s)!", queryPredicate, region.getFullPath()), e); } }
Example 3
Source File: PRQueryJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Tests the execution of query on a PartitionedRegion created on a single * data store. <br> * 1. Creates a PR with redundancy=0 on a single VM. 2. Puts some test Objects * in cache. 3. Fires queries on the data and verifies the result. * * @throws Exception */ public void testQueryOnSingleDataStore() throws Exception { Region region = PartitionedRegionTestHelper.createPartitionedRegion( regionName, "100", 0); PortfolioData[] portfolios = new PortfolioData[100]; for (int j = 0; j < 100; j++) { portfolios[j] = new PortfolioData(j); } try { populateData(region, portfolios); String queryString = "ID < 5"; SelectResults resSet = region.query(queryString); Assert.assertTrue(resSet.size() == 5); queryString = "ID > 5 and ID <=15"; resSet = region.query(queryString); Assert.assertTrue(resSet.size() == 10); } finally { region.close(); } }
Example 4
Source File: PRQueryNumThreadsJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Tests the execution of query on a PartitionedRegion created on a single * data store. <br> * 1. Creates a PR with redundancy=0 on a single VM. 2. Puts some test Objects * in cache. 3. Fires queries on the data and verifies the result. * * @throws Exception */ public void testQueryOnSingleDataStore() throws Exception { Region region = PartitionedRegionTestHelper.createPartitionedRegion( regionName, "100", 0); PortfolioData[] portfolios = new PortfolioData[100]; for (int j = 0; j < 100; j++) { portfolios[j] = new PortfolioData(j); } PRQueryProcessor.TEST_NUM_THREADS = 10; try { populateData(region, portfolios); String queryString = "ID < 5"; SelectResults resSet = region.query(queryString); Assert.assertTrue(resSet.size() == 5); queryString = "ID > 5 and ID <=15"; resSet = region.query(queryString); Assert.assertTrue(resSet.size() == 10); } finally { PRQueryProcessor.TEST_NUM_THREADS = 0; region.close(); } }
Example 5
Source File: PRQueryNumThreadsJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Tests the execution of query on a PartitionedRegion created on a single * data store. <br> * 1. Creates a PR with redundancy=0 on a single VM. 2. Puts some test Objects * in cache. 3. Fires queries on the data and verifies the result. * * @throws Exception */ public void testQueryOnSingleDataStore() throws Exception { Region region = PartitionedRegionTestHelper.createPartitionedRegion( regionName, "100", 0); PortfolioData[] portfolios = new PortfolioData[100]; for (int j = 0; j < 100; j++) { portfolios[j] = new PortfolioData(j); } PRQueryProcessor.TEST_NUM_THREADS = 10; try { populateData(region, portfolios); String queryString = "ID < 5"; SelectResults resSet = region.query(queryString); Assert.assertTrue(resSet.size() == 5); queryString = "ID > 5 and ID <=15"; resSet = region.query(queryString); Assert.assertTrue(resSet.size() == 10); } finally { PRQueryProcessor.TEST_NUM_THREADS = 0; region.close(); } }
Example 6
Source File: I18nClient.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public static void main(String [] args) throws Exception { System.out.println("Connecting to the distributed system and creating the cache."); // Create the cache which causes the cache-xml-file to be parsed ClientCache cache = new ClientCacheFactory() .set("name", "I18nClient") .set("cache-xml-file", "xml/I18nClient.xml") .create(); // Get the exampleRegion Region<String, String> region = cache.getRegion("家具店"); System.out.println("Example region, " + region.getFullPath() + ", created in cache."); System.out.println(); System.out.println("Getting values from the server..."); String query = "SELECT DISTINCT * FROM " + region.getFullPath() + ".keys"; SelectResults<String> results = region.query(query); List<String> keys = results.asList(); for (String key : keys) { String value = region.get(key); System.out.println("item: " + key + " price: " + value); } System.out.println(); System.out.println("Closing the cache and disconnecting."); cache.close(); }
Example 7
Source File: ListIndexCommandDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
protected <T extends Comparable<T>, B extends AbstractBean<T>> B query(final Region<T, B> region, final String queryPredicate) { try { getLogWriter().info(String.format("Running Query (%1$s) on Region (%2$s)...", queryPredicate, region.getFullPath())); final SelectResults<B> results = region.query(queryPredicate); getLogWriter().info(String.format("Running Query (%1$s) on Region (%2$s) returned (%3$d) result(s).", queryPredicate, region.getFullPath(), results.size())); return (results.iterator().hasNext() ? results.iterator().next() : null); } catch (Exception e) { throw new RuntimeException(String.format("An error occurred running Query (%1$s) on Region (%2$s)!", queryPredicate, region.getFullPath()), e); } }
Example 8
Source File: PRQueryJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Tests the execution of query on a PartitionedRegion created on a single * data store. <br> * 1. Creates a PR with redundancy=0 on a single VM. 2. Puts some test Objects * in cache. 3. Fires queries on the data and verifies the result. * * @throws Exception */ public void testQueryOnSingleDataStore() throws Exception { Region region = PartitionedRegionTestHelper.createPartitionedRegion( regionName, "100", 0); PortfolioData[] portfolios = new PortfolioData[100]; for (int j = 0; j < 100; j++) { portfolios[j] = new PortfolioData(j); } try { populateData(region, portfolios); String queryString = "ID < 5"; SelectResults resSet = region.query(queryString); Assert.assertTrue(resSet.size() == 5); queryString = "ID > 5 and ID <=15"; resSet = region.query(queryString); Assert.assertTrue(resSet.size() == 10); } finally { region.close(); } }
Example 9
Source File: PRQueryDUnitHelper.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * This function <br> * 1. Creates & executes a query with Logical Operators on the given PR Region * 2. Executes the same query on the local region <br> * 3. Compares the appropriate resultSet <br> * * @param regionName * * * @return cacheSerializable object */ public CacheSerializableRunnable getCacheSerializableRunnableForPRInvalidQuery( final String regionName, final String invalidQuery) { SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") { @Override public void run2() throws CacheException { Cache cache = getCache(); // Querying the PR region with an Invalid query string String query = "INVALID QUERY"; Region region = cache.getRegion(regionName); try { region.query(query); fail("PRQueryDUnitHelper#getCacheSerializableRunnableForPRInvalidQuery: InvalidQueryException expected"); } catch (QueryInvalidException e) { // pass } catch (QueryException qe) { getLogWriter() .error( "PRQueryDUnitHelper#getCacheSerializableRunnableForPRInvalidQuery: Caught another Exception while querying , Exception is " + qe, qe); fail("PRQueryDUnitHelper#getCacheSerializableRunnableForPRInvalidQuery: Caught another Exception while querying , Exception is " + qe); } } }; return (CacheSerializableRunnable)PrRegion; }
Example 10
Source File: PRQueryDUnitHelper.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * This function <br> * 1. Creates & executes a query with Logical Operators on the given PR Region * 2. Executes the same query on the local region <br> * 3. Compares the appropriate resultSet <br> * * @param regionName * * * @return cacheSerializable object */ public CacheSerializableRunnable getCacheSerializableRunnableForPRInvalidQuery( final String regionName, final String invalidQuery) { SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") { @Override public void run2() throws CacheException { Cache cache = getCache(); // Querying the PR region with an Invalid query string String query = "INVALID QUERY"; Region region = cache.getRegion(regionName); try { region.query(query); fail("PRQueryDUnitHelper#getCacheSerializableRunnableForPRInvalidQuery: InvalidQueryException expected"); } catch (QueryInvalidException e) { // pass } catch (QueryException qe) { getLogWriter() .error( "PRQueryDUnitHelper#getCacheSerializableRunnableForPRInvalidQuery: Caught another Exception while querying , Exception is " + qe, qe); fail("PRQueryDUnitHelper#getCacheSerializableRunnableForPRInvalidQuery: Caught another Exception while querying , Exception is " + qe); } } }; return (CacheSerializableRunnable)PrRegion; }
Example 11
Source File: PRQueryDUnitHelper.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * This function <br> * 1. Creates & executes a query with Logical Operators on the given PR Region * 2. Executes the same query on the local region <br> * 3. Compares the appropriate resultSet <br> * 4. Compares and Print's the time taken for each <br> * * @param regionName * @param localRegionNeme * * @return cacheSerializable object */ public CacheSerializableRunnable PRQueryingVsLocalQuerying( final String regionName, final String localRegion, final ResultsObject perfR) { SerializableRunnable PrRegion = new CacheSerializableRunnable("PRvsLocal") { @Override public void run2() throws CacheException { PerfResultsObject prfRObject=new PerfResultsObject(perfR); Cache cache = getCache(); // Querying the localRegion and the PR region String[] query = { "ID = 0 OR ID = 1", "ID > 4 AND ID < 9", "ID = 5", "ID < 5 ", "ID <= 5" , "ID > 7 AND status ='active'" }; Object r[][] = new Object[query.length][2]; Region local = cache.getRegion(localRegion); Region region = cache.getRegion(regionName); assertEquals(local.values(), region.values()); long startTimeLocal = System.currentTimeMillis(); try { for (int j = 0; j < query.length; j++) { r[j][0] = local.query(query[j]); } long endTimeLocal=System.currentTimeMillis(); long queryTimeLocal = endTimeLocal-startTimeLocal; getLogWriter().info("PRQueryDUnitHelper#PRQueryingVsLocalQuerying: Time to Query Local cache "+queryTimeLocal + " ms"); long startTimePR = System.currentTimeMillis(); for (int k = 0; k < query.length; k++) { r[k][1] = region.query(query[k]); } long endTimePR = System.currentTimeMillis(); long queryTimePR = endTimePR-startTimePR; getLogWriter().info("PRQueryDUnitHelper#PRQueryingVsLocalQuerying: Time to Query PR "+queryTimePR+" ms"); getLogWriter() .info( "PRQueryDUnitHelper#PRQueryingVsLocalQuerying: Queries Executed successfully on Local region & PR Region"); prfRObject.QueryingTimeLocal=queryTimeLocal; prfRObject.QueryingTimePR=queryTimePR; prfRObject.displayResults(); compareTwoQueryResults(r, query.length); } catch (QueryException e) { getLogWriter() .error( "PRQueryDUnitHelper#PRQueryingVsLocalQuerying: Caught QueryException while querying" + e, e); fail("PRQueryDUnitHelper#PRQueryingVsLocalQuerying: Caught unexpected query exception. Exception is " + e); } } }; return (CacheSerializableRunnable)PrRegion; }
Example 12
Source File: JSONClient.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { System.out.println("Connecting to the distributed system and creating the cache."); // Create the cache which causes the cache-xml-file to be parsed ClientCache cache = new ClientCacheFactory() .set("name", "JSONClient") .set("cache-xml-file", "xml/JsonClient.xml") .create(); // Get the exampleRegion Region<String, PdxInstance> exampleRegion = cache.getRegion(EXAMPLE_REGION_NAME); System.out.println("Example region \"" + exampleRegion.getFullPath() + "\" created in cache."); System.out.println(); System.out.println("Putting JSON documents."); String jsonCustomer = "{" + "\"firstName\": \"John\"," + "\"lastName\": \"Smith\"," + " \"age\": 25," + "\"address\":" + "{" + "\"streetAddress\": \"21 2nd Street\"," + "\"city\": \"New York\"," + "\"state\": \"NY\"," + "\"postalCode\": \"10021\"" + "}," + "\"phoneNumber\":" + "[" + "{" + " \"type\": \"home\"," + "\"number\": \"212 555-1234\"" + "}," + "{" + " \"type\": \"fax\"," + "\"number\": \"646 555-4567\"" + "}" + "]" + "}"; System.out.println("JSON documents added into Cache: " + jsonCustomer); System.out.println(); exampleRegion.put("jsondoc1", JSONFormatter.fromJSON(jsonCustomer)); String getJsonCustomer = JSONFormatter.toJSON(exampleRegion.get("jsondoc1")); System.out.println("Got JSON documents from Cache: " + getJsonCustomer); System.out.println(); System.out.println("Executed query on JSON doc with predicate \" age = 25 \""); System.out.println(); SelectResults<PdxInstance> sr = exampleRegion.query("age = 25"); System.out.println("got expected result = " + sr.size()); System.out.println(); System.out.println("got expected result value = " + JSONFormatter.toJSON(sr.iterator().next())); System.out.println(); // Close the cache and disconnect from GemFire distributed system System.out.println("Closing the cache and disconnecting."); cache.close(); System.out.println("In the other session, please hit Enter in the JSON client"); System.out.println("and then stop the cacheserver with 'gfsh stop server --dir=server_json'."); }
Example 13
Source File: PRQueryDUnitHelper.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * This function <br> * 1. Creates & executes a query with Constants on the given PR Region <br> * 2. Executes the same query on the local region <br> * 3. Compares the appropriate resultSet <br> * * @param regionName * @param localRegionNeme * * @return cacheSerializable object */ public CacheSerializableRunnable getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults( final String regionName, final String localRegion) { SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") { @Override public void run2() throws CacheException { Cache cache = getCache(); // Querying the localRegion and the PR region String[] query = { "TRUE", "FALSE", "UNDEFINED", "NULL" }; Object r[][] = new Object[query.length][2]; Region local = cache.getRegion(localRegion); Region region = cache.getRegion(regionName); try { for (int j = 0; j < query.length; j++) { r[j][0] = local.query(query[j]); r[j][1] = region.query(query[j]); } getLogWriter() .info( "PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults: Queries Executed successfully on Local region & PR Region"); compareTwoQueryResults(r, query.length); } catch (QueryException e) { // assertTrue("caught Exception"+ e.getMessage(),false); getLogWriter() .error( "PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults: Caught an Exception while querying Constants" + e, e); fail("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults: Caught Exception while querying Constants. Exception is " + e); } } }; return (CacheSerializableRunnable)PrRegion; }
Example 14
Source File: PRInvalidQueryJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Tests the execution of an Invalid query <br> * (of the nature Select Distinct * from /Portfolios ) <br> * on a PartitionedRegion created on a single data store. <br> * 1. Creates a PR with redundancy=0 on a single VM.<br> * 2. Puts some test Objects in cache.<br> * 3. Fires querie on the data and verifies the result.<br> * 4. Since region#query() doesn't support this type of query syntax it should * throw QueryInvalidException <br> * * @throws Exception */ public void testInvalidQueryOnSingleDS() throws Exception { logger .info("PRInvalidQueryJUnitTest#testInvalidQueryOnSingleDS: Test Started "); Region region = PartitionedRegionTestHelper.createPartitionedRegion( regionName, "100", 0); logger .info("PRInvalidQueryJUnitTest#testInvalidQueryOnSingleDS: creating portfolioData objects"); PortfolioData[] portfolios = new PortfolioData[100]; for (int j = 0; j < 100; j++) { portfolios[j] = new PortfolioData(j); } populateData(region, portfolios); logger .info("PRInvalidQueryJUnitTest#testInvalidQueryOnSingleDS: creating Select Query"); String queryString = "SELECT DISTINCT * FROM /Portfolios WHERE pkid < '5'"; final String expectedQueryInvalidException = QueryInvalidException.class .getName(); logger.info("<ExpectedException action=add>" + expectedQueryInvalidException + "</ExpectedException>"); try { region.query(queryString); fail("PRInvalidQueryJUnitTest#testInvalidQueryOnSingleDS: Expected an Invalid Query Exception for the query :" + queryString + " this is not supported for region#query()"); } catch (QueryInvalidException qe) { logger .info("PRInvalidQueryJUnitTest#testInvalidQueryOnSingleDS: Caught an Invalid Query Exception for the query :" + queryString + " this is not supported for region#query()"); } logger .info("PRInvalidQueryJUnitTest#testInvalidQueryOnSingleDS: Test Ended"); logger.info("<ExpectedException action=remove>" + expectedQueryInvalidException + "</ExpectedException>"); }
Example 15
Source File: JSONClient.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { System.out.println("Connecting to the distributed system and creating the cache."); // Create the cache which causes the cache-xml-file to be parsed ClientCache cache = new ClientCacheFactory() .set("name", "JSONClient") .set("cache-xml-file", "xml/JsonClient.xml") .create(); // Get the exampleRegion Region<String, PdxInstance> exampleRegion = cache.getRegion(EXAMPLE_REGION_NAME); System.out.println("Example region \"" + exampleRegion.getFullPath() + "\" created in cache."); System.out.println(); System.out.println("Putting JSON documents."); String jsonCustomer = "{" + "\"firstName\": \"John\"," + "\"lastName\": \"Smith\"," + " \"age\": 25," + "\"address\":" + "{" + "\"streetAddress\": \"21 2nd Street\"," + "\"city\": \"New York\"," + "\"state\": \"NY\"," + "\"postalCode\": \"10021\"" + "}," + "\"phoneNumber\":" + "[" + "{" + " \"type\": \"home\"," + "\"number\": \"212 555-1234\"" + "}," + "{" + " \"type\": \"fax\"," + "\"number\": \"646 555-4567\"" + "}" + "]" + "}"; System.out.println("JSON documents added into Cache: " + jsonCustomer); System.out.println(); exampleRegion.put("jsondoc1", JSONFormatter.fromJSON(jsonCustomer)); String getJsonCustomer = JSONFormatter.toJSON(exampleRegion.get("jsondoc1")); System.out.println("Got JSON documents from Cache: " + getJsonCustomer); System.out.println(); System.out.println("Executed query on JSON doc with predicate \" age = 25 \""); System.out.println(); SelectResults<PdxInstance> sr = exampleRegion.query("age = 25"); System.out.println("got expected result = " + sr.size()); System.out.println(); System.out.println("got expected result value = " + JSONFormatter.toJSON(sr.iterator().next())); System.out.println(); // Close the cache and disconnect from GemFire distributed system System.out.println("Closing the cache and disconnecting."); cache.close(); System.out.println("In the other session, please hit Enter in the JSON client"); System.out.println("and then stop the cacheserver with 'gfsh stop server --dir=server_json'."); }
Example 16
Source File: PRQueryDUnitHelper.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * This function <br> * 1. Creates & executes a query with Logical Operators on the given PR Region * 2. Executes the same query on the local region <br> * 3. Compares the appropriate resultSet <br> * 4. Compares and Print's the time taken for each <br> * * @param regionName * @param localRegionNeme * * @return cacheSerializable object */ public CacheSerializableRunnable PRQueryingVsLocalQuerying( final String regionName, final String localRegion, final ResultsObject perfR) { SerializableRunnable PrRegion = new CacheSerializableRunnable("PRvsLocal") { @Override public void run2() throws CacheException { PerfResultsObject prfRObject=new PerfResultsObject(perfR); Cache cache = getCache(); // Querying the localRegion and the PR region String[] query = { "ID = 0 OR ID = 1", "ID > 4 AND ID < 9", "ID = 5", "ID < 5 ", "ID <= 5" , "ID > 7 AND status ='active'" }; Object r[][] = new Object[query.length][2]; Region local = cache.getRegion(localRegion); Region region = cache.getRegion(regionName); assertEquals(local.values(), region.values()); long startTimeLocal = System.currentTimeMillis(); try { for (int j = 0; j < query.length; j++) { r[j][0] = local.query(query[j]); } long endTimeLocal=System.currentTimeMillis(); long queryTimeLocal = endTimeLocal-startTimeLocal; getLogWriter().info("PRQueryDUnitHelper#PRQueryingVsLocalQuerying: Time to Query Local cache "+queryTimeLocal + " ms"); long startTimePR = System.currentTimeMillis(); for (int k = 0; k < query.length; k++) { r[k][1] = region.query(query[k]); } long endTimePR = System.currentTimeMillis(); long queryTimePR = endTimePR-startTimePR; getLogWriter().info("PRQueryDUnitHelper#PRQueryingVsLocalQuerying: Time to Query PR "+queryTimePR+" ms"); getLogWriter() .info( "PRQueryDUnitHelper#PRQueryingVsLocalQuerying: Queries Executed successfully on Local region & PR Region"); prfRObject.QueryingTimeLocal=queryTimeLocal; prfRObject.QueryingTimePR=queryTimePR; prfRObject.displayResults(); compareTwoQueryResults(r, query.length); } catch (QueryException e) { getLogWriter() .error( "PRQueryDUnitHelper#PRQueryingVsLocalQuerying: Caught QueryException while querying" + e, e); fail("PRQueryDUnitHelper#PRQueryingVsLocalQuerying: Caught unexpected query exception. Exception is " + e); } } }; return (CacheSerializableRunnable)PrRegion; }
Example 17
Source File: PRQueryDUnitHelper.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * This function <br> * 1. Creates & executes a query with Constants on the given PR Region <br> * 2. Executes the same query on the local region <br> * 3. Compares the appropriate resultSet <br> * * @param regionName * @param localRegionNeme * * @return cacheSerializable object */ public CacheSerializableRunnable getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults( final String regionName, final String localRegion) { SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") { @Override public void run2() throws CacheException { Cache cache = getCache(); // Querying the localRegion and the PR region String[] query = { "TRUE", "FALSE", "UNDEFINED", "NULL" }; Object r[][] = new Object[query.length][2]; Region local = cache.getRegion(localRegion); Region region = cache.getRegion(regionName); try { for (int j = 0; j < query.length; j++) { r[j][0] = local.query(query[j]); r[j][1] = region.query(query[j]); } getLogWriter() .info( "PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults: Queries Executed successfully on Local region & PR Region"); compareTwoQueryResults(r, query.length); } catch (QueryException e) { // assertTrue("caught Exception"+ e.getMessage(),false); getLogWriter() .error( "PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults: Caught an Exception while querying Constants" + e, e); fail("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults: Caught Exception while querying Constants. Exception is " + e); } } }; return (CacheSerializableRunnable)PrRegion; }
Example 18
Source File: PRInvalidQueryJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Tests the execution of an Invalid query <br> * (of the nature Select Distinct * from /Portfolios ) <br> * on a PartitionedRegion created on a single data store. <br> * 1. Creates a PR with redundancy=0 on a single VM.<br> * 2. Puts some test Objects in cache.<br> * 3. Fires querie on the data and verifies the result.<br> * 4. Since region#query() doesn't support this type of query syntax it should * throw QueryInvalidException <br> * * @throws Exception */ public void testInvalidQueryOnSingleDS() throws Exception { logger .info("PRInvalidQueryJUnitTest#testInvalidQueryOnSingleDS: Test Started "); Region region = PartitionedRegionTestHelper.createPartitionedRegion( regionName, "100", 0); logger .info("PRInvalidQueryJUnitTest#testInvalidQueryOnSingleDS: creating portfolioData objects"); PortfolioData[] portfolios = new PortfolioData[100]; for (int j = 0; j < 100; j++) { portfolios[j] = new PortfolioData(j); } populateData(region, portfolios); logger .info("PRInvalidQueryJUnitTest#testInvalidQueryOnSingleDS: creating Select Query"); String queryString = "SELECT DISTINCT * FROM /Portfolios WHERE pkid < '5'"; final String expectedQueryInvalidException = QueryInvalidException.class .getName(); logger.info("<ExpectedException action=add>" + expectedQueryInvalidException + "</ExpectedException>"); try { region.query(queryString); fail("PRInvalidQueryJUnitTest#testInvalidQueryOnSingleDS: Expected an Invalid Query Exception for the query :" + queryString + " this is not supported for region#query()"); } catch (QueryInvalidException qe) { logger .info("PRInvalidQueryJUnitTest#testInvalidQueryOnSingleDS: Caught an Invalid Query Exception for the query :" + queryString + " this is not supported for region#query()"); } logger .info("PRInvalidQueryJUnitTest#testInvalidQueryOnSingleDS: Test Ended"); logger.info("<ExpectedException action=remove>" + expectedQueryInvalidException + "</ExpectedException>"); }