本文整理汇总了Java中org.apache.ibatis.migration.MigrationLoader类的典型用法代码示例。如果您正苦于以下问题:Java MigrationLoader类的具体用法?Java MigrationLoader怎么用?Java MigrationLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MigrationLoader类属于org.apache.ibatis.migration包,在下文中一共展示了MigrationLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNoMigrationNecessary
import org.apache.ibatis.migration.MigrationLoader; //导入依赖的package包/类
@Test
public void testNoMigrationNecessary() throws Exception {
MigrationLoader loader = new JavaMigrationLoader(
"org.apache.aurora.scheduler.storage.db.testmigration");
Injector injector = createMigrationInjector(loader);
MigrationManager migrationManager = injector.getInstance(MigrationManager.class);
migrationManager.migrate();
SqlSessionFactory sqlSessionFactory = injector.getInstance(SqlSessionFactory.class);
assertMigrationComplete(sqlSessionFactory, loader);
// Run the migration a second time, no changes should be made.
migrationManager.migrate();
assertMigrationComplete(sqlSessionFactory, loader);
}
示例2: testRollback
import org.apache.ibatis.migration.MigrationLoader; //导入依赖的package包/类
@Test
public void testRollback() throws Exception {
// Run a normal migration which will apply one the change found in the testmigration package.
MigrationLoader loader = new JavaMigrationLoader(
"org.apache.aurora.scheduler.storage.db.testmigration");
Injector injector = createMigrationInjector(loader);
MigrationManager migrationManager = injector.getInstance(MigrationManager.class);
migrationManager.migrate();
// Now we intentionally pass a reference to a non-existent package to ensure that no migrations
// are found. As such a rollback is expected to be detected and a downgrade be performed.
MigrationLoader rollbackLoader = new JavaMigrationLoader(
"org.apache.aurora.scheduler.storage.db.nomigrations");
Injector rollbackInjector = createMigrationInjector(rollbackLoader);
MigrationManager rollbackManager = rollbackInjector.getInstance(MigrationManager.class);
rollbackManager.migrate();
assertRollbackComplete(rollbackInjector.getInstance(SqlSessionFactory.class));
}
示例3: configure
import org.apache.ibatis.migration.MigrationLoader; //导入依赖的package包/类
@Override
protected void configure() {
bind(MigrationLoader.class).toInstance(migrationLoader);
bind(MigrationManager.class).to(MigrationManagerImpl.class);
expose(MigrationManager.class);
}
示例4: assertMigrationComplete
import org.apache.ibatis.migration.MigrationLoader; //导入依赖的package包/类
/**
* Ensure all changes have been applied and their downgrade scripts stored appropriately.
*
* @param sqlSessionFactory The sql session factory.
* @param loader A migration loader.
* @throws Exception If the changes were not applied properly.
*/
private void assertMigrationComplete(
SqlSessionFactory sqlSessionFactory,
MigrationLoader loader) throws Exception {
try (SqlSession session = sqlSessionFactory.openSession()) {
MigrationMapper mapper = session.getMapper(MigrationMapper.class);
List<MigrationChangelogEntry> appliedChanges = mapper.selectAll();
for (Change change : loader.getMigrations()) {
Optional<MigrationChangelogEntry> appliedChange = appliedChanges
.stream()
.filter(c -> c.getId().equals(change.getId()))
.findFirst();
assertTrue(appliedChange.isPresent());
assertEquals(
CharStreams.toString(loader.getScriptReader(change, true /* undo */)),
appliedChange.get().getDowngradeScript());
}
// As long as the tables exist, neither of these statements should fail.
try (Connection c = session.getConnection()) {
try (PreparedStatement select = c.prepareStatement("SELECT * FROM V001_test_table")) {
select.execute();
}
try (PreparedStatement select = c.prepareStatement("SELECT * FROM V002_test_table2")) {
select.execute();
}
}
}
}
示例5: testMigrate
import org.apache.ibatis.migration.MigrationLoader; //导入依赖的package包/类
@Test
public void testMigrate() throws Exception {
MigrationLoader loader = new JavaMigrationLoader(
"org.apache.aurora.scheduler.storage.db.testmigration");
Injector injector = createMigrationInjector(loader);
injector.getInstance(MigrationManager.class).migrate();
assertMigrationComplete(injector.getInstance(SqlSessionFactory.class), loader);
}
示例6: getMigrationLoader
import org.apache.ibatis.migration.MigrationLoader; //导入依赖的package包/类
protected MigrationLoader getMigrationLoader() {
Environment env = environment();
MigrationLoader migrationLoader = null;
for (FileMigrationLoaderFactory factory : ServiceLoader.load(FileMigrationLoaderFactory.class)) {
if (migrationLoader != null) {
throw new MigrationException("Found multiple implementations of FileMigrationLoaderFactory via SPI.");
}
migrationLoader = factory.create(paths, env);
}
return migrationLoader != null ? migrationLoader
: new FileMigrationLoader(paths.getScriptPath(), env.getScriptCharset(), env.getVariables());
}
示例7: getPendingChanges
import org.apache.ibatis.migration.MigrationLoader; //导入依赖的package包/类
private List<Change> getPendingChanges(ConnectionProvider connectionProvider, MigrationLoader migrationsLoader,
DatabaseOperationOption option) {
List<Change> pending = new ArrayList<Change>();
List<Change> migrations = migrationsLoader.getMigrations();
List<Change> changelog = getChangelog(connectionProvider, option);
for (Change change : migrations) {
int index = changelog.indexOf(change);
if (index < 0) {
pending.add(change);
}
}
Collections.sort(pending);
return pending;
}
示例8: operate
import org.apache.ibatis.migration.MigrationLoader; //导入依赖的package包/类
public Object operate(
ConnectionProvider connectionProvider,
MigrationLoader migrationsLoader,
DatabaseOperationOption option,
PrintStream printStream);
示例9: MigrationManagerModule
import org.apache.ibatis.migration.MigrationLoader; //导入依赖的package包/类
public MigrationManagerModule(MigrationLoader migrationLoader) {
this.migrationLoader = requireNonNull(migrationLoader);
}
示例10: MigrationManagerImpl
import org.apache.ibatis.migration.MigrationLoader; //导入依赖的package包/类
@Inject
MigrationManagerImpl(SqlSessionFactory sqlSessionFactory, MigrationLoader migrationLoader) {
this.sqlSessionFactory = requireNonNull(sqlSessionFactory);
this.migrationLoader = requireNonNull(migrationLoader);
}
示例11: createMigrationInjector
import org.apache.ibatis.migration.MigrationLoader; //导入依赖的package包/类
private Injector createMigrationInjector(MigrationLoader migrationLoader) {
return DbUtil.createStorageInjector(
testModuleWithWorkQueue(),
new DbModule.MigrationManagerModule(migrationLoader));
}
示例12: operate
import org.apache.ibatis.migration.MigrationLoader; //导入依赖的package包/类
public VersionOperation operate(ConnectionProvider connectionProvider, MigrationLoader migrationsLoader,
DatabaseOperationOption option, PrintStream printStream) {
return operate(connectionProvider, migrationsLoader, option, printStream, null, null);
}
示例13: ensureVersionExists
import org.apache.ibatis.migration.MigrationLoader; //导入依赖的package包/类
private void ensureVersionExists(MigrationLoader migrationsLoader) {
List<Change> migrations = migrationsLoader.getMigrations();
if (!migrations.contains(new Change(version))) {
throw new MigrationException("A migration for the specified version number does not exist.");
}
}
示例14: operate
import org.apache.ibatis.migration.MigrationLoader; //导入依赖的package包/类
public DownOperation operate(ConnectionProvider connectionProvider, MigrationLoader migrationsLoader,
DatabaseOperationOption option, PrintStream printStream) {
return operate(connectionProvider, migrationsLoader, option, printStream, null);
}
示例15: operate
import org.apache.ibatis.migration.MigrationLoader; //导入依赖的package包/类
public UpOperation operate(ConnectionProvider connectionProvider, MigrationLoader migrationsLoader,
DatabaseOperationOption option, PrintStream printStream) {
return operate(connectionProvider, migrationsLoader, option, printStream, null);
}