Java Code Examples for org.apache.ddlutils.model.Table#addColumn()

The following examples show how to use org.apache.ddlutils.model.Table#addColumn() . 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: PlatformImplBase.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a temporary table object that corresponds to the given table.
 * Database-specific implementations may redefine this method if e.g. the
 * database directly supports temporary tables. The default implementation
 * simply appends an underscore to the table name and uses that as the
 * table name.  
 * 
 * @param targetTable The target table
 * @return The temporary table
 */
protected Table getTemporaryTableFor(Table targetTable)
{
    CloneHelper cloneHelper = new CloneHelper();
    Table       table       = new Table();

    table.setCatalog(targetTable.getCatalog());
    table.setSchema(targetTable.getSchema());
    table.setName(targetTable.getName() + "_");
    table.setType(targetTable.getType());
    for (int idx = 0; idx < targetTable.getColumnCount(); idx++)
    {
        // TODO: clone PK status ?
        table.addColumn(cloneHelper.clone(targetTable.getColumn(idx), true));
    }

    return table;
}
 
Example 2
Source File: PlatformImplBase.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a temporary table object that corresponds to the given table.
 * Database-specific implementations may redefine this method if e.g. the
 * database directly supports temporary tables. The default implementation
 * simply appends an underscore to the table name and uses that as the
 * table name.  
 * 
 * @param targetTable The target table
 * @return The temporary table
 */
protected Table getTemporaryTableFor(Table targetTable)
{
    CloneHelper cloneHelper = new CloneHelper();
    Table       table       = new Table();

    table.setCatalog(targetTable.getCatalog());
    table.setSchema(targetTable.getSchema());
    table.setName(targetTable.getName() + "_");
    table.setType(targetTable.getType());
    for (int idx = 0; idx < targetTable.getColumnCount(); idx++)
    {
        // TODO: clone PK status ?
        table.addColumn(cloneHelper.clone(targetTable.getColumn(idx), true));
    }

    return table;
}
 
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 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 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 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 5
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 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 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 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 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 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 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 9
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Reads table sub elements (column, foreign key, index) from the XML stream reader and adds
 * them to the given table.
 * 
 * @param xmlReader The reader
 * @param table     The table
 */
private void readTableSubElements(XMLStreamReader xmlReader, Table table) throws XMLStreamException, IOException
{
    int eventType = XMLStreamReader.START_ELEMENT;

    while (eventType != XMLStreamReader.END_ELEMENT)
    {
        eventType = xmlReader.next();
        if (eventType == XMLStreamReader.START_ELEMENT)
        {
            QName elemQName = xmlReader.getName();

            if (isSameAs(elemQName, QNAME_ELEMENT_COLUMN))
            {
                table.addColumn(readColumnElement(xmlReader));
            }
            else if (isSameAs(elemQName, QNAME_ELEMENT_FOREIGN_KEY))
            {
                table.addForeignKey(readForeignKeyElement(xmlReader));
            }
            else if (isSameAs(elemQName, QNAME_ELEMENT_INDEX))
            {
                table.addIndex(readIndexElement(xmlReader));
            }
            else if (isSameAs(elemQName, QNAME_ELEMENT_UNIQUE))
            {
                table.addIndex(readUniqueElement(xmlReader));
            }
            else {
                readOverElement(xmlReader);
            }
        }
    }
}
 
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 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 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 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 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 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 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 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 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 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 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: 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 17
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 18
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 19
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Reads table sub elements (column, foreign key, index) from the XML stream reader and adds
 * them to the given table.
 * 
 * @param xmlReader The reader
 * @param table     The table
 */
private void readTableSubElements(XMLStreamReader xmlReader, Table table) throws XMLStreamException, IOException
{
    int eventType = XMLStreamReader.START_ELEMENT;

    while (eventType != XMLStreamReader.END_ELEMENT)
    {
        eventType = xmlReader.next();
        if (eventType == XMLStreamReader.START_ELEMENT)
        {
            QName elemQName = xmlReader.getName();

            if (isSameAs(elemQName, QNAME_ELEMENT_COLUMN))
            {
                table.addColumn(readColumnElement(xmlReader));
            }
            else if (isSameAs(elemQName, QNAME_ELEMENT_FOREIGN_KEY))
            {
                table.addForeignKey(readForeignKeyElement(xmlReader));
            }
            else if (isSameAs(elemQName, QNAME_ELEMENT_INDEX))
            {
                table.addIndex(readIndexElement(xmlReader));
            }
            else if (isSameAs(elemQName, QNAME_ELEMENT_UNIQUE))
            {
                table.addIndex(readUniqueElement(xmlReader));
            }
            else {
                readOverElement(xmlReader);
            }
        }
    }
}
 
Example 20
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());

}