org.modeshape.sequencer.ddl.datatype

## Class DataTypeParser

- java.lang.Object
- - org.modeshape.sequencer.ddl.datatype.DataTypeParser

- All Implemented Interfaces:
    DdlConstants

      public class DataTypeParser
      extends Object
      implements DdlConstants

  A parser for SQL data types.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.modeshape.sequencer.ddl.DdlConstants

      `DdlConstants.AstNodeNames, DdlConstants.DataTypes, DdlConstants.DropBehavior, DdlConstants.MatchType, DdlConstants.Problems, DdlConstants.ReferencialAction, DdlConstants.StatementStartPhrases`

  - ### Field Summary

    - ### Fields inherited from interface org.modeshape.sequencer.ddl.DdlConstants

      `ALTER, CHECK, COLUMN, COMMA, CONSTRAINT, CONSTRAINT_C, CONSTRAINT_FK, CONSTRAINT_PK, CONSTRAINT_UC, CREATE, DECLARE, DEFAULT_TERMINATOR, DELETE, DROP, FOREIGN, FOREIGN_KEY, GIGA, GRANT, INDEX, INSERT, KEY, KILO, L_PAREN, L_SQUOTE, MEGA, MISSING_TERMINATOR_NODE_LITERAL, NOT, NULL, OFF, ON, PERIOD, PRIMARY, PRIMARY_KEY, R_PAREN, REVOKE, SCHEMA, SELECT, SEMICOLON, SET, SPACE, SQL_92_RESERVED_WORDS, TABLE, UNIQUE, UPDATE, VIEW`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DataTypeParser()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected boolean` | `canConsume(DdlTokenStream tokens, DataType dataType, boolean addSpacePrefix, int type)`
    `protected boolean` | `canConsume(DdlTokenStream tokens, DataType dataType, boolean addSpacePrefix, String[] additionalStrs)`
    `protected boolean` | `canConsume(DdlTokenStream tokens, DataType dataType, boolean addSpacePrefix, String initialStr, String... additionalStrs)`
    `protected boolean` | `canConsumeAnyOf(DdlTokenStream tokens, DataType dataType, boolean addSpacePrefix, String initialStr, String... additionalStrs)`
    `protected String` | `consume(DdlTokenStream tokens, DataType dataType, boolean addSpacePrefix)`
    `protected String` | `consume(DdlTokenStream tokens, DataType dataType, boolean addSpacePrefix, String str)`
    `protected String` | `consume(DdlTokenStream tokens, DataType dataType, boolean addSpacePrefix, String[] additionalStrs)`
    `protected String` | `consume(DdlTokenStream tokens, DataType dataType, boolean addSpacePrefix, String initialStr, String... additionalStrs)`
    `int` | `getDefaultLength()`
    `int` | `getDefaultPrecision()`
    `int` | `getDefaultScale()`
    `String` | `getStatementTypeName(String[] stmtPhrase)`
    `protected boolean` | `isCustomDataType(DdlTokenStream tokens)` Method to determine of next tokens represent a custom data type.
    `boolean` | `isDatatype(DdlTokenStream tokens)` Method determines if the next set of tokens matches one of the registered data type token sets.
    `DataType` | `parse(DdlTokenStream tokens)` Method which performs the actual parsing of the data type name and applicable values (i.e.
    `protected DataType` | `parseApproxNumericType(DdlTokenStream tokens)` Parses SQL-92 Approximate numeric data types.
    `protected DataType` | `parseBitStringType(DdlTokenStream tokens)` Parses SQL-92 Bit string data types.
    `protected long` | `parseBracketedLong(DdlTokenStream tokens, DataType dataType)` Returns a long value from the input token stream assuming the long is bracketed with parenthesis.
    `protected DataType` | `parseCharStringType(DdlTokenStream tokens)` Parses SQL-92 Character string data types.
    `protected DataType` | `parseCustomType(DdlTokenStream tokens)` General catch-all data type parsing method that sub-classes can override to parse database-specific data types.
    `protected DataType` | `parseDateTimeType(DdlTokenStream tokens)` Parses SQL-92 Date and Time data types.
    `protected DataType` | `parseExactNumericType(DdlTokenStream tokens)` Parses SQL-92 Exact numeric data types.
    `protected long` | `parseLong(DdlTokenStream tokens, DataType dataType)` Returns a long value from the input token stream assuming the long is not bracketed with parenthesis.
    `protected long` | `parseLong(String value)` Returns the integer value of the input string.
    `protected DataType` | `parseMiscellaneousType(DdlTokenStream tokens)` Parses SQL-92 Misc data types.
    `protected DataType` | `parseNationalCharStringType(DdlTokenStream tokens)` Parses SQL-92 National Character string data types.
    `void` | `setDefaultLength(int defaultLength)`
    `void` | `setDefaultPrecision(int defaultPrecision)`
    `void` | `setDefaultScale(int defaultScale)`
    `void` | `setPropertiesOnNode(AstNode columnNode, DataType datatype)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DataTypeParser

          public DataTypeParser()

  - ### Method Detail

    - #### isDatatype

          public final boolean isDatatype(DdlTokenStream tokens)
                                   throws ParsingException

      Method determines if the next set of tokens matches one of the registered data type token sets.
      Parameters:
        `tokens` -
      Returns:
        is registered data type
      Throws:
        `ParsingException`

    - #### isCustomDataType

          protected boolean isCustomDataType(DdlTokenStream tokens)
                                      throws ParsingException

      Method to determine of next tokens represent a custom data type. Subclasses should override this method and perform token checks for any non-SQL92 spec'd data types.
      Parameters:
        `tokens` -
      Returns:
        is custom data type
      Throws:
        `ParsingException`

    - #### parse

          public DataType parse(DdlTokenStream tokens)
                         throws ParsingException

      Method which performs the actual parsing of the data type name and applicable values (i.e. VARCHAR(20)) if data type is found.
      Parameters:
        `tokens` -
      Returns:
        the `DataType`
      Throws:
        `ParsingException`

    - #### parseCharStringType

          protected DataType parseCharStringType(DdlTokenStream tokens)
                                          throws ParsingException

      Parses SQL-92 Character string data types. ::= CHARACTER [ ] | CHAR [ ] | CHARACTER VARYING | CHAR VARYING | VARCHAR
      Parameters:
        `tokens` -
      Returns:
        the `DataType`
      Throws:
        `ParsingException`

    - #### parseNationalCharStringType

          protected DataType parseNationalCharStringType(DdlTokenStream tokens)
                                                  throws ParsingException

      Parses SQL-92 National Character string data types. ::= NATIONAL CHARACTER [ ] | NATIONAL CHAR [ ] | NCHAR [ ] | NATIONAL CHARACTER VARYING | NATIONAL CHAR VARYING | NCHAR VARYING
      Parameters:
        `tokens` -
      Returns:
        the `DataType`
      Throws:
        `ParsingException`

    - #### parseBitStringType

          protected DataType parseBitStringType(DdlTokenStream tokens)
                                         throws ParsingException

      Parses SQL-92 Bit string data types. ::= BIT [ ] | BIT VARYING
      Parameters:
        `tokens` -
      Returns:
        the `DataType`
      Throws:
        `ParsingException`

    - #### parseExactNumericType

          protected DataType parseExactNumericType(DdlTokenStream tokens)
                                            throws ParsingException

      Parses SQL-92 Exact numeric data types. ::= NUMERIC [ [ ] ] | DECIMAL [ [ ] ] | DEC [ [ ] ] | INTEGER | INT | SMALLINT
      Parameters:
        `tokens` -
      Returns:
        the `DataType`
      Throws:
        `ParsingException`

    - #### parseApproxNumericType

          protected DataType parseApproxNumericType(DdlTokenStream tokens)
                                             throws ParsingException

      Parses SQL-92 Approximate numeric data types. ::= FLOAT [ ] | REAL | DOUBLE PRECISION
      Parameters:
        `tokens` -
      Returns:
        the `DataType`
      Throws:
        `ParsingException`

    - #### parseDateTimeType

          protected DataType parseDateTimeType(DdlTokenStream tokens)
                                        throws ParsingException

      Parses SQL-92 Date and Time data types. ::= DATE | TIME [ ] [ WITH TIME ZONE ] | TIMESTAMP [ ] [ WITH TIME ZONE ]
      Parameters:
        `tokens` -
      Returns:
        the `DataType`
      Throws:
        `ParsingException`

    - #### parseMiscellaneousType

          protected DataType parseMiscellaneousType(DdlTokenStream tokens)
                                             throws ParsingException

      Parses SQL-92 Misc data types. ::= INTERVAL ::= TO | ::= [ ] ::= YEAR | MONTH | DAY | HOUR | MINUTE ::= ::= | SECOND [ ] ::= ::= [ ] | SECOND [ [ ] ]
      Parameters:
        `tokens` -
      Returns:
        the `DataType`
      Throws:
        `ParsingException`

    - #### parseCustomType

          protected DataType parseCustomType(DdlTokenStream tokens)
                                      throws ParsingException

      General catch-all data type parsing method that sub-classes can override to parse database-specific data types.
      Parameters:
        `tokens` -
      Returns:
        the `DataType`
      Throws:
        `ParsingException`

    - #### getDefaultLength

          public int getDefaultLength()

      Returns:
        integer default value for length

    - #### setDefaultLength

          public void setDefaultLength(int defaultLength)

      Parameters:
        `defaultLength` -

    - #### getDefaultPrecision

          public int getDefaultPrecision()

      Returns:
        integer default value for precision

    - #### setDefaultPrecision

          public void setDefaultPrecision(int defaultPrecision)

      Parameters:
        `defaultPrecision` -

    - #### getDefaultScale

          public int getDefaultScale()

      Returns:
        integer default value for scale

    - #### setDefaultScale

          public void setDefaultScale(int defaultScale)

      Parameters:
        `defaultScale` -

    - #### parseLong

          protected long parseLong(DdlTokenStream tokens,
                       DataType dataType)

      Returns a long value from the input token stream assuming the long is not bracketed with parenthesis.
      Parameters:
        `tokens` -
        `dataType` -
      Returns:
        the long value

    - #### parseBracketedLong

          protected long parseBracketedLong(DdlTokenStream tokens,
                                DataType dataType)

      Returns a long value from the input token stream assuming the long is bracketed with parenthesis.
      Parameters:
        `tokens` -
        `dataType` -
      Returns:
        the long value

    - #### parseLong

          protected long parseLong(String value)

      Returns the integer value of the input string. Handles both straight integer string or complex KMG (CLOB or BLOB) value.
      Parameters:
        `value` -
      Returns:
        integer value
      Throws:
        `NumberFormatException` - if a valid integer is not found

    - #### consume

          protected String consume(DdlTokenStream tokens,
                       DataType dataType,
                       boolean addSpacePrefix)
                            throws ParsingException

      Parameters:
        `tokens` -
        `dataType` -
        `addSpacePrefix` -
      Returns:
        consumed String value
      Throws:
        `ParsingException`

    - #### consume

          protected String consume(DdlTokenStream tokens,
                       DataType dataType,
                       boolean addSpacePrefix,
                       String str)
                            throws ParsingException

      Parameters:
        `tokens` -
        `dataType` -
        `addSpacePrefix` -
        `str` -
      Returns:
        consumed string value
      Throws:
        `ParsingException`

    - #### consume

          protected String consume(DdlTokenStream tokens,
                       DataType dataType,
                       boolean addSpacePrefix,
                       String initialStr,
                       String... additionalStrs)
                            throws ParsingException

      Parameters:
        `tokens` -
        `dataType` -
        `addSpacePrefix` -
        `initialStr` -
        `additionalStrs` -
      Returns:
        the consumed String
      Throws:
        `ParsingException`

    - #### consume

          protected String consume(DdlTokenStream tokens,
                       DataType dataType,
                       boolean addSpacePrefix,
                       String[] additionalStrs)
                            throws ParsingException

      Throws:
        `ParsingException`

    - #### canConsume

          protected boolean canConsume(DdlTokenStream tokens,
                           DataType dataType,
                           boolean addSpacePrefix,
                           String initialStr,
                           String... additionalStrs)
                                throws ParsingException

      Parameters:
        `tokens` -
        `dataType` -
        `addSpacePrefix` -
        `initialStr` -
        `additionalStrs` -
      Returns:
        did consume
      Throws:
        `ParsingException`

    - #### canConsume

          protected boolean canConsume(DdlTokenStream tokens,
                           DataType dataType,
                           boolean addSpacePrefix,
                           String[] additionalStrs)
                                throws ParsingException

      Parameters:
        `tokens` -
        `dataType` -
        `addSpacePrefix` -
        `additionalStrs` -
      Returns:
        did consume
      Throws:
        `ParsingException`

    - #### canConsume

          protected boolean canConsume(DdlTokenStream tokens,
                           DataType dataType,
                           boolean addSpacePrefix,
                           int type)
                                throws ParsingException

      Parameters:
        `tokens` -
        `dataType` -
        `addSpacePrefix` -
        `type` -
      Returns:
        consumed String value
      Throws:
        `ParsingException`

    - #### canConsumeAnyOf

          protected boolean canConsumeAnyOf(DdlTokenStream tokens,
                                DataType dataType,
                                boolean addSpacePrefix,
                                String initialStr,
                                String... additionalStrs)
                                     throws ParsingException

      Parameters:
        `tokens` -
        `dataType` -
        `addSpacePrefix` -
        `initialStr` -
        `additionalStrs` -
      Returns:
        did consume any
      Throws:
        `ParsingException`

    - #### getStatementTypeName

          public String getStatementTypeName(String[] stmtPhrase)

      Parameters:
        `stmtPhrase` -
      Returns:
        concatenated name

    - #### setPropertiesOnNode

          public void setPropertiesOnNode(AstNode columnNode,
                                 DataType datatype)

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.