Java Code Examples for liquibase.resource.FileSystemResourceAccessor

The following examples show how to use liquibase.resource.FileSystemResourceAccessor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: flux   Source File: MigrationsRunner.java    License: Apache License 2.0 6 votes vote down vote up
public void migrate(String dbName) {
    try {
        Configuration configuration = yamlConfiguration.subset(dbName + ".Hibernate");
        Properties properties = new Properties();
        properties.put("user", configuration.getProperty("hibernate.connection.username"));
        properties.put("password", configuration.getProperty("hibernate.connection.password"));
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        String url = (String) configuration.getProperty("hibernate.connection.url");
        java.sql.Connection connection = DriverManager.getConnection(url, properties);
        Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
        ClassLoader classLoader = getClass().getClassLoader();
        File file = new File(classLoader.getResource(dbName +  "/migrations.xml").getFile());
        Liquibase liquibase = new Liquibase(file.getCanonicalPath(), new FileSystemResourceAccessor(), database);
        liquibase.update(new Contexts());
    } catch (Exception e) {
        System.err.println("Unable to perform database migration.");
        e.printStackTrace();
    }
}
 
Example 2
Source Project: modeldb   Source File: ModelDBHibernateUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static void createTablesLiquibaseMigration(MetadataSources metaDataSrc)
    throws LiquibaseException, SQLException, InterruptedException {
  // Get database connection
  try (Connection con =
      metaDataSrc.getServiceRegistry().getService(ConnectionProvider.class).getConnection()) {
    JdbcConnection jdbcCon = new JdbcConnection(con);

    // Overwrite default liquibase table names by custom
    GlobalConfiguration liquibaseConfiguration =
        LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class);
    liquibaseConfiguration.setDatabaseChangeLogLockWaitTime(1L);

    // Initialize Liquibase and run the update
    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(jdbcCon);
    String rootPath = System.getProperty(ModelDBConstants.userDir);
    rootPath = rootPath + "\\src\\main\\resources\\liquibase\\db-changelog-1.0.xml";
    Liquibase liquibase = new Liquibase(rootPath, new FileSystemResourceAccessor(), database);

    boolean liquibaseExecuted = false;
    while (!liquibaseExecuted) {
      try {
        liquibase.update(new Contexts(), new LabelExpression());
        liquibaseExecuted = true;
      } catch (LockException ex) {
        LOGGER.warn(
            "ModelDBHibernateUtil createTablesLiquibaseMigration() getting LockException ", ex);
        releaseLiquibaseLock(metaDataSrc);
      }
    }
  }
}
 
Example 3
Source Project: Singularity   Source File: SingularityCuratorTestBase.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeAll
public void setup() throws Exception {
  JerseyGuiceUtils.reset();
  singularityTestModule = new SingularityTestModule(useDBTests, customConfigSetup);

  singularityTestModule.getInjector().injectMembers(this);
  singularityTestModule.start();
  leaderCacheCoordinator.activateLeaderCache();
  configuration.setThreadpoolShutdownDelayInSeconds(0);
  if (useDBTests) {
    Handle handle = dbiProvider.get().open();
    handle.getConnection().setAutoCommit(true);

    Database database = DatabaseFactory
      .getInstance()
      .findCorrectDatabaseImplementation(new JdbcConnection(handle.getConnection()));

    Liquibase liquibase = new Liquibase(
      "singularity_test.sql",
      new FileSystemResourceAccessor(),
      database
    );
    liquibase.update((String) null);

    try {
      database.close();
      handle.close();
    } catch (Throwable t) {}
  }
}
 
Example 4
Source Project: aerogear-unifiedpush-server   Source File: MigratorTest.java    License: Apache License 2.0 4 votes vote down vote up
private void initResourceAccessor() {
    String baseDir = "target/classes/liquibase";
    resourceAccessor = new FileSystemResourceAccessor(baseDir);
}
 
Example 5
Source Project: hmdm-server   Source File: LiquibaseModule.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * <p>Gets the resource accessor to be uused for loading the change log file.</p>
 *
 * @return a resource accessor for change log file.
 */
@Override
protected ResourceAccessor getResourceAccessor() {
    return new FileSystemResourceAccessor();
}