Class BoundExpressionParser

java.lang.Object
org.synchronoss.cpo.core.parser.BoundExpressionParser
All Implemented Interfaces:
ExpressionParser

public class BoundExpressionParser extends Object implements ExpressionParser
ExpressionParser implementation for native expressions that use positional ? bind markers (the common JDBC/CQL convention). Parses INSERT statements by matching the column-list and values-list parentheses, and all other statement types by scanning left of each ? for the preceding column/attribute token.
Since:
10/20/2008
Author:
Michael Bellomo
  • Constructor Details

    • BoundExpressionParser

      public BoundExpressionParser()
      Creates a parser with no expression set. Call setExpression(String) before use.
  • Method Details

    • getExpression

      public String getExpression()
      Returns the expression used by this parser
      Specified by:
      getExpression in interface ExpressionParser
      Returns:
      The expression
    • setExpression

      public void setExpression(String expression)
      Sets the expression to be used for this parser
      Specified by:
      setExpression in interface ExpressionParser
      Parameters:
      expression - The expression
    • countArguments

      public int countArguments()
      Returns the count of the bind markers in the expression
      Specified by:
      countArguments in interface ExpressionParser
      Returns:
      the number of bind markers
    • getBindMarkerIndexes

      public static Collection<Integer> getBindMarkerIndexes(String source)
      Finds the character offsets of every unquoted ? bind marker in source. Markers inside single- or double-quoted literals are ignored.
      Parameters:
      source - the expression to scan, may be null or empty
      Returns:
      the offsets of each bind marker, in order; empty if source is null or empty
    • parse

      public List<String> parse() throws ParseException
      Returns a list of columns from the expression for each bind marker

      Supports two expression shapes: INSERT INTO table(col1, col2...) VALUES(val1, val2...), parsed by matching the column-list and values-list parentheses; and any other expression of the form ...col1 = ?, col2 = ?..., parsed by scanning left from each ? for the preceding column/attribute token.

      Specified by:
      parse in interface ExpressionParser
      Returns:
      List of Strings for the columns for the bind markers
      Throws:
      ParseException - thrown if the expression cannot be parsed