本文整理汇总了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);
}
}
示例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()));
}
示例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();
}
示例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();
}
}
示例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();
}
示例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);
}
}
示例7: clean
import org.flywaydb.core.api.FlywayException; //导入依赖的package包/类
public void clean() throws IOException {
try {
flyway.clean();
} catch (FlywayException e) {
throw new IOException(e);
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
}