org.apache.ignite.internal.processors.cache.query

## Class GridCacheQueryAdapter<T>

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.query.GridCacheQueryAdapter<T>

All Implemented Interfaces:
  CacheQuery<T>

    public class GridCacheQueryAdapter<T>
    extends Object
    implements CacheQuery<T>

Query adapter.

### Constructor Summary

Constructors
Constructor and Description
`GridCacheQueryAdapter(GridCacheContext<?,?> cctx, GridCacheQueryType type, IgniteLogger log, int pageSize, long timeout, boolean keepAll, boolean incBackups, boolean dedup, ClusterGroup prj, IgniteBiPredicate<Object,Object> filter, String clsName, String clause, boolean incMeta, boolean keepPortable, UUID subjId, int taskHash)`
`GridCacheQueryAdapter(GridCacheContext<?,?> cctx, GridCacheQueryType type, String clsName, String clause, IgniteBiPredicate<Object,Object> filter, boolean incMeta, boolean keepPortable)`

### Method Summary

Methods
`String` `clause()`
`boolean` `enableDedup()`
`CacheQuery<T>` `enableDedup(boolean dedup)` Sets whether or not to deduplicate query result set.
`<R> CacheQueryFuture<R>` `execute(IgniteClosure<T,R> rmtTransform, Object... args)` Executes the query the same way as `CacheQuery.execute(Object...)` method but transforms result remotely.
`<R> CacheQueryFuture<R>` `execute(IgniteReducer<T,R> rmtReducer, Object... args)` Executes the query the same way as `CacheQuery.execute(Object...)` method but reduces result remotely.
`CacheQueryFuture<T>` `execute(Object... args)` Executes the query and returns the query future.
`boolean` `includeBackups()`
`CacheQuery<T>` `includeBackups(boolean incBackups)` Sets whether or not to include backup entries into query result.
`boolean` `includeMetadata()`
`boolean` `keepAll()`
`CacheQuery<T>` `keepAll(boolean keepAll)` Sets whether or not to keep all query results local.
`boolean` `keepPortable()`
`void` `keepPortable(boolean keepPortable)` Forces query to keep portable object representation even if query was created on plain projection.
`QueryMetrics` `metrics()` Gets metrics for this query.
`void` `onExecuted(Object res, Throwable err, long startTime, long duration)`
`int` `pageSize()`
`CacheQuery<T>` `pageSize(int pageSize)` Sets result page size.
`ClusterGroup` `projection()`
`CacheQuery<T>` `projection(ClusterGroup prj)` Sets optional grid projection to execute this query on.
`String` `queryClassName()`
`void` `resetMetrics()` Resets metrics for this query.
`<K,V> IgniteBiPredicate<K,V>` `scanFilter()`
`UUID` `subjectId()`
`void` `subjectId(UUID subjId)`
`int` `taskHash()`
`long` `timeout()`
`CacheQuery<T>` `timeout(long timeout)` Sets query timeout.
`String` `toString()`
`GridCacheQueryType` `type()`
`void` `validate()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### GridCacheQueryAdapter

    public GridCacheQueryAdapter(GridCacheContext<?,?> cctx,
                         GridCacheQueryType type,
                         @Nullable
                         String clsName,
                         @Nullable
                         String clause,
                         @Nullable
                         IgniteBiPredicate<Object,Object> filter,
                         boolean incMeta,
                         boolean keepPortable)

Parameters:
  `cctx` - Context.
  `type` - Query type.
  `clsName` - Class name.
  `clause` - Clause.
  `filter` - Scan filter.
  `incMeta` - Include metadata flag.
  `keepPortable` - Keep portable flag.

#### GridCacheQueryAdapter

    public GridCacheQueryAdapter(GridCacheContext<?,?> cctx,
                         GridCacheQueryType type,
                         IgniteLogger log,
                         int pageSize,
                         long timeout,
                         boolean keepAll,
                         boolean incBackups,
                         boolean dedup,
                         ClusterGroup prj,
                         IgniteBiPredicate<Object,Object> filter,
                         @Nullable
                         String clsName,
                         String clause,
                         boolean incMeta,
                         boolean keepPortable,
                         UUID subjId,
                         int taskHash)

Parameters:
  `cctx` - Context.
  `type` - Query type.
  `log` - Logger.
  `pageSize` - Page size.
  `timeout` - Timeout.
  `keepAll` - Keep all flag.
  `incBackups` - Include backups flag.
  `dedup` - Enable dedup flag.
  `prj` - Grid projection.
  `filter` - Key-value filter.
  `clsName` - Class name.
  `clause` - Clause.
  `incMeta` - Include metadata flag.
  `keepPortable` - Keep portable flag.
  `subjId` - Security subject ID.
  `taskHash` - Task hash.

### Method Detail

#### type

    public GridCacheQueryType type()

Returns:
  Type.

#### queryClassName

    @Nullable
    public String queryClassName()

Returns:
  Class name.

#### clause

    @Nullable
    public String clause()

Returns:
  Clause.

#### includeMetadata

    public boolean includeMetadata()

Returns:
  Include metadata flag.

#### keepPortable

    public boolean keepPortable()

Returns:
  `True` if portable should not be deserialized.

#### keepPortable

    public void keepPortable(boolean keepPortable)

Forces query to keep portable object representation even if query was created on plain projection.

Parameters:
  `keepPortable` - Keep portable flag.

#### subjectId

    public UUID subjectId()

Returns:
  Security subject ID.

#### taskHash

    public int taskHash()

Returns:
  Task hash.

#### subjectId

    public void subjectId(UUID subjId)

Parameters:
  `subjId` - Security subject ID.

#### pageSize

    public CacheQuery<T> pageSize(int pageSize)

Sets result page size. If not provided, `Query.DFLT_PAGE_SIZE` will be used. Results are returned from queried nodes one page at a tme.

Specified by:
  `pageSize` in interface `CacheQuery<T>`
Parameters:
  `pageSize` - Page size.
Returns:
  `this` query instance for chaining.

#### pageSize

    public int pageSize()

Returns:
  Page size.

#### timeout

    public CacheQuery<T> timeout(long timeout)

Sets query timeout. `0` means there is no timeout (this is a default value).

Specified by:
  `timeout` in interface `CacheQuery<T>`
Parameters:
  `timeout` - Query timeout.
Returns:
  `this` query instance for chaining.

#### timeout

    public long timeout()

Returns:
  Timeout.

#### keepAll

    public CacheQuery<T> keepAll(boolean keepAll)

Sets whether or not to keep all query results local. If not - only the current page is kept locally. Default value is `true`.

Specified by:
  `keepAll` in interface `CacheQuery<T>`
Parameters:
  `keepAll` - Keep results or not.
Returns:
  `this` query instance for chaining.

#### keepAll

    public boolean keepAll()

Returns:
  Keep all flag.

#### includeBackups

    public CacheQuery<T> includeBackups(boolean incBackups)

Sets whether or not to include backup entries into query result. This flag is `false` by default.

Specified by:
  `includeBackups` in interface `CacheQuery<T>`
Parameters:
  `incBackups` - Query `includeBackups` flag.
Returns:
  `this` query instance for chaining.

#### includeBackups

    public boolean includeBackups()

Returns:
  Include backups.

#### enableDedup

    public CacheQuery<T> enableDedup(boolean dedup)

Sets whether or not to deduplicate query result set. If this flag is `true` then query result will not contain some key more than once even if several nodes returned entries with the same keys. Default value is `false`.

Specified by:
  `enableDedup` in interface `CacheQuery<T>`
Parameters:
  `dedup` - Query `enableDedup` flag.
Returns:
  `this` query instance for chaining.

#### enableDedup

    public boolean enableDedup()

Returns:
  Enable dedup flag.

#### projection

    public CacheQuery<T> projection(ClusterGroup prj)

Sets optional grid projection to execute this query on.

Specified by:
  `projection` in interface `CacheQuery<T>`
Parameters:
  `prj` - Projection.
Returns:
  `this` query instance for chaining.

#### projection

    public ClusterGroup projection()

Returns:
  Grid projection.

#### scanFilter

    @Nullable
    public <K,V> IgniteBiPredicate<K,V> scanFilter()

Returns:
  Key-value filter.

#### validate

    public void validate()
                  throws IgniteCheckedException

Throws:
  `IgniteCheckedException` - If query is invalid.

#### onExecuted

    public void onExecuted(Object res,
                  Throwable err,
                  long startTime,
                  long duration)

Parameters:
  `res` - Query result.
  `err` - Error or `null` if query executed successfully.
  `startTime` - Start time.
  `duration` - Duration.

#### execute

    public CacheQueryFuture<T> execute(@Nullable
                              Object... args)

Executes the query and returns the query future. Caller may decide to iterate over the returned future directly in which case the iterator may block until the next value will become available, or wait for the whole query to finish by calling any of the `'get(..)'` methods on the returned future. If `CacheQuery.keepAll(boolean)` flag is set to `false`, then `'get(..)'` methods will only return the last page received, otherwise all pages will be accumulated and returned to user as a collection.

Note that if the passed in grid projection is a local node, then query will be executed locally without distribution to other nodes.

Also note that query state cannot be changed (clause, timeout etc.), except arguments, if this method was called at least once.

Specified by:
  `execute` in interface `CacheQuery<T>`
Parameters:
  `args` - Optional arguments.
Returns:
  Future for the query result.

#### execute

    public <R> CacheQueryFuture<R> execute(IgniteReducer<T,R> rmtReducer,
                                  @Nullable
                                  Object... args)

Executes the query the same way as `CacheQuery.execute(Object...)` method but reduces result remotely.

Specified by:
  `execute` in interface `CacheQuery<T>`
Parameters:
  `rmtReducer` - Remote reducer.
  `args` - Optional arguments.
Returns:
  Future for the query result.

#### execute

    public <R> CacheQueryFuture<R> execute(IgniteClosure<T,R> rmtTransform,
                                  @Nullable
                                  Object... args)

Executes the query the same way as `CacheQuery.execute(Object...)` method but transforms result remotely.

Specified by:
  `execute` in interface `CacheQuery<T>`
Parameters:
  `rmtTransform` - Remote transformer.
  `args` - Optional arguments.
Returns:
  Future for the query result.

#### metrics

    public QueryMetrics metrics()

Description copied from interface: `CacheQuery`
Gets metrics for this query.

Specified by:
  `metrics` in interface `CacheQuery<T>`
Returns:
  Query metrics.

#### resetMetrics

    public void resetMetrics()

Description copied from interface: `CacheQuery`
Resets metrics for this query.

Specified by:
  `resetMetrics` in interface `CacheQuery<T>`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.1.0-incubating
Release Date | : May 20 2015