Package org.databene.mad4db.cmd

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


    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

    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

    // 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

  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

  public void testIndexMadeNonUnique() {
    // given an index which was unique before but is not now
    DBTable table = createTableWithColumns("tbl", 3);
    DBIndex index1 = new DBUniqueIndex("idx", true, new DBUniqueConstraint(table, "uk1", false, "col1"));
    DBIndex index2 = new DBNonUniqueIndex("idx", true, table, "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

  public void testColumnOrderChanged() {
    // given a table with an index of which the column order changed
    DBTable table = createTableWithColumns("tbl", 2);
    DBIndex index1 = new DBNonUniqueIndex("idx", true, table, "col1", "col2");
    DBIndex index2 = new DBNonUniqueIndex("idx", true, table, "col2", "col1");
    TableChange tableChange = new TableChange(table, null);
    // when performing a comparison
    new IndexComparator(config).compareObjects(index1, index2, tableChange);
    // then the result must be a ColumnOrderChange
    System.out.println(tableChange);
    List<StructuralChange<?>> indexSubChanges = assertSingleSubChangeAndGetItsSubChanges(IndexChange.class,
View Full Code Here

  public void testSingleIndexColumnReplaced() {
    // given an index consisting of exactly one column which was replaced in a newer index version
    DBTable table = createTableWithColumns("tbl", 2);
    DBIndex index1 = new DBNonUniqueIndex("idx", true, table, "col1");
    DBIndex index2 = new DBNonUniqueIndex("idx", true, table, "col2");
    TableChange tableChange = new TableChange(table, null);
    // when performing a comparison
    new IndexComparator(config).compareObjects(index1, index2, tableChange);
    // then the result must be deletion of the former index version and creation of the new one
    System.out.println(tableChange);
    List<StructuralChange<?>> indexChanges = tableChange.getSubChanges();
    assertEquals(2, indexChanges.size());
    assertChange(IndexDeletion.class, DBIndex.class, "idx", ChangeSeverity.REORGANIZATION, indexChanges.get(0));
    assertChange(IndexCreation.class, DBIndex.class, "idx", ChangeSeverity.REORGANIZATION, indexChanges.get(1));
  }
View Full Code Here

  public void testAllIndexColumnsReplaced() {
    // given an index consisting of two columns which are replaced in a newer index version
    DBTable table = createTableWithColumns("tbl", 4);
    DBIndex index1 = new DBNonUniqueIndex("idx", true, table, "col1", "col2");
    DBIndex index2 = new DBNonUniqueIndex("idx", true, table, "col3", "col4");
    TableChange tableChange = new TableChange(table, null);
    // when performing a comparison
    new IndexComparator(config).compareObjects(index1, index2, tableChange);
    // then the result must be deletion of the former index version and creation of the new one
    System.out.println(tableChange);
    List<StructuralChange<?>> indexChanges = tableChange.getSubChanges();
    assertEquals(2, indexChanges.size());
    assertChange(IndexDeletion.class, DBIndex.class, "idx", ChangeSeverity.REORGANIZATION, indexChanges.get(0));
    assertChange(IndexCreation.class, DBIndex.class, "idx", ChangeSeverity.REORGANIZATION, indexChanges.get(1));
  }
View Full Code Here

  public void testIndexColumnAdded() {
    // given a tbale with an index to which one more column has been added
    DBTable table = createTableWithColumns("tbl", 2);
    DBIndex index1 = new DBNonUniqueIndex("idx", true, table, "col1");
    DBIndex index2 = new DBNonUniqueIndex("idx", true, table, "col1", "col2");
    TableChange tableChange = new TableChange(table, null);
    // when performing a comparison
    new IndexComparator(config).compareObjects(index1, index2, tableChange);
    // then the result must be a ColumnsAddition
    System.out.println(tableChange);
    List<StructuralChange<?>> indexSubChanges = assertSingleSubChangeAndGetItsSubChanges(IndexChange.class,
View Full Code Here

TOP

Related Classes of org.databene.mad4db.cmd.TableChange

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.