Package org.apache.ddlutils.model

Examples of org.apache.ddlutils.model.Table


        writer.println("<!-- DTD for XML data files for database "+model.getName()+" -->\n");
        writer.println("<!ELEMENT data (");
        for (int idx = 0; idx < model.getTableCount(); idx++)
        {
            Table table = model.getTable(idx);

            writer.print("    "+table.getName());
            if (idx < model.getTableCount() - 1)
            {
                writer.println(" |");
            }
            else
View Full Code Here


        for (int idx = 1; idx <= metaData.getColumnCount(); idx++)
        {
            String columnName    = metaData.getColumnName(idx);
            String tableOfColumn = metaData.getTableName(idx);
            Table  table         = null;

            if ((tableOfColumn != null) && (tableOfColumn.length() > 0))
            {
                // jConnect might return a table name enclosed in quotes
                if (tableOfColumn.startsWith("\"") && tableOfColumn.endsWith("\"") && (tableOfColumn.length() > 1))
                {
                    tableOfColumn = tableOfColumn.substring(1, tableOfColumn.length() - 1);
                }
                // the JDBC driver gave us enough meta data info
                table = model.findTable(tableOfColumn, _caseSensitive);
            }
            else
            {
                // not enough info in the meta data of the result set, lets try the
                // user-supplied query hints
                table         = (Table)_preparedQueryHints.get(_caseSensitive ? columnName : columnName.toLowerCase());
                tableOfColumn = (table == null ? null : table.getName());
            }
            if (tableName == null)
            {
                tableName = tableOfColumn;
            }
            else if (!tableName.equals(tableOfColumn))
            {
                singleKnownTable = false;
            }

            String propName = columnName;

            if (table != null)
            {
                Column column = table.findColumn(columnName, _caseSensitive);

                if (column != null)
                {
                    propName = column.getName();
                }
View Full Code Here

        else
        {
            try
            {
                DynaBean bean  = _dynaClass.newInstance();
                Table    table = null;

                if (bean instanceof SqlDynaBean)
                {
                    SqlDynaClass dynaClass = (SqlDynaClass)((SqlDynaBean)bean).getDynaClass();

                    table = dynaClass.getTable();
                }

                for (Iterator it = _columnsToProperties.entrySet().iterator(); it.hasNext();)
                {
                    Map.Entry entry      = (Map.Entry)it.next();
                    String    columnName = (String)entry.getKey();
                    String    propName   = (String)entry.getValue();
                    Table     curTable   = table;

                    if (curTable == null)
                    {
                        curTable = (Table)_preparedQueryHints.get(_caseSensitive ? columnName : columnName.toLowerCase());
                    }
View Full Code Here

            if (param.isForPlatform(platformName))
            {
                for (int idx = 0; idx < model.getTableCount(); idx++)
                {
                    Table table = model.getTable(idx);

                    if (param.isForTable(table, isCaseSensitive))
                    {
                        parameters.addParameter(table, param.getName(), param.getValue());
                    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    protected Table readTable(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
    {
        Table table = super.readTable(metaData, values);

        if (table != null)
        {
            // PostgreSQL also returns unique indics for non-pk auto-increment columns
            // which are of the form "[table]_[column]_key"
            HashMap uniquesByName = new HashMap();
   
            for (int indexIdx = 0; indexIdx < table.getIndexCount(); indexIdx++)
            {
                Index index = table.getIndex(indexIdx);
   
                if (index.isUnique() && (index.getName() != null))
                {
                    uniquesByName.put(index.getName(), index);
                }
            }
            for (int columnIdx = 0; columnIdx < table.getColumnCount(); columnIdx++)
            {
                Column column = table.getColumn(columnIdx);
                if (column.isAutoIncrement() && !column.isPrimaryKey())
                {
                    String indexName = table.getName() + "_" + column.getName() + "_key";
   
                    if (uniquesByName.containsKey(indexName))
                    {
                        table.removeIndex((Index)uniquesByName.get(indexName));
                        uniquesByName.remove(indexName);
                    }
                }
            }
        }
View Full Code Here

    {
        boolean hasError = false;

        for (int idx = 0; idx < model.getTableCount(); idx++)
        {
            Table    table  = model.getTable(idx);
            Column[] pkCols = table.getPrimaryKeyColumns();

            for (Iterator it = origDbPlatform.query(model, buildQueryString(origDbPlatform, table, null, null), new Table[] { table }); it.hasNext();)
            {
                DynaBean   obj    = (DynaBean)it.next();
                Collection result = testedDbPlatform.fetch(model, buildQueryString(origDbPlatform, table, pkCols, obj), new Table[] { table });
View Full Code Here

        assertEquals("test",
                     model.getName());
        assertEquals(1,
                     model.getTableCount());
       
        Table table = model.getTable(0);

        assertEquals("SomeTable",
                     table.getName());
        assertNull(table.getDescription());
        assertEquals(0, table.getAutoIncrementColumns().length);
        assertEquals(2,
                     table.getColumnCount());
        assertEquals(0,
                     table.getForeignKeyCount());
        assertEquals(0,
                     table.getIndexCount());

        Column column = table.getColumn(0);

        assertEquals("intField",
                     column.getName());
        assertEquals("TINYINT",
                     column.getType());
        assertEquals(Types.TINYINT,
                     column.getTypeCode());
        assertFalse(column.isPrimaryKey());
        assertFalse(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertNull(column.getDescription());

        column = table.getColumn(1);

        assertEquals("charField",
                     column.getName());
        assertEquals("CHAR",
                     column.getType());
View Full Code Here

     * @param tableName    The name of the table (case insensitive)
     * @param columnValues The values for the columns in order of definition
     */
    protected void insertRow(String tableName, Object[] columnValues)
    {
        Table    table = getModel().findTable(tableName);
        DynaBean bean  = getModel().createDynaBeanFor(table);

        for (int idx = 0; (idx < table.getColumnCount()) && (idx < columnValues.length); idx++)
        {
            Column column = table.getColumn(idx);

            bean.set(column.getName(), columnValues[idx]);
        }
        getPlatform().insert(getModel(), bean);
    }
View Full Code Here

        assertEquals("test",
                     model.getName());
        assertEquals(1,
                     model.getTableCount());
       
        Table table = model.getTable(0);

        assertEquals("SomeTable",
                     table.getName());
        assertEquals("Some table",
                     table.getDescription());
        assertEquals(0, table.getAutoIncrementColumns().length);
        assertEquals(1,
                     table.getColumnCount());
        assertEquals(0,
                     table.getForeignKeyCount());
        assertEquals(0,
                     table.getIndexCount());

        Column column = table.getColumn(0);

        assertEquals("ID",
                     column.getName());
        assertEquals("INTEGER",
                     column.getType());
View Full Code Here

        assertEquals("test",
                     model.getName());
        assertEquals(2,
                     model.getTableCount());

        Table someTable = model.getTable(0);

        assertEquals("SomeTable",
                     someTable.getName());
        assertEquals("Some table",
                     someTable.getDescription());
        assertEquals(0, someTable.getAutoIncrementColumns().length);
        assertEquals(1,
                     someTable.getColumnCount());
        assertEquals(0,
                     someTable.getForeignKeyCount());
        assertEquals(0,
                     someTable.getIndexCount());

        Column pkColumn = someTable.getColumn(0);

        assertEquals("ID",
                     pkColumn.getName());
        assertEquals("VARCHAR",
                     pkColumn.getType());
        assertEquals(Types.VARCHAR,
                     pkColumn.getTypeCode());
        assertEquals(16,
                     pkColumn.getSizeAsInt());
        assertTrue(pkColumn.isPrimaryKey());
        assertTrue(pkColumn.isRequired());
        assertFalse(pkColumn.isAutoIncrement());
        assertNull(pkColumn.getDefaultValue());
        assertEquals("The primary key",
                     pkColumn.getDescription());

        Table anotherTable = model.getTable(1);

        assertEquals("AnotherTable",
                     anotherTable.getName());
        assertEquals("And another table",
                     anotherTable.getDescription());
        assertEquals(0, anotherTable.getAutoIncrementColumns().length);
        assertEquals(1,
                     anotherTable.getColumnCount());
        assertEquals(1,
                     anotherTable.getForeignKeyCount());
        assertEquals(0,
                     anotherTable.getIndexCount());

        Column fkColumn = anotherTable.getColumn(0);

        assertEquals("Some_ID",
                     fkColumn.getName());
        assertEquals("VARCHAR",
                     fkColumn.getType());
        assertEquals(Types.VARCHAR,
                     fkColumn.getTypeCode());
        assertEquals(16,
                     fkColumn.getSizeAsInt());
        assertFalse(fkColumn.isPrimaryKey());
        assertFalse(fkColumn.isRequired());
        assertFalse(fkColumn.isAutoIncrement());
        assertEquals("The foreign key",
                     fkColumn.getDescription());

        ForeignKey fk = anotherTable.getForeignKey(0);

        assertNull(fk.getName());
        assertEquals(someTable,
                     fk.getForeignTable());
        assertEquals(someTable.getName(),
View Full Code Here

TOP

Related Classes of org.apache.ddlutils.model.Table

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.