liquibase.Liquibase类的使用及代码示例

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

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

Liquibase介绍

暂无

代码示例

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

@Override
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public void run(Namespace namespace, Liquibase liquibase) throws Exception {
  final String context = getContext(namespace);
  final Integer count = namespace.getInt("count");
  final boolean dryRun = namespace.getBoolean("dry-run") == null ? false : namespace.getBoolean("dry-run");
  if (count != null) {
    if (dryRun) {
      liquibase.update(count, context, new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));
    } else {
      liquibase.update(count, context);
    }
  } else {
    if (dryRun) {
      liquibase.update(context, new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));
    } else {
      liquibase.update(context);
    }
  }
}

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

private void initDatabaseSchema() throws SQLException, LiquibaseException {
  if (config.hasKey("database.changelog")) {
    ResourceAccessor resourceAccessor = new FileSystemResourceAccessor();
    Database database = DatabaseFactory.getInstance().openDatabase(
        config.getString("database.url"),
        config.getString("database.user"),
        config.getString("database.password"),
        config.getString("database.driver"),
        null, null, null, resourceAccessor);
    Liquibase liquibase = new Liquibase(
        config.getString("database.changelog"), resourceAccessor, database);
    liquibase.clearCheckSums();
    liquibase.update(new Contexts());
  }
}

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

final Set<Class<? extends DatabaseObject>> compareTypes = new HashSet<>();
if (isTrue(namespace.getBoolean("columns"))) {
  compareTypes.add(Column.class);
if (isTrue(namespace.getBoolean("data"))) {
  compareTypes.add(Data.class);
if (isTrue(namespace.getBoolean("foreign-keys"))) {
  compareTypes.add(ForeignKey.class);
final Database database = liquibase.getDatabase();
final String filename = namespace.getString("output");
if (filename != null) {
  try (PrintStream file = new PrintStream(filename, StandardCharsets.UTF_8.name())) {
    generateChangeLog(database, database.getDefaultSchema(), diffToChangeLog, file, compareTypes);
  generateChangeLog(database, database.getDefaultSchema(), diffToChangeLog, outputStream, compareTypes);

代码示例来源:origin: HubSpot/Singularity

@Before
public void createTestData() throws Exception {
 Handle handle = dbiProvider.get().open();
 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();
 } catch (Throwable t) {
 }
 handle.close();
}

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

DatabaseConnection connection = new JdbcConnection(jdbcConnection);
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
database.setDatabaseChangeLogTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());
database.setDatabaseChangeLogLockTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());
Liquibase liquibase = new Liquibase(LIQUIBASE_CHANGELOG, new ClassLoaderResourceAccessor(), database);
return liquibase;

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

Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(
  new JdbcConnection(connection));
database.setDatabaseChangeLogTableName("liquibasechangelog");
database.setDatabaseChangeLogLockTableName("liquibasechangeloglock");
  database.setDatabaseChangeLogTableName(database.getDatabaseChangeLogTableName().toUpperCase());
  database.setDatabaseChangeLogLockTableName(database.getDatabaseChangeLogLockTableName().toUpperCase());
database.checkDatabaseChangeLogTable(false, null, null);
return new Liquibase(changeLogFile, new CompositeResourceAccessor(openmrsFO, fsFO), database);

代码示例来源:origin: com.peterphi.std.guice/stdlib-guice-liquibase

ResourceAccessor threadClFO = new ClassLoaderResourceAccessor(contextClassLoader);
    ResourceAccessor clFO = new ClassLoaderResourceAccessor();
  database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
  database.setDefaultSchemaName(defaultSchema);
Liquibase liquibase = new Liquibase(changeLogFile, resourceAccessor, database);
  liquibase.setChangeLogParameter(param.getKey(), param.getValue());
    List<ChangeSet> unrun = liquibase.listUnrunChangeSets(new Contexts(contexts), new LabelExpression(labels));
  case UPDATE:
    liquibase.update(new Contexts(contexts), new LabelExpression(labels));
    return;
  case MARK_UPDATED:
    liquibase.changeLogSync(new Contexts(contexts), new LabelExpression(labels));
    return;
  case GENERATE_CHANGELOG:
    liquibase.generateChangeLog(catalogueAndSchema, writer, pw);

代码示例来源:origin: ch.inftec.ju/ju-testing

@Override
public void execute(Connection conn) {
  try {
    JdbcConnection jdbcConn = new JdbcConnection(conn);
    Database db = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(jdbcConn);
    if (dbType == DbType.ORACLE) {
      db.setDefaultSchemaName(metaDataUserName);
    ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor();
    if (dbType == DbType.DERBY || dbType == DbType.H2 || dbType == DbType.HSQL) {
      resourceAccessor = new ResourceAccessorFilter(resourceAccessor);
    Liquibase liquibase = new Liquibase(changeLogResourceName, resourceAccessor, db);
        liquibase.setChangeLogParameter(key, parameters.get(key));
    liquibase.update((String)null);
  } catch (Exception ex) {
    throw new JuRuntimeException("Couldn't run Liquibase Update %s", ex, changeLogResourceName);

代码示例来源:origin: OpenNMS/opennms

/**
 * <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: com.moodysalem.java/jaxrs-lib

/**
 * Run the migrations in the changelog associated with this entity manager
 */
private void runMigrations(String changelogFile, String url, String user, String password, String context) {
  if (changelogFile != null) {
    try (Connection c = DriverManager.getConnection(url, user, password)) {
      LOG.info("Running Migrations");
      // first run the liquibase migrations against the database
      Liquibase lb = new Liquibase(changelogFile, new ClassLoaderResourceAccessor(), new JdbcConnection(c));
      lb.update(context);
    } catch (LiquibaseException e) {
      LOG.log(Level.SEVERE, "Liquibase exception thrown while trying to run migrations", e);
    } catch (SQLException e) {
      LOG.log(Level.SEVERE, "SQL Exception thrown while trying to open a connection", e);
    }
  } else {
    LOG.info("No changelog file specified, not running migrations.");
  }
}

代码示例来源:origin: stackoverflow.com

public void verify(DataSource ds) {
   boolean throwException = false;
   Contexts contexts = new Contexts("");
   for(LiquibaseConfiguration c : configs) {
     try(Connection con = ds.getConnection()) {
         Database db = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(con));
         db.setDatabaseChangeLogLockTableName(c.changeLogLockTableName());
         db.setDatabaseChangeLogTableName(c.changeLogTableName());
         Liquibase liquibase = new ShureviewNonCreationLiquibase(c.liquibaseResource(), new ClassLoaderResourceAccessor(), db);
         liquibase.getLog();
         liquibase.validate();
         List<ChangeSet> listUnrunChangeSets = liquibase.listUnrunChangeSets(contexts, new LabelExpression());
         if(!listUnrunChangeSets.isEmpty()) {
           StringWriter writer = new StringWriter();
           liquibase.update(contexts, writer);
           liquibase.futureRollbackSQL(writer);
           log.warn(writer.toString());
           throwException = true;
         }
     } catch (SQLException | LiquibaseException e) {
       throw new RuntimeException("Failed to verify database.", e);
     }
   }
   if(throwException){
     throw new RuntimeException("Unrun changesets in chengelog.");
   }
 }

代码示例来源:origin: io.choerodon/choerodon-liquibase

Liquibase liquibase = new Liquibase("drop", accessor, new JdbcConnection(additionDataSource.getDataSource().getConnection()));
  liquibase.dropAll();
Liquibase liquibase = new Liquibase("clearCheckSums", accessor, new JdbcConnection(additionDataSource.getDataSource().getConnection()));
liquibase.clearCheckSums();
    liquibase = new Liquibase(file, accessor, new JdbcConnection(additionDataSource.getDataSource().getConnection()));
    liquibase.update(new Contexts());

代码示例来源:origin: com.expanset.utils/utils-dbmigration

final ConnectionProvider connectionProvider = 
      sessionManager.getPersistenceContext(key, ConnectionProvider.class, null)) {
final Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(
    new JdbcConnection(connectionProvider.provide()) {
      @Override
if(database.supportsCatalogs() && StringUtils.isNotEmpty(catalogName)) {
  database.setDefaultCatalogName(catalogName);
  database.setOutputDefaultCatalog(true);
  final Liquibase liquibase = new Liquibase(
      changeLogFile, 
      new ClassLoaderResourceAccessor(), 
      database);
  if (expressionVars != null) {
    for (Map.Entry<Object, Object> var : expressionVars.entrySet()) {
      liquibase.setChangeLogParameter(var.getKey().toString(), var.getValue());

代码示例来源:origin: stackoverflow.com

// Create the test database with the LiquiBase migrations.
@BeforeClass
public static void up() throws Exception
{
  ManagedDataSource ds = RULE.getConfiguration().getMainDataSource().build(
    RULE.getEnvironment().metrics(), "migrations");
  try (Connection connection = ds.getConnection())
  {
    Liquibase migrator = new Liquibase("migrations.xml", new ClassLoaderResourceAccessor(), new JdbcConnection(connection));
    migrator.update("");
  }
}

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

@Override
public Liquibase newConnectedLiquibase() throws SQLException, LiquibaseException
{
  config.refresh();
  DatabaseConnection dbConnection = new JdbcConnection( dataSource.get().getConnection() );
  return new Liquibase( config.get().changeLog().get(),
             new ClassLoaderResourceAccessor(),
             dbConnection );
}

代码示例来源:origin: vmware/admiral

private static void update(DataSource ds, String changeLogFile,
    ResourceAccessor resourceAccessor) throws Exception {
  // TODO: workaround to resolve locking issue with postgres
  checkLiquibaseTables(ds);
  try (Connection conn = ds.getConnection()) {
    Contexts contexts = new Contexts("");
    LabelExpression labels = new LabelExpression();
    Liquibase liquibase = new Liquibase(changeLogFile, resourceAccessor,
        new JdbcConnection(conn));
    // Check if update is needed without locking liquibase tables
    List<ChangeSet> changes = liquibase.listUnrunChangeSets(contexts, labels);
    if (changes.isEmpty()) {
      return;
    }
    // Release locks on timeout
    releaseLockOnTimeout(liquibase);
    // Reset liquibase as it has cached the run change sets during the
    // listUnrunChangeSets() call which happens before acquiring the update lock and may
    // miss latest entries
    ChangeLogHistoryServiceFactory.getInstance().resetAll();
    // Update
    liquibase.update(contexts, labels);
  }
}

代码示例来源:origin: stackoverflow.com

java.sql.Connection c = YOUR_CONNECTION;
 Liquibase liquibase = null;
 try {
   Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(c))
   liquibase = new Liquibase(YOUR_CHANGELOG, new FileSystemResourceAccessor(), database);
   liquibase.update();
 } catch (SQLException e) {
   throw new DatabaseException(e);
 } finally {
   if (c != null) {
     try {
       c.rollback();
       c.close();
     } catch (SQLException e) {
       //nothing to do
     }
   }
 }

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

public void upgrade(String filename) throws IOException, SQLException {
  try {
    Liquibase liquibase = new Liquibase(filename, new ClassLoaderResourceAccessor(getClass()
        .getClassLoader()), liqubaseConnection);
    liquibase.update(null);
    
    connection.commit();
  }
  catch (LiquibaseException e) {
    throw new IOException(e);
  }
}

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

public void initSchema(ContentEngineConfiguration configuration, String databaseSchemaUpdate) {
  Liquibase liquibase = null;
  try {
    liquibase = createLiquibaseInstance(configuration);
    if (ContentEngineConfiguration.DB_SCHEMA_UPDATE_DROP_CREATE.equals(databaseSchemaUpdate)) {
      LOGGER.debug("Dropping and creating schema Content");
      liquibase.dropAll();
      liquibase.update("content");
    } else if (ContentEngineConfiguration.DB_SCHEMA_UPDATE_TRUE.equals(databaseSchemaUpdate)) {
      LOGGER.debug("Updating schema Content");
      liquibase.update("content");
    } else if (ContentEngineConfiguration.DB_SCHEMA_UPDATE_FALSE.equals(databaseSchemaUpdate)) {
      LOGGER.debug("Validating schema Content");
      liquibase.validate();
    }
  } catch (Exception e) {
    throw new FlowableException("Error initialising Content schema", e);
  } finally {
    closeDatabase(liquibase);
  }
}

代码示例来源:origin: com.blazebit/blaze-weblink-core-model

public void update(Connection connection) {
  logger.fine("Starting database update");
  try {
    Liquibase liquibase = getLiquibase(connection);
    List<ChangeSet> changeSets = liquibase.listUnrunChangeSets((Contexts) null);
    if (!changeSets.isEmpty()) {
      if (changeSets.get(0).getId().equals(FIRST_VERSION)) {
        logger.info("Initializing database schema");
      } else {
        if (logger.isLoggable(Level.FINE)) {
          List<RanChangeSet> ranChangeSets = liquibase.getDatabase().getRanChangeSetList();
          final String msg = MessageFormat.format("Updating database from {0} to {1}", ranChangeSets.get(ranChangeSets.size() - 1).getId(), changeSets.get(changeSets.size() - 1).getId());
          logger.fine(msg);
        } else {
          logger.info("Updating database");
        }
      }
      liquibase.update((Contexts) null);
    }
  } catch (Exception e) {
    throw new RuntimeException("Failed to update database", e);
  }
  logger.fine("Completed database update");
}

相关文章