Package org.apache.ddlutils.model

Examples of org.apache.ddlutils.model.Table


    {
        // TODO This needs some more work, since table names can be case sensitive or lowercase
        //      depending on the platform (really cute).
        //      See http://dev.mysql.com/doc/refman/4.1/en/name-case-sensitivity.html for more info.

        Table table = super.readTable(metaData, values);

        if (table != null)
        {
            determineAutoIncrementFromResultSetMetaData(table, table.getPrimaryKeyColumns());
        }
        return table;
    }
View Full Code Here


        if (tableName.indexOf('$') > 0)
        {
            return null;
        }

        Table table = super.readTable(metaData, values);

        if (table != null)
        {
            determineAutoIncrementColumns(table);
        }
View Full Code Here

        HashSet        processed = new HashSet();
        ListOrderedMap pending   = new ListOrderedMap();

        for (int idx = 0; idx < tables.length; idx++)
        {
            Table table = tables[idx];

            if (table.getForeignKeyCount() == 0)
            {
                result.add(table);
                processed.add(table);
            }
            else
            {
                HashSet waitedFor = new HashSet();

                for (int fkIdx = 0; fkIdx < table.getForeignKeyCount(); fkIdx++)
                {
                    Table waitedForTable = table.getForeignKey(fkIdx).getForeignTable();

                    if (!table.equals(waitedForTable))
                    {
                        waitedFor.add(waitedForTable);
                    }
                }
                pending.put(table, waitedFor);
            }
        }

        HashSet newProcessed = new HashSet();

        while (!processed.isEmpty() && !pending.isEmpty())
        {
            newProcessed.clear();
            for (Iterator it = pending.entrySet().iterator(); it.hasNext();)
            {
                Map.Entry entry     = (Map.Entry)it.next();
                Table     table     = (Table)entry.getKey();
                HashSet   waitedFor = (HashSet)entry.getValue();

                waitedFor.removeAll(processed);
                if (waitedFor.isEmpty())
                {
View Full Code Here

            rules.setCaseSensitive(isCaseSensitive());
            setRules(rules);
            for (int tableIdx = 0; tableIdx < _model.getTableCount(); tableIdx++)
            {
                // TODO: For now we hardcode the root as 'data' but ultimately we should wildcard it ('?')
                Table  table = _model.getTable(tableIdx);
                String path  = "data/"+table.getName();
   
                addRule(path, new DynaSqlCreateRule(_model, table, _sink));
                for (int columnIdx = 0; columnIdx < table.getColumnCount(); columnIdx++)
                {
                    Column           column    = (Column)table.getColumn(columnIdx);
                    SqlTypeConverter converter = _converterConf.getRegisteredConverter(table, column);
   
                    addRule(path, new SetColumnPropertyRule(column, converter, isCaseSensitive()));
                    addRule(path + "/" + column.getName(), new SetColumnPropertyFromSubElementRule(column, converter));
                }
View Full Code Here

            dropTables(database);
        }

        for (int idx = 0; idx < database.getTableCount(); idx++)
        {
            Table table = database.getTable(idx);

            writeTableComment(table);
            createTable(database,
                        table,
                        params == null ? null : params.getParametersFor(table));
View Full Code Here

        // we're dropping the unchanged foreign keys
        for (Iterator tableFKIt = unchangedFKs.entrySet().iterator(); tableFKIt.hasNext();)
        {
            Map.Entry entry       = (Map.Entry)tableFKIt.next();
            Table     targetTable = desiredModel.findTable((String)entry.getKey(), caseSensitive);

            for (Iterator fkIt = ((List)entry.getValue()).iterator(); fkIt.hasNext();)
            {
                writeExternalForeignKeyDropStmt(targetTable, (ForeignKey)fkIt.next());
            }
        }

        // We're using a copy of the current model so that the table structure changes can
        // modify it
        Database copyOfCurrentModel = null;

        try
        {
            copyOfCurrentModel = (Database)currentModel.clone();
        }
        catch (CloneNotSupportedException ex)
        {
            throw new DdlUtilsException(ex);
        }
       
        for (Iterator tableChangeIt = changesPerTable.entrySet().iterator(); tableChangeIt.hasNext();)
        {
            Map.Entry entry       = (Map.Entry)tableChangeIt.next();
            Table     targetTable = desiredModel.findTable((String)entry.getKey(), caseSensitive);

            processTableStructureChanges(copyOfCurrentModel,
                                         desiredModel,
                                         (String)entry.getKey(),
                                         params == null ? null : params.getParametersFor(targetTable),
                                         (List)entry.getValue());
        }
        // and finally we're re-creating the unchanged foreign keys
        for (Iterator tableFKIt = unchangedFKs.entrySet().iterator(); tableFKIt.hasNext();)
        {
            Map.Entry entry       = (Map.Entry)tableFKIt.next();
            Table     targetTable = desiredModel.findTable((String)entry.getKey(), caseSensitive);

            for (Iterator fkIt = ((List)entry.getValue()).iterator(); fkIt.hasNext();)
            {
                writeExternalForeignKeyCreateStmt(desiredModel, targetTable, (ForeignKey)fkIt.next());
            }
View Full Code Here

                                         Database desiredModel,
                                         String   tableName)
    {
        ArrayList unchangedFKs  = new ArrayList();
        boolean   caseSensitive = getPlatform().isDelimitedIdentifierModeOn();
        Table     sourceTable   = currentModel.findTable(tableName, caseSensitive);
        Table     targetTable   = desiredModel.findTable(tableName, caseSensitive);

        for (int idx = 0; idx < targetTable.getForeignKeyCount(); idx++)
        {
            ForeignKey targetFK = targetTable.getForeignKey(idx);
            ForeignKey sourceFK = sourceTable.findForeignKey(targetFK, caseSensitive);

            if (sourceFK != null)
            {
                unchangedFKs.add(targetFK);
View Full Code Here

    {
        boolean caseSensitive = getPlatform().isDelimitedIdentifierModeOn();

        for (int tableIdx = 0; tableIdx < desiredModel.getTableCount(); tableIdx++)
        {
            Table  targetTable = desiredModel.getTable(tableIdx);
            String name        = targetTable.getName();
            Table  sourceTable = currentModel.findTable(name, caseSensitive);
            List   relevantFks = null;

            if (!caseSensitive)
            {
                name = name.toUpperCase();
            }
            if ((sourceTable != null) && !namesOfKnownChangedTables.contains(name))
            {
                for (int fkIdx = 0; fkIdx < targetTable.getForeignKeyCount(); fkIdx++)
                {
                    ForeignKey targetFk = targetTable.getForeignKey(fkIdx);
                    ForeignKey sourceFk = sourceTable.findForeignKey(targetFk, caseSensitive);
                    String     refName  = targetFk.getForeignTableName();

                    if (!caseSensitive)
                    {
                        refName = refName.toUpperCase();
View Full Code Here

                                                Database desiredModel,
                                                String   tableName,
                                                Map      parameters,
                                                List     changes) throws IOException
    {
        Table sourceTable = currentModel.findTable(tableName, getPlatform().isDelimitedIdentifierModeOn());
        Table targetTable = desiredModel.findTable(tableName, getPlatform().isDelimitedIdentifierModeOn());

        // we're enforcing a full rebuild in case of the addition of a required
        // column without a default value that is not autoincrement
        boolean requiresFullRebuild = false;

        for (Iterator changeIt = changes.iterator(); !requiresFullRebuild && changeIt.hasNext();)
        {
            TableChange change = (TableChange)changeIt.next();

            if (change instanceof AddColumnChange)
            {
                AddColumnChange addColumnChange = (AddColumnChange)change;

                if (addColumnChange.getNewColumn().isRequired() &&
                    (addColumnChange.getNewColumn().getDefaultValue() == null) &&
                    !addColumnChange.getNewColumn().isAutoIncrement())
                {
                    requiresFullRebuild = true;
                }
            }
        }
        if (!requiresFullRebuild)
        {
            processTableStructureChanges(currentModel, desiredModel, sourceTable, targetTable, parameters, changes);
        }

        if (!changes.isEmpty())
        {
            // we can only copy the data if no required columns without default value and
            // non-autoincrement have been added
            boolean canMigrateData = true;

            for (Iterator it = changes.iterator(); canMigrateData && it.hasNext();)
            {
                TableChange change = (TableChange)it.next();

                if (change instanceof AddColumnChange)
                {
                    AddColumnChange addColumnChange = (AddColumnChange)change;

                    if (addColumnChange.getNewColumn().isRequired() &&
                        !addColumnChange.getNewColumn().isAutoIncrement() &&
                        (addColumnChange.getNewColumn().getDefaultValue() == null))
                    {
                        _log.warn("Data cannot be retained in table " + change.getChangedTable().getName() +
                                  " because of the addition of the required column " + addColumnChange.getNewColumn().getName());
                        canMigrateData = false;
                    }
                }
            }

            Table realTargetTable = getRealTargetTableFor(desiredModel, sourceTable, targetTable);

            if (canMigrateData)
            {
                Table tempTable = getTemporaryTableFor(desiredModel, targetTable);
   
                createTemporaryTable(desiredModel, tempTable, parameters);
                writeCopyDataStatement(sourceTable, tempTable);
                // Note that we don't drop the indices here because the DROP TABLE will take care of that
                // Likewise, foreign keys have already been dropped as necessary
View Full Code Here

     * @param targetTable The target table
     * @return The temporary table
     */
    protected Table getTemporaryTableFor(Database targetModel, Table targetTable) throws IOException
    {
        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++)
        {
            try
            {
                table.addColumn((Column)targetTable.getColumn(idx).clone());
            }
            catch (CloneNotSupportedException ex)
            {
                throw new DdlUtilsException(ex);
            }
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.