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

The following examples show how to use org.apache.ddlutils.model.Column#setRequired() . 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: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when a column value contains an invalid character.
 */
public void testColumnValueContainsInvalidCharacters() throws Exception
{
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();
    String   columnName  = "the\u0000value";

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName(columnName);
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName("test");
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = "Some Text";

    bean.set("id", new Integer(1));
    bean.set(columnName, testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <test id=\"1\">\n" +
                  "    <column>\n" +
                  "      <column-name " + DatabaseIO.BASE64_ATTR_NAME + "=\"true\">" + new String(Base64.encodeBase64(columnName.getBytes("UTF-8")), "UTF-8") + "</column-name>\n" +
                  "      <column-value>" + testedValue + "</column-value>\n" +
                  "    </column>\n" +
                  "  </test>\n" +
                  "</data>\n");
}
 
Example 2
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when the table name contains a '&' character.
 */
public void testTableNameContainsAmpersand() throws Exception
{
    String   tableName   = "test&table";
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName("value");
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName(tableName);
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = "Some Text";

    bean.set("id", new Integer(1));
    bean.set("value", testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <table table-name=\"test&amp;table\" id=\"1\" value=\"" + testedValue + "\" />\n" +
                  "</data>\n");
}
 
Example 3
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when a column name is not a valid tag,
 * and the value is invalid, and both are short.
 */
public void testColumnNameAndValueLongAndInvalid() throws Exception
{
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();
    String   columnName  = StringUtils.repeat("the\u0000name", 100);

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName(columnName);
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName("test");
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = StringUtils.repeat("the\u0000value", 40);

    bean.set("id", new Integer(1));
    bean.set(columnName, testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <test id=\"1\">\n" +
                  "    <column>\n" +
                  "      <column-name " + DatabaseIO.BASE64_ATTR_NAME + "=\"true\">" + new String(Base64.encodeBase64(columnName.getBytes("UTF-8")), "UTF-8") + "</column-name>\n" +
                  "      <column-value " + DatabaseIO.BASE64_ATTR_NAME + "=\"true\">" + new String(Base64.encodeBase64(testedValue.getBytes("UTF-8")), "UTF-8") + "</column-value>\n" +
                  "    </column>\n" +
                  "  </test>\n" +
                  "</data>\n");
}
 
Example 4
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when a column value contains the '&' character.
 */
public void testColumnValueContainsAmpersand() throws Exception
{
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();
    String   columnName  = "foo&bar";

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName(columnName);
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName("test");
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = "Some Text";

    bean.set("id", new Integer(1));
    bean.set(columnName, testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <test id=\"1\">\n" +
                  "    <column column-name=\"foo&amp;bar\">" + testedValue + "</column>\n" +
                  "  </test>\n" +
                  "</data>\n");
}
 
Example 5
Source File: JdbcSchemaManager.java    From eagle with Apache License 2.0 5 votes vote down vote up
private void buildTable(Table table) {
    Column id = new Column();
    id.setName("id");
    id.setPrimaryKey(true);
    id.setRequired(true);
    id.setTypeCode(Types.VARCHAR);
    id.setSize("50");
    table.addColumn(id);

    Column value = new Column();
    value.setName("value");
    value.setTypeCode(Types.CLOB);
    table.addColumn(value);
}
 
Example 6
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when a column value contains the '>' character.
 */
public void testColumnValueContainsMoreCharacter() throws Exception
{
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();
    String   columnName  = "foo>bar";

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName(columnName);
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName("test");
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = "Some Text";

    bean.set("id", new Integer(1));
    bean.set(columnName, testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <test id=\"1\">\n" +
                  "    <column column-name=\"foo>bar\">" + testedValue + "</column>\n" +
                  "  </test>\n" +
                  "</data>\n");
}
 
Example 7
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when a column value contains the '<' character.
 */
public void testColumnValueContainsLessCharacter() throws Exception
{
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();
    String   columnName  = "foo<bar";

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName(columnName);
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName("test");
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = "Some Text";

    bean.set("id", new Integer(1));
    bean.set(columnName, testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <test id=\"1\">\n" +
                  "    <column column-name=\"foo&lt;bar\">" + testedValue + "</column>\n" +
                  "  </test>\n" +
                  "</data>\n");
}
 
Example 8
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when a column value contains the '&' character.
 */
public void testColumnValueContainsAmpersand() throws Exception
{
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();
    String   columnName  = "foo&bar";

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName(columnName);
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName("test");
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = "Some Text";

    bean.set("id", new Integer(1));
    bean.set(columnName, testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <test id=\"1\">\n" +
                  "    <column column-name=\"foo&amp;bar\">" + testedValue + "</column>\n" +
                  "  </test>\n" +
                  "</data>\n");
}
 
Example 9
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when a column value contains an invalid character.
 */
public void testColumnValueContainsInvalidCharacters() throws Exception
{
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();
    String   columnName  = "the\u0000value";

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName(columnName);
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName("test");
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = "Some Text";

    bean.set("id", new Integer(1));
    bean.set(columnName, testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <test id=\"1\">\n" +
                  "    <column>\n" +
                  "      <column-name " + DatabaseIO.BASE64_ATTR_NAME + "=\"true\">" + new String(Base64.encodeBase64(columnName.getBytes("UTF-8")), "UTF-8") + "</column-name>\n" +
                  "      <column-value>" + testedValue + "</column-value>\n" +
                  "    </column>\n" +
                  "  </test>\n" +
                  "</data>\n");
}
 
Example 10
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when the table name contains characters not allowed in XML.
 */
public void testTableNameContainsInvalidCharacters() throws Exception
{
    String   tableName   = "test\u0000table";
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName("value");
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName(tableName);
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = "Some Text";

    bean.set("id", new Integer(1));
    bean.set("value", testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <table id=\"1\" value=\"" + testedValue + "\">\n" +
                  "    <table-name " + DatabaseIO.BASE64_ATTR_NAME + "=\"true\">" + new String(Base64.encodeBase64(tableName.getBytes("UTF-8")), "UTF-8") + "</table-name>\n" +
                  "  </table>\n" +
                  "</data>\n");
}
 
Example 11
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when the table name contains a '>' character.
 */
public void testTableNameContainsMoreCharacter() throws Exception
{
    String   tableName   = "test>table";
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName("value");
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName(tableName);
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = "Some Text";

    bean.set("id", new Integer(1));
    bean.set("value", testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <table table-name=\"test>table\" id=\"1\" value=\"" + testedValue + "\" />\n" +
                  "</data>\n");
}
 
Example 12
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when the table name contains a '<' character.
 */
public void testTableNameContainsLessCharacter() throws Exception
{
    String   tableName   = "test<table";
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName("value");
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName(tableName);
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = "Some Text";

    bean.set("id", new Integer(1));
    bean.set("value", testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <table table-name=\"test&lt;table\" id=\"1\" value=\"" + testedValue + "\" />\n" +
                  "</data>\n");
}
 
Example 13
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when the table name contains a '&' character.
 */
public void testTableNameContainsAmpersand() throws Exception
{
    String   tableName   = "test&table";
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName("value");
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName(tableName);
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = "Some Text";

    bean.set("id", new Integer(1));
    bean.set("value", testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <table table-name=\"test&amp;table\" id=\"1\" value=\"" + testedValue + "\" />\n" +
                  "</data>\n");
}
 
Example 14
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when a column value contains the '<' character.
 */
public void testColumnValueContainsLessCharacter() throws Exception
{
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();
    String   columnName  = "foo<bar";

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName(columnName);
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName("test");
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = "Some Text";

    bean.set("id", new Integer(1));
    bean.set(columnName, testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <test id=\"1\">\n" +
                  "    <column column-name=\"foo&lt;bar\">" + testedValue + "</column>\n" +
                  "  </test>\n" +
                  "</data>\n");
}
 
Example 15
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when the table name contains characters not allowed in XML.
 */
public void testTableNameContainsInvalidCharacters() throws Exception
{
    String   tableName   = "test\u0000table";
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName("value");
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName(tableName);
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = "Some Text";

    bean.set("id", new Integer(1));
    bean.set("value", testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <table id=\"1\" value=\"" + testedValue + "\">\n" +
                  "    <table-name " + DatabaseIO.BASE64_ATTR_NAME + "=\"true\">" + new String(Base64.encodeBase64(tableName.getBytes("UTF-8")), "UTF-8") + "</table-name>\n" +
                  "  </table>\n" +
                  "</data>\n");
}
 
Example 16
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 17
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 18
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 19
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 20
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;
}