com.endeca.portal.lql
Class LQLUtils

java.lang.Object
  extended by com.endeca.portal.lql.LQLUtils

public class LQLUtils
extends java.lang.Object

A collection of utilities for use when working with LQL ASTs, expressions, fragments, statements, etc.

Author:
Endeca Technologies, Inc.

Constructor Summary
LQLUtils()
           
 
Method Summary
static void addAliases(java.util.Set<java.lang.String> aliases, com.endeca.mdex.eql_parser.types.SourceBase source)
           
static void addNullGroupFilterToStatement(SemanticView view, com.endeca.mdex.eql_parser.types.Statement statement)
          Utility method to filter out NULL groups from a RETURN statement.
static void addNullGroupFilterToStatement(com.endeca.mdex.eql_parser.types.Statement statement)
          Deprecated. Use addNullGroupFilterToStatement(SemanticView, Statement) instead
static java.lang.String expressionToFilterString(com.endeca.mdex.eql_parser.types.ExpressionBase expr)
          Converts the supplied ExpressionBase into a String suitable for serialization, such as persistence into a portlet's preferences.
static void filterOutNullGroups(com.endeca.mdex.eql_parser.types.Query query)
          Deprecated. Use filterOutNullGroups(SemanticView, Query) instead
static void filterOutNullGroups(SemanticView view, com.endeca.mdex.eql_parser.types.Query query)
          Utility method to filter out NULL groups from the RETURN statement of a query.
static com.endeca.mdex.eql_parser.types.ExpressionBase filterStringToExpression(java.lang.String str)
          Converts a previously serialized JAXB XML representation of an LQL expression back into a Java ExpressionBase object suitable for use in runtime queries.
static java.lang.String getAttributeKey(com.endeca.mdex.eql_parser.types.GroupingKeyBase groupBy)
           
static java.util.List<java.lang.String> getAttributeKeys(java.util.Collection<com.endeca.mdex.eql_parser.types.GroupingKeyBase> groupBys)
          Utility method to get a list of attribute keys from a list of GroupingKeyBase objects
static java.util.Set<java.lang.String> getStatementAliases(com.endeca.mdex.eql_parser.types.Statement statement)
           
static java.util.Set<java.lang.String> getStatementKeys(com.endeca.mdex.eql_parser.types.Query query)
           
static boolean hasGroupingSetsFunctions(com.endeca.mdex.eql_parser.types.FunctionCallExpression fce)
           
static boolean hasGroupingSetsFunctions(com.endeca.mdex.eql_parser.types.Query query)
          Utility method to identify queries that use grouping sets functions.
static boolean hasGroupingSetsFunctions(com.endeca.mdex.eql_parser.types.Statement statement)
           
static boolean hasGroupingSetsGroupBy(com.endeca.mdex.eql_parser.types.Query query)
          Utility method to identify queries which use a grouping sets with a size > 1
static boolean hasGroupingSetsGroupBy(com.endeca.mdex.eql_parser.types.Statement statement)
           
static com.endeca.mdex.eql_parser.types.ExpressionBase parseExpression(DataSource ds, java.lang.String expression)
          Parses an expression using the LQL Parsing service This involves a round trip and should be used only if absolutely necessary.
static void prefixDefineKeys(com.endeca.mdex.eql_parser.types.Query query, java.lang.String prefix)
          Prefixes all statement keys.
static void prefixExpression(com.endeca.mdex.eql_parser.types.ExpressionBase expression, java.lang.String prefix, java.util.Set<java.lang.String> statementKeys, java.util.Set<java.lang.String> aliases)
          Prefixes statement keys depending on the type of expression.
static void prefixSource(com.endeca.mdex.eql_parser.types.SourceBase source, java.lang.String prefix, java.util.Set<java.lang.String> statementKeys, java.util.Set<java.lang.String> aliases)
          Prefixes statement keys depending on the type of source.
static java.lang.String queryToString(com.endeca.mdex.eql_parser.types.Query query)
          Converts the supplied Query into a String suitable for serialization, such as persistence into a portlet's preferences.
static com.endeca.mdex.eql_parser.types.Query stringToQuery(java.lang.String str)
          Converts a previously serialized JAXB XML representation of an LQL Query back into a Java Query object suitable for use at runtime.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LQLUtils

public LQLUtils()
Method Detail

parseExpression

public static com.endeca.mdex.eql_parser.types.ExpressionBase parseExpression(DataSource ds,
                                                                              java.lang.String expression)
                                                                       throws DataSourceException,
                                                                              LQLException
Parses an expression using the LQL Parsing service This involves a round trip and should be used only if absolutely necessary.

Parameters:
ds - a DataSource
expression - an expression to be parsed
Returns:
An ExpressionBase object representing the parsed expression
Throws:
DataSourceException
LQLException

expressionToFilterString

public static java.lang.String expressionToFilterString(com.endeca.mdex.eql_parser.types.ExpressionBase expr)
                                                 throws LQLException
Converts the supplied ExpressionBase into a String suitable for serialization, such as persistence into a portlet's preferences. The returned String is a JAXB XML representation of the expression wrapped in a StandaloneFilter. The wrapping is necessary since ExpressionBase is an abstract object, which causes problems with JAXB serialization/deserialization. To deserialize the string back into an ExpressionBase object, see filterStringToExpression(String)

Parameters:
expr - the ExpressionBase to serialize
Returns:
a JAXB XML representation of the wrapped ExpressionBase
Throws:
LQLException - if the ExpressionBase could not be serialized to a string

filterStringToExpression

public static com.endeca.mdex.eql_parser.types.ExpressionBase filterStringToExpression(java.lang.String str)
                                                                                throws LQLException
Converts a previously serialized JAXB XML representation of an LQL expression back into a Java ExpressionBase object suitable for use in runtime queries. The supplied String should have been previously serialized by expressionToFilterString(ExpressionBase). Any other format is not expected to work.

Parameters:
str - a JAXB representation of a wrapped ExpressionBase
Returns:
the reconstituted ExpressionBase object
Throws:
LQLException - if the string could not be used to generate an ExpressionBase

queryToString

public static java.lang.String queryToString(com.endeca.mdex.eql_parser.types.Query query)
                                      throws LQLException
Converts the supplied Query into a String suitable for serialization, such as persistence into a portlet's preferences. The returned String is a JAXB XML representation of the query. The wrapping is necessary since Query is an abstract object, which causes problems with JAXB serialization/deserialization. To deserialize the string back into an ExpressionBase object, see stringToQuery(String)

Parameters:
query - the Query to serialize
Returns:
a JAXB XML representation of the wrapped Query
Throws:
LQLException - if the Query could not be serialized to a string

stringToQuery

public static com.endeca.mdex.eql_parser.types.Query stringToQuery(java.lang.String str)
                                                            throws LQLException
Converts a previously serialized JAXB XML representation of an LQL Query back into a Java Query object suitable for use at runtime. The supplied String should have been previously serialized by queryToString(Query). Any other format is not expected to work.

Parameters:
str - a JAXB representation of a Query
Returns:
the reconstituted Query object
Throws:
LQLException - if the string could not be used to generate a Query

prefixDefineKeys

public static void prefixDefineKeys(com.endeca.mdex.eql_parser.types.Query query,
                                    java.lang.String prefix)
Prefixes all statement keys. Primarily used for previewing entity queries. The conversation service automatically prepends all entity definitions to each query, including the current entity definition if it has already been saved. DEFINE keys are prefixed with a unique key so that they don't conflict with existing keys in the already saved entity definition.

Parameters:
query -
prefix -

prefixExpression

public static void prefixExpression(com.endeca.mdex.eql_parser.types.ExpressionBase expression,
                                    java.lang.String prefix,
                                    java.util.Set<java.lang.String> statementKeys,
                                    java.util.Set<java.lang.String> aliases)
Prefixes statement keys depending on the type of expression. When expressions contain other expressions, the method is called recursively.

Parameters:
expression -
prefix -
statementKeys -

prefixSource

public static void prefixSource(com.endeca.mdex.eql_parser.types.SourceBase source,
                                java.lang.String prefix,
                                java.util.Set<java.lang.String> statementKeys,
                                java.util.Set<java.lang.String> aliases)
Prefixes statement keys depending on the type of source. When sources contain other sources, the method is called recursively.

Parameters:
source -
prefix -
statementKeys -

addAliases

public static void addAliases(java.util.Set<java.lang.String> aliases,
                              com.endeca.mdex.eql_parser.types.SourceBase source)

getStatementKeys

public static java.util.Set<java.lang.String> getStatementKeys(com.endeca.mdex.eql_parser.types.Query query)

getStatementAliases

public static java.util.Set<java.lang.String> getStatementAliases(com.endeca.mdex.eql_parser.types.Statement statement)

hasGroupingSetsGroupBy

public static boolean hasGroupingSetsGroupBy(com.endeca.mdex.eql_parser.types.Query query)
Utility method to identify queries which use a grouping sets with a size > 1

Parameters:
query -
Returns:

hasGroupingSetsGroupBy

public static boolean hasGroupingSetsGroupBy(com.endeca.mdex.eql_parser.types.Statement statement)

hasGroupingSetsFunctions

public static boolean hasGroupingSetsFunctions(com.endeca.mdex.eql_parser.types.Query query)
Utility method to identify queries that use grouping sets functions.

Parameters:
query -
Returns:

hasGroupingSetsFunctions

public static boolean hasGroupingSetsFunctions(com.endeca.mdex.eql_parser.types.Statement statement)

hasGroupingSetsFunctions

public static boolean hasGroupingSetsFunctions(com.endeca.mdex.eql_parser.types.FunctionCallExpression fce)

filterOutNullGroups

@Deprecated
public static void filterOutNullGroups(com.endeca.mdex.eql_parser.types.Query query)
Deprecated. Use filterOutNullGroups(SemanticView, Query) instead

Utility method to filter out NULL groups from the RETURN statement of a query. Adds a NOT IS_NULL filter to the where clause for each attribute in the GROUP BY clause.

Parameters:
query - The query to be modified

addNullGroupFilterToStatement

@Deprecated
public static void addNullGroupFilterToStatement(com.endeca.mdex.eql_parser.types.Statement statement)
Deprecated. Use addNullGroupFilterToStatement(SemanticView, Statement) instead

Utility method to filter out NULL groups from a RETURN statement. Adds a NOT IS_NULL filter to the where clause for each attribute in the GROUP BY clause.

Parameters:
statement - The statement to be modified

filterOutNullGroups

public static void filterOutNullGroups(SemanticView view,
                                       com.endeca.mdex.eql_parser.types.Query query)
Utility method to filter out NULL groups from the RETURN statement of a query. Adds a NOT IS_NULL filter to the where clause for each attribute in the GROUP BY clause.

Parameters:
query - The query to be modified

addNullGroupFilterToStatement

public static void addNullGroupFilterToStatement(SemanticView view,
                                                 com.endeca.mdex.eql_parser.types.Statement statement)
Utility method to filter out NULL groups from a RETURN statement. Adds a NOT IS_NULL filter to the where clause for each attribute in the GROUP BY clause.

Parameters:
statement - The statement to be modified

getAttributeKeys

public static java.util.List<java.lang.String> getAttributeKeys(java.util.Collection<com.endeca.mdex.eql_parser.types.GroupingKeyBase> groupBys)
Utility method to get a list of attribute keys from a list of GroupingKeyBase objects


getAttributeKey

public static java.lang.String getAttributeKey(com.endeca.mdex.eql_parser.types.GroupingKeyBase groupBy)