Java Code Examples for org.apache.geode.cache.client.ClientCache#getQueryService()
The following examples show how to use
org.apache.geode.cache.client.ClientCache#getQueryService() .
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: Example.java From geode-examples with Apache License 2.0 | 6 votes |
public static void doQueries(ClientCache cache) throws NameResolutionException, TypeMismatchException, QueryInvocationTargetException, FunctionDomainException { QueryService queryService = cache.getQueryService(); // Query for every entry in the region, and print query results. System.out.println("\nExecuting query: " + QUERY1); SelectResults<EmployeeData> results = (SelectResults<EmployeeData>) queryService.newQuery(QUERY1).execute(); printSetOfEmployees(results); // Query for all part time employees, and print query results. System.out.println("\nExecuting query: " + QUERY2); results = (SelectResults<EmployeeData>) queryService.newQuery(QUERY2).execute(); printSetOfEmployees(results); // Query for last name of Jive, and print the full name and employee number. System.out.println("\nExecuting query: " + QUERY3); results = (SelectResults<EmployeeData>) queryService.newQuery(QUERY3).execute(new String[] {"Jive"}); for (EmployeeData eachEmployee : results) { System.out.println(String.format("Employee %s %s has employee number %d", eachEmployee.getFirstName(), eachEmployee.getLastName(), eachEmployee.getEmplNumber())); } }
Example 2
Source File: Example.java From geode-examples with Apache License 2.0 | 6 votes |
public static void doQueries(ClientCache cache) throws NameResolutionException, TypeMismatchException, QueryInvocationTargetException, FunctionDomainException { QueryService queryService = cache.getQueryService(); // Query for every entry in the region, and print query results. System.out.println("\nExecuting query: " + QUERY1); SelectResults<EmployeeData> results = (SelectResults<EmployeeData>) queryService.newQuery(QUERY1).execute(); printSetOfEmployees(results); // Query for all part time employees, and print query results. System.out.println("\nExecuting query: " + QUERY2); results = (SelectResults<EmployeeData>) queryService.newQuery(QUERY2).execute(); printSetOfEmployees(results); // Query for last name of Jive, and print the full name and employee number. System.out.println("\nExecuting query: " + QUERY3); results = (SelectResults<EmployeeData>) queryService.newQuery(QUERY3).execute(new String[] {"Jive"}); for (EmployeeData eachEmployee : results) { System.out.println(String.format("Employee %s %s has employee number %d", eachEmployee.getFirstName(), eachEmployee.getLastName(), eachEmployee.getEmplNumber())); } }
Example 3
Source File: BookMasterRegionTest.java From calcite with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { ClientCache clientCache = new ClientCacheFactory() .addPoolLocator("localhost", 10334) .setPdxSerializer(new ReflectionBasedAutoSerializer("org.apache.calcite.adapter.geode.*")) .create(); // Using Key/Value Region bookMaster = clientCache .createClientRegionFactory(ClientRegionShortcut.PROXY) .create("BookMaster"); System.out.println("BookMaster = " + bookMaster.get(789)); // Using OQL QueryService queryService = clientCache.getQueryService(); String oql = "select itemNumber, description, retailCost from /BookMaster"; SelectResults result = (SelectResults) queryService.newQuery(oql).execute(); System.out.println(result.asList()); }
Example 4
Source File: Example.java From geode-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) { // connect to the locator using default port 10334 ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334) .set("log-level", "WARN").create(); Example example = new Example(); // create a local region that matches the server region ClientRegionFactory<String, Passenger> clientRegionFactory = cache.createClientRegionFactory(ClientRegionShortcut.PROXY); Region<String, Passenger> region = clientRegionFactory.create("example-region"); QueryService queryService = cache.getQueryService(); RegionPopulator populator = new RegionPopulator(); populator.populateRegion(region); System.out.println("Total number of passengers: " + example.countResults(queryService, NON_INDEXED_QUERY, new Object[] {})); for (String lastName : populator.lastNames) { System.out.println("Flights for " + lastName + ": " + example.countResults(queryService, TOP_LEVEL_INDEX_QUERY, new Object[] {"%" + lastName})); } for (String airline : populator.airlines) { System.out.println("Flights for " + airline + ": " + example.countResults(queryService, NESTED_INDEX_QUERY, new Object[] {airline})); } cache.close(); }
Example 5
Source File: Example.java From geode-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) { // connect to the locator using default port 10334 ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334) .set("log-level", "WARN").create(); Example example = new Example(); // create a local region that matches the server region ClientRegionFactory<String, Passenger> clientRegionFactory = cache.createClientRegionFactory(ClientRegionShortcut.PROXY); Region<String, Passenger> region = clientRegionFactory.create("example-region"); QueryService queryService = cache.getQueryService(); RegionPopulator populator = new RegionPopulator(); populator.populateRegion(region); System.out.println("Total number of passengers: " + example.countResults(queryService, NON_INDEXED_QUERY, new Object[] {})); for (String lastName : populator.lastNames) { System.out.println("Flights for " + lastName + ": " + example.countResults(queryService, TOP_LEVEL_INDEX_QUERY, new Object[] {"%" + lastName})); } for (String airline : populator.airlines) { System.out.println("Flights for " + airline + ": " + example.countResults(queryService, NESTED_INDEX_QUERY, new Object[] {airline})); } cache.close(); }
Example 6
Source File: GeodeSimpleEnumerator.java From calcite with Apache License 2.0 | 5 votes |
public GeodeSimpleEnumerator(ClientCache clientCache, String regionName) { this.clientCache = clientCache; QueryService queryService = clientCache.getQueryService(); String oql = "select * from /" + regionName.trim(); try { results = ((SelectResults) queryService.newQuery(oql).execute()).iterator(); } catch (Exception e) { e.printStackTrace(); results = null; } }
Example 7
Source File: DefaultQueryServiceResolver.java From immutables with Apache License 2.0 | 5 votes |
private static QueryService resolveClientQueryService(Region<?, ?> region) { Preconditions.checkArgument(region.getRegionService() instanceof ClientCache, "Expected to get %s got %s for region %s", ClientCache.class, region.getRegionService(), region.getFullPath()); ClientCache clientCache = (ClientCache) region.getRegionService(); return requiresLocalQueryService(region) ? clientCache.getLocalQueryService() : (requiresPooledQueryService(region) ? clientCache.getQueryService(poolNameFrom(region)) : queryServiceFrom(region)); }