liquibase.Liquibase.getDatabase()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(267)

本文整理了Java中liquibase.Liquibase.getDatabase()方法的一些代码示例,展示了Liquibase.getDatabase()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Liquibase.getDatabase()方法的具体详情如下:
包路径:liquibase.Liquibase
类名称:Liquibase
方法名:getDatabase

Liquibase.getDatabase介绍

暂无

代码示例

代码示例来源:origin: dropwizard/dropwizard

final Database database = liquibase.getDatabase();

代码示例来源:origin: openmrs/openmrs-core

for (String changelogFile : changeLogFilenames) {
  Liquibase liquibase = getLiquibase(changelogFile, null);
  database = liquibase.getDatabase();
  List<ChangeSet> changeSets = liquibase.listUnrunChangeSets(CONTEXT);

代码示例来源:origin: openmrs/openmrs-core

/**
   * This method currently checks the liquibasechangeloglock table to see if there is a row
   * with a lock in it.  This uses the liquibase API to do this
   *
   * @return true if database is currently locked
   */
  public static boolean isLocked() {
    Database database = null;
    try {
      Liquibase liquibase = getLiquibase(null, null);
      database = liquibase.getDatabase();
      return LockService.getInstance(database).listLocks().length > 0;
    }
    catch (Exception e) {
      return false;
    }
    finally {
      try {
        database.getConnection().close();
      }
      catch (Exception e) {
        // pass
      }
    }
  }
}

代码示例来源:origin: openmrs/openmrs-core

database = liquibase.getDatabase();
DatabaseChangeLog changeLog = new XMLChangeLogSAXParser().parse(CHANGE_LOG_FILE, new ChangeLogParameters(),
  liquibase.getFileOpener());

代码示例来源:origin: openmrs/openmrs-core

/**
 * Interface used for callbacks when updating the database. Implement this interface and pass it
 * to {@link DatabaseUpdater#executeChangelog(String, Map, ChangeSetExecutorCallback)}
 */
public interface ChangeSetExecutorCallback {
  
  /**
   * This method is called after each changeset is executed.
   *
   * @param changeSet the liquibase changeset that was just run
   * @param numChangeSetsToRun the total number of changesets in the current file
   */
  public void executing(ChangeSet changeSet, int numChangeSetsToRun);
}

代码示例来源:origin: openmrs/openmrs-core

database = liquibase.getDatabase();
if (database.hasDatabaseChangeLogLockTable() && isLocked()) {
  LockService.getInstance(database).forceReleaseLock();

代码示例来源:origin: org.flowable/flowable-form-engine

private void closeDatabase(Liquibase liquibase) {
  if (liquibase != null) {
    Database database = liquibase.getDatabase();
    if (database != null) {
      try {
        database.close();
      } catch (DatabaseException e) {
        logger.warn("Error closing database", e);
      }
    }
  }
}

代码示例来源:origin: org.flowable/flowable-ui-admin-conf

private void closeDatabase(Liquibase liquibase) {
    if (liquibase != null) {
      Database database = liquibase.getDatabase();
      if (database != null) {
        try {
          database.close();
        } catch (DatabaseException e) {
          LOGGER.warn("Error closing database", e);
        }
      }
    }
  }
}

代码示例来源:origin: org.flowable/flowable-form-engine

private void closeDatabase(Liquibase liquibase) {
  if (liquibase != null) {
    Database database = liquibase.getDatabase();
    if (database != null) {
      // do not close the shared connection if a command context is currently active
      if (CommandContextUtil.getCommandContext() == null) {
        try {
          database.close();
        } catch (DatabaseException e) {
          LOGGER.warn("Error closing database", e);
        }
      }
    }
  }
}

代码示例来源:origin: org.flowable/flowable-content-engine

private void closeDatabase(Liquibase liquibase) {
    if (liquibase != null) {
      Database database = liquibase.getDatabase();
      if (database != null) {
        // do not close the shared connection if a command context is currently active
        if (CommandContextUtil.getCommandContext() == null) {
          try {
            database.close();
          } catch (DatabaseException e) {
            LOGGER.warn("Error closing database", e);
          }
        }
      }
    }
  }
}

代码示例来源:origin: org.flowable/flowable-dmn-engine

private void closeDatabase(Liquibase liquibase) {
    if (liquibase != null) {
      Database database = liquibase.getDatabase();
      if (database != null) {
        // do not close the shared connection if a command context is currently active
        if (CommandContextUtil.getCommandContext() == null) {
          try {
            database.close();
          } catch (DatabaseException e) {
            LOGGER.warn("Error closing database", e);
          }
        }
      }
    }
  }
}

代码示例来源:origin: org.flowable/flowable-app-engine

private void closeDatabase(Liquibase liquibase) {
    if (liquibase != null) {
      Database database = liquibase.getDatabase();
      if (database != null) {
        // do not close the shared connection if a command context is currently active
        if (CommandContextUtil.getCommandContext() == null) {
          try {
            database.close();
          } catch (DatabaseException e) {
            LOGGER.warn("Error closing database", e);
          }
        }
      }
    }
  }
}

代码示例来源:origin: org.flowable/flowable-cmmn-engine

private void closeDatabase(Liquibase liquibase) {
    if (liquibase != null) {
      Database database = liquibase.getDatabase();
      if (database != null) {
        // do not close the shared connection if a command context is currently active
        if (CommandContextUtil.getCommandContext() == null) {
          try {
            database.close();
          } catch (DatabaseException e) {
            LOGGER.warn("Error closing database", e);
          }
        }
      }
    }
  }
}

代码示例来源:origin: org.apache.polygene.libraries/org.apache.polygene.library.sql-liquibase

@Override
  public void applyChangelog( Map<String, Object> parameters )
    throws SQLException, LiquibaseException
  {
    Liquibase liquibase = null;
    try
    {
      liquibase = newConnectedLiquibase();
      for( Map.Entry<String, Object> entry : parameters.entrySet() )
      {
        liquibase.getChangeLogParameters().set( entry.getKey(), entry.getValue() );
      }
      liquibase.update( config.get().contexts().get() );
    }
    finally
    {
      if( liquibase != null )
      {
        liquibase.getDatabase().close();
      }
    }
  }
}

代码示例来源:origin: apache/attic-polygene-java

@Override
  public void applyChangelog( Map<String, Object> parameters )
    throws SQLException, LiquibaseException
  {
    Liquibase liquibase = null;
    try
    {
      liquibase = newConnectedLiquibase();
      for( Map.Entry<String, Object> entry : parameters.entrySet() )
      {
        liquibase.getChangeLogParameters().set( entry.getKey(), entry.getValue() );
      }
      liquibase.update( config.get().contexts().get() );
    }
    finally
    {
      if( liquibase != null )
      {
        liquibase.getDatabase().close();
      }
    }
  }
}

代码示例来源:origin: org.keycloak/keycloak-model-jpa

private void lazyInit() {
  if (!initialized) {
    LiquibaseConnectionProvider liquibaseProvider = session.getProvider(LiquibaseConnectionProvider.class);
    JpaConnectionProviderFactory jpaProviderFactory = (JpaConnectionProviderFactory) session.getKeycloakSessionFactory().getProviderFactory(JpaConnectionProvider.class);
    this.dbConnection = jpaProviderFactory.getConnection();
    String defaultSchema = jpaProviderFactory.getSchema();
    try {
      Liquibase liquibase = liquibaseProvider.getLiquibase(dbConnection, defaultSchema);
      this.lockService = new CustomLockService();
      lockService.setChangeLogLockWaitTime(factory.getLockWaitTimeoutMillis());
      lockService.setDatabase(liquibase.getDatabase());
      initialized = true;
    } catch (LiquibaseException exception) {
      safeRollbackConnection();
      safeCloseConnection();
      throw new IllegalStateException(exception);
    }
  }
}

代码示例来源:origin: org.opennms.core/org.opennms.core.schema

/**
 * <p>migrate</p>
 *
 * @param migration a {@link org.opennms.core.schema.Migration} object.
 * @throws org.opennms.core.schema.MigrationException if any.
 */
public void migrate(final Migration migration) throws MigrationException {
  Connection connection = null;
  DatabaseConnection dbConnection = null;
  try {
    connection = m_dataSource.getConnection();
    dbConnection = new JdbcConnection(connection);
    ResourceAccessor accessor = migration.getAccessor();
    if (accessor == null) accessor = new SpringResourceAccessor();
    final Liquibase liquibase = new Liquibase( migration.getChangeLog(), accessor, dbConnection );
    liquibase.setChangeLogParameter("install.database.admin.user", migration.getAdminUser());
    liquibase.setChangeLogParameter("install.database.admin.password", migration.getAdminPassword());
    liquibase.setChangeLogParameter("install.database.user", migration.getDatabaseUser());
    liquibase.getDatabase().setDefaultSchemaName(migration.getSchemaName());
    final String contexts = System.getProperty("opennms.contexts", "production");
    liquibase.update(contexts);
  } catch (final Throwable e) {
    throw new MigrationException("unable to migrate the database", e);
  } finally {
    cleanUpDatabase(connection, dbConnection, null, null);
  }
}

代码示例来源:origin: org.flowable/flowable-content-engine

public static void main(String[] args) {
    try {
      ContentEngine contentEngine = ContentEngines.getDefaultContentEngine();
      DataSource dataSource = contentEngine.getContentEngineConfiguration().getDataSource();

      DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
      Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
      database.setDatabaseChangeLogTableName(ContentEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());
      database.setDatabaseChangeLogLockTableName(ContentEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());

      if (StringUtils.isNotEmpty(contentEngine.getContentEngineConfiguration().getDatabaseSchema())) {
        database.setDefaultSchemaName(contentEngine.getContentEngineConfiguration().getDatabaseSchema());
        database.setLiquibaseSchemaName(contentEngine.getContentEngineConfiguration().getDatabaseSchema());
      }

      if (StringUtils.isNotEmpty(contentEngine.getContentEngineConfiguration().getDatabaseCatalog())) {
        database.setDefaultCatalogName(contentEngine.getContentEngineConfiguration().getDatabaseCatalog());
        database.setLiquibaseCatalogName(contentEngine.getContentEngineConfiguration().getDatabaseCatalog());
      }

      Liquibase liquibase = new Liquibase("org/flowable/content/db/liquibase/flowable-content-db-changelog.xml", new ClassLoaderResourceAccessor(), database);
      liquibase.dropAll();
      liquibase.getDatabase().close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: org.flowable/flowable-dmn-engine

public static void main(String[] args) {
    try {
      DmnEngine dmnEngine = DmnEngines.getDefaultDmnEngine();
      DataSource dataSource = dmnEngine.getDmnEngineConfiguration().getDataSource();

      DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
      Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
      database.setDatabaseChangeLogTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());
      database.setDatabaseChangeLogLockTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());

      if (StringUtils.isNotEmpty(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema())) {
        database.setDefaultSchemaName(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema());
        database.setLiquibaseSchemaName(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema());
      }

      if (StringUtils.isNotEmpty(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog())) {
        database.setDefaultCatalogName(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog());
        database.setLiquibaseCatalogName(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog());
      }

      Liquibase liquibase = new Liquibase("org/flowable/dmn/db/liquibase/flowable-dmn-db-changelog.xml", new ClassLoaderResourceAccessor(), database);
      liquibase.dropAll();
      liquibase.getDatabase().close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: org.keycloak/keycloak-model-jpa

private void outputChangeLogTableCreationScript(Liquibase liquibase, final Writer exportWriter) throws DatabaseException {
  Database database = liquibase.getDatabase();
  Executor oldTemplate = ExecutorService.getInstance().getExecutor(database);
  LoggingExecutor executor = new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), exportWriter, database);
  ExecutorService.getInstance().setExecutor(database, executor);
  executor.comment("*********************************************************************");
  executor.comment("* Keycloak database creation script - apply this script to empty DB *");
  executor.comment("*********************************************************************" + StreamUtil.getLineSeparator());
  executor.execute(new CreateDatabaseChangeLogTableStatement());
  // DatabaseChangeLogLockTable is created before this code is executed and recreated if it does not exist automatically
  // in org.keycloak.connections.jpa.updater.liquibase.lock.CustomLockService.init() called indirectly from
  // KeycloakApplication constructor (search for waitForLock() call). Hence it is not included in the creation script.
  executor.comment("*********************************************************************" + StreamUtil.getLineSeparator());
  ExecutorService.getInstance().setExecutor(database, oldTemplate);
}

相关文章