org.apache.ignite.internal.processors.query

## Class QueryUtils

- java.lang.Object
- - org.apache.ignite.internal.processors.query.QueryUtils

    public class QueryUtils
    extends Object

Utility methods for queries.

### Nested Class Summary

Nested Classes
`static class` `QueryUtils.KeyOrValProperty` Property used for keyFieldName or valueFieldName

### Field Summary

Fields
`static String` `DFLT_SCHEMA` Default schema.
`static String` `KEY_FIELD_NAME` Field name for key.
`static String` `SCHEMA_SYS` Schema for system view.
`static String` `TEMPLATE_PARTITIONED` Well-known template name for PARTITIONED cache.
`static String` `TEMPLATE_REPLICATED` Well-known template name for REPLICATED cache.
`static String` `VAL_FIELD_NAME` Field name for value.
`static String` `VER_FIELD_NAME` Version field name.

### Method Summary

All Methods Static Methods Concrete Methods
`static QueryBinaryProperty` `buildBinaryProperty(GridKernalContext ctx, String pathStr, Class<?> resType, Map<String,String> aliases, Boolean isKeyField, boolean notNull, Object dlftVal, int precision, int scale)` Builds binary object property.
`static QueryClassProperty` `buildClassProperty(boolean key, Class<?> cls, String pathStr, Class<?> resType, Map<String,String> aliases, boolean notNull, CacheObjectContext coCtx)`
`static QueryClassProperty` `buildClassProperty(Class<?> keyCls, Class<?> valCls, String pathStr, Class<?> resType, Map<String,String> aliases, boolean notNull, CacheObjectContext coCtx)`
`static GridQueryProperty` `buildProperty(Class<?> keyCls, Class<?> valCls, String keyFieldName, String valueFieldName, String pathStr, Class<?> resType, Map<String,String> aliases, boolean notNull, CacheObjectContext coCtx)`
`static void` `checkNotNullAllowed(CacheConfiguration cfg)` Performs checks to forbid cache configurations that are not compatible with NOT NULL query fields.
`static SchemaOperationException` `checkQueryEntityConflicts(CacheConfiguration<?,?> ccfg, Collection<DynamicCacheDescriptor> descs)` Check given `CacheConfiguration` for conflicts in table and index names from any query entities found in collection of `DynamicCacheDescriptor`s and belonging to the same schema.
`static QueryEntity` `copy(QueryEntity entity)` Copy query entity.
`static QueryIndexDescriptorImpl` `createIndexDescriptor(QueryTypeDescriptorImpl typeDesc, QueryIndex idx)` Create index descriptor.
`static String` `createTableCacheName(String schemaName, String tblName)` Construct cache name for table.
`static String` `createTableKeyTypeName(String valTypeName)` Construct key type name for table.
`static String` `createTableValueTypeName(String schemaName, String tblName)` Construct value type name for table.
`static int` `discoveryHistorySize()` Discovery history size.
`static String` `indexName(QueryEntity entity, QueryIndex idx)` Get index name.
`static String` `indexName(String tblName, QueryIndex idx)` Get index name.
`static boolean` `isEnabled(CacheConfiguration<?,?> ccfg)`
`static boolean` `isGeometryClass(Class<?> cls)` Checks if the given class is GEOMETRY.
`static boolean` `isSqlType(Class<?> cls)` Checks if the given class can be mapped to a simple SQL type.
`static String` `normalizeObjectName(String str, boolean replace)` Normalize object name.
`static Collection<QueryEntity>` `normalizeQueryEntities(Collection<QueryEntity> entities, CacheConfiguration<?,?> cfg)` Normalize cache query entities.
`static QueryEntity` `normalizeQueryEntity(QueryEntity entity, boolean escape)` Normalize query entity.
`static String` `normalizeSchemaName(String cacheName, String schemaName)` Stores rule for constructing schemaName according to cache configuration.
`static void` `processBinaryMeta(GridKernalContext ctx, QueryEntity qryEntity, QueryTypeDescriptorImpl d)` Processes declarative metadata for binary object.
`static void` `processClassMeta(QueryEntity qryEntity, QueryTypeDescriptorImpl d, CacheObjectContext coCtx)` Processes declarative metadata for binary object.
`static void` `processDynamicIndexChange(String idxName, QueryIndex idx, QueryTypeDescriptorImpl d)` Process dynamic index change.
`static String` `propertyInitializationExceptionMessage(Class<?> keyCls, Class<?> valCls, String pathStr, Class<?> resType)` Exception message to compare in tests.
`static String` `tableName(QueryEntity entity)` Get table name for entity.
`static QueryTypeCandidate` `typeForQueryEntity(String cacheName, String schemaName, GridCacheContext cctx, QueryEntity qryEntity, List<Class<?>> mustDeserializeClss, boolean escape)` Create type candidate for query entity.
`static String` `typeName(Class<?> cls)` Gets type name by class.
`static String` `typeName(String clsName)` Gets type name by class.
`static SchemaOperationException` `validateDropColumn(GridQueryTypeDescriptor type, String colName)` Checks if given column can be removed from the table using its `GridQueryTypeDescriptor`.
`static SchemaOperationException` `validateDropColumn(QueryEntity entity, String fieldName, String colName)` Checks if given column can be removed from table using its `QueryEntity`.
`static int` `validateTimeout(int timeout, TimeUnit timeUnit)`
`static SchemaOperationException` `wrapIfNeeded(Exception e)` Wrap schema exception if needed.

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

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

### Field Detail

#### DFLT_SCHEMA

    public static final String DFLT_SCHEMA

Default schema.

See Also:
  Constant Field Values

#### SCHEMA_SYS

    public static final String SCHEMA_SYS

Schema for system view.

See Also:
  Constant Field Values

#### KEY_FIELD_NAME

    public static final String KEY_FIELD_NAME

Field name for key.

See Also:
  Constant Field Values

#### VAL_FIELD_NAME

    public static final String VAL_FIELD_NAME

Field name for value.

See Also:
  Constant Field Values

#### VER_FIELD_NAME

    public static final String VER_FIELD_NAME

Version field name.

See Also:
  Constant Field Values

#### TEMPLATE_PARTITIONED

    public static final String TEMPLATE_PARTITIONED

Well-known template name for PARTITIONED cache.

See Also:
  Constant Field Values

#### TEMPLATE_REPLICATED

    public static final String TEMPLATE_REPLICATED

Well-known template name for REPLICATED cache.

See Also:
  Constant Field Values

### Method Detail

#### tableName

    public static String tableName(QueryEntity entity)

Get table name for entity.

Parameters:
  `entity` - Entity.
Returns:
  Table name.

#### indexName

    public static String indexName(QueryEntity entity,
                                   QueryIndex idx)

Get index name.

Parameters:
  `entity` - Query entity.
  `idx` - Index.
Returns:
  Index name.

#### indexName

    public static String indexName(String tblName,
                                   QueryIndex idx)

Get index name.

Parameters:
  `tblName` - Table name.
  `idx` - Index.
Returns:
  Index name.

#### normalizeQueryEntities

    public static Collection<QueryEntity> normalizeQueryEntities(Collection<QueryEntity> entities,
                                                                 CacheConfiguration<?,?> cfg)

Normalize cache query entities.

Parameters:
  `entities` - Query entities.
  `cfg` - Cache config.
Returns:
  Normalized query entities.

#### normalizeQueryEntity

    public static QueryEntity normalizeQueryEntity(QueryEntity entity,
                                                   boolean escape)

Normalize query entity. If "escape" flag is set, nothing changes. Otherwise we convert all object names to upper case and replace inner class separator characters ('$' for Java and '.' for .NET) with underscore.

Parameters:
  `entity` - Query entity.
  `escape` - Escape flag taken form configuration.
Returns:
  Normalized query entity.

#### normalizeSchemaName

    public static String normalizeSchemaName(String cacheName,
                                             @Nullable
                                             String schemaName)

Stores rule for constructing schemaName according to cache configuration.

Parameters:
  `cacheName` - Cache name.
  `schemaName` - Schema name.
Returns:
  Proper schema name according to ANSI-99 standard.

#### normalizeObjectName

    @Nullable
    public static String normalizeObjectName(@Nullable
                                                       String str,
                                                       boolean replace)

Normalize object name.

Parameters:
  `str` - String.
  `replace` - Whether to perform replace of special characters.
Returns:
  Escaped string.

#### typeForQueryEntity

    public static QueryTypeCandidate typeForQueryEntity(String cacheName,
                                                        String schemaName,
                                                        GridCacheContext cctx,
                                                        QueryEntity qryEntity,
                                                        List<Class<?>> mustDeserializeClss,
                                                        boolean escape)
                                                 throws IgniteCheckedException

Create type candidate for query entity.

Parameters:
  `cacheName` - Cache name.
  `schemaName` - Schema name.
  `cctx` - Cache context.
  `qryEntity` - Query entity.
  `mustDeserializeClss` - Classes which must be deserialized.
  `escape` - Escape flag.
Returns:
  Type candidate.
Throws:
  `IgniteCheckedException` - If failed.

#### processBinaryMeta

    public static void processBinaryMeta(GridKernalContext ctx,
                                         QueryEntity qryEntity,
                                         QueryTypeDescriptorImpl d)
                                  throws IgniteCheckedException

Processes declarative metadata for binary object.

Parameters:
  `ctx` - Kernal context.
  `qryEntity` - Declared metadata.
  `d` - Type descriptor.
Throws:
  `IgniteCheckedException` - If failed.

#### processClassMeta

    public static void processClassMeta(QueryEntity qryEntity,
                                        QueryTypeDescriptorImpl d,
                                        CacheObjectContext coCtx)
                                 throws IgniteCheckedException

Processes declarative metadata for binary object.

Parameters:
  `qryEntity` - Declared metadata.
  `d` - Type descriptor.
Throws:
  `IgniteCheckedException` - If failed.

#### processDynamicIndexChange

    public static void processDynamicIndexChange(String idxName,
                                                 @Nullable
                                                 QueryIndex idx,
                                                 QueryTypeDescriptorImpl d)
                                          throws IgniteCheckedException

Process dynamic index change.

Parameters:
  `idx` - Index.
  `d` - Type descriptor to populate.
Throws:
  `IgniteCheckedException` - If failed to build index information.

#### createIndexDescriptor

    public static QueryIndexDescriptorImpl createIndexDescriptor(QueryTypeDescriptorImpl typeDesc,
                                                                 QueryIndex idx)
                                                          throws IgniteCheckedException

Create index descriptor.

Parameters:
  `typeDesc` - Type descriptor.
  `idx` - Index.
Returns:
  Index descriptor.
Throws:
  `IgniteCheckedException` - If failed.

#### buildBinaryProperty

    public static QueryBinaryProperty buildBinaryProperty(GridKernalContext ctx,
                                                          String pathStr,
                                                          Class<?> resType,
                                                          Map<String,String> aliases,
                                                          @Nullable
                                                          Boolean isKeyField,
                                                          boolean notNull,
                                                          Object dlftVal,
                                                          int precision,
                                                          int scale)

Builds binary object property.

Parameters:
  `ctx` - Kernal context.
  `pathStr` - String representing path to the property. May contains dots '.' to identify nested fields.
  `resType` - Result type.
  `aliases` - Aliases.
  `isKeyField` - Key ownership flag, as defined in `QueryEntity.keyFields`: `true` if field belongs to key, `false` if it belongs to value, `null` if QueryEntity#keyFields is null.
  `notNull` - `true` if `null` value is not allowed.
  `dlftVal` - Default value.
  `precision` - Precision.
  `scale` - Scale.
Returns:
  Binary property.

#### buildClassProperty

    public static QueryClassProperty buildClassProperty(Class<?> keyCls,
                                                        Class<?> valCls,
                                                        String pathStr,
                                                        Class<?> resType,
                                                        Map<String,String> aliases,
                                                        boolean notNull,
                                                        CacheObjectContext coCtx)
                                                 throws IgniteCheckedException

Parameters:
  `keyCls` - Key class.
  `valCls` - Value class.
  `pathStr` - Path string.
  `resType` - Result type.
  `aliases` - Aliases.
  `notNull` - `true` if `null` value is not allowed.
  `coCtx` - Cache object context.
Returns:
  Class property.
Throws:
  `IgniteCheckedException` - If failed.

#### buildProperty

    public static GridQueryProperty buildProperty(Class<?> keyCls,
                                                  Class<?> valCls,
                                                  String keyFieldName,
                                                  String valueFieldName,
                                                  String pathStr,
                                                  Class<?> resType,
                                                  Map<String,String> aliases,
                                                  boolean notNull,
                                                  CacheObjectContext coCtx)
                                           throws IgniteCheckedException

Parameters:
  `keyCls` - Key class.
  `valCls` - Value class.
  `keyFieldName` - Key Field.
  `valueFieldName` - Value Field.
  `pathStr` - Path string.
  `resType` - Result type.
  `aliases` - Aliases.
  `notNull` - `true` if `null` value is not allowed.
  `coCtx` - Cache object context.
Returns:
  Class property.
Throws:
  `IgniteCheckedException` - If failed.

#### propertyInitializationExceptionMessage

    public static String propertyInitializationExceptionMessage(Class<?> keyCls,
                                                                Class<?> valCls,
                                                                String pathStr,
                                                                Class<?> resType)

Exception message to compare in tests.

Parameters:
  `keyCls` - key class
  `valCls` - value class
  `pathStr` - property name
  `resType` - property type
Returns:
  Exception message.

#### buildClassProperty

    public static QueryClassProperty buildClassProperty(boolean key,
                                                        Class<?> cls,
                                                        String pathStr,
                                                        Class<?> resType,
                                                        Map<String,String> aliases,
                                                        boolean notNull,
                                                        CacheObjectContext coCtx)

Parameters:
  `key` - If this is a key property.
  `cls` - Source type class.
  `pathStr` - String representing path to the property. May contains dots '.' to identify nested fields.
  `resType` - Expected result type.
  `aliases` - Aliases.
  `notNull` - `true` if `null` value is not allowed.
  `coCtx` - Cache object context.
Returns:
  Property instance corresponding to the given path.

#### isSqlType

    public static boolean isSqlType(Class<?> cls)

Checks if the given class can be mapped to a simple SQL type.

Parameters:
  `cls` - Class.
Returns:
  `true` If can.

#### isGeometryClass

    public static boolean isGeometryClass(Class<?> cls)

Checks if the given class is GEOMETRY.

Parameters:
  `cls` - Class.
Returns:
  `true` If this is geometry.

#### typeName

    public static String typeName(String clsName)

Gets type name by class.

Parameters:
  `clsName` - Class name.
Returns:
  Type name.

#### typeName

    public static String typeName(Class<?> cls)

Gets type name by class.

Parameters:
  `cls` - Class.
Returns:
  Type name.

#### validateTimeout

    public static int validateTimeout(int timeout,
                                      TimeUnit timeUnit)

Parameters:
  `timeout` - Timeout.
  `timeUnit` - Time unit.
Returns:
  Converted time.

#### isEnabled

    public static boolean isEnabled(CacheConfiguration<?,?> ccfg)

Parameters:
  `ccfg` - Cache configuration.
Returns:
  `true` If query index must be enabled for this cache.

#### discoveryHistorySize

    public static int discoveryHistorySize()

Discovery history size.

Returns:
  Discovery history size.

#### wrapIfNeeded

    @Nullable
    public static SchemaOperationException wrapIfNeeded(@Nullable
                                                                  Exception e)

Wrap schema exception if needed.

Parameters:
  `e` - Original exception.
Returns:
  Schema exception.

#### checkQueryEntityConflicts

    public static SchemaOperationException checkQueryEntityConflicts(CacheConfiguration<?,?> ccfg,
                                                                     Collection<DynamicCacheDescriptor> descs)

Check given `CacheConfiguration` for conflicts in table and index names from any query entities found in collection of `DynamicCacheDescriptor`s and belonging to the same schema.

Parameters:
  `ccfg` - New cache configuration.
  `descs` - Cache descriptors.
Returns:
  Exception message describing found conflict or `null` if none found.

#### createTableCacheName

    public static String createTableCacheName(String schemaName,
                                              String tblName)

Construct cache name for table.

Parameters:
  `schemaName` - Schema name.
  `tblName` - Table name.
Returns:
  Cache name.

#### createTableValueTypeName

    public static String createTableValueTypeName(String schemaName,
                                                  String tblName)

Construct value type name for table.

Parameters:
  `schemaName` - Schema name.
  `tblName` - Table name.
Returns:
  Value type name.

#### createTableKeyTypeName

    public static String createTableKeyTypeName(String valTypeName)

Construct key type name for table.

Parameters:
  `valTypeName` - Value type name.
Returns:
  Key type name.

#### copy

    public static QueryEntity copy(QueryEntity entity)

Copy query entity.

Parameters:
  `entity` - Query entity.
Returns:
  Copied entity.

#### checkNotNullAllowed

    public static void checkNotNullAllowed(CacheConfiguration cfg)

Performs checks to forbid cache configurations that are not compatible with NOT NULL query fields. See `QueryEntity.setNotNullFields(Set)`.

Parameters:
  `cfg` - Cache configuration.

#### validateDropColumn

    public static SchemaOperationException validateDropColumn(QueryEntity entity,
                                                              String fieldName,
                                                              String colName)

Checks if given column can be removed from table using its `QueryEntity`.

Parameters:
  `entity` - Query entity.
  `fieldName` - Name of the field of the key or value object.
  `colName` - Name of the column.
Returns:
  `null` if it's OK to remove the column and exception otherwise.

#### validateDropColumn

    public static SchemaOperationException validateDropColumn(GridQueryTypeDescriptor type,
                                                              String colName)

Checks if given column can be removed from the table using its `GridQueryTypeDescriptor`.

Parameters:
  `type` - Type descriptor.
  `colName` - Name of the column.
Returns:
  `null` if it's OK to remove the column and exception otherwise.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.7.6
Release Date | : September 11 2019