Executing a Query from the Client
This
.NET and C++ example uses the example portfolios
region to show how to execute a query from the client.
Note:
In all queries that use the example data, it is assumed that the portfolios
region has javaobject.Portfolio
objects on the cache server.
- If you are using the C++ client, get a pointer to the
QueryService
method. - Create a
QueryPtr
to a query (C++) or create a query instance (.NET) that is compatible with the OQL specification. - Use the
execute
method for theQuery
interface to submit the query string to the cache server. The server remotely evaluates the query string and returns the results to the client. - You can iterate through the returned objects as part of the query process.
C#/.NET Example
Query<Portfolio> qry = qrySvc.NewQuery("SELECT DISTINCT * FROM /portfolios");
ISelectResults<Portfolio> results = qry.Execute();
SelectResultsIterator<Portfolio> iter = results.GetIterator();
while (iter.MoveNext()) {
Console.WriteLine( iter.Current.ToString());
}
C++ Example
Note:
The C++ examples in this chapter all assume that you have already obtained a pointer to the QueryService
.
QueryServicePtr qrySvcPtr = cachePtr->getQueryService("examplePool");
QueryPtr qry = qrySvcPtr->newQuery(
"SELECT DISTINCT * FROM /Portfolios WHERE status = ‘active’");
SelectResultsPtr resultsPtr = qry->execute(10);
SelectResultsIterator iter = resultsPtr->getIterator();
while (iter.hasNext()) {
PortfolioPtr portfolio = dynCast<PortfolioPtr > (iter.next());
}