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.
`IgniteDataStreamer<?,?>` `createStreamer(String spaceName, PreparedStatement nativeStmt, long autoFlushFreq, int nodeBufSize, int nodeParOps, boolean allowOverwrite)`
`void` `dynamicIndexCreate(String spaceName, String tblName, QueryIndexDescriptorImpl idxDesc, boolean ifNotExists, SchemaIndexCacheVisitor cacheVisitor)` Create new index locally.
`void` `dynamicIndexDrop(String spaceName, String idxName, boolean ifExists)` Remove index from the space.
`void` `markForRebuildFromHash(String spaceName, GridQueryTypeDescriptor type)` 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 space, String sql)` Prepare native statement to retrieve JDBC metadata from.
`<K,V> QueryCursor<javax.cache.Cache.Entry<K,V>>` `queryLocalSql(GridCacheContext<?,?> cctx, SqlQuery qry, IndexingQueryFilter filter, boolean keepBinary)` Executes regular query.
`<K,V> QueryCursor<List<?>>` `queryLocalSqlFields(GridCacheContext<?,?> cctx, SqlFieldsQuery qry, IndexingQueryFilter filter, GridQueryCancel cancel)` Queries individual fields (generally used by JDBC drivers).
`<K,V> GridCloseableIterator<IgniteBiTuple<K,V>>` `queryLocalText(String spaceName, String qry, String typeName, IndexingQueryFilter filter)` Executes text query.
`QueryCursor<List<?>>` `queryTwoStep(GridCacheContext<?,?> cctx, SqlFieldsQuery qry, GridQueryCancel cancel)` Parses SQL query into two step query and executes it.
`<K,V> QueryCursor<javax.cache.Cache.Entry<K,V>>` `queryTwoStep(GridCacheContext<?,?> cctx, SqlQuery qry)` Parses SQL query into two step query and executes it.
`void` `rebuildIndexesFromHash(String spaceName, GridQueryTypeDescriptor type)` Rebuilds all indexes of given type from hash index.
`void` `registerCache(String spaceName, GridCacheContext<?,?> cctx, CacheConfiguration<?,?> ccfg)` Registers cache.
`boolean` `registerType(String spaceName, GridQueryTypeDescriptor desc)` Registers type if it was not known before or updates it otherwise.
`void` `remove(String spaceName, 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` `space(String schemaName)` Gets space name from database schema.
`void` `start(GridKernalContext ctx, GridSpinBusyLock busyLock)` Starts indexing.
`void` `stop()` Stops indexing.
`void` `store(String spaceName, String typeName, KeyCacheObject key, int partId, CacheObject val, GridCacheVersion ver, long expirationTime, long link)` Updates index.
`long` `streamUpdateQuery(String spaceName, String qry, Object[] params, IgniteDataStreamer<?,?> streamer)` Perform a MERGE statement using data streamer as receiver.
`void` `unregisterCache(String spaceName)` Unregisters cache.
`void` `unregisterType(String spaceName, String typeName)` Unregisters type and removes all corresponding data.

### 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.

#### queryTwoStep

    QueryCursor<List<?>> queryTwoStep(GridCacheContext<?,?> cctx,
                                    SqlFieldsQuery qry,
                                    GridQueryCancel cancel)
                                      throws IgniteCheckedException

Parses SQL query into two step query and executes it.

Parameters:
  `cctx` - Cache context.
  `qry` - Query.
  `cancel` - Query cancel.
Returns:
  Cursor.
Throws:
  `IgniteCheckedException` - If failed.

#### queryTwoStep

    <K,V> QueryCursor<javax.cache.Cache.Entry<K,V>> queryTwoStep(GridCacheContext<?,?> cctx,
                                                               SqlQuery qry)
                                                           throws IgniteCheckedException

Parses SQL query into two step query and executes it.

Parameters:
  `cctx` - Cache context.
  `qry` - Query.
Returns:
  Cursor.
Throws:
  `IgniteCheckedException` - If failed.

#### queryLocalSqlFields

    <K,V> QueryCursor<List<?>> queryLocalSqlFields(GridCacheContext<?,?> cctx,
                                                 SqlFieldsQuery qry,
                                                 IndexingQueryFilter filter,
                                                 GridQueryCancel cancel)
                                             throws IgniteCheckedException

Queries individual fields (generally used by JDBC drivers).

Parameters:
  `cctx` - Cache context.
  `qry` - Query.
  `filter` - Space name and key filter.
  `cancel` - Query cancel.
Returns:
  Cursor.
Throws:
  `IgniteCheckedException`

#### streamUpdateQuery

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

Perform a MERGE statement using data streamer as receiver.

Parameters:
  `spaceName` - Space 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(GridCacheContext<?,?> cctx,
                                                                SqlQuery qry,
                                                                IndexingQueryFilter filter,
                                                                boolean keepBinary)
                                                            throws IgniteCheckedException

Executes regular query.

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

#### queryLocalText

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

Executes text query.

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

#### dynamicIndexCreate

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

Create new index locally.

Parameters:
  `spaceName` - Space 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 spaceName,
                        String idxName,
                        boolean ifExists)
                          throws IgniteCheckedException

Remove index from the space.

Parameters:
  `spaceName` - Space 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 spaceName,
                     GridCacheContext<?,?> cctx,
                     CacheConfiguration<?,?> ccfg)
                       throws IgniteCheckedException

Registers cache.

Parameters:
  `spaceName` - Space name.
  `cctx` - Cache context.
  `ccfg` - Cache configuration.
Throws:
  `IgniteCheckedException` - If failed.

#### unregisterCache

    void unregisterCache(String spaceName)
                         throws IgniteCheckedException

Unregisters cache.

Parameters:
  `spaceName` - Space name.
Throws:
  `IgniteCheckedException` - If failed to drop cache schema.

#### registerType

    boolean registerType(String spaceName,
                       GridQueryTypeDescriptor desc)
                         throws IgniteCheckedException

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

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

#### unregisterType

    void unregisterType(String spaceName,
                      String typeName)
                        throws IgniteCheckedException

Unregisters type and removes all corresponding data.

Parameters:
  `spaceName` - Space name.
  `typeName` - Type name.
Throws:
  `IgniteCheckedException` - If failed.

#### store

    void store(String spaceName,
             String typeName,
             KeyCacheObject key,
             int partId,
             CacheObject val,
             GridCacheVersion ver,
             long expirationTime,
             long link)
               throws IgniteCheckedException

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

Parameters:
  `spaceName` - Space name.
  `typeName` - Type name.
  `key` - Key.
  `val` - Value.
  `ver` - Version.
  `expirationTime` - Expiration time or 0 if never expires.
Throws:
  `IgniteCheckedException` - If failed.

#### remove

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

Removes index entry by key.

Parameters:
  `spaceName` - Space name.
  `key` - Key.
  `val` - Value.
Throws:
  `IgniteCheckedException` - If failed.

#### rebuildIndexesFromHash

    void rebuildIndexesFromHash(String spaceName,
                              GridQueryTypeDescriptor type)
                                throws IgniteCheckedException

Rebuilds all indexes of given type from hash index.

Parameters:
  `spaceName` - Space name.
  `type` - Type descriptor.
Throws:
  `IgniteCheckedException` - If failed.

#### markForRebuildFromHash

    void markForRebuildFromHash(String spaceName,
                              GridQueryTypeDescriptor type)

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

Parameters:
  `spaceName` - Space name.
  `type` - Type descriptor.

#### 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 space,
                                           String sql)
                                             throws SQLException

Prepare native statement to retrieve JDBC metadata from.

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

#### space

    String space(String schemaName)

Gets space name from database schema.

Parameters:
  `schemaName` - Schema name. Could not be null. Could be empty.
Returns:
  Space name. Could be null.

#### 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.

#### createStreamer

    IgniteDataStreamer<?,?> createStreamer(String spaceName,
                                         PreparedStatement nativeStmt,
                                         long autoFlushFreq,
                                         int nodeBufSize,
                                         int nodeParOps,
                                         boolean allowOverwrite)

Parameters:
  `spaceName` - Space name.
  `nativeStmt` - Native statement.
  `autoFlushFreq` - Automatic data flushing frequency, disabled if `0`.
  `nodeBufSize` - Per node buffer size - see `IgniteDataStreamer.perNodeBufferSize(int)`
  `nodeParOps` - Per node parallel ops count - see `IgniteDataStreamer.perNodeParallelOperations(int)`
  `allowOverwrite` - Overwrite existing cache values on key duplication.
Returns:
  `IgniteDataStreamer` tailored to specific needs of given native statement based on its metadata; `null` if given statement is a query.

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.0.0
Release Date | : April 30 2017