Examples of TableChange


Examples of org.apache.ddlutils.alteration.TableChange

        // 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;
                    }
                }
            }
View Full Code Here

Examples of org.apache.ddlutils.alteration.TableChange

                                                Map      parameters,
                                                List     changes) throws IOException
    {
        if (changes.size() == 1)
        {
            TableChange change = (TableChange)changes.get(0);

            if (change instanceof AddPrimaryKeyChange)
            {
                processChange(currentModel, desiredModel, (AddPrimaryKeyChange)change);
                changes.clear();
View Full Code Here

Examples of org.apache.ddlutils.alteration.TableChange

        //       This will be easier once named primary keys are supported
        boolean pkColumnAdded = false;

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

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

                // TODO: we cannot add columns to the primary key this way
                //       because we would have to drop the pk first and then
                //       add a new one afterwards which is not supported yet
                if (addColumnChange.getNewColumn().isPrimaryKey())
                {
                    pkColumnAdded = true;  
                }
                else
                {
                    processChange(currentModel, desiredModel, addColumnChange);
                    changeIt.remove();
                }
            }
            else if (change instanceof RemoveColumnChange)
            {
                RemoveColumnChange removeColumnChange = (RemoveColumnChange)change;

                // TODO: we cannot drop primary key columns this way
                //       because we would have to drop the pk first and then
                //       add a new one afterwards which is not supported yet
                if (!removeColumnChange.getColumn().isPrimaryKey())
                {
                    processChange(currentModel, desiredModel, removeColumnChange);
                    changeIt.remove();
                }
            }
        }
        for (Iterator changeIt = changes.iterator(); changeIt.hasNext();)
        {
            TableChange change = (TableChange)changeIt.next();

            // we can only add a primary key if all columns are present in the table
            // i.e. none was added during this alteration
            if ((change instanceof AddPrimaryKeyChange) && !pkColumnAdded)
            {
View Full Code Here

Examples of org.apache.ddlutils.alteration.TableChange

                                                List     changes) throws IOException
    {
        // DB2 provides only limited ways to alter a column, so we don't use them
        for (Iterator changeIt = changes.iterator(); changeIt.hasNext();)
        {
            TableChange change = (TableChange)changeIt.next();

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

                // DB2 can only add not insert columns
                // Also, DB2 does not allow the GENERATED BY DEFAULT AS IDENTITY clause in
                // the ALTER TABLE ADD COLUMN statement, so we have to rebuild the table instead
                if ((addColumnChange.getNextColumn() == null) && !addColumnChange.getNewColumn().isAutoIncrement())
                {
                    processChange(currentModel, desiredModel, addColumnChange);
                    changeIt.remove();
                }
            }
        }

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

            if (change instanceof AddPrimaryKeyChange)
            {
                processChange(currentModel, desiredModel, (AddPrimaryKeyChange)change);
                changeIt.remove();
View Full Code Here

Examples of org.apache.ddlutils.alteration.TableChange

                                                Map      parameters,
                                                List     changes) throws IOException
    {
        for (Iterator changeIt = changes.iterator(); changeIt.hasNext();)
        {
            TableChange change = (TableChange)changeIt.next();

            if (change instanceof AddColumnChange)
            {
                AddColumnChange addColumnChange = (AddColumnChange)change;
View Full Code Here

Examples of org.databene.mad4db.cmd.TableChange

  @Override
  public void compareObjects(DBTable table1, DBTable table2, CompositeStructuralChange<?> schemaChange) {
    if (!config.acceptTable(table1))
      return;
    TableChange tableChange = new TableChange(table1, table2);
    compareColumns(table1, table2, tableChange);
    comparePKs(table1, table2, tableChange);
    compareTableFKs(table1, table2, tableChange);
    compareTableUKs(table1, table2, tableChange);
    compareTableCKs(table1, table2, tableChange);
    if (!config.isIgnoringIndexes())
      compareIndexes(table1, table2, tableChange);
    if (tableChange.getSubChanges().size() > 0)
      schemaChange.addSubChange(tableChange);
  }
View Full Code Here

Examples of org.databene.mad4db.cmd.TableChange

    newColumn.setNotNullConstraint(constraint);
   
    NotNullConstraintCreation constraintCreation = new NotNullConstraintCreation(constraint);
    ColumnChange columnChange = new ColumnChange(newColumn);
    columnChange.addSubChange(constraintCreation);
    TableChange tableChange = new TableChange(oldTable, newTable);
    tableChange.addSubChange(columnChange);
   
    assertFalse(new ChangeByAffectedObjectFilter(newColumn2).accept(columnChange));
    assertFalse(new ChangeByAffectedObjectFilter(oldColumn2).accept(columnChange));
    assertTrue(new ChangeByAffectedObjectFilter(newColumn).accept(columnChange));
    assertTrue(new ChangeByAffectedObjectFilter(oldColumn).accept(columnChange));
View Full Code Here

Examples of org.databene.mad4db.cmd.TableChange

    Filter<StructuralChange<?>> filter = new ConstraintOperationFilter();
    for (StructuralChange<?> constraintOperation : schemaChange.getSubChanges(filter)) {
      DBConstraint constraint = (DBConstraint) constraintOperation.getAffectedObject();
      String[] columns = (constraintOperation instanceof CheckConstraintChange ? ((CheckConstraintChange) constraintOperation).getNewCheck().getColumnNames() : constraint.getColumnNames());
      String tableName = constraint.getTable().getName();
      TableChange tableChange = schemaChange.getSubChange(TableChange.class, tableName);
      boolean containsNewColumn = false;
      boolean containsNewMandatoryColumn = false;
      for (ColumnCreation columnCreation : tableChange.getSubChanges(ColumnCreation.class)) {
        boolean newColumn = ArrayUtil.contains(columnCreation.getAffectedObject().getName(), columns);
        if (newColumn) {
          containsNewColumn = true;
          if (!columnCreation.getAffectedObject().isNullable())
            containsNewMandatoryColumn = true;
View Full Code Here

Examples of org.databene.mad4db.cmd.TableChange

    // given a table of which the index has not changed
    DBTable table = createTableWithColumns("tbl", 3);
    DBIndex index1 = new DBNonUniqueIndex("idx", true, table, "col1");
    DBIndex index2 = new DBNonUniqueIndex("idx", true, table, "col1");
    // when performing a comparison
    TableChange tableChange = new TableChange(table, null);
    new IndexComparator(new ComparisonConfig("db1", "db2", null)).compareObjects(index1, index2, tableChange);
    // then the result must be empty
    System.out.println(tableChange);
    List<StructuralChange<?>> indexChanges = tableChange.getSubChanges();
    assertEquals(0, indexChanges.size());
  }
View Full Code Here

Examples of org.databene.mad4db.cmd.TableChange

  public void testIndexMadeUnique() {
    // given an index which only changed by becoming unique
    DBTable table = createTableWithColumns("tbl", 3);
    DBIndex index1 = new DBNonUniqueIndex("idx", true, table, "col1");
    DBIndex index2 = new DBUniqueIndex("idx", true, new DBUniqueConstraint(table, "uk1", false, "col1"));
    TableChange tableChange = new TableChange(table, null);
    // when performing a comparison
    new IndexComparator(config).compareObjects(index1, index2, tableChange);
    // then the result must be an IndexUniquenessChange
    System.out.println(tableChange);
    List<StructuralChange<?>> indexSubChanges = assertSingleSubChangeAndGetItsSubChanges(IndexChange.class,
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.