com.endeca.portal.lql
Class LQLBuilder

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

public class LQLBuilder
extends java.lang.Object


Nested Class Summary
static class LQLBuilder.AdditiveOp
          Enum detailing mathematical operations that can be used in LQL queries.
static class LQLBuilder.CompareOp
          Enum detailing operations usable in the LQL ComparisonExpression.
static class LQLBuilder.Function
          Enum detailing functions usable in the LQL FunctionCallExpression.
static class LQLBuilder.LQLMDEXType
          Represents types that come from MDEX records generated by LQL.
static class LQLBuilder.MultiplicativeOp
           
 
Constructor Summary
LQLBuilder()
           
 
Method Summary
static com.endeca.mdex.lql_parser.types.AdditiveExpression makeAdditiveExpression(com.endeca.mdex.lql_parser.types.ExpressionBase left, com.endeca.mdex.lql_parser.types.ExpressionBase right, LQLBuilder.AdditiveOp op)
          Creates an AdditiveExpression with the give left expression and right expression, using the given math operation.
static com.endeca.mdex.lql_parser.types.AndExpression makeAnd(com.endeca.mdex.lql_parser.types.ExpressionBase left, com.endeca.mdex.lql_parser.types.ExpressionBase right)
          Creates an AndExpression representing a logical AND of the two sub expressions.
static com.endeca.mdex.lql_parser.types.AttributeRefExpression makeAttributeRef(java.lang.String attributeKey)
          Creates an AttributeRefExpression that is used when an attribute key is needed.
static com.endeca.mdex.lql_parser.types.BooleanLiteral makeBooleanLiteral(boolean value)
           
static com.endeca.mdex.lql_parser.types.BooleanLiteral makeBooleanLiteral(java.lang.String value)
           
static com.endeca.mdex.lql_parser.types.ComparisonExpression makeComparisonExpression(com.endeca.mdex.lql_parser.types.ExpressionBase left, com.endeca.mdex.lql_parser.types.ExpressionBase right, LQLBuilder.CompareOp op)
          Creates a ComparisonExpression comparing a left expression with a right expression, using the given compare operation.
static com.endeca.mdex.lql_parser.types.DoubleLiteral makeDoubleLiteral(java.lang.Double value)
          Creates a DoubleLiteral for the given value.
static com.endeca.mdex.lql_parser.types.DoubleLiteral makeDoubleLiteral(java.lang.String d)
           
static com.endeca.mdex.lql_parser.types.ComparisonExpression makeEquals(java.lang.String key, com.endeca.mdex.lql_parser.types.ExpressionBase rhs)
          Convenience function to create a ComparrisonExpression representing "key = " where the type of the attribute represented by key matches the type computed by the expression.
static com.endeca.mdex.lql_parser.types.From makeFrom(com.endeca.mdex.lql_parser.types.SourceBase source)
          Creates a LQL From object with the given source.
static com.endeca.mdex.lql_parser.types.From makeFrom(java.lang.String statementName)
          Convenience function to create an LQL From denoting a named statement.
static com.endeca.mdex.lql_parser.types.FunctionCallExpression makeFunctionCallExpression(LQLBuilder.Function f, com.endeca.mdex.lql_parser.types.ExpressionBase... args)
          Helper method for making FunctionCallExpressions.
static com.endeca.mdex.lql_parser.types.FunctionCallExpression makeFunctionCallExpression(LQLBuilder.Function f, com.endeca.mdex.lql_parser.types.Where w, com.endeca.mdex.lql_parser.types.ExpressionBase... args)
          Helper method for making FunctionCallExpressions.
static com.endeca.mdex.lql_parser.types.GroupBy makeGroupBy(java.lang.String key)
          Creates a GroupBy for the given attribute key.
static com.endeca.mdex.lql_parser.types.GroupBy makeGroupBy(java.lang.String key, java.math.BigInteger depth)
          Creates a GroupBy for the given attribute key and a depth.
static com.endeca.mdex.lql_parser.types.GroupByList makeGroupByList(java.lang.String... groupKeys)
          Creates a GroupByList containing one GroupBy for each key in the list of groupKeys
static com.endeca.mdex.lql_parser.types.Having makeHaving(com.endeca.mdex.lql_parser.types.ExpressionBase filter)
          Creates a Having object with the given filter.
static com.endeca.mdex.lql_parser.types.InExpression makeInExpression(java.lang.String targetStatementKey, java.util.List<? extends com.endeca.mdex.lql_parser.types.ExpressionBase> lookupValues)
          Creates a InExpression with the given target statement and lookup values.
static com.endeca.mdex.lql_parser.types.InnerJoin makeInnerJoin(com.endeca.mdex.lql_parser.types.SourceBase left, com.endeca.mdex.lql_parser.types.SourceBase right, com.endeca.mdex.lql_parser.types.ExpressionBase condition)
          Creates an InnerJoin that can be used as part of a From.
static com.endeca.mdex.lql_parser.types.IntegerLiteral makeIntegerLiteral(java.math.BigInteger value)
           
static com.endeca.mdex.lql_parser.types.LookupExpression makeLookupExpression(java.lang.String targetStatementKey, java.lang.String targetAttributeKey, java.util.List<? extends com.endeca.mdex.lql_parser.types.ExpressionBase> lookupValues)
          Creates a LookupExpression with the given target statement, target attribute key, and lookup values.
static com.endeca.mdex.lql_parser.types.MultiplicativeExpression makeMultiplicativeExpression(com.endeca.mdex.lql_parser.types.ExpressionBase leftOperand, com.endeca.mdex.lql_parser.types.ExpressionBase rightOperand, LQLBuilder.MultiplicativeOp op)
          Creates a multiplicative expression with the given left hand expression, right hand expression, and the mathematical operation to be performed.
static com.endeca.mdex.lql_parser.types.OrExpression makeOr(com.endeca.mdex.lql_parser.types.ExpressionBase left, com.endeca.mdex.lql_parser.types.ExpressionBase right)
          Creates an ORExpression representing a logical OR of the two sub expressions.
static com.endeca.mdex.lql_parser.types.OrderBy makeOrderBy(java.lang.String attributeKey, boolean isAscending)
          Creates an OrderBy on the given attribute key with the given direction.
static com.endeca.mdex.lql_parser.types.OrderByList makeOrderByList(com.endeca.mdex.lql_parser.types.OrderBy... orderBys)
          Creates an OrderByList given a set of OrderBy objects
static com.endeca.mdex.lql_parser.types.OrderByList makeOrderByList(java.lang.String attributeKey, boolean isAscending)
          Creates an OrderByList containing one OrderBy for the given attribute key and direction.
static com.endeca.mdex.lql_parser.types.Paging makePaging(java.math.BigInteger offset, java.math.BigInteger count)
          Creates a Paging object specifying which records should be returned by an LQL query.
static com.endeca.mdex.lql_parser.types.Select makeSelect(java.lang.String attributeKey)
          Convenience function to create a new LQL Select object that selects a particular attribute key.
static com.endeca.mdex.lql_parser.types.Select makeSelect(java.lang.String name, com.endeca.mdex.lql_parser.types.ExpressionBase expression)
          Creates a new LQL Select object with the given name and expression.
static com.endeca.mdex.lql_parser.types.Statement makeStatement(java.lang.String statementKey, boolean isReturnTable)
          Convenience function to create a new Statement object
static com.endeca.mdex.lql_parser.types.StatementSource makeStatementSource(java.lang.String statementKey)
          Creates a StatementSouce to be used in a From or an InnerJoin.
static com.endeca.mdex.lql_parser.types.StringLiteral makeStringLiteral(java.lang.String value)
           
static com.endeca.mdex.lql_parser.types.Where makeWhere(com.endeca.mdex.lql_parser.types.ExpressionBase filter)
          Creates a Where that can be set on an LQL statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LQLBuilder

public LQLBuilder()
Method Detail

makeStatement

public static com.endeca.mdex.lql_parser.types.Statement makeStatement(java.lang.String statementKey,
                                                                       boolean isReturnTable)
Convenience function to create a new Statement object

Parameters:
statementKey -
isReturnTable -
Returns:
a new LQL statement with the given key

makeSelect

public static com.endeca.mdex.lql_parser.types.Select makeSelect(java.lang.String attributeKey)
Convenience function to create a new LQL Select object that selects a particular attribute key. An equivalent string form would be "attributeKey AS attributeKey".

Parameters:
attributeKey - Attribute key to select
Returns:
LQL Select object can be added to an LQL Statement's select list

makeSelect

public static com.endeca.mdex.lql_parser.types.Select makeSelect(java.lang.String name,
                                                                 com.endeca.mdex.lql_parser.types.ExpressionBase expression)
Creates a new LQL Select object with the given name and expression. An Equivalent string form would be "expression AS name".

Parameters:
name - Name for the selection. This would be used as an attribute key or if referenced in another statement.
expression - An expression to be selected. This can be any expression that returns a value (e.g. a FunctionCallExpression representing "AVG(P_Price)")
Returns:
LQL Select object can be added to an LQL Statement's select list

makeStatementSource

public static com.endeca.mdex.lql_parser.types.StatementSource makeStatementSource(java.lang.String statementKey)
Creates a StatementSouce to be used in a From or an InnerJoin. Represents a named LQL statement.

Parameters:
statementKey - Name of an LQL statement
Returns:
StatementSource that can be used in a From or an InnerJoin

makeAttributeRef

public static com.endeca.mdex.lql_parser.types.AttributeRefExpression makeAttributeRef(java.lang.String attributeKey)
Creates an AttributeRefExpression that is used when an attribute key is needed. Denotes a string as a reference to an attribute key either from the MDEX or defined in another statement.

Parameters:
attributeKey - Attribute key to reference.
Returns:
AttributeRefExpression that can be used in places expecting an ExpressionBase

makeLookupExpression

public static com.endeca.mdex.lql_parser.types.LookupExpression makeLookupExpression(java.lang.String targetStatementKey,
                                                                                     java.lang.String targetAttributeKey,
                                                                                     java.util.List<? extends com.endeca.mdex.lql_parser.types.ExpressionBase> lookupValues)
Creates a LookupExpression with the given target statement, target attribute key, and lookup values.

Parameters:
targetStatementKey -
targetAttributeKey -
lookupValues -
Returns:
a lookup expression

makeInExpression

public static com.endeca.mdex.lql_parser.types.InExpression makeInExpression(java.lang.String targetStatementKey,
                                                                             java.util.List<? extends com.endeca.mdex.lql_parser.types.ExpressionBase> lookupValues)
Creates a InExpression with the given target statement and lookup values.

Parameters:
targetStatementKey -
lookupValues -
Returns:
an in expression

makeMultiplicativeExpression

public static com.endeca.mdex.lql_parser.types.MultiplicativeExpression makeMultiplicativeExpression(com.endeca.mdex.lql_parser.types.ExpressionBase leftOperand,
                                                                                                     com.endeca.mdex.lql_parser.types.ExpressionBase rightOperand,
                                                                                                     LQLBuilder.MultiplicativeOp op)
Creates a multiplicative expression with the given left hand expression, right hand expression, and the mathematical operation to be performed.

Parameters:
leftOperand -
rightOperand -
op -
Returns:
an expression multiplying left by right operands

makeFrom

public static com.endeca.mdex.lql_parser.types.From makeFrom(java.lang.String statementName)
Convenience function to create an LQL From denoting a named statement.

Parameters:
statementName - Name of the statement to use as a source.
Returns:
From object that can be added to a statement's from list.

makeFrom

public static com.endeca.mdex.lql_parser.types.From makeFrom(com.endeca.mdex.lql_parser.types.SourceBase source)
Creates a LQL From object with the given source. Can be a StatementSource or an InnerJoin.

Parameters:
source - Source to use in the From clause. Can be a StatementSource or an InnerJoin
Returns:
From object that can be added to a statement's from list.

makeInnerJoin

public static com.endeca.mdex.lql_parser.types.InnerJoin makeInnerJoin(com.endeca.mdex.lql_parser.types.SourceBase left,
                                                                       com.endeca.mdex.lql_parser.types.SourceBase right,
                                                                       com.endeca.mdex.lql_parser.types.ExpressionBase condition)
Creates an InnerJoin that can be used as part of a From. Performs an inner join between two sources (either StatementSource or another InnerJoin) according to an expression.

Parameters:
left - Source to join
right - Source to join
condition - Expression to join on. (For example a ComparrisonExpression representing "key1 = key2")
Returns:
InnerJoin that can be used as part of another InnerJoin or a From

makeWhere

public static com.endeca.mdex.lql_parser.types.Where makeWhere(com.endeca.mdex.lql_parser.types.ExpressionBase filter)
Creates a Where that can be set on an LQL statement.

Parameters:
filter - Expression to filter by.
Returns:
Where that can be set onto a statement.

makeEquals

public static com.endeca.mdex.lql_parser.types.ComparisonExpression makeEquals(java.lang.String key,
                                                                               com.endeca.mdex.lql_parser.types.ExpressionBase rhs)
Convenience function to create a ComparrisonExpression representing "key = " where the type of the attribute represented by key matches the type computed by the expression. This would normally be used in a Where or a Having.

Parameters:
key - Attribute key to use in the comparrison function.
rhs - the expression to compare the attribute to
Returns:
ComparrisonExpression to be used where expressions are needed

makeAnd

public static com.endeca.mdex.lql_parser.types.AndExpression makeAnd(com.endeca.mdex.lql_parser.types.ExpressionBase left,
                                                                     com.endeca.mdex.lql_parser.types.ExpressionBase right)
Creates an AndExpression representing a logical AND of the two sub expressions. String equivalent would be "AND(left, right)".

Parameters:
left - Expression to AND
right - Expression to AND
Returns:
AndExpression that can be used where expressions are needed

makeOr

public static com.endeca.mdex.lql_parser.types.OrExpression makeOr(com.endeca.mdex.lql_parser.types.ExpressionBase left,
                                                                   com.endeca.mdex.lql_parser.types.ExpressionBase right)
Creates an ORExpression representing a logical OR of the two sub expressions. String equivalent would be "OR(left, right)".

Parameters:
left - Expression to OR
right - Expression to OR
Returns:
OrExpression that can be used where expressions are needed

makeGroupByList

public static com.endeca.mdex.lql_parser.types.GroupByList makeGroupByList(java.lang.String... groupKeys)
Creates a GroupByList containing one GroupBy for each key in the list of groupKeys

Parameters:
groupKeys -
Returns:
a group by list assembled from the given keys

makeGroupBy

public static com.endeca.mdex.lql_parser.types.GroupBy makeGroupBy(java.lang.String key)
Creates a GroupBy for the given attribute key.

Parameters:
key - Attribute key to group by
Returns:
GroupBy object that can be added to a GroupByList

makeGroupBy

public static com.endeca.mdex.lql_parser.types.GroupBy makeGroupBy(java.lang.String key,
                                                                   java.math.BigInteger depth)
Creates a GroupBy for the given attribute key and a depth. Used for managed attributes if you want to limit tree depth.

Parameters:
key - Attribute key to group by
depth - Tree depth in a manage attribute to limit the group by value on
Returns:
GroupBy object that can be added to a GroupByList

makeOrderByList

public static com.endeca.mdex.lql_parser.types.OrderByList makeOrderByList(com.endeca.mdex.lql_parser.types.OrderBy... orderBys)
Creates an OrderByList given a set of OrderBy objects

Parameters:
orderBys -
Returns:
OrderByList to use in an LQL Statement

makeOrderByList

public static com.endeca.mdex.lql_parser.types.OrderByList makeOrderByList(java.lang.String attributeKey,
                                                                           boolean isAscending)
Creates an OrderByList containing one OrderBy for the given attribute key and direction.

Parameters:
attributeKey -
isAscending -
Returns:
an order by list

makeOrderBy

public static com.endeca.mdex.lql_parser.types.OrderBy makeOrderBy(java.lang.String attributeKey,
                                                                   boolean isAscending)
Creates an OrderBy on the given attribute key with the given direction.

Parameters:
attributeKey - Attribute key to sort on
isAscending - True if the ordering should be ascending, false if descending
Returns:
OrderBy object that can be added to a statement's order by list.

makeDoubleLiteral

public static com.endeca.mdex.lql_parser.types.DoubleLiteral makeDoubleLiteral(java.lang.Double value)
Creates a DoubleLiteral for the given value.

Parameters:
value -
Returns:
a literal with the given double value

makeComparisonExpression

public static com.endeca.mdex.lql_parser.types.ComparisonExpression makeComparisonExpression(com.endeca.mdex.lql_parser.types.ExpressionBase left,
                                                                                             com.endeca.mdex.lql_parser.types.ExpressionBase right,
                                                                                             LQLBuilder.CompareOp op)
Creates a ComparisonExpression comparing a left expression with a right expression, using the given compare operation.

Parameters:
op -
left -
right -
Returns:
an expression comparing left to right by the provided compare operation

makeAdditiveExpression

public static com.endeca.mdex.lql_parser.types.AdditiveExpression makeAdditiveExpression(com.endeca.mdex.lql_parser.types.ExpressionBase left,
                                                                                         com.endeca.mdex.lql_parser.types.ExpressionBase right,
                                                                                         LQLBuilder.AdditiveOp op)
Creates an AdditiveExpression with the give left expression and right expression, using the given math operation.

Parameters:
left -
right -
op -
Returns:
an expression adding left to right

makePaging

public static com.endeca.mdex.lql_parser.types.Paging makePaging(java.math.BigInteger offset,
                                                                 java.math.BigInteger count)
Creates a Paging object specifying which records should be returned by an LQL query.

Parameters:
offset - The offset into the entire record set.
count - The number of records that should be returned.
Returns:
Paging object that can be set on a Statement.

makeHaving

public static com.endeca.mdex.lql_parser.types.Having makeHaving(com.endeca.mdex.lql_parser.types.ExpressionBase filter)
Creates a Having object with the given filter. Used in post-filtering for aggregate functions.

Parameters:
filter - Filter to restrict the results by.
Returns:
Having object that can be added to a statement's having list.

makeFunctionCallExpression

public static com.endeca.mdex.lql_parser.types.FunctionCallExpression makeFunctionCallExpression(LQLBuilder.Function f,
                                                                                                 com.endeca.mdex.lql_parser.types.Where w,
                                                                                                 com.endeca.mdex.lql_parser.types.ExpressionBase... args)
Helper method for making FunctionCallExpressions. Function call expressions are expressions that use LQLBuilder.Function s. An equivalent string form could be "count(1)"

Parameters:
f - Function to use for the expression
w - Where filter that should be applied to the function
args - ExpressionBase arguments to pass into the function
Returns:
FunctionCallExpression representing a function

makeFunctionCallExpression

public static com.endeca.mdex.lql_parser.types.FunctionCallExpression makeFunctionCallExpression(LQLBuilder.Function f,
                                                                                                 com.endeca.mdex.lql_parser.types.ExpressionBase... args)
Helper method for making FunctionCallExpressions. Function call expressions are expressions that use LQLBuilder.Function s. An equivalent string form could be "count(1)"

Parameters:
f - Function to use for the expression
args - ExpressionBase arguments to pass into the function
Returns:
FunctionCallExpression representing a function

makeBooleanLiteral

public static com.endeca.mdex.lql_parser.types.BooleanLiteral makeBooleanLiteral(java.lang.String value)

makeBooleanLiteral

public static com.endeca.mdex.lql_parser.types.BooleanLiteral makeBooleanLiteral(boolean value)

makeIntegerLiteral

public static com.endeca.mdex.lql_parser.types.IntegerLiteral makeIntegerLiteral(java.math.BigInteger value)

makeDoubleLiteral

public static com.endeca.mdex.lql_parser.types.DoubleLiteral makeDoubleLiteral(java.lang.String d)

makeStringLiteral

public static com.endeca.mdex.lql_parser.types.StringLiteral makeStringLiteral(java.lang.String value)