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

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

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

Liquibase.getDatabase介绍

暂无

代码示例

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

  1. final Database database = liquibase.getDatabase();

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

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

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

  1. /**
  2. * This method currently checks the liquibasechangeloglock table to see if there is a row
  3. * with a lock in it. This uses the liquibase API to do this
  4. *
  5. * @return true if database is currently locked
  6. */
  7. public static boolean isLocked() {
  8. Database database = null;
  9. try {
  10. Liquibase liquibase = getLiquibase(null, null);
  11. database = liquibase.getDatabase();
  12. return LockService.getInstance(database).listLocks().length > 0;
  13. }
  14. catch (Exception e) {
  15. return false;
  16. }
  17. finally {
  18. try {
  19. database.getConnection().close();
  20. }
  21. catch (Exception e) {
  22. // pass
  23. }
  24. }
  25. }
  26. }

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

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

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

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

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

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

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

  1. private void closeDatabase(Liquibase liquibase) {
  2. if (liquibase != null) {
  3. Database database = liquibase.getDatabase();
  4. if (database != null) {
  5. try {
  6. database.close();
  7. } catch (DatabaseException e) {
  8. logger.warn("Error closing database", e);
  9. }
  10. }
  11. }
  12. }

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

  1. private void closeDatabase(Liquibase liquibase) {
  2. if (liquibase != null) {
  3. Database database = liquibase.getDatabase();
  4. if (database != null) {
  5. try {
  6. database.close();
  7. } catch (DatabaseException e) {
  8. LOGGER.warn("Error closing database", e);
  9. }
  10. }
  11. }
  12. }
  13. }

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

  1. private void closeDatabase(Liquibase liquibase) {
  2. if (liquibase != null) {
  3. Database database = liquibase.getDatabase();
  4. if (database != null) {
  5. // do not close the shared connection if a command context is currently active
  6. if (CommandContextUtil.getCommandContext() == null) {
  7. try {
  8. database.close();
  9. } catch (DatabaseException e) {
  10. LOGGER.warn("Error closing database", e);
  11. }
  12. }
  13. }
  14. }
  15. }

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

  1. private void closeDatabase(Liquibase liquibase) {
  2. if (liquibase != null) {
  3. Database database = liquibase.getDatabase();
  4. if (database != null) {
  5. // do not close the shared connection if a command context is currently active
  6. if (CommandContextUtil.getCommandContext() == null) {
  7. try {
  8. database.close();
  9. } catch (DatabaseException e) {
  10. LOGGER.warn("Error closing database", e);
  11. }
  12. }
  13. }
  14. }
  15. }
  16. }

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

  1. private void closeDatabase(Liquibase liquibase) {
  2. if (liquibase != null) {
  3. Database database = liquibase.getDatabase();
  4. if (database != null) {
  5. // do not close the shared connection if a command context is currently active
  6. if (CommandContextUtil.getCommandContext() == null) {
  7. try {
  8. database.close();
  9. } catch (DatabaseException e) {
  10. LOGGER.warn("Error closing database", e);
  11. }
  12. }
  13. }
  14. }
  15. }
  16. }

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

  1. private void closeDatabase(Liquibase liquibase) {
  2. if (liquibase != null) {
  3. Database database = liquibase.getDatabase();
  4. if (database != null) {
  5. // do not close the shared connection if a command context is currently active
  6. if (CommandContextUtil.getCommandContext() == null) {
  7. try {
  8. database.close();
  9. } catch (DatabaseException e) {
  10. LOGGER.warn("Error closing database", e);
  11. }
  12. }
  13. }
  14. }
  15. }
  16. }

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

  1. private void closeDatabase(Liquibase liquibase) {
  2. if (liquibase != null) {
  3. Database database = liquibase.getDatabase();
  4. if (database != null) {
  5. // do not close the shared connection if a command context is currently active
  6. if (CommandContextUtil.getCommandContext() == null) {
  7. try {
  8. database.close();
  9. } catch (DatabaseException e) {
  10. LOGGER.warn("Error closing database", e);
  11. }
  12. }
  13. }
  14. }
  15. }
  16. }

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

  1. @Override
  2. public void applyChangelog( Map<String, Object> parameters )
  3. throws SQLException, LiquibaseException
  4. {
  5. Liquibase liquibase = null;
  6. try
  7. {
  8. liquibase = newConnectedLiquibase();
  9. for( Map.Entry<String, Object> entry : parameters.entrySet() )
  10. {
  11. liquibase.getChangeLogParameters().set( entry.getKey(), entry.getValue() );
  12. }
  13. liquibase.update( config.get().contexts().get() );
  14. }
  15. finally
  16. {
  17. if( liquibase != null )
  18. {
  19. liquibase.getDatabase().close();
  20. }
  21. }
  22. }
  23. }

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

  1. @Override
  2. public void applyChangelog( Map<String, Object> parameters )
  3. throws SQLException, LiquibaseException
  4. {
  5. Liquibase liquibase = null;
  6. try
  7. {
  8. liquibase = newConnectedLiquibase();
  9. for( Map.Entry<String, Object> entry : parameters.entrySet() )
  10. {
  11. liquibase.getChangeLogParameters().set( entry.getKey(), entry.getValue() );
  12. }
  13. liquibase.update( config.get().contexts().get() );
  14. }
  15. finally
  16. {
  17. if( liquibase != null )
  18. {
  19. liquibase.getDatabase().close();
  20. }
  21. }
  22. }
  23. }

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

  1. private void lazyInit() {
  2. if (!initialized) {
  3. LiquibaseConnectionProvider liquibaseProvider = session.getProvider(LiquibaseConnectionProvider.class);
  4. JpaConnectionProviderFactory jpaProviderFactory = (JpaConnectionProviderFactory) session.getKeycloakSessionFactory().getProviderFactory(JpaConnectionProvider.class);
  5. this.dbConnection = jpaProviderFactory.getConnection();
  6. String defaultSchema = jpaProviderFactory.getSchema();
  7. try {
  8. Liquibase liquibase = liquibaseProvider.getLiquibase(dbConnection, defaultSchema);
  9. this.lockService = new CustomLockService();
  10. lockService.setChangeLogLockWaitTime(factory.getLockWaitTimeoutMillis());
  11. lockService.setDatabase(liquibase.getDatabase());
  12. initialized = true;
  13. } catch (LiquibaseException exception) {
  14. safeRollbackConnection();
  15. safeCloseConnection();
  16. throw new IllegalStateException(exception);
  17. }
  18. }
  19. }

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

  1. /**
  2. * <p>migrate</p>
  3. *
  4. * @param migration a {@link org.opennms.core.schema.Migration} object.
  5. * @throws org.opennms.core.schema.MigrationException if any.
  6. */
  7. public void migrate(final Migration migration) throws MigrationException {
  8. Connection connection = null;
  9. DatabaseConnection dbConnection = null;
  10. try {
  11. connection = m_dataSource.getConnection();
  12. dbConnection = new JdbcConnection(connection);
  13. ResourceAccessor accessor = migration.getAccessor();
  14. if (accessor == null) accessor = new SpringResourceAccessor();
  15. final Liquibase liquibase = new Liquibase( migration.getChangeLog(), accessor, dbConnection );
  16. liquibase.setChangeLogParameter("install.database.admin.user", migration.getAdminUser());
  17. liquibase.setChangeLogParameter("install.database.admin.password", migration.getAdminPassword());
  18. liquibase.setChangeLogParameter("install.database.user", migration.getDatabaseUser());
  19. liquibase.getDatabase().setDefaultSchemaName(migration.getSchemaName());
  20. final String contexts = System.getProperty("opennms.contexts", "production");
  21. liquibase.update(contexts);
  22. } catch (final Throwable e) {
  23. throw new MigrationException("unable to migrate the database", e);
  24. } finally {
  25. cleanUpDatabase(connection, dbConnection, null, null);
  26. }
  27. }

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

  1. public static void main(String[] args) {
  2. try {
  3. ContentEngine contentEngine = ContentEngines.getDefaultContentEngine();
  4. DataSource dataSource = contentEngine.getContentEngineConfiguration().getDataSource();
  5. DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
  6. Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
  7. database.setDatabaseChangeLogTableName(ContentEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());
  8. database.setDatabaseChangeLogLockTableName(ContentEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());
  9. if (StringUtils.isNotEmpty(contentEngine.getContentEngineConfiguration().getDatabaseSchema())) {
  10. database.setDefaultSchemaName(contentEngine.getContentEngineConfiguration().getDatabaseSchema());
  11. database.setLiquibaseSchemaName(contentEngine.getContentEngineConfiguration().getDatabaseSchema());
  12. }
  13. if (StringUtils.isNotEmpty(contentEngine.getContentEngineConfiguration().getDatabaseCatalog())) {
  14. database.setDefaultCatalogName(contentEngine.getContentEngineConfiguration().getDatabaseCatalog());
  15. database.setLiquibaseCatalogName(contentEngine.getContentEngineConfiguration().getDatabaseCatalog());
  16. }
  17. Liquibase liquibase = new Liquibase("org/flowable/content/db/liquibase/flowable-content-db-changelog.xml", new ClassLoaderResourceAccessor(), database);
  18. liquibase.dropAll();
  19. liquibase.getDatabase().close();
  20. } catch (Exception e) {
  21. e.printStackTrace();
  22. }
  23. }
  24. }

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

  1. public static void main(String[] args) {
  2. try {
  3. DmnEngine dmnEngine = DmnEngines.getDefaultDmnEngine();
  4. DataSource dataSource = dmnEngine.getDmnEngineConfiguration().getDataSource();
  5. DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
  6. Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
  7. database.setDatabaseChangeLogTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());
  8. database.setDatabaseChangeLogLockTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());
  9. if (StringUtils.isNotEmpty(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema())) {
  10. database.setDefaultSchemaName(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema());
  11. database.setLiquibaseSchemaName(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema());
  12. }
  13. if (StringUtils.isNotEmpty(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog())) {
  14. database.setDefaultCatalogName(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog());
  15. database.setLiquibaseCatalogName(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog());
  16. }
  17. Liquibase liquibase = new Liquibase("org/flowable/dmn/db/liquibase/flowable-dmn-db-changelog.xml", new ClassLoaderResourceAccessor(), database);
  18. liquibase.dropAll();
  19. liquibase.getDatabase().close();
  20. } catch (Exception e) {
  21. e.printStackTrace();
  22. }
  23. }
  24. }

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

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

相关文章