protected Column readColumn()

in src/main/java/org/apache/ddlutils/platform/db2/Db2ModelReader.java [105:171]


    protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
    {
		Column column = super.readColumn(metaData, values);

		if (column.getDefaultValue() != null)
		{
			if (column.getTypeCode() == Types.TIME)
			{
				Matcher matcher = _db2TimePattern.matcher(column.getDefaultValue());

				// Db2 returns "HH24.MI.SS"
				if (matcher.matches())
				{
					StringBuffer newDefault = new StringBuffer();

					newDefault.append("'");
					// the hour
					newDefault.append(matcher.group(1));
					newDefault.append(":");
					// the minute
					newDefault.append(matcher.group(2));
					newDefault.append(":");
					// the second
					newDefault.append(matcher.group(3));
					newDefault.append("'");

					column.setDefaultValue(newDefault.toString());
				}
			}
			else if (column.getTypeCode() == Types.TIMESTAMP)
			{
                Matcher matcher = _db2TimestampPattern.matcher(column.getDefaultValue());

				// Db2 returns "YYYY-MM-DD-HH24.MI.SS.FF"
				if (matcher.matches())
				{
					StringBuffer newDefault = new StringBuffer();

					newDefault.append("'");
					// group 1 is the date which has the correct format
					newDefault.append(matcher.group(1));
					newDefault.append(" ");
					// the hour
					newDefault.append(matcher.group(2));
					newDefault.append(":");
					// the minute
					newDefault.append(matcher.group(3));
					newDefault.append(":");
					// the second
					newDefault.append(matcher.group(4));
					// optionally, the fraction
					if ((matcher.groupCount() >= 5) && (matcher.group(5) != null))
					{
						newDefault.append(matcher.group(5));
					}
					newDefault.append("'");

					column.setDefaultValue(newDefault.toString());
				}
			}
            else if (TypeMap.isTextType(column.getTypeCode()))
            {
                column.setDefaultValue(unescape(column.getDefaultValue(), "'", "''"));
            }
		}
		return column;
	}