com.metamatrix.query.resolver.util
Class ResolverUtil

java.lang.Object
  extended by com.metamatrix.query.resolver.util.ResolverUtil

public class ResolverUtil
extends java.lang.Object

Utilities used during resolution


Nested Class Summary
static class ResolverUtil.ResolvedLookup
           
 
Method Summary
static TempMetadataID addTempGroup(TempMetadataAdapter metadata, GroupSymbol symbol, java.util.List symbols, boolean tempTable)
           
static void addTempTable(TempMetadataAdapter metadata, GroupSymbol symbol, java.util.List symbols)
           
static boolean canImplicitlyConvert(java.lang.String fromType, java.lang.String toType)
          Gets whether there exists an implicit conversion from the source type to the target type
static Constant convertConstant(java.lang.String sourceTypeName, java.lang.String targetTypeName, Constant constant)
           
static Expression convertExpression(Expression sourceExpression, java.lang.String targetTypeName)
          Replaces a sourceExpression with a conversion of the source expression to the target type.
static Expression convertExpression(Expression sourceExpression, java.lang.String sourceTypeName, java.lang.String targetTypeName)
          Replaces a sourceExpression with a conversion of the source expression to the target type.
static java.util.List findMatchingGroups(java.lang.String groupContext, java.util.Collection groups, QueryMetadataInterface metadata)
           
static java.util.List getAccessPatternElementsInGroups(QueryMetadataInterface metadata, java.util.Collection groups, boolean flatten)
          When access patterns are flattened, they are an approximation the user may need to enter as criteria.
static java.lang.String getCommonType(java.lang.String[] typeNames)
          Gets the most specific type to which all the given types have an implicit conversion.
static Expression getDefault(ElementSymbol symbol, QueryMetadataInterface metadata)
          Get the default value for the parameter, which could be null if the parameter is set to NULLABLE.
static boolean orderByContainsVariable(OrderBy orderBy, SingleElementSymbol ses, int position)
          Checks if a variable is in the ORDER BY
static java.util.List resolveElements(GroupSymbol group, QueryMetadataInterface metadata, java.util.List elementIDs)
           
static java.util.List<ElementSymbol> resolveElementsInGroup(GroupSymbol group, QueryMetadataInterface metadata)
          Returns the resolved elements in the given group.
static void resolveGroup(GroupSymbol symbol, QueryMetadataInterface metadata)
           
static void resolveImplicitTempGroup(TempMetadataAdapter metadata, GroupSymbol symbol, java.util.List symbols)
           
static void resolveLimit(Limit limit)
           
static ResolverUtil.ResolvedLookup resolveLookup(Function lookup, QueryMetadataInterface metadata)
           
static void resolveNullLiterals(java.util.List symbols)
          Look for a null literal in the SELECT clause and set it's type to STRING.
static void resolveOrderBy(OrderBy orderBy, java.util.List fromClauseGroups, java.util.List knownElements, QueryMetadataInterface metadata, boolean isSimpleQuery)
          Attempt to resolve the order by throws QueryResolverException if the symbol is not of SingleElementSymbol type
static void setDesiredType(Expression expression, java.lang.Class<?> targetType, LanguageObject surroundingExpression)
          Utility to set the type of an expression if it is a Reference and has a null type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCommonType

public static java.lang.String getCommonType(java.lang.String[] typeNames)
Gets the most specific type to which all the given types have an implicit conversion. The method decides a common type as follows:

Parameters:
typeNames - an ordered array of unique type names.
Returns:
a type name to which all the given types can be converted

canImplicitlyConvert

public static boolean canImplicitlyConvert(java.lang.String fromType,
                                           java.lang.String toType)
Gets whether there exists an implicit conversion from the source type to the target type

Parameters:
fromType -
toType -
Returns:
true if there exists an implicit conversion from the fromType to the toType.

convertExpression

public static Expression convertExpression(Expression sourceExpression,
                                           java.lang.String targetTypeName)
                                    throws QueryResolverException
Replaces a sourceExpression with a conversion of the source expression to the target type. If the source type and target type are the same, this method does nothing.

Parameters:
sourceExpression -
targetTypeName -
Returns:
Throws:
QueryResolverException

convertExpression

public static Expression convertExpression(Expression sourceExpression,
                                           java.lang.String sourceTypeName,
                                           java.lang.String targetTypeName)
                                    throws QueryResolverException
Replaces a sourceExpression with a conversion of the source expression to the target type. If the source type and target type are the same, this method does nothing.

Parameters:
sourceExpression -
sourceTypeName -
targetTypeName -
Returns:
Throws:
QueryResolverException

convertConstant

public static Constant convertConstant(java.lang.String sourceTypeName,
                                       java.lang.String targetTypeName,
                                       Constant constant)

setDesiredType

public static void setDesiredType(Expression expression,
                                  java.lang.Class<?> targetType,
                                  LanguageObject surroundingExpression)
                           throws QueryResolverException
Utility to set the type of an expression if it is a Reference and has a null type.

Parameters:
expression - the expression to test
targetType - the target type, if the expression's type is null.
Throws:
QueryResolverException - if unable to set the reference type to the target type.

resolveOrderBy

public static void resolveOrderBy(OrderBy orderBy,
                                  java.util.List fromClauseGroups,
                                  java.util.List knownElements,
                                  QueryMetadataInterface metadata,
                                  boolean isSimpleQuery)
                           throws QueryResolverException,
                                  QueryMetadataException,
                                  MetaMatrixComponentException
Attempt to resolve the order by throws QueryResolverException if the symbol is not of SingleElementSymbol type

Parameters:
orderBy -
fromClauseGroups - groups of the FROM clause of the query (for resolving ambiguous unqualified element names), or empty List if a Set Query Order By is being resolved
knownElements - resolved elements from SELECT clause, which are only ones allowed to be in ORDER BY
metadata - QueryMetadataInterface
isSimpleQuery -
Throws:
QueryResolverException
QueryMetadataException
MetaMatrixComponentException

getDefault

public static Expression getDefault(ElementSymbol symbol,
                                    QueryMetadataInterface metadata)
                             throws MetaMatrixComponentException,
                                    QueryMetadataException,
                                    QueryResolverException
Get the default value for the parameter, which could be null if the parameter is set to NULLABLE. If no default is available, a QueryResolverException will be thrown.

Parameters:
symbol - ElementSymbol retrieved from metadata, fully-resolved
metadata - QueryMetadataInterface
Returns:
expr param (if it is non-null) or default value (if there is one) or null Constant (if parameter is optional and therefore allows this)
Throws:
QueryResolverException - if expr is null, parameter is required and no default value is defined
QueryMetadataException - for error retrieving metadata
MetaMatrixComponentException
Since:
4.3

resolveElementsInGroup

public static java.util.List<ElementSymbol> resolveElementsInGroup(GroupSymbol group,
                                                                   QueryMetadataInterface metadata)
                                                            throws QueryMetadataException,
                                                                   MetaMatrixComponentException
Returns the resolved elements in the given group. This method has the side effect of caching the resolved elements on the group object. The resolved elements may not contain non-selectable columns depending on the metadata first used for resolving.

Throws:
QueryMetadataException
MetaMatrixComponentException

resolveElements

public static java.util.List resolveElements(GroupSymbol group,
                                             QueryMetadataInterface metadata,
                                             java.util.List elementIDs)
                                      throws MetaMatrixComponentException,
                                             QueryMetadataException
Throws:
MetaMatrixComponentException
QueryMetadataException

getAccessPatternElementsInGroups

public static java.util.List getAccessPatternElementsInGroups(QueryMetadataInterface metadata,
                                                              java.util.Collection groups,
                                                              boolean flatten)
                                                       throws MetaMatrixComponentException,
                                                              QueryMetadataException
When access patterns are flattened, they are an approximation the user may need to enter as criteria.

Parameters:
metadata -
groups -
flatten -
Returns:
Throws:
MetaMatrixComponentException
QueryMetadataException

resolveLimit

public static void resolveLimit(Limit limit)
                         throws QueryResolverException
Throws:
QueryResolverException

resolveImplicitTempGroup

public static void resolveImplicitTempGroup(TempMetadataAdapter metadata,
                                            GroupSymbol symbol,
                                            java.util.List symbols)
                                     throws MetaMatrixComponentException,
                                            QueryResolverException
Throws:
MetaMatrixComponentException
QueryResolverException

addTempGroup

public static TempMetadataID addTempGroup(TempMetadataAdapter metadata,
                                          GroupSymbol symbol,
                                          java.util.List symbols,
                                          boolean tempTable)
                                   throws QueryResolverException
Throws:
QueryResolverException

addTempTable

public static void addTempTable(TempMetadataAdapter metadata,
                                GroupSymbol symbol,
                                java.util.List symbols)
                         throws QueryResolverException
Throws:
QueryResolverException

resolveNullLiterals

public static void resolveNullLiterals(java.util.List symbols)
Look for a null literal in the SELECT clause and set it's type to STRING. This ensures that the result set metadata retrieved for this query will be properly set to something other than the internal NullType. Added for defect 15437.

Parameters:
select - The select clause
Since:
4.2

findMatchingGroups

public static java.util.List findMatchingGroups(java.lang.String groupContext,
                                                java.util.Collection groups,
                                                QueryMetadataInterface metadata)
                                         throws MetaMatrixComponentException,
                                                QueryMetadataException
Parameters:
groupContext -
groups -
metadata -
Returns:
the List of groups that match the given groupContext out of the supplied collection
Throws:
MetaMatrixComponentException
QueryMetadataException

orderByContainsVariable

public static boolean orderByContainsVariable(OrderBy orderBy,
                                              SingleElementSymbol ses,
                                              int position)
Checks if a variable is in the ORDER BY

Parameters:
position - 0-based index of the variable
Returns:
True if the ORDER BY contains the element

resolveLookup

public static ResolverUtil.ResolvedLookup resolveLookup(Function lookup,
                                                        QueryMetadataInterface metadata)
                                                 throws QueryResolverException,
                                                        MetaMatrixComponentException
Throws:
QueryResolverException
MetaMatrixComponentException

resolveGroup

public static void resolveGroup(GroupSymbol symbol,
                                QueryMetadataInterface metadata)
                         throws MetaMatrixComponentException,
                                QueryResolverException
Throws:
MetaMatrixComponentException
QueryResolverException


Copyright © 2009. All Rights Reserved.