Class Expression


  • @ThreadSafe
    public final class Expression
    extends Object
    High-level representation of a DynamoDB 'expression' that can be used in various situations where the API requires or accepts an expression. In addition various convenience methods are provided to help manipulate expressions.

    At a minimum, an expression must contain a string that is the expression itself.

    Optionally, attribute names can be substituted with tokens using the '#name_token' syntax; also attribute values can be substituted with tokens using the ':value_token' syntax. If tokens are used in the expression then the values or names associated with those tokens must be explicitly added to the expressionValues and expressionNames maps respectively that are also stored on this object.

    Example:- Expression myExpression = Expression.builder() .expression("#a = :b") .putExpressionName("#a", "myAttribute") .putExpressionValue(":b", myAttributeValue) .build();

    • Method Detail

      • builder

        public static Expression.Builder builder()
        Constructs a new expression builder.
        Returns:
        a new expression builder.
      • join

        public static Expression join​(Expression expression1,
                                      Expression expression2,
                                      String joinToken)
        Coalesces two complete expressions into a single expression. The expression string will be joined using the supplied join token, and the ExpressionNames and ExpressionValues maps will be merged.
        Parameters:
        expression1 - The first expression to coalesce
        expression2 - The second expression to coalesce
        joinToken - The join token to be used to join the expression strings (e.g.: 'AND', 'OR')
        Returns:
        The coalesced expression
        Throws:
        IllegalArgumentException - if a conflict occurs when merging ExpressionNames or ExpressionValues
      • join

        public static Expression join​(String joinToken,
                                      Collection<Expression> expressions)
        Coalesces multiple complete expressions into a single expression. The expression string will be joined using the supplied join token, and the ExpressionNames and ExpressionValues maps will be merged.
        Parameters:
        joinToken - The join token to be used to join the expression strings (e.g.: 'AND', 'OR')
        expressions - The expressions to coalesce
        Returns:
        The coalesced expression
        Throws:
        IllegalArgumentException - if a conflict occurs when merging ExpressionNames or ExpressionValues
      • joinExpressions

        public static String joinExpressions​(String expression1,
                                             String expression2,
                                             String joinToken)
        Coalesces two expression strings into a single expression string. The expression string will be joined using the supplied join token.
        Parameters:
        expression1 - The first expression string to coalesce
        expression2 - The second expression string to coalesce
        joinToken - The join token to be used to join the expression strings (e.g.: 'AND', 'OR)
        Returns:
        The coalesced expression
      • joinValues

        public static Map<String,​AttributeValue> joinValues​(Map<String,​AttributeValue> expressionValues1,
                                                                  Map<String,​AttributeValue> expressionValues2)
        Coalesces two ExpressionValues maps into a single ExpressionValues map. The ExpressionValues map is an optional component of an expression.
        Parameters:
        expressionValues1 - The first ExpressionValues map
        expressionValues2 - The second ExpressionValues map
        Returns:
        The coalesced ExpressionValues map
        Throws:
        IllegalArgumentException - if a conflict occurs when merging ExpressionValues
      • joinNames

        public static Map<String,​String> joinNames​(Map<String,​String> expressionNames1,
                                                         Map<String,​String> expressionNames2)
        Coalesces two ExpressionNames maps into a single ExpressionNames map. The ExpressionNames map is an optional component of an expression.
        Parameters:
        expressionNames1 - The first ExpressionNames map
        expressionNames2 - The second ExpressionNames map
        Returns:
        The coalesced ExpressionNames map
        Throws:
        IllegalArgumentException - if a conflict occurs when merging ExpressionNames
      • expression

        public String expression()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object