Class ConstraintParser


  • public class ConstraintParser
    extends Object
    SQL constraint parser from create table statements
    Since:
    3.3.0
    Author:
    osbornb
    • Constructor Detail

      • ConstraintParser

        public ConstraintParser()
    • Method Detail

      • getConstraints

        public static TableConstraints getConstraints​(String tableSql)
        Get the constraints for the table SQL
        Parameters:
        tableSql - table SQL
        Returns:
        constraints
      • getColumnConstraints

        public static ColumnConstraints getColumnConstraints​(String constraintSql)
        Attempt to get column constraints by parsing the SQL statement
        Parameters:
        constraintSql - constraint SQL statement
        Returns:
        constraints
      • getTableConstraint

        public static Constraint getTableConstraint​(String constraintSql)
        Attempt to get a table constraint by parsing the SQL statement
        Parameters:
        constraintSql - constraint SQL statement
        Returns:
        constraint or null
      • isTableConstraint

        public static boolean isTableConstraint​(String constraintSql)
        Check if the SQL is a table type constraint
        Parameters:
        constraintSql - constraint SQL statement
        Returns:
        true if a table constraint
      • getTableType

        public static ConstraintType getTableType​(String constraintSql)
        Get the table constraint type of the constraint SQL
        Parameters:
        constraintSql - constraint SQL
        Returns:
        constraint type or null
      • isTableType

        public static boolean isTableType​(ConstraintType type,
                                          String constraintSql)
        Determine if the table constraint SQL is the constraint type
        Parameters:
        type - constraint type
        constraintSql - constraint SQL
        Returns:
        true if the constraint type
      • getColumnConstraint

        public static Constraint getColumnConstraint​(String constraintSql)
        Attempt to get a column constraint by parsing the SQL statement
        Parameters:
        constraintSql - constraint SQL statement
        Returns:
        constraint or null
      • isColumnConstraint

        public static boolean isColumnConstraint​(String constraintSql)
        Check if the SQL is a column type constraint
        Parameters:
        constraintSql - constraint SQL statement
        Returns:
        true if a column constraint
      • getColumnType

        public static ConstraintType getColumnType​(String constraintSql)
        Get the column constraint type of the constraint SQL
        Parameters:
        constraintSql - constraint SQL
        Returns:
        constraint type or null
      • isColumnType

        public static boolean isColumnType​(ConstraintType type,
                                           String constraintSql)
        Determine if the column constraint SQL is the constraint type
        Parameters:
        type - constraint type
        constraintSql - constraint SQL
        Returns:
        true if the constraint type
      • getConstraint

        public static Constraint getConstraint​(String constraintSql)
        Attempt to get a constraint by parsing the SQL statement
        Parameters:
        constraintSql - constraint SQL statement
        Returns:
        constraint or null
      • isConstraint

        public static boolean isConstraint​(String constraintSql)
        Check if the SQL is a constraint
        Parameters:
        constraintSql - constraint SQL statement
        Returns:
        true if a constraint
      • getType

        public static ConstraintType getType​(String constraintSql)
        Get the constraint type of the constraint SQL
        Parameters:
        constraintSql - constraint SQL
        Returns:
        constraint type or null
      • isType

        public static boolean isType​(ConstraintType type,
                                     String constraintSql)
        Determine if the constraint SQL is the constraint type
        Parameters:
        type - constraint type
        constraintSql - constraint SQL
        Returns:
        true if the constraint type
      • getName

        public static String getName​(String constraintSql)
        Get the constraint name if it has one
        Parameters:
        constraintSql - constraint SQL
        Returns:
        constraint name or null
      • getNameAndDefinition

        public static String[] getNameAndDefinition​(String constraintSql)
        Get the constraint name and remaining definition
        Parameters:
        constraintSql - constraint SQL
        Returns:
        array with name or null at index 0, definition at index 1