@Test
 public void testEdnParser() throws LiquibaseException {
   ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor();
   Connection connection = getH2Connection();
   DatabaseConnection databaseConnection = new JdbcConnection(connection);
   Liquibase lb = new Liquibase(changeLogFile, resourceAccessor, databaseConnection);
   lb.update("");
 }
예제 #2
0
 private void liquibaseDropAll(Application application) {
   Liquibase liquibase = null;
   try {
     liquibase = newLiquibase(application);
     liquibase.dropAll();
   } catch (ClassNotFoundException | LiquibaseException | SQLException ex) {
     throw new WervalException("Unable to drop database data: " + ex.getMessage(), ex);
   } finally {
     closeLiquibaseSilently(liquibase);
   }
 }
예제 #3
0
 private void liquibaseUpdate(Application application) {
   Liquibase liquibase = null;
   try {
     liquibase = newLiquibase(application);
     liquibase.update(EMPTY);
   } catch (ClassNotFoundException | LiquibaseException | SQLException ex) {
     throw new WervalException("Unable to apply database changelog: " + ex.getMessage(), ex);
   } finally {
     closeLiquibaseSilently(liquibase);
   }
 }
  private void runLiquibaseUpdate(Connection connection) {
    try {
      ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor();
      Database database =
          DatabaseFactory.getInstance()
              .findCorrectDatabaseImplementation(new JdbcConnection(connection));
      Liquibase liquibase = new Liquibase(getChangeLogFile(), resourceAccessor, database);

      liquibase.update(getContext());
    } catch (LiquibaseException e) {
      throw new RuntimeException(e);
    }
  }
  public void upgrade() throws IOException, SQLException {
    try {
      Liquibase liquibase =
          new Liquibase(
              "liquibase-update-to-latest.xml",
              new ClassLoaderResourceAccessor(getClass().getClassLoader()),
              liqubaseConnection);
      liquibase.update(null);

      connection.commit();
    } catch (LiquibaseException e) {
      throw new IOException(e);
    }
  }
예제 #6
0
 public void setUp(String contexts) {
   try {
     ResourceAccessor resourceAccessor = new FileSystemResourceAccessor();
     Class.forName("org.hsqldb.jdbcDriver");
     holdingConnection = getConnectionImpl();
     HsqlConnection hsconn = new HsqlConnection(holdingConnection);
     LogFactory.getLogger().setLogLevel("severe");
     liquibase = new Liquibase(CHANGE_LOG, resourceAccessor, hsconn);
     liquibase.dropAll();
     liquibase.update(contexts);
     hsconn.close();
   } catch (Exception e) {
     LOG.error("Error during database initialization", e);
     throw new RuntimeException("Error during database initialization", e);
   }
 }
예제 #7
0
 private void closeLiquibaseSilently(Liquibase liquibase) {
   if (liquibase != null) {
     try {
       liquibase.getDatabase().getConnection().close();
     } catch (DatabaseException ignored) {
     }
   }
 }
예제 #8
0
 public void checkSchema(String schema) throws LiquibaseException {
   Connection connection = resolveConnection();
   ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
   ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor(classLoader);
   Database database =
       DatabaseFactory.getInstance()
           .findCorrectDatabaseImplementation(new JdbcConnection(connection));
   Liquibase liquibase = new Liquibase(schema, resourceAccessor, database);
   liquibase.forceReleaseLocks();
   LOG.info("Comprobando actualizaciones de esquema de BBDD");
   liquibase.update("");
   LOG.info("Comprobacion de esquema de BBDD finalizada");
   try {
     connection.close();
   } catch (SQLException ignore) {
   }
 }
    @Override
    protected void starting(final Description description) {

      // ----------------------
      // Clear the cache
      // ----------------------
      try {
        context.clearCache();
      } catch (NamingException e) {
        e.printStackTrace();
        throw new Error(e);
      }

      // --------------------
      // Gain liquidbaseList
      // --------------------
      TestInputSet dataSetAnnnotation =
          (TestInputSet) description.getAnnotation(TestInputSet.class);
      if (null != dataSetAnnnotation) {
        for (String value : dataSetAnnnotation.value()) {
          // databaseChangeLogXmlList.add( value );

          try {
            Liquibase liquibase = new Liquibase(value, new FileSystemResourceAccessor(), database);
            liquibaseList.add(liquibase);
          } catch (LiquibaseException e) {
            e.printStackTrace();
            throw new Error(e);
          }
        }
      }

      // ----------------------
      // Clears all tables
      // Fill out tables
      // ----------------------
      for (Liquibase liquibase : liquibaseList) {
        try {
          liquibase.update("");
        } catch (LiquibaseException e) {
          e.printStackTrace();
          throw new Error(e);
        }
      }
    }
 public void contextInitialized(ServletContextEvent arg0) {
   try {
     ConfigDBMapper.getInstance().setDefaultConnectionName("fatec");
     Connection conn = ConfigDBMapper.getInstance().getDefaultConnection();
     Database database =
         DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(conn));
     Liquibase liquibase =
         new Liquibase(
             "br/com/fatec/aulas/liquibase/changelog-master.xml",
             new ClassLoaderResourceAccessor(),
             database);
     liquibase.forceReleaseLocks();
     liquibase.update("fatec");
     conn.prepareStatement("COMMIT;").execute();
   } catch (Exception e) {
     // TODO: handle exception
   }
 }
    @Override
    protected void finished(final Description description) {
      super.finished(description);

      try {
        for (Liquibase liquibase : liquibaseList) {
          liquibase.rollback(1000, null);
        }
      } catch (Exception e) {
        e.printStackTrace();
        throw new Error(e);
      } finally {
        try {
          conn.close();
        } catch (Exception f) {
        }
      }
    }
예제 #12
0
  @Override
  public void execute() throws BuildException {
    super.execute();

    Liquibase liquibase = null;
    try {
      PrintStream writer = createPrintStream();
      if (writer == null) {
        throw new BuildException("generateChangeLog requires outputFile to be set");
      }

      liquibase = createLiquibase();

      Database database = liquibase.getDatabase();
      DiffControl diffControl =
          new DiffControl(
              getDefaultCatalogName(), getDefaultSchemaName(), null, null, getDiffTypes());
      diffControl.setDataDir(getDataDir());

      DatabaseSnapshot referenceSnapshot =
          DatabaseSnapshotGeneratorFactory.getInstance()
              .createSnapshot(database, diffControl, DiffControl.DatabaseRole.REFERENCE);

      DiffResult diffResult =
          DiffGeneratorFactory.getInstance()
              .compare(referenceSnapshot, new DatabaseSnapshot(database), diffControl);
      //			diff.addStatusListener(new OutDiffStatusListener());

      if (getChangeLogFile() == null) {
        new DiffToChangeLog(diffResult).print(writer);
      } else {
        new DiffToChangeLog(diffResult).print(getChangeLogFile());
      }

      writer.flush();
      writer.close();
    } catch (Exception e) {
      throw new BuildException(e);
    } finally {
      closeDatabase(liquibase);
    }
  }
예제 #13
0
  private static void initDB() throws LiquibaseException {
    Database database =
        DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(conn));

    // TODO: We should not point to a relative file outside of the project.
    liquibase =
        new Liquibase(
            "../task-management/src/main/resources/db/changelog/db.changelog-1.0.0.xml",
            new FileSystemResourceAccessor(),
            database);
    liquibase.update((String) null);
  }
예제 #14
0
 public static void cleanDB() throws Exception {
   liquiBase = new Liquibase(changeLogFile, new ClassLoaderResourceAccessor(), jdbcConnection);
   liquiBase.dropAll();
 }
 @Override
 protected void doUpdate(Liquibase liquibase) throws LiquibaseException {
   liquibase.updateTestingRollback(contexts);
 }
예제 #16
0
 public static void closeDB() throws LiquibaseException, SQLException {
   liquibase.rollback(1000, null);
   conn.close();
 }