Class QueryUtils


  • public class QueryUtils
    extends Object
    Utility methods for queries.
    • 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.
      • normalizeQueryEntity

        public static QueryEntity normalizeQueryEntity​(GridKernalContext ctx,
                                                       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
                                                 @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 @Nullable String normalizeObjectName​(@Nullable
                                                           @Nullable String str,
                                                           boolean replace)
        Normalize object name.
        Parameters:
        str - String.
        replace - Whether to perform replace of special characters.
        Returns:
        Escaped string.
      • buildBinaryProperty

        public 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.
        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, true if this property is a field of the key object. Note that key not a field of itself.
        notNull - true if null value is not allowed.
        dlftVal - Default value.
        precision - Precision.
        scale - Scale.
        Returns:
        Binary property.
      • 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 @Nullable SchemaOperationException wrapIfNeeded​(@Nullable
                                                                      @Nullable Throwable e)
        Wrap schema exception if needed.
        Parameters:
        e - Original exception.
        Returns:
        Schema exception.
      • 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.
      • isCustomAffinityMapper

        public static boolean isCustomAffinityMapper​(AffinityKeyMapper affinityKeyMapper)
        Checks whether affinity key mapper is custom or default.
        Parameters:
        affinityKeyMapper - Affinity key mapper.
        Returns:
        true if affinity key mapper is custom.
      • 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.
      • wasCancelled

        public static boolean wasCancelled​(Throwable e)
        Returns true if the exception is triggered by query cancel.
        Parameters:
        e - Exception.
        Returns:
        true if exception is caused by cancel.
      • toSqlException

        @NotNull
        public static @NotNull SQLException toSqlException​(Exception e)
        Converts exception in to IgniteSqlException.
        Parameters:
        e - Exception.
        Returns:
        IgniteSqlException.
      • globalQueryId

        public static String globalQueryId​(UUID nodeId,
                                           long qryId)
        Get global query ID.
        Parameters:
        nodeId - Node ID.
        qryId - Query ID.
        Returns:
        Global query ID.
      • matches

        public static boolean matches​(String str,
                                      String sqlPtrn)
        Checks whether string matches SQL pattern.
        Parameters:
        str - String.
        sqlPtrn - Pattern.
        Returns:
        Whether string matches pattern.
      • fieldNameByAlias

        public static String fieldNameByAlias​(QueryEntity entity,
                                              String alias)
        Get field name by alias.
        Parameters:
        entity - Query entity.
        alias - Filed's alias.
        Returns:
        Field name.
      • isDdlOnSchemaSupported

        public static void isDdlOnSchemaSupported​(String schemaName)
        Check if schema supports DDL statement.
        Parameters:
        schemaName - Schema name.
      • removeFieldAndAlias

        public static boolean removeFieldAndAlias​(QueryEntity entity,
                                                  String alias)
        Remove field and corresponding alias by the alias name.
        Parameters:
        entity - Query entity.
        alias - Name of the field alias.
        Returns:
        true if the field and corresponding alias is removed. Otherwise, returns false.
      • withQueryTimeout

        public static SqlFieldsQuery withQueryTimeout​(SqlFieldsQuery qry,
                                                      int timeout,
                                                      TimeUnit timeUnit)
        Parameters:
        qry - Query.
        timeout - Timeout.
        timeUnit - Time units.
      • includeSensitive

        public static boolean includeSensitive()
        Returns:
        True if output sensitive data allowed.
      • delimeter

        public static char delimeter()
        Return space character as an SQL delimeter in case includeSensitive() is false to make output SQL one line. Default multiline SQL output looks ugly in system view and other view tool. See, GridSqlConst and IgniteH2Indexing#sqlWithoutConst() for details.
        Returns:
        Delimeter to use.
      • isConvertibleTypes

        public static boolean isConvertibleTypes​(Object val,
                                                 Class<?> expCls)