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


Java Flyway.setDataSource方法代码示例

本文整理汇总了Java中org.flywaydb.core.Flyway.setDataSource方法的典型用法代码示例。如果您正苦于以下问题:Java Flyway.setDataSource方法的具体用法?Java Flyway.setDataSource怎么用?Java Flyway.setDataSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.flywaydb.core.Flyway的用法示例。


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

示例1: initFlyway

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
/**
 * Initialise Flyway
 * 
 * @param ds
 */
private void initFlyway(DataSource ds) {
	try {
		logger.info("Database analysis: in progress...");
		Flyway flyway = new Flyway();
		flyway.setDataSource(ds);
		flyway.setCallbacks(new FlywayCallbackMigration());
		flyway.setBaselineOnMigrate(true);
		flyway.setValidateOnMigrate(true);
		flyway.repair();
		flyway.migrate();
		logger.info("Database analysis: finish...");
	} catch (Exception e) {
		logger.error("Database analysis: ERROR", e);
		throw e;
	}
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:22,代码来源:JpaConfigEcandidat.java

示例2: migrateOrCreateIfNotExists

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
public static boolean migrateOrCreateIfNotExists(String dbname) {
    String dbpath = getDbPath(dbname);
    String jdbcurl = "jdbc:h2:file:" + dbpath + ";DB_CLOSE_ON_EXIT=FALSE";
    LOG.info("new jdbcurl = {}", jdbcurl);
    Connection conn = null;
    try {
        conn = DriverManager.getConnection(jdbcurl, "sa", "");

        DataSource ds = new CustomFlywayDataSource(new PrintWriter(System.out), conn);
        Flyway flyway = new Flyway();
        flyway.setDataSource(ds);
        // explicitly set h2db driver loaded (= including this jar file) class loader
        flyway.setClassLoader(conn.getClass().getClassLoader());
        flyway.migrate();
        LOG.info("db[{}] migration success", dbname);

        // may be already closed -> reconnect.
        DbUtils.closeQuietly(conn);
        conn = DriverManager.getConnection(jdbcurl, "sa", "");

        QueryRunner r = new QueryRunner();
        Long cnt = r.query(conn, "select count(*) from PROXY_HISTORY", new ScalarHandler<Long>());
        LOG.info("db[{}] open/creation success(select count(*) from logtable returns {})", dbname, cnt);

        return true;
    } catch (SQLException e) {
        LOG.error("db[" + dbname + "] open/migrate/creation error", e);
        return false;
    } finally {
        DbUtils.closeQuietly(conn);
    }
}
 
开发者ID:SecureSkyTechnology,项目名称:burpextender-proxyhistory-webui,代码行数:33,代码来源:DataStore.java

示例3: migrateFlyway

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
@PostConstruct
public void migrateFlyway() {
    Flyway flyway = new Flyway();

    if (this.nakadiProducerFlywayDataSource != null) {
        flyway.setDataSource(nakadiProducerFlywayDataSource);
    } else if (this.flywayProperties.isCreateDataSource()) {
        flyway.setDataSource(this.flywayProperties.getUrl(), this.flywayProperties.getUser(),
            this.flywayProperties.getPassword(),
            this.flywayProperties.getInitSqls().toArray(new String[0]));
    } else if (this.flywayDataSource != null) {
        flyway.setDataSource(this.flywayDataSource);
    } else {
        flyway.setDataSource(dataSource);
    }

    flyway.setLocations("classpath:db_nakadiproducer/migrations");
    flyway.setSchemas("nakadi_events");
    if (callback != null) {
        flyway.setCallbacks(callback);
    }
    flyway.setBaselineOnMigrate(true);
    flyway.setBaselineVersionAsString("2133546886.1.0");
    flyway.migrate();
}
 
开发者ID:zalando-nakadi,项目名称:nakadi-producer-spring-boot-starter,代码行数:26,代码来源:FlywayMigrator.java

示例4: updateDatabase

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
@PostConstruct
public void updateDatabase() throws IOException {
    try {
        Flyway flyway = new Flyway();
        flyway.setEncoding("UTF-8");
        flyway.setTable("flyway_schema");
        flyway.setLocations("db/migration");
        flyway.setSchemas(env.getProperty(PropertyNames.jdbcUser));
        flyway.setDataSource(
                env.getProperty(PropertyNames.jdbcURL),
                env.getProperty(PropertyNames.flywayUser),
                env.getProperty(PropertyNames.flywayPassword));

        flyway.setBaselineOnMigrate(true);
        flyway.migrate();
    } catch (Exception e) {
        log.error("FAILED TO MIGRATE DATABASE", e);
    }
}
 
开发者ID:solita,项目名称:kansalaisaloite,代码行数:20,代码来源:JdbcConfiguration.java

示例5: configure

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
  Config $base = conf.getConfig("flyway");
  Config $flyway = Try.apply(() -> conf.getConfig(name).withFallback($base))
      .orElse($base);

  Flyway flyway = new Flyway();
  flyway.configure(props($flyway));
  if (!$flyway.hasPath("url")) {
    Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
    DataSource dataSource = env.get(dskey)
        .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
    flyway.setDataSource(dataSource);
  }
  // bind
  env.serviceKey()
      .generate(Flyway.class, name, key -> binder.bind(key).toInstance(flyway));
  // run
  Iterable<Command> cmds = commands($flyway);
  env.onStart(registry -> {
    cmds.forEach(cmd -> cmd.run(flyway));
  });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:24,代码来源:Flywaydb.java

示例6: initDatasource

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
public void initDatasource(YadaConfiguration config) throws NamingException {
	MysqlDataSource dataSource = new MysqlDataSource();
	dataSource.setDatabaseName(config.getString("config/database/dbName"));
	dataSource.setUser(config.getString("config/database/user"));
	dataSource.setPassword(config.getString("config/database/password"));
	dataSource.setServerName(config.getString("config/database/server"));
	SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
	builder.bind("java:comp/env/jdbc/yadatestdb", dataSource);
	super.dataSource = dataSource;
	builder.activate();
	// Database
	Flyway flyway = new Flyway();
	flyway.setLocations("filesystem:schema"); // Where sql test scripts are stored
	flyway.setDataSource(dataSource);
	flyway.clean();
	flyway.migrate();
}
 
开发者ID:xtianus,项目名称:yadaframework,代码行数:18,代码来源:YadaTestConfig.java

示例7: migrate

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
/**
 * Migrate the database to the latest available migration.
 */
public void migrate() {

  if (this.enabled) {
    final Flyway flyway = new Flyway();
    flyway.setDataSource(this.dataSource);
    if (this.testdata) {
      flyway.setLocations(masterDataPath, testDataPath);
    } else {
      flyway.setLocations(masterDataPath);
    }
    if (this.clean) {
      flyway.clean();
    }
    flyway.migrate();
  }
}
 
开发者ID:oasp,项目名称:oasp-tutorial-sources,代码行数:20,代码来源:DatabaseMigrator.java

示例8: DBManager

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
public DBManager() {
    ds = new BasicDataSource();
    ds.setDriver(new EmbeddedDriver());
    ds.setUrl(Constants.JDBC);
    
    flyway = new Flyway();
    flyway.setDataSource(ds);
    //flyway.clean();
    flyway.migrate();

    // just to be sure, try to close
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                LOG.info("Closing DB connection...");
                ds.close();
                LOG.info("DB closed");
            } catch (SQLException ex) {
                LOG.error("Error closing DB cconnection", ex);
            }
        }
    });
}
 
开发者ID:dainesch,项目名称:HueSense,代码行数:25,代码来源:DBManager.java

示例9: onStartup

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
@PostConstruct
    private void onStartup() {
        if (dataSource == null) {
            log.severe("No datasource found to execute the db migrations!");
            throw new EJBException("No datasource found to execute the db migrations!");
        }

        Flyway flyway = new Flyway();
        flyway.setDataSource(dataSource);
        flyway.setBaselineOnMigrate(true);
        for (MigrationInfo i : flyway.info().all()) {
            log.log(Level.INFO, "Migrate task: {0} : {1} from file: {2}", new Object[]{i.getVersion(), i.getDescription(), i.getScript()});
        }
        flyway.migrate();

        // aby ustawił kierunki relacji z pliku, odkomentować i ustawić ścieżkę do pliku disp_relations.cfg
//        try {
//            TempRelationsDirectionsUpdater.run("/home/rdyszlewski/Projekty/wordnetloom3/WordnetLoom/wordnetloom-client/src/main/resources/disp_relations.cfg", dataSource.getConnection());
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
    }
 
开发者ID:CLARIN-PL,项目名称:WordnetLoom,代码行数:23,代码来源:DbMigrator.java

示例10: onStartup

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
@PostConstruct
private void onStartup() throws SQLException {
	if (dataSource == null) {
		LOG.error("no datasource found to execute the db migrations!");
		throw new EJBException(
				"no datasource found to execute the db migrations!");
	}

	String schema = "sql" + FS + "mysql";
	if (DB != null) {
		 schema = "sql" + FS + DB;
	}
	Flyway flyway = new Flyway();
	flyway.setDataSource(dataSource);
	flyway.setBaselineOnMigrate(true);
	flyway.setPlaceholderPrefix("%{");
	flyway.setLocations("sql" + FS + "configdata", schema);
	flyway.setBaselineVersion(MigrationVersion.fromVersion("201609221422"));
	for (MigrationInfo i : flyway.info().all()) {
		LOG.info("migrate task: " + i.getVersion() + " : "
				+ i.getDescription() + " from file: " + i.getScript());
	}
	flyway.repair();
	flyway.migrate();
}
 
开发者ID:witchpou,项目名称:lj-projectbuilder,代码行数:26,代码来源:DataStartupService.java

示例11: initDatabase

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
private void initDatabase(ReaperApplicationConfiguration config) throws ReaperException {
  Flyway flyway = new Flyway();
  DataSourceFactory dsfactory = config.getDataSourceFactory();
  flyway.setDataSource(
      dsfactory.getUrl(),
      dsfactory.getUser(),
      dsfactory.getPassword());

  if ("database".equals(config.getStorageType())) {
    LOG.warn("!!!!!!!!!!    USAGE 'database' AS STORAGE TYPE IS NOW DEPRECATED   !!!!!!!!!!!!!!");
    LOG.warn("!!!!!!!!!!    PLEASE USE EITHER 'postgres' OR 'h2' FROM NOW ON     !!!!!!!!!!!!!!");
    if (config.getDataSourceFactory().getUrl().contains("h2")) {
      flyway.setLocations("/db/h2");
    } else {
      flyway.setLocations("/db/postgres");
    }
  } else {
    flyway.setLocations("/db/".concat(config.getStorageType().toLowerCase()));
  }
  flyway.setBaselineOnMigrate(true);
  flyway.repair();
  flyway.migrate();
}
 
开发者ID:thelastpickle,项目名称:cassandra-reaper,代码行数:24,代码来源:ReaperApplication.java

示例12: initMigration

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
@BeforeClass
public static void initMigration() throws SQLException {
    flyway = new Flyway();
    flyway.setDataSource(DB_URL, "sa", "");
    flyway.setLocations("filesystem:src/main/resources/db/migration");
    flyway.migrate();

    connection = flyway.getDataSource().getConnection();
    //add some data to test db cleanup
    try (Statement stmt = connection.createStatement()) {
        stmt.addBatch("INSERT INTO flyway_test.author(id, first_name, last_name, date_of_birth, year_of_birth, address) VALUES (1, 'Erich', 'Gamma','1903-06-25','1900',null)");
        stmt.addBatch("INSERT INTO flyway_test.author(id, first_name, last_name, date_of_birth, year_of_birth, address) VALUES (2, 'Richard', 'Helm','1903-06-25','1900',null)");
        int[] result = stmt.executeBatch();
        assertEquals(result.length, 2);
    }
}
 
开发者ID:database-rider,项目名称:database-rider,代码行数:17,代码来源:JooqDBUnitTest.java

示例13: get

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
public static Flyway get(StorageProviderConfiguration conf, String scriptRootPath) {
    Flyway flyway = new Flyway();

    String location = "filesystem:" + scriptRootPath;
    flyway.setEncoding(encoding);
    flyway.setTable(metaDataTableName);
    flyway.setValidateOnMigrate(validateOnMigrate);
    flyway.setOutOfOrder(outOfOrder);
    flyway.setBaselineOnMigrate(baselineOnMigrate);
    flyway.setBaselineVersion(MigrationVersion.fromVersion(baselineVersion));
    flyway.setCleanOnValidationError(cleanOnValidationError);
    flyway.setLocations(location);
    flyway.setResolvers(new ShellMigrationResolver(flyway.getClassLoader(), location, shellMigrationPrefix, shellMigrationSeperator, shellMigrationSuffix));
    flyway.setDataSource(conf.getUrl(), conf.getUser(), conf.getPassword(), null);

    return flyway;
}
 
开发者ID:hortonworks,项目名称:registry,代码行数:18,代码来源:ShellFlywayFactory.java

示例14: get

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
public static Flyway get(StorageProviderConfiguration conf, String scriptRootPath) {
    Flyway flyway = new Flyway();

    String location = "filesystem:" + scriptRootPath + File.separator + conf.getDbType();
    flyway.setEncoding(encoding);
    flyway.setTable(metaDataTableName);
    flyway.setSqlMigrationPrefix(sqlMigrationPrefix);
    flyway.setValidateOnMigrate(validateOnMigrate);
    flyway.setOutOfOrder(outOfOrder);
    flyway.setBaselineOnMigrate(baselineOnMigrate);
    flyway.setBaselineVersion(MigrationVersion.fromVersion(baselineVersion));
    flyway.setCleanOnValidationError(cleanOnValidationError);
    flyway.setLocations(location);
    flyway.setDataSource(conf.getUrl(), conf.getUser(), conf.getPassword(), null);

    return flyway;
}
 
开发者ID:hortonworks,项目名称:registry,代码行数:18,代码来源:SchemaFlywayFactory.java

示例15: contextInitialized

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext sc = sce.getServletContext();
    Flyway flyway = new Flyway();
    String dataSourceJndi = sc.getInitParameter(FLYWAY_JNDI_DATASOURCE);
    if (dataSourceJndi != null) {
        try {
            DataSource dataSource = (DataSource) new InitialContext().lookup(dataSourceJndi);
            flyway.setDataSource(dataSource);
        } catch (NamingException ex) {
            logger.log(Level.SEVERE, "Error while looking up DataSource", ex);
            // Do not proceed
            return;
        }
    } else {
        String url = sc.getInitParameter(FLYWAY_JDBC_URL);
        String user = sc.getInitParameter(FLYWAY_JDBC_USER);
        String password = sc.getInitParameter(FLYWAY_JDBC_PASSWORD);
        flyway.setDataSource(url, user, password);
    }
    flyway.migrate();
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:23,代码来源:FlywayMigrationServletContextListener.java


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