|
IBM WebSphereTM eXtreme Scale, Release 8.6 API Specification |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ObjectQuery
An ObjectQuery provides a mechanism for introspecting one or more ObjectMaps using
standard ObjectGrid query language syntax. ObjectQuery instances are retrieved using
the Session.createObjectQuery(String)
method and
are valid for the session and inherits the session's current state. For example,
if the session has a transaction active, the ObjectQuery.getResultMap()
method will participate in that transaction.
Session.createObjectQuery(String)
Nested Class Summary | |
---|---|
static class |
ObjectQuery.ResultType
The result type indicates when the query engine will return the cached objects results in their native Object form or in the RAW form. |
Field Summary | |
---|---|
static String |
HINT_USEINDEX
Hint to the query engine to use the specified index. |
Method Summary | |
---|---|
String |
getPlan()
Return a string representation of the query plan. |
Iterator |
getResultIterator()
Execute a SELECT query and return the query results in an Iterator where each result is either an Object (for a single valued query) or Object[] (for a multiple valued query). |
ObjectMap |
getResultMap()
Execute a SELECT query and return the query results in an ObjectMap with the results in query-specified order. |
ObjectQuery.ResultType |
getResultType()
Return the current ResultType for the ObjectQuery. |
Object |
getSingleResult()
Execute a SELECT query that returns a single result. |
ObjectQuery |
setFirstResult(int startPosition)
Set the position of the first result to retrieve. |
ObjectQuery |
setForUpdate(boolean forUpdate)
Set the update intent for the query. |
ObjectQuery |
setHint(String hintName,
Object value)
Set a query hint. |
ObjectQuery |
setMaxResults(int maxResults)
Set the maximum number of results to retrieve. |
ObjectQuery |
setParameter(int position,
Object value)
Bind an argument to a positional parameter. |
ObjectQuery |
setParameter(String name,
Object value)
Bind an argument to a named parameter. |
ObjectQuery |
setPartition(int partitionId)
Set the partition to route the query to. |
ObjectQuery |
setResultMapName(String resultMapName)
The map to insert the results into. |
void |
setResultType(ObjectQuery.ResultType type)
Set the ObjectQuery.ResultType for a query using an ObjectMap that is configured with a KeySerializerPlugin
or ValueSerializerPlugin . |
Field Detail |
---|
static final String HINT_USEINDEX
String Format:
<IndexHint> ::= <Entity Name> "." <AttributeName> <Entity Name> ::= ObjectGrid map name <AttributeName> ::= An indexed attribute.Example:
ObjectQuery q = session.createObjectQuery("SELECT p FROM Person p WHERE p.name=?1 AND p.city=?2 AND p.state=?3"); q.setHint(ObjectQuery.HINT_USEINDEX, "Person.city"); q.setParameter(1, "Smith"); q.setParameter(2, "Rochester"); q.setParameter(3, "MN"); Iterator it = q.getResultIterator();
setHint(String, Object)
,
Constant Field ValuesMethod Detail |
---|
void setResultType(ObjectQuery.ResultType type)
ObjectQuery.ResultType
for a query using an ObjectMap
that is configured with a KeySerializerPlugin
or ValueSerializerPlugin
. The keys and values objects returned from the query
will be SerializedKey
or SerializedValue
objects respectively. If required, you
can use the SerializedEntry.getObject()
method to retrieve (possibly inflating
the serialized object) the original key or value object.
Attribute objects returned from the query will be in their native format even if the RAW result type is set. Example:
ObjectQuery q = session.createObjectQuery("SELECT p FROM Person p WHERE p.name=?1 AND p.city=?2 AND p.state=?3"); q.setResultType(ObjectQuery.ResultType.RAW); q.setParameter(1, "Smith"); q.setParameter(2, "Rochester"); q.setParameter(3, "MN"); Iterator it = q.getResultIterator(); while (it.hasNext()) { Person p = ((SerializedValue)it.next()).getObject(); }
type
- the type of object to return when returning cache objects.ObjectQuery.ResultType getResultType()
ObjectMap getResultMap()
The map key is the result number (of type long) starting at 0.
The map value is of type Object[]
where each element in the object array is based on it's ordinal
position within the query's select clause.
Example:
The following query returns 2 rows:
String ql = "SELECT e.name, e.id, d from Employee e join e.dept d WHERE d.number=5"; ObjectQuery q = createObjectQuery(ql); ObjectMap resultMap = q.getResultMap(); Object oResult = (Object[]) resultMap.get(new Long(0)); while(oResult != null) { // The first attribute is name and has an ordinal position of 0. String name = (String) oResult[0]; Integer id = (Integer) oResult[1]; Dept d = (Dept) oResult[2]; ... }
ObjectQueryException
- thrown if query validation
fails or if there is no active transaction. The resulting
transaction will be marked to rollback.Iterator getResultIterator()
Example:
The following query returns 2 rows:
String ql = "SELECT e.name, e.id, e from Employee e WHERE e.dept.number=5"; ObjectQuery q = session.createObjectQuery(ql); Iterator results = q.getResultIterator(); while(results.hasNext()) { Object[] curEmp = (Object[]) results.next(); String name = (String)curEmp[0]; Integer id = (Integer)curEmp[1] Dept d = (Dept)curEmp[2]; ... }
Object
or Object[]
ObjectQueryException
- thrown if query validation
fails or if there is no active transaction. The resulting
transaction will be marked to rollback.Object getSingleResult()
If the SELECT clause has more than one field defined, then the result
will be of type Object[]
where each element in the object array is based on it's ordinal
position within the query's select clause.
String ql = "SELECT e from Employee e WHERE e.id=100"; Employee e = (Employee) session.createObjectQuery(ql).getSingleResult(); String ql = "SELECT e.name, e.dept from Employee e WHERE e.id=100"; Object[] empData = (Object[]) session.createObjectQuery(ql).getSingleResult(); String empName= (String) empData[0]; Department empDept = (Department) empData[1];
NoResultException
- if there is no result
NonUniqueResultException
- if more than one result
ObjectQueryException
- thrown if query validation fails. The resulting
transaction will be marked to rollback.ObjectQuery setMaxResults(int maxResults)
maxResults
- the maximum number of results to retrieve.
IllegalArgumentException
- if the argument is negativeObjectQuery setFirstResult(int startPosition)
startPosition
- position of the first result, numbered from 0
IllegalArgumentException
- if the argument is negativeObjectQuery setResultMapName(String resultMapName)
If the result map name is specified and the map already exists, the query will fail.
resultMapName
- the name of the ObjectMap to insert the query results into.
ObjectQuery setHint(String hintName, Object value)
hintName
- the name of the hint. See the constant values defined in this interface.value
- the value of the hint.
IllegalArgumentException
- thrown if the second argument is not valid for the hint.
This exception may be deferred until the query is run.ObjectQuery setParameter(String name, Object value)
name
- the parameter namevalue
- the value of the parameter.
IllegalArgumentException
- if parameter name does not correspond to parameter in query string or argument is of incorrect type.
This exception may be deferred until the query is run.ObjectQuery setParameter(int position, Object value)
position
- the position of the parameter. The first parameter is 1.value
- the value of the parameter.
IllegalArgumentException
- if position does not correspond to positional parameter of query or argument is of incorrect type.
This exception may be deferred until the query is run.ObjectQuery setPartition(int partitionId)
The partition id is required if the maps in the query are partitioned and the Session commit strategy is set to LOCAL.
Use the PartitionManager
to determine the number of partitions
for a given backing map and to calculate the partition number from an
object.
partitionId
- the partition to route the query to.
ObjectQuery setForUpdate(boolean forUpdate)
If not set, the default is false.
forUpdate
- if true, lock records for update.
String getPlan()
This method can be used to explain the plan of a query without running the query. The plan describes when a map is to be scanned, an index used and the order in which the maps are accessed.
ObjectQueryException
- thrown if query validation fails. The transaction will not be marked to rollback.
|
IBM WebSphereTM eXtreme Scale, Release 8.6 API Specification |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |