当前位置: 首页>>代码示例>>Java>>正文


Java FlywayException类代码示例

本文整理汇总了Java中org.flywaydb.core.api.FlywayException的典型用法代码示例。如果您正苦于以下问题:Java FlywayException类的具体用法?Java FlywayException怎么用?Java FlywayException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FlywayException类属于org.flywaydb.core.api包,在下文中一共展示了FlywayException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
@Override
public void execute(Connection connection) throws SQLException {
    String scriptLocation = this.shellScriptResource.getLocationOnDisk();
    try {
        List<String> args = new ArrayList<String>();
        args.add(scriptLocation);
        ProcessBuilder builder = new ProcessBuilder(args);
        builder.redirectErrorStream(true);
        Process process = builder.start();
        Scanner in = new Scanner(process.getInputStream());
        System.out.println(StringUtils.repeat("+",200));
        while (in.hasNextLine()) {
            System.out.println(in.nextLine());
        }
        int returnCode = process.waitFor();
        System.out.println(StringUtils.repeat("+",200));
        if (returnCode != 0) {
            throw new FlywayException("script exited with value : " + returnCode);
        }
    } catch (Exception e) {
        LOG.error(e.toString());
        // Only if SQLException or FlywaySqlScriptException is thrown flyway will mark the migration as failed in the metadata table
        throw new SQLException(String.format("Failed to run script \"%s\", %s", scriptLocation, e.getMessage()), e);
    }
}
 
开发者ID:hortonworks,项目名称:registry,代码行数:26,代码来源:ShellMigrationExecutor.java

示例2: createScript

import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
/**
 * Create a new instance of script based on location and resource.
 *
 * @param location root location of the given resource
 * @param resource script resource
 * @return a new instance of sql script based on location and resource
 * @throws FlywayException when script can't be created from the resource
 */
SqlScript createScript(Location location, Resource resource) {
  final String separator = location.isClassPath() ? "/" : File.separator;
  // '/root-location/5.0.0-M7/v1__init.sql' -> '5.0.0-M7/v1__init.sql'
  final String relLocation = resource.getLocation().substring(location.getPath().length() + 1);
  final String[] paths = relLocation.split(separator);
  // 5.0.0-M1/v1__init.sql
  if (paths.length == 2) {
    return new SqlScript(resource, location, paths[0], null, paths[1]);
  }
  // 5.0.0-M1/postgresql/v1__init.sql
  if (paths.length == 3) {
    return new SqlScript(resource, location, paths[0], paths[1], paths[2]);
  }
  throw new FlywayException(
      format(
          "Sql script location must be either in 'location-root/version-dir' "
              + "or in 'location-root/version-dir/provider-name', but script '%s' is not in root '%s'",
          resource.getLocation(), location.getPath()));
}
 
开发者ID:eclipse,项目名称:che,代码行数:28,代码来源:SqlScriptCreator.java

示例3: calculateChecksum

import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
static int calculateChecksum(String str) {
    Hasher hasher = Hashing.murmur3_32().newHasher();

    BufferedReader bufferedReader = new BufferedReader(new StringReader(str));
    try {
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            hasher.putString(line.trim(), Charsets.UTF_8);
        }
    } catch (IOException e) {
        String message = "Unable to calculate checksum";
        throw new FlywayException(message, e);
    }

    return hasher.hash().asInt();
}
 
开发者ID:icode,项目名称:ameba,代码行数:17,代码来源:DatabaseMigrationResolver.java

示例4: migrate

import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
public void migrate() {
    try {
        System.out.println("start migration");
        Flyway flyway = new Flyway();
        flyway.setDataSource(url, username, password);
        flyway.repair();// repair migration data schema before migrating
        flyway.migrate();
    } catch (FlywayException e) {
        e.printStackTrace();
    }
}
 
开发者ID:codedrinker,项目名称:commenthub,代码行数:12,代码来源:Migrations.java

示例5: sleepAfterFailedMigration

import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
@Test
public void sleepAfterFailedMigration() {
    props.addProperty("databaseServer", "foo");
    Flyway flyway = mock(Flyway.class);
    when(flyway.migrate()).thenThrow(new FlywayException());
    migrator.flyway = flyway;
    migrator.flywayFailedSemaphore.release();
    migrator.migrate();
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:10,代码来源:SchemaMigratorIntegrationTest.java

示例6: migrate

import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
public void migrate() throws SQLException, IOException {
    try {
        LegacyDBMigration.migrate((org.apache.tomcat.jdbc.pool.DataSource) flyway.getDataSource());
        flyway.migrate();
    } catch (FlywayException e) {
        throw new IOException(e);
    }
}
 
开发者ID:retz,项目名称:retz,代码行数:9,代码来源:DBMigration.java

示例7: clean

import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
public void clean() throws IOException {
    try {
        flyway.clean();
    } catch (FlywayException e) {
        throw new IOException(e);
    }
}
 
开发者ID:retz,项目名称:retz,代码行数:8,代码来源:DBMigration.java

示例8: isFinished

import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
public boolean isFinished() throws IOException {
    try {
        return LegacyDBMigration.allTableExists() && flyway.info().pending().length < 1;
    } catch (FlywayException e) {
        throw new IOException(e);
    }
}
 
开发者ID:retz,项目名称:retz,代码行数:8,代码来源:DBMigration.java

示例9: start

import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
@Override
public boolean start() {
    _gcExecutor.scheduleWithFixedDelay(new ContainerClusterGarbageCollector(), 300, 300, TimeUnit.SECONDS);
    _stateScanner.scheduleWithFixedDelay(new ContainerClusterStatusScanner(), 300, 30, TimeUnit.SECONDS);

    // run the data base migration.
    Properties dbProps = DbProperties.getDbProperties();
    final String cloudUsername = dbProps.getProperty("db.cloud.username");
    final String cloudPassword = dbProps.getProperty("db.cloud.password");
    final String cloudHost = dbProps.getProperty("db.cloud.host");
    final int cloudPort = Integer.parseInt(dbProps.getProperty("db.cloud.port"));
    final String dbUrl = "jdbc:mysql://" + cloudHost + ":" + cloudPort + "/cloud";

    try {
        Flyway flyway = new Flyway();
        flyway.setDataSource(dbUrl, cloudUsername, cloudPassword);

        // name the meta table as sb_ccs_schema_version
        flyway.setTable("sb_ccs_schema_version");

        // make the existing cloud DB schema and data as baseline
        flyway.setBaselineOnMigrate(true);
        flyway.setBaselineVersionAsString("0");

        // apply CCS schema
        flyway.migrate();
    } catch (FlywayException fwe) {
        s_logger.error("Failed to run migration on Cloudstack Container Service database due to " + fwe);
        return false;
    }

    return true;
}
 
开发者ID:shapeblue,项目名称:ccs,代码行数:34,代码来源:ContainerClusterManagerImpl.java

示例10: resolve

import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
/**
 * Creates migration version based on script data.
 *
 * @param script script for which to resolve the version
 * @param configuration flyway configuration used for resolution parameters
 */
MigrationVersion resolve(SqlScript script, FlywayConfiguration configuration) {
  String normalizedDir = normalizedDirs.get(script.dir);
  if (normalizedDir == null) {
    // 5.0.0-M1 -> 5.0.0.M1 -> 5.0.0.1
    normalizedDir =
        NOT_VERSION_CHARS_PATTERN.matcher(script.dir.replace("-", ".")).replaceAll("");
    normalizedDirs.put(script.dir, normalizedDir);
  }

  // separate version from the other part of the name
  final int sepIdx = script.name.indexOf(configuration.getSqlMigrationSeparator());
  if (sepIdx == -1) {
    throw new FlywayException(
        format(
            "sql script name '%s' is not valid, name must contain '%s'",
            script.name, configuration.getSqlMigrationSeparator()));
  }

  // check whether part before separator is not empty
  String version = script.name.substring(0, sepIdx);
  if (version.isEmpty()) {
    throw new FlywayException(
        format(
            "sql script name '%s' is not valid, name must provide version like "
                + "'%s4%smigration_description.sql",
            configuration.getSqlMigrationPrefix(),
            script.name,
            configuration.getSqlMigrationSeparator()));
  }

  // extract sql script version without prefix
  final String prefix = configuration.getSqlMigrationPrefix();
  if (!isNullOrEmpty(prefix) && script.name.startsWith(prefix)) {
    version = version.substring(prefix.length());
  }
  return MigrationVersion.fromVersion(normalizedDir + '.' + version);
}
 
开发者ID:eclipse,项目名称:che,代码行数:44,代码来源:VersionResolver.java

示例11: failsToCreateResourceWhenPathIsInvalid

import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
@Test(expectedExceptions = FlywayException.class)
public void failsToCreateResourceWhenPathIsInvalid() throws Exception {
  final Location location = new Location("filesystem:schema");
  final Resource resource = new FileSystemResource("schema/v1__init.sql");

  new SqlScriptCreator().createScript(location, resource);
}
 
开发者ID:eclipse,项目名称:che,代码行数:8,代码来源:SqlScriptCreatorTest.java

示例12: failsToResolveVersions

import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
@Test(dataProvider = "invalidScripts", expectedExceptions = FlywayException.class)
public void failsToResolveVersions(String dir, String name) throws Exception {
  final SqlScript script =
      new SqlScript(
          new FileSystemResource("sql/" + dir + "/" + name),
          new Location("filesystem:sql"),
          dir,
          null,
          name);
  resolver.resolve(script, flyway);
}
 
开发者ID:eclipse,项目名称:che,代码行数:12,代码来源:VersionResolverTest.java

示例13: getDatabaseVersion

import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
private static MigrationVersion getDatabaseVersion(DataSource dataSource) throws FlywayException {
  Flyway flyway = new Flyway();
  flyway.setDataSource(dataSource);
  MigrationInfoService info = flyway.info();
  MigrationVersion currentVersion = MigrationVersion.EMPTY;
  if (info.current() != null) {
    currentVersion = info.current().getVersion();
  }
  return currentVersion;
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:11,代码来源:DatabaseJobHistoryStore.java

示例14: run

import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
@Override
public void run() {
	// Perform Database Migration
	Flyway flyway = new Flyway();
	flyway.setBaselineOnMigrate(true);
	flyway.setLocations("io/andrewohara/tinkertime/db/migration");
	flyway.setDataSource(connectionString.getUrl(), null, null);
	try {
		flyway.migrate();
	} catch (FlywayException e){
		flyway.repair();
		throw e;
	}
}
 
开发者ID:oharaandrew314,项目名称:TinkerTime,代码行数:15,代码来源:TinkerTimeLauncher.java

示例15: run

import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
@Override
protected void run(final Bootstrap<T> bootstrap, final Namespace namespace, final T configuration) throws Exception {
    final PooledDataSourceFactory datasourceFactory = databaseConfiguration.getDataSourceFactory(configuration);
    final FlywayFactory flywayFactory = flywayConfiguration.getFlywayFactory(configuration);
    final Flyway flyway = flywayFactory.build(datasourceFactory.build(bootstrap.getMetricRegistry(), "Flyway"));

    try {
        run(namespace, flyway);
    } catch (FlywayException e) {
        LOG.error("Error while running database command", e);
        throw e;
    }
}
 
开发者ID:dropwizard,项目名称:dropwizard-flyway,代码行数:14,代码来源:AbstractFlywayCommand.java


注:本文中的org.flywaydb.core.api.FlywayException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。