Java Code Examples for org.apache.ddlutils.model.Column#setDescription()

The following examples show how to use org.apache.ddlutils.model.Column#setDescription() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelComparator.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Compares the two columns and returns the change necessary to create the second
 * column from the first one if they differe.
 *  
 * @param sourceTable  The source table which contains the source column
 * @param sourceColumn The source column
 * @param targetTable  The target table which contains the target column
 * @param targetColumn The target column
 * @return The change or <code>null</code> if the columns are the same
 */
protected ColumnDefinitionChange compareColumns(Table  sourceTable,
                                                Column sourceColumn,
                                                Table  targetTable,
                                                Column targetColumn)
{
    if (ColumnDefinitionChange.isChanged(getPlatformInfo(), sourceColumn, targetColumn))
    {
        Column  newColumnDef   = _cloneHelper.clone(sourceColumn, true);
        int     targetTypeCode = _platformInfo.getTargetJdbcType(targetColumn.getTypeCode());
        boolean sizeMatters    = _platformInfo.hasSize(targetTypeCode);
        boolean scaleMatters   = _platformInfo.hasPrecisionAndScale(targetTypeCode);

        newColumnDef.setTypeCode(targetColumn.getTypeCode());
        newColumnDef.setSize(sizeMatters || scaleMatters ? targetColumn.getSize() : null);
        newColumnDef.setAutoIncrement(targetColumn.isAutoIncrement());
        newColumnDef.setRequired(targetColumn.isRequired());
        newColumnDef.setDescription(targetColumn.getDescription());
        newColumnDef.setDefaultValue(targetColumn.getDefaultValue());
        return new ColumnDefinitionChange(sourceTable.getQualifiedName(), sourceColumn.getName(), newColumnDef);
    }
    else
    {
        return null;
    }
}
 
Example 2
Source File: ModelComparator.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Compares the two columns and returns the change necessary to create the second
 * column from the first one if they differe.
 *  
 * @param sourceTable  The source table which contains the source column
 * @param sourceColumn The source column
 * @param targetTable  The target table which contains the target column
 * @param targetColumn The target column
 * @return The change or <code>null</code> if the columns are the same
 */
protected ColumnDefinitionChange compareColumns(Table  sourceTable,
                                                Column sourceColumn,
                                                Table  targetTable,
                                                Column targetColumn)
{
    if (ColumnDefinitionChange.isChanged(getPlatformInfo(), sourceColumn, targetColumn))
    {
        Column  newColumnDef   = _cloneHelper.clone(sourceColumn, true);
        int     targetTypeCode = _platformInfo.getTargetJdbcType(targetColumn.getTypeCode());
        boolean sizeMatters    = _platformInfo.hasSize(targetTypeCode);
        boolean scaleMatters   = _platformInfo.hasPrecisionAndScale(targetTypeCode);

        newColumnDef.setTypeCode(targetColumn.getTypeCode());
        newColumnDef.setSize(sizeMatters || scaleMatters ? targetColumn.getSize() : null);
        newColumnDef.setAutoIncrement(targetColumn.isAutoIncrement());
        newColumnDef.setRequired(targetColumn.isRequired());
        newColumnDef.setDescription(targetColumn.getDescription());
        newColumnDef.setDefaultValue(targetColumn.getDefaultValue());
        return new ColumnDefinitionChange(sourceTable.getQualifiedName(), sourceColumn.getName(), newColumnDef);
    }
    else
    {
        return null;
    }
}
 
Example 3
Source File: ColumnDefinitionChange.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void apply(Database model, boolean caseSensitive)
{
    Column column = findChangedColumn(model, caseSensitive);

    column.setTypeCode(_newColumnDef.getTypeCode());
    column.setSize(_newColumnDef.getSize());
    column.setAutoIncrement(_newColumnDef.isAutoIncrement());
    column.setRequired(_newColumnDef.isRequired());
    column.setDescription(_newColumnDef.getDescription());
    column.setDefaultValue(_newColumnDef.getDefaultValue());
}
 
Example 4
Source File: ColumnDefinitionChange.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void apply(Database model, boolean caseSensitive)
{
    Column column = findChangedColumn(model, caseSensitive);

    column.setTypeCode(_newColumnDef.getTypeCode());
    column.setSize(_newColumnDef.getSize());
    column.setAutoIncrement(_newColumnDef.isAutoIncrement());
    column.setRequired(_newColumnDef.isRequired());
    column.setDescription(_newColumnDef.getDescription());
    column.setDefaultValue(_newColumnDef.getDefaultValue());
}
 
Example 5
Source File: TestDllUtils.java    From Eagle with Apache License 2.0 5 votes vote down vote up
@Test
public void testTable(){
    Table table = new Table();
    Column column = new Column();
    column.setName("id");
    column.setDefaultValue("-1");
    column.setDescription("rowkey");
    column.setPrimaryKey(true);
    column.setType(TypeMap.VARCHAR);
    table.addColumn(column);
    table.setName("eagle_table");

    System.out.println(table.toString());

}
 
Example 6
Source File: TestDllUtils.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Test
public void testTable(){
    Table table = new Table();
    Column column = new Column();
    column.setName("id");
    column.setDefaultValue("-1");
    column.setDescription("rowkey");
    column.setPrimaryKey(true);
    column.setType(TypeMap.VARCHAR);
    table.addColumn(column);
    table.setName("eagle_table");

    System.out.println(table.toString());

}
 
Example 7
Source File: JdbcModelReader.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Extracts a column definition from the result set.
 * 
 * @param metaData The database meta data
 * @param values   The column meta data values as defined by {@link #getColumnsForColumn()}
 * @return The column
 */
protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
{
    Column column = new Column();

    column.setName((String)values.get("COLUMN_NAME"));
    column.setDefaultValue((String)values.get("COLUMN_DEF"));
    column.setTypeCode(((Integer)values.get("DATA_TYPE")).intValue());

    Integer precision = (Integer)values.get("NUM_PREC_RADIX");

    if (precision != null)
    {
        column.setPrecisionRadix(precision.intValue());
    }

    String size = (String)values.get("COLUMN_SIZE");

    if (size == null)
    {
        size = (String)_defaultSizes.get(Integer.valueOf(column.getTypeCode()));
    }
    // we're setting the size after the precision and radix in case
    // the database prefers to return them in the size value
    column.setSize(size);

    Integer scale = (Integer)values.get("DECIMAL_DIGITS");

    if (scale != null)
    {
        // if there is a scale value, set it after the size (which probably did not contain
        // a scale specification)
        column.setScale(scale.intValue());
    }
    column.setRequired("NO".equalsIgnoreCase(((String)values.get("IS_NULLABLE")).trim()));

    String description = (String)values.get("REMARKS");

    if (!org.apache.ddlutils.util.StringUtilsExt.isEmpty(description))
    {
        column.setDescription(description);
    }
    return column;
}
 
Example 8
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Reads a column element from the XML stream reader.
 * 
 * @param xmlReader The reader
 * @return The column object
 */
private Column readColumnElement(XMLStreamReader xmlReader) throws XMLStreamException, IOException
{
    Column column = new Column();

    for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
    {
        QName attrQName = xmlReader.getAttributeName(idx);

        if (isSameAs(attrQName, QNAME_ATTRIBUTE_NAME))
        {
            column.setName(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_PRIMARY_KEY))
        {
            column.setPrimaryKey(getAttributeValueAsBoolean(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_REQUIRED))
        {
            column.setRequired(getAttributeValueAsBoolean(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_TYPE))
        {
            column.setType(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_SIZE))
        {
            column.setSize(getAttributeValueBeingNullAware(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_DEFAULT))
        {
            column.setDefaultValue(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_AUTO_INCREMENT))
        {
            column.setAutoIncrement(getAttributeValueAsBoolean(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_DESCRIPTION))
        {
            column.setDescription(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_JAVA_NAME))
        {
            column.setJavaName(xmlReader.getAttributeValue(idx));
        }
    }
    consumeRestOfElement(xmlReader);
    return column;
}
 
Example 9
Source File: JdbcModelReader.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Extracts a column definition from the result set.
 * 
 * @param metaData The database meta data
 * @param values   The column meta data values as defined by {@link #getColumnsForColumn()}
 * @return The column
 */
protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
{
    Column column = new Column();

    column.setName((String)values.get("COLUMN_NAME"));
    column.setDefaultValue((String)values.get("COLUMN_DEF"));
    column.setTypeCode(((Integer)values.get("DATA_TYPE")).intValue());

    Integer precision = (Integer)values.get("NUM_PREC_RADIX");

    if (precision != null)
    {
        column.setPrecisionRadix(precision.intValue());
    }

    String size = (String)values.get("COLUMN_SIZE");

    if (size == null)
    {
        size = (String)_defaultSizes.get(Integer.valueOf(column.getTypeCode()));
    }
    // we're setting the size after the precision and radix in case
    // the database prefers to return them in the size value
    column.setSize(size);

    Integer scale = (Integer)values.get("DECIMAL_DIGITS");

    if (scale != null)
    {
        // if there is a scale value, set it after the size (which probably did not contain
        // a scale specification)
        column.setScale(scale.intValue());
    }
    column.setRequired("NO".equalsIgnoreCase(((String)values.get("IS_NULLABLE")).trim()));

    String description = (String)values.get("REMARKS");

    if (!org.apache.ddlutils.util.StringUtilsExt.isEmpty(description))
    {
        column.setDescription(description);
    }
    return column;
}
 
Example 10
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Reads a column element from the XML stream reader.
 * 
 * @param xmlReader The reader
 * @return The column object
 */
private Column readColumnElement(XMLStreamReader xmlReader) throws XMLStreamException, IOException
{
    Column column = new Column();

    for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
    {
        QName attrQName = xmlReader.getAttributeName(idx);

        if (isSameAs(attrQName, QNAME_ATTRIBUTE_NAME))
        {
            column.setName(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_PRIMARY_KEY))
        {
            column.setPrimaryKey(getAttributeValueAsBoolean(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_REQUIRED))
        {
            column.setRequired(getAttributeValueAsBoolean(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_TYPE))
        {
            column.setType(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_SIZE))
        {
            column.setSize(getAttributeValueBeingNullAware(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_DEFAULT))
        {
            column.setDefaultValue(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_AUTO_INCREMENT))
        {
            column.setAutoIncrement(getAttributeValueAsBoolean(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_DESCRIPTION))
        {
            column.setDescription(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_JAVA_NAME))
        {
            column.setJavaName(xmlReader.getAttributeValue(idx));
        }
    }
    consumeRestOfElement(xmlReader);
    return column;
}