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.lql_parser.types.SourceBase source)
           
static java.lang.String expressionToFilterString(com.endeca.mdex.lql_parser.types.ExpressionBase expr)
          Converts the supplied ExpressionBase into a String suitable for serialization, such as persistence into a portlet's preferences.
static com.endeca.mdex.lql_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.util.Set<java.lang.String> getStatementAliases(com.endeca.mdex.lql_parser.types.Statement statement)
           
static java.util.Set<java.lang.String> getStatementKeys(com.endeca.mdex.lql_parser.types.Query query)
           
static com.endeca.mdex.lql_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.lql_parser.types.Query query, java.lang.String prefix)
          Prefixes all statement keys.
static void prefixExpression(com.endeca.mdex.lql_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.lql_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.lql_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.lql_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.lql_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.lql_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.lql_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.lql_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.lql_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.lql_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.lql_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.lql_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.lql_parser.types.SourceBase source)

getStatementKeys

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

getStatementAliases

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