- 4.3.1.17.1 Synopsis
- 4.3.1.17.2 INDEX_USED
- 4.3.1.17.3 SCAN_TYPE
- 4.3.1.17.4 SCAN_TYPE_INDEX_SCAN
- 4.3.1.17.5 SCAN_TYPE_PRIMARY_KEY
- 4.3.1.17.6 SCAN_TYPE_TABLE_SCAN
- 4.3.1.17.7 SCAN_TYPE_UNIQUE_KEY
- 4.3.1.17.8 deletePersistentAll()
- 4.3.1.17.9 execute(Map<String, ?>)
- 4.3.1.17.10 execute(Object...)
- 4.3.1.17.11 execute(Object)
- 4.3.1.17.12 explain()
- 4.3.1.17.13 getResultList()
- 4.3.1.17.14 setLimits(long, long)
- 4.3.1.17.15 setOrdering(Query.Ordering, String...)
- 4.3.1.17.16 setParameter(String, Object)
A Query instance represents a specific query with bound
parameters. The instance is created by the method
com.mysql.clusterj.Session.<T>createQuery(com.mysql.clusterj.query.QueryDefinition<T>)
.
public interface Query<E> {
// Public Static Fieldspublic static final String INDEX_USED = "IndexUsed";
public static final String SCAN_TYPE = "ScanType";
public static final String SCAN_TYPE_INDEX_SCAN = "INDEX_SCAN";
public static final String SCAN_TYPE_PRIMARY_KEY = "PRIMARY_KEY";
public static final String SCAN_TYPE_TABLE_SCAN = "TABLE_SCAN";
public static final String SCAN_TYPE_UNIQUE_KEY = "UNIQUE_KEY";
// Public Methodspublic abstract int deletePersistentAll();
public abstract Results<E> execute(Object parameter);
public abstract Results<E> execute(Object[] parameters);
public abstract Results<E> execute(Map<String, ?> parameters);
public abstract Map<String, Object> explain();
public abstract List<E> getResultList();
public abstract void setLimits(long skip,
long limit);public abstract void setOrdering(Ordering ordering,
String[] orderingFields);public abstract void setParameter(String parameterName,
Object value);
}
public static final String SCAN_TYPE_INDEX_SCAN = "INDEX_SCAN";
The query explain scan type value for index scan
public static final String SCAN_TYPE_PRIMARY_KEY = "PRIMARY_KEY";
The query explain scan type value for primary key
public static final String SCAN_TYPE_TABLE_SCAN = "TABLE_SCAN";
The query explain scan type value for table scan
public static final String SCAN_TYPE_UNIQUE_KEY = "UNIQUE_KEY";
The query explain scan type value for unique key
public abstract int deletePersistentAll();
Delete the instances that satisfy the query criteria.
public abstract Results<E> execute(Map<String, ?> parameters);
Execute the query with one or more named parameters. Parameters are resolved by name.
Table 4.36 execute(Map<String, ?>)
Parameter | Description |
---|---|
parameters | the parameters |
return | the result |
public abstract Results<E> execute(Object[] parameters);
Execute the query with one or more parameters. Parameters are resolved in the order they were declared in the query.
public abstract Results<E> execute(Object parameter);
Execute the query with exactly one parameter.
public abstract Map<String, Object> explain();
Explain how this query will be or was executed. If called before binding all parameters, throws ClusterJUserException. Return a map of key:value pairs that explain how the query will be or was executed. Details can be obtained by calling toString on the value. The following keys are returned:
-
ScanType: the type of scan, with values:
PRIMARY_KEY: the query used key lookup with the primary key
UNIQUE_KEY: the query used key lookup with a unique key
INDEX_SCAN: the query used a range scan with a non-unique key
TABLE_SCAN: the query used a table scan
IndexUsed: the name of the index used, if any
Exceptions
-
ClusterJUserException
if not all parameters are bound
public abstract List<E> getResultList();
Get the results as a list.
Exceptions
-
ClusterJUserException
if not all parameters are bound
-
ClusterJDatastoreException
if an exception is reported by the datastore
public abstract void setLimits(long skip,
long limit);
Set limits on results to return. The execution of the query is modified to return only a subset of results. If the filter would normally return 100 instances, skip is set to 50, and limit is set to 40, then the first 50 results that would have been returned are skipped, the next 40 results are returned and the remaining 10 results are ignored.
The parameter skip must be greater than or equal to 0 (see an exception below) and limit must be greater than or equal to 0.
When used with deletePersistentAll, skip must be 0, and the instances should be deleted iteratively until the count of deleted instances is less than the batch size. For example:
/* Delete in batches */
query.setLimits(0, DeleteBatchSize);
int result = 0;
do { result = query.deletePersistentAll();
System.out.println("Batch result: " + result);
} while(result == DeleteBatchSize);
Table 4.41 setLimits(long, long)
Parameter | Description |
---|---|
skip | the number of results to skip |
limit | the number of results to return after skipping; use Long.MAX_VALUE for no limit. |
public abstract void setOrdering(Ordering ordering,
String[] orderingFields);
Set ordering for the results of this query. The execution of the query is modified to use an index previously defined.
There must be an index defined on the columns mapped to the ordering fields, in the order of the ordering fields.
There must be no gaps in the ordering fields relative to the index.
All ordering fields must be in the index, but not all fields in the index need be in the ordering fields.
If an "in" predicate is used in the filter on a field in the ordering, it can only be used with the first field.
If any of these conditions is violated, ClusterJUserException is thrown when the query is executed.
If an "in" predicate is used, each element in the parameter defines a separate range, and ordering is performed within that range. There may be a better (more efficient) index based on the filter, but specifying the ordering will force the query to use an index that contains the ordering fields.
Table 4.42 setOrdering(Query.Ordering, String...)
Parameter | Description |
---|---|
ordering | either Ordering.ASCENDING or Ordering.DESCENDING |
orderingFields | the fields to order by |
public abstract void setParameter(String parameterName,
Object value);
Set the value of a parameter. If called multiple times for the same parameter, silently replace the value.
Table 4.43 setParameter(String, Object)
Parameter | Description |
---|---|
parameterName | the name of the parameter |
value | the value for the parameter |