DataTypeParser implements DdlConstants { public DataType parse( DdlTokenStream tokens ) throws ParsingException { DataType result = null; if (isDatatype(tokens, DataTypes.DTYPE_CODE_CHAR_STRING)) { result = parseCharStringType(tokens); } else if (isDatatype(tokens, DataTypes.DTYPE_CODE_NCHAR_STRING)) { result = parseNationalCharStringType(tokens); } else if (isDatatype(tokens, DataTypes.DTYPE_CODE_BIT_STRING)) { result = parseBitStringType(tokens); } else if (isDatatype(tokens, DataTypes.DTYPE_CODE_EXACT_NUMERIC)) { result = parseExactNumericType(tokens); } else if (isDatatype(tokens, DataTypes.DTYPE_CODE_APROX_NUMERIC)) { result = parseApproxNumericType(tokens); } else if (isDatatype(tokens, DataTypes.DTYPE_CODE_DATE_TIME)) { result = parseDateTimeType(tokens); } else if (isDatatype(tokens, DataTypes.DTYPE_CODE_MISC)) { result = parseMiscellaneousType(tokens); } else { result = parseCustomType(tokens); } if (tokens.canConsume('[')) { if (!tokens.canConsume(']')) { tokens.consume(); tokens.consume(']'); } if (tokens.canConsume('[')) { if (!tokens.canConsume(']')) { tokens.consume(); tokens.consume(']'); } } } return result; } DataTypeParser(); final boolean isDatatype( DdlTokenStream tokens ); DataType parse( DdlTokenStream tokens ); int getDefaultLength(); void setDefaultLength( int defaultLength ); int getDefaultPrecision(); void setDefaultPrecision( int defaultPrecision ); int getDefaultScale(); void setDefaultScale( int defaultScale ); String getStatementTypeName( String[] stmtPhrase ); void setPropertiesOnNode( AstNode columnNode,
                                     DataType datatype );  }
@Test public void shouldParseCHAR() { printTest("shouldParseCHAR()"); String typeString = getDataTypeString(DataTypes.DTYPE_CHAR); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); content = typeString + " (255)"; tokens = getTokens(content); dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 255, dType.getLength()); }
@Test public void shouldParseCHARACTER() { printTest("shouldParseCHARACTER()"); String typeString = getDataTypeString(DataTypes.DTYPE_CHARACTER); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); content = typeString + " (255)"; tokens = getTokens(content); dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 255, dType.getLength()); }
@Test public void shouldParseCHAR_VARYING() { printTest("shouldParseCHAR_VARYING()"); String typeString = getDataTypeString(DataTypes.DTYPE_CHAR_VARYING); String content = typeString + " (255)"; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 255, dType.getLength()); }
@Test public void shouldParseCHARACTER_VARYING() { printTest("shouldParseCHARACTER_VARYING()"); String typeString = getDataTypeString(DataTypes.DTYPE_CHARACTER_VARYING); String content = typeString + " (255)"; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 255, dType.getLength()); }
@Test public void shouldParseVARCHAR() { printTest("shouldParseVARCHAR()"); String typeString = getDataTypeString(DataTypes.DTYPE_VARCHAR); String content = typeString + " (255)"; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 255, dType.getLength()); content = typeString; tokens = getTokens(content); dType = null; try { dType = parser.parse(tokens); } catch (ParsingException e) { } Assert.assertNull("DataType should NOT have been found for Type = " + content, dType); }
@Test public void shouldParseNATIONAL_CHAR() { printTest("shouldParseNATIONAL_CHAR()"); String typeString = getDataTypeString(DataTypes.DTYPE_NATIONAL_CHAR); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); content = typeString + " (255)"; tokens = getTokens(content); dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 255, dType.getLength()); }
@Test public void shouldParseNATIONAL_CHARACTER() { printTest("shouldParseNATIONAL_CHARACTER()"); String typeString = getDataTypeString(DataTypes.DTYPE_NATIONAL_CHARACTER); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); content = typeString + " (255)"; tokens = getTokens(content); dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 255, dType.getLength()); }
@Test public void shouldParseNATIONAL_CHAR_VARYING() { printTest("shouldParseNATIONAL_CHAR_VARYING()"); String typeString = getDataTypeString(DataTypes.DTYPE_NATIONAL_CHAR_VARYING); String content = typeString + " (255)"; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 255, dType.getLength()); }
@Test public void shouldParseNATIONAL_CHARACTER_VARYING() { printTest("shouldParseNATIONAL_CHARACTER_VARYING()"); String typeString = getDataTypeString(DataTypes.DTYPE_NATIONAL_CHARACTER_VARYING); String content = typeString + " (255)"; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 255, dType.getLength()); }
@Test public void shouldParseNCHAR_VARYING() { printTest("shouldParseNCHAR_VARYING()"); String typeString = getDataTypeString(DataTypes.DTYPE_NCHAR_VARYING); String content = typeString + " (255)"; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 255, dType.getLength()); content = typeString; tokens = getTokens(content); dType = null; try { dType = parser.parse(tokens); } catch (ParsingException e) { } Assert.assertNull("DataType should NOT have been found for Type = " + content, dType); }
@Test public void shouldParseBIT() { printTest("shouldParseBIT()"); String typeString = getDataTypeString(DataTypes.DTYPE_BIT); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); }
@Test public void shouldParseBITWithLength() { printTest("shouldParseBITWithLength()"); String typeString = getDataTypeString(DataTypes.DTYPE_BIT); String content = typeString + " (255)"; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 255, dType.getLength()); }
@Test public void shouldParseBIT_VARYINGWithLength() { printTest("shouldParseBIT_VARYINGWithLength()"); String typeString = getDataTypeString(DataTypes.DTYPE_BIT_VARYING); String content = typeString + " (255)"; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 255, dType.getLength()); content = typeString; tokens = getTokens(content); dType = null; try { dType = parser.parse(tokens); } catch (ParsingException e) { } Assert.assertNull("DataType should NOT have been found for Type = " + content, dType); }
@Test public void shouldNotParseXXXXXXTYPE() { printTest("shouldNotParseXXXXXXTYPE()"); String typeString = "XXXXXXTYPE"; String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = null; try { dType = parser.parse(tokens); } catch (ParsingException e) { } Assert.assertNull("DataType should NOT have been found for Type = " + typeString, dType); }
@Test public void shouldParseINT() { printTest("shouldParseINT()"); String typeString = getDataTypeString(DataTypes.DTYPE_INT); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); }
@Test public void shouldParseINTEGER() { printTest("shouldParseINTEGER()"); String typeString = getDataTypeString(DataTypes.DTYPE_INTEGER); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); }
@Test public void shouldParseSMALLINT() { printTest("shouldParseSMALLINT()"); String typeString = getDataTypeString(DataTypes.DTYPE_SMALLINT); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); }
@Test public void shouldParseNUMERIC() { printTest("shouldParseNUMERIC()"); String typeString = getDataTypeString(DataTypes.DTYPE_NUMERIC); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); content = typeString + " (5)"; tokens = getTokens(content); dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 5, dType.getPrecision()); content = typeString + " (5, 2)"; tokens = getTokens(content); dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 5, dType.getPrecision()); Assert.assertEquals("DataType length is not correct", 2, dType.getScale()); content = typeString + " (5 2)"; tokens = getTokens(content); dType = null; try { dType = parser.parse(tokens); } catch (ParsingException e) { } Assert.assertNull("DataType should NOT have been found for Type = " + content, dType); content = typeString + " (5 A)"; tokens = getTokens(content); try { dType = parser.parse(tokens); } catch (ParsingException e) { } Assert.assertNull("DataType should NOT have been found for Type = " + content, dType); }
@Test public void shouldParseDECIMAL() { printTest("shouldParseDECIMAL()"); String typeString = getDataTypeString(DataTypes.DTYPE_DECIMAL); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); content = typeString + " (5)"; tokens = getTokens(content); dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 5, dType.getPrecision()); content = typeString + " (5, 2)"; tokens = getTokens(content); dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 5, dType.getPrecision()); Assert.assertEquals("DataType length is not correct", 2, dType.getScale()); content = typeString + " (5 2)"; tokens = getTokens(content); dType = null; try { dType = parser.parse(tokens); } catch (ParsingException e) { } Assert.assertNull("DataType should NOT have been found for Type = " + content, dType); content = typeString + " (5 A)"; tokens = getTokens(content); assert dType == null; try { dType = parser.parse(tokens); } catch (ParsingException e) { } Assert.assertNull("DataType should NOT have been found for Type = " + content, dType); }
@Test public void shouldParseDEC() { printTest("shouldParseDEC()"); String typeString = getDataTypeString(DataTypes.DTYPE_DEC); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); content = typeString + " (5)"; tokens = getTokens(content); dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 5, dType.getPrecision()); content = typeString + " (5, 2)"; tokens = getTokens(content); dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 5, dType.getPrecision()); Assert.assertEquals("DataType length is not correct", 2, dType.getScale()); content = typeString + " (5 2)"; tokens = getTokens(content); dType = null; try { dType = parser.parse(tokens); } catch (ParsingException e) { } Assert.assertNull("DataType should NOT have been found for Type = " + content, dType); content = typeString + " (5 A)"; tokens = getTokens(content); assert dType == null; try { dType = parser.parse(tokens); } catch (ParsingException e) { } Assert.assertNull("DataType should NOT have been found for Type = " + content, dType); }
@Test public void shouldParseFLOAT() { printTest("shouldParseFLOAT()"); String typeString = getDataTypeString(DataTypes.DTYPE_FLOAT); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); content = typeString + " (5)"; tokens = getTokens(content); dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 5, dType.getPrecision()); content = typeString + " (5, 2)"; tokens = getTokens(content); dType = null; try { dType = parser.parse(tokens); } catch (ParsingException e) { } Assert.assertNull("DataType should NOT have been found for Type = " + content, dType); }
@Test public void shouldParseREAL() { printTest("shouldParseREAL()"); String typeString = getDataTypeString(DataTypes.DTYPE_REAL); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); }
@Test public void shouldParseDOUBLE_PRECISION() { printTest("shouldParseDOUBLE_PRECISION()"); String typeString = getDataTypeString(DataTypes.DTYPE_DOUBLE_PRECISION); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); }
@Test public void shouldParseDATE() { printTest("shouldParseDATE()"); String typeString = getDataTypeString(DataTypes.DTYPE_DATE); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); }
@Test public void shouldParseTIME() { printTest("shouldParseTIME()"); String typeString = getDataTypeString(DataTypes.DTYPE_TIME); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); content = typeString + " (6)"; tokens = getTokens(content); dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 6, dType.getPrecision()); }
@Test public void shouldParseTIMESTAMP() { printTest("shouldParseTIMESTAMP()"); String typeString = getDataTypeString(DataTypes.DTYPE_TIMESTAMP); String content = typeString; DdlTokenStream tokens = getTokens(content); DataType dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); content = typeString + " (6)"; tokens = getTokens(content); dType = parser.parse(tokens); Assert.assertNotNull("DataType was NOT found for Type = " + typeString, dType); Assert.assertEquals("Wrong DataType found", typeString, dType.getName()); Assert.assertEquals("DataType length is not correct", 6, dType.getPrecision()); }