Package org.databene.mad4db.cmd

Examples of org.databene.mad4db.cmd.SchemaChange


  public void testIndexCreated() {
    // given a table of which an index was added
    DBTable table1 = createTableWithColumns("tbl", 2);
    DBTable table2 = createTableWithColumns("tbl", 2);
    new DBNonUniqueIndex("idx", true, table2, "col1");
    SchemaChange schemaChange = new SchemaChange(config);
    // when comparing the tables
    new TableComparator(config).compareObjects(table1, table2, schemaChange);
    // then the result must be an index creation
    System.out.println(schemaChange);
    List<StructuralChange<?>> tableChanges = assertSingleSubChangeAndGetItsSubChanges(TableChange.class, DBTable.class, "tbl", ChangeSeverity.REORGANIZATION, schemaChange);
View Full Code Here


  public void testIndexDeleted() {
    // given a table of which an index was deleted
    DBTable table1 = createTableWithColumns("tbl", 2);
    new DBNonUniqueIndex("idx", true, table1, "col1");
    DBTable table2 = createTableWithColumns("tbl", 2);
    SchemaChange schemaChange = new SchemaChange(config);
    // when comparing the tables
    new TableComparator(config).compareObjects(table1, table2, schemaChange);
    // then the result must be an index deletion
    System.out.println(schemaChange);
    List<StructuralChange<?>> tableChanges = assertSingleSubChangeAndGetItsSubChanges(TableChange.class, DBTable.class, "tbl", ChangeSeverity.REORGANIZATION, schemaChange);
View Full Code Here

    // given a table of which an index was redefined to another column
    DBTable table1 = createTableWithColumns("tbl", 2);
    new DBNonUniqueIndex("idx", true, table1, "col1");
    DBTable table2 = createTableWithColumns("tbl", 2);
    new DBNonUniqueIndex("idx", true, table1, "col2");
    SchemaChange schemaChange = new SchemaChange(config);
    // when comparing the tables
    new TableComparator(config).compareObjects(table1, table2, schemaChange);
    // then the result must be an index deletion and an index creation
    System.out.println(schemaChange);
    List<StructuralChange<?>> tableChanges = assertSingleSubChangeAndGetItsSubChanges(TableChange.class, DBTable.class, "tbl", ChangeSeverity.REORGANIZATION, schemaChange);
View Full Code Here

    DBSchema schema2 = new DBSchema("public", cat2);
    DBTable table2 = createTableWithColumns("tbl", 3);
    schema2.addTable(table2);
   
    // when comparing the tables
    SchemaChange schemaChange = new SchemaComparator(config).compare(db1, db2);
   
    // then the result must be empty
    System.out.println(schemaChange);
    List<StructuralChange<?>> tableChanges = schemaChange.getSubChanges();
    assertEquals(0, tableChanges.size());
  }
View Full Code Here

  @Test
  public void testColumnsAdded() {
    // given a table which got two additional columns
    DBTable table1 = createTableWithColumns("tbl", 2);
    DBTable table2 = createTableWithColumns("tbl", 4);
    SchemaChange schemaChange = new SchemaChange(config);
    // when comparing the tables
    new TableComparator(config).compareObjects(table1, table2, schemaChange);
    // then the result must be two ColumnCreations
    System.out.println(schemaChange);
    List<StructuralChange<?>> tableChanges = assertSingleSubChangeAndGetItsSubChanges(TableChange.class, DBTable.class, "tbl", ChangeSeverity.EXTENSION, schemaChange);
View Full Code Here

  @Test
  public void testColumnsRemoved() {
    // given a table of which two columns were removed
    DBTable table1 = createTableWithColumns("tbl", 4);
    DBTable table2 = createTableWithColumns("tbl", 2);
    SchemaChange schemaChange = new SchemaChange(config);
    // when comparing the tables
    new TableComparator(config).compareObjects(table1, table2, schemaChange);
    // then the result must be two ColumnDeletions
    System.out.println(schemaChange);
    List<StructuralChange<?>> tableChanges = assertSingleSubChangeAndGetItsSubChanges(TableChange.class, DBTable.class, "tbl", ChangeSeverity.DELETION, schemaChange);
View Full Code Here

    Database db1 = config.getMetaData1();
    Database db2 = config.getMetaData2();
   
    LOGGER.info("Comparing databases...");
    SchemaComparator comparator = new SchemaComparator(config);
    SchemaChange schemaChange = comparator.compare(db1, db2);
    LOGGER.info("Database comparison finished");
   
    // print out all changes
    System.out.println("All Changes:");
    System.out.println(schemaChange);

    // process changes
    System.out.println("Processing changes...");
    for (SchemaChangeProcessor processor : processors)
      processor.process(schemaChange);
   
    // run db sanity checks for the restrictions
    CachingDBImporter.updateCacheFile(db2); // save cache file for DB Sanity
    int errorCount = 0;
    if (checkingData && schemaChange.countChanges() > 0)
      errorCount = checkRestrictions(schemaChange);

    createReport(schemaChange);
   
    // the report modules are likely to have fetched additional detail data,
    // so we should make a cache update at the very end
    CachingDBImporter.updateCacheFile(db1);
    CachingDBImporter.updateCacheFile(db2);
   
    // print profile if requested
    if (Profiling.isEnabled())
      CounterRepository.getInstance().printSummary();
   
    // create result code
    if (schemaChange.countChanges() == 0)
      return MadResult.UNCHANGED;
    return (errorCount > 0 ? MadResult.ERROR : MadResult.CHANGED);
  }
View Full Code Here

TOP

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

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.