org.apache.ignite.internal.processors.query

## Interface GridQueryIndexing

    public interface GridQueryIndexing

Abstraction for internal indexing implementation.

### Method Summary

Methods
`IndexingQueryFilter` `backupFilter(AffinityTopologyVersion topVer, int[] parts)` Returns backup filter.
`void` `cancelAllQueries()` Cancels all executing queries.
`void` `cancelQueries(Collection<Long> queries)` Cancel specified queries.
`void` `dynamicIndexCreate(String schemaName, String tblName, QueryIndexDescriptorImpl idxDesc, boolean ifNotExists, SchemaIndexCacheVisitor cacheVisitor)` Create new index locally.
`void` `dynamicIndexDrop(String schemaName, String idxName, boolean ifExists)` Remove index from the cache.
`boolean` `isInsertStatement(PreparedStatement nativeStmt)` Check if passed statement is insert statemtn.
`void` `markForRebuildFromHash(String cacheName)` Marks all indexes of given type for rebuild from hash index, making them unusable until rebuild finishes.
`void` `onDisconnected(IgniteFuture<?> reconnectFut)` Client disconnected callback.
`PreparedStatement` `prepareNativeStatement(String schemaName, String sql)` Prepare native statement to retrieve JDBC metadata from.
`<K,V> QueryCursor<javax.cache.Cache.Entry<K,V>>` `queryDistributedSql(String schemaName, SqlQuery qry, boolean keepBinary, int mainCacheId)` Parses SQL query into two step query and executes it.
`FieldsQueryCursor<List<?>>` `queryDistributedSqlFields(String schemaName, SqlFieldsQuery qry, boolean keepBinary, GridQueryCancel cancel, Integer mainCacheId)` Parses SQL query into two step query and executes it.
`<K,V> QueryCursor<javax.cache.Cache.Entry<K,V>>` `queryLocalSql(String schemaName, SqlQuery qry, IndexingQueryFilter filter, boolean keepBinary)` Executes regular query.
`FieldsQueryCursor<List<?>>` `queryLocalSqlFields(String schemaName, SqlFieldsQuery qry, boolean keepBinary, IndexingQueryFilter filter, GridQueryCancel cancel)` Queries individual fields (generally used by JDBC drivers).
`<K,V> GridCloseableIterator<IgniteBiTuple<K,V>>` `queryLocalText(String schemaName, String qry, String typeName, IndexingQueryFilter filter)` Executes text query.
`void` `rebuildIndexesFromHash(String cacheName)` Rebuilds all indexes of given type from hash index.
`void` `registerCache(String cacheName, String schemaName, GridCacheContext<?,?> cctx)` Registers cache.
`boolean` `registerType(GridCacheContext cctx, GridQueryTypeDescriptor desc)` Registers type if it was not known before or updates it otherwise.
`void` `remove(String cacheName, GridQueryTypeDescriptor type, KeyCacheObject key, int partId, CacheObject val, GridCacheVersion ver)` Removes index entry by key.
`Collection<GridRunningQueryInfo>` `runningQueries(long duration)` Collect queries that already running more than specified duration.
`String` `schema(String cacheName)` Gets database schema from cache name.
`void` `start(GridKernalContext ctx, GridSpinBusyLock busyLock)` Starts indexing.
`void` `stop()` Stops indexing.
`void` `store(String cacheName, GridQueryTypeDescriptor type, KeyCacheObject key, int partId, CacheObject val, GridCacheVersion ver, long expirationTime, long link)` Updates index.
`long` `streamUpdateQuery(String schemaName, String qry, Object[] params, IgniteDataStreamer<?,?> streamer)` Perform a MERGE statement using data streamer as receiver.
`void` `unregisterCache(String cacheName)` Unregisters cache.

### Method Detail

#### start

    void start(GridKernalContext ctx,
             GridSpinBusyLock busyLock)
               throws IgniteCheckedException

Starts indexing.

Parameters:
  `ctx` - Context.
  `busyLock` - Busy lock.
Throws:
  `IgniteCheckedException` - If failed.

#### stop

    void stop()
              throws IgniteCheckedException

Stops indexing.

Throws:
  `IgniteCheckedException` - If failed.

#### queryDistributedSql

    <K,V> QueryCursor<javax.cache.Cache.Entry<K,V>> queryDistributedSql(String schemaName,
                                                                      SqlQuery qry,
                                                                      boolean keepBinary,
                                                                      int mainCacheId)
                                                                  throws IgniteCheckedException

Parses SQL query into two step query and executes it.

Parameters:
  `schemaName` - Schema name.
  `qry` - Query.
  `keepBinary` - Keep binary flag.
  `mainCacheId` - Main cache ID.
Returns:
  Cursor.
Throws:
  `IgniteCheckedException` - If failed.

#### queryDistributedSqlFields

    FieldsQueryCursor<List<?>> queryDistributedSqlFields(String schemaName,
                                                       SqlFieldsQuery qry,
                                                       boolean keepBinary,
                                                       GridQueryCancel cancel,
                                                       @Nullable
                                                       Integer mainCacheId)
                                                         throws IgniteCheckedException

Parses SQL query into two step query and executes it.

Parameters:
  `schemaName` - Schema name.
  `qry` - Query.
  `keepBinary` - Keep binary flag.
  `cancel` - Query cancel.
  `mainCacheId` - Main cache ID.
Returns:
  Cursor.
Throws:
  `IgniteCheckedException` - If failed.

#### streamUpdateQuery

    long streamUpdateQuery(String schemaName,
                         String qry,
                         @Nullable
                         Object[] params,
                         IgniteDataStreamer<?,?> streamer)
                           throws IgniteCheckedException

Perform a MERGE statement using data streamer as receiver.

Parameters:
  `schemaName` - Schema name.
  `qry` - Query.
  `params` - Query parameters.
  `streamer` - Data streamer to feed data to.
Returns:
  Query result.
Throws:
  `IgniteCheckedException` - If failed.

#### queryLocalSql

    <K,V> QueryCursor<javax.cache.Cache.Entry<K,V>> queryLocalSql(String schemaName,
                                                                SqlQuery qry,
                                                                IndexingQueryFilter filter,
                                                                boolean keepBinary)
                                                            throws IgniteCheckedException

Executes regular query.

Parameters:
  `schemaName` - Schema name.
  `qry` - Query.
  `filter` - Cache name and key filter.
  `keepBinary` - Keep binary flag.
Returns:
  Cursor.
Throws:
  `IgniteCheckedException`

#### queryLocalSqlFields

    FieldsQueryCursor<List<?>> queryLocalSqlFields(String schemaName,
                                                 SqlFieldsQuery qry,
                                                 boolean keepBinary,
                                                 IndexingQueryFilter filter,
                                                 GridQueryCancel cancel)
                                                   throws IgniteCheckedException

Queries individual fields (generally used by JDBC drivers).

Parameters:
  `schemaName` - Schema name.
  `qry` - Query.
  `keepBinary` - Keep binary flag.
  `filter` - Cache name and key filter.
  `cancel` - Query cancel.
Returns:
  Cursor.
Throws:
  `IgniteCheckedException`

#### queryLocalText

    <K,V> GridCloseableIterator<IgniteBiTuple<K,V>> queryLocalText(String schemaName,
                                                                 String qry,
                                                                 String typeName,
                                                                 IndexingQueryFilter filter)
                                                             throws IgniteCheckedException

Executes text query.

Parameters:
  `schemaName` - Schema name.
  `qry` - Text query.
  `typeName` - Type name.
  `filter` - Cache name and key filter.
Returns:
  Queried rows.
Throws:
  `IgniteCheckedException` - If failed.

#### dynamicIndexCreate

    void dynamicIndexCreate(String schemaName,
                          String tblName,
                          QueryIndexDescriptorImpl idxDesc,
                          boolean ifNotExists,
                          SchemaIndexCacheVisitor cacheVisitor)
                            throws IgniteCheckedException

Create new index locally.

Parameters:
  `schemaName` - Schema name.
  `tblName` - Table name.
  `idxDesc` - Index descriptor.
  `ifNotExists` - Ignore operation if index exists (instead of throwing an error).
  `cacheVisitor` - Cache visitor
Throws:
  `IgniteCheckedException` - if failed.

#### dynamicIndexDrop

    void dynamicIndexDrop(String schemaName,
                        String idxName,
                        boolean ifExists)
                          throws IgniteCheckedException

Remove index from the cache.

Parameters:
  `schemaName` - Schema name.
  `idxName` - Index name.
  `ifExists` - Ignore operation if index does not exist (instead of throwing an error).
Throws:
  `IgniteCheckedException` - If failed.

#### registerCache

    void registerCache(String cacheName,
                     String schemaName,
                     GridCacheContext<?,?> cctx)
                       throws IgniteCheckedException

Registers cache.

Parameters:
  `cacheName` - Cache name.
  `schemaName` - Schema name.
  `cctx` - Cache context.
Throws:
  `IgniteCheckedException` - If failed.

#### unregisterCache

    void unregisterCache(String cacheName)
                         throws IgniteCheckedException

Unregisters cache.

Parameters:
  `cacheName` - Cache name.
Throws:
  `IgniteCheckedException` - If failed to drop cache schema.

#### registerType

    boolean registerType(GridCacheContext cctx,
                       GridQueryTypeDescriptor desc)
                         throws IgniteCheckedException

Registers type if it was not known before or updates it otherwise.

Parameters:
  `cctx` - Cache context.
  `desc` - Type descriptor.
Returns:
  `True` if type was registered, `false` if for some reason it was rejected.
Throws:
  `IgniteCheckedException` - If failed.

#### store

    void store(String cacheName,
             GridQueryTypeDescriptor type,
             KeyCacheObject key,
             int partId,
             CacheObject val,
             GridCacheVersion ver,
             long expirationTime,
             long link)
               throws IgniteCheckedException

Updates index. Note that key is unique for cache, so if cache contains multiple indexes the key should be removed from indexes other than one being updated.

Parameters:
  `cacheName` - Cache name.
  `type` - Type descriptor.
  `key` - Key.
  `val` - Value.
  `ver` - Version.
  `expirationTime` - Expiration time or 0 if never expires.
Throws:
  `IgniteCheckedException` - If failed.

#### remove

    void remove(String cacheName,
              GridQueryTypeDescriptor type,
              KeyCacheObject key,
              int partId,
              CacheObject val,
              GridCacheVersion ver)
                throws IgniteCheckedException

Removes index entry by key.

Parameters:
  `cacheName` - Cache name.
  `key` - Key.
  `val` - Value.
Throws:
  `IgniteCheckedException` - If failed.

#### rebuildIndexesFromHash

    void rebuildIndexesFromHash(String cacheName)
                                throws IgniteCheckedException

Rebuilds all indexes of given type from hash index.

Parameters:
  `cacheName` - Cache name.
Throws:
  `IgniteCheckedException` - If failed.

#### markForRebuildFromHash

    void markForRebuildFromHash(String cacheName)

Marks all indexes of given type for rebuild from hash index, making them unusable until rebuild finishes.

Parameters:
  `cacheName` - Cache name.

#### backupFilter

    IndexingQueryFilter backupFilter(AffinityTopologyVersion topVer,
                                   int[] parts)

Returns backup filter.

Parameters:
  `topVer` - Topology version.
  `parts` - Partitions.
Returns:
  Backup filter.

#### onDisconnected

    void onDisconnected(IgniteFuture<?> reconnectFut)

Client disconnected callback.

Parameters:
  `reconnectFut` - Reconnect future.

#### prepareNativeStatement

    PreparedStatement prepareNativeStatement(String schemaName,
                                           String sql)
                                             throws SQLException

Prepare native statement to retrieve JDBC metadata from.

Parameters:
  `schemaName` - Schema name.
  `sql` - Query.
Returns:
  `PreparedStatement` from underlying engine to supply metadata to Prepared - most likely H2.
Throws:
  `SQLException`

#### runningQueries

    Collection<GridRunningQueryInfo> runningQueries(long duration)

Collect queries that already running more than specified duration.

Parameters:
  `duration` - Duration to check.
Returns:
  Collection of long running queries.

#### cancelQueries

    void cancelQueries(Collection<Long> queries)

Cancel specified queries.

Parameters:
  `queries` - Queries ID's to cancel.

#### cancelAllQueries

    void cancelAllQueries()

Cancels all executing queries.

#### schema

    String schema(String cacheName)

Gets database schema from cache name.

Parameters:
  `cacheName` - Cache name. `null` would be converted to an empty string.
Returns:
  Schema name. Should not be null since we should not fail for an invalid cache name.

#### isInsertStatement

    boolean isInsertStatement(PreparedStatement nativeStmt)

Check if passed statement is insert statemtn.

Parameters:
  `nativeStmt` - Native statement.
Returns:
  `True` if insert.

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.2.0
Release Date | : September 15 2017