- 4.3.1.17.1 概要
- 4.3.1.17.2 INDEX_USED
- 4.3.1.17.3 扫描类型
- 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 执行(地图<字符串,?>)
- 4.3.1.17.10 执行(对象...)
- 4.3.1.17.11 执行(对象)
- 4.3.1.17.12 说明()
- 4.3.1.17.13 获取结果列表()
- 4.3.1.17.14 设置限制(长,长)
- 4.3.1.17.15 setOrdering(Query.Ordering, String...)
- 4.3.1.17.16 设置参数(字符串,对象)
Query 实例表示具有绑定参数的特定查询。该实例由方法创建
com.mysql.clusterj.Session.<T>createQuery(com.mysql.clusterj.query.QueryDefinition<T>)
。
public interface Query<E> {
// 公共静态字段// 公共方法}public 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 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 abstract int deletePersistentAll();
删除满足查询条件的实例。
public abstract Results<E> execute(Map<String, ?> parameters);
使用一个或多个命名参数执行查询。参数按名称解析。
public abstract Results<E> execute(Object[] parameters);
使用一个或多个参数执行查询。参数按照它们在查询中声明的顺序解析。
public abstract Results<E> execute(Object 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.
Skip must be greater than or equal to 0. Limit must be greater than or equal to 0. Limits may not be used with deletePersistentAll.
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 |