use of org.flywaydb.core.internal.database.DatabaseType in project flyway by flyway.
the class BaseDatabaseType method createSqlScriptExecutorFactory.
public SqlScriptExecutorFactory createSqlScriptExecutorFactory(final JdbcConnectionFactory jdbcConnectionFactory, final CallbackExecutor callbackExecutor, final StatementInterceptor statementInterceptor) {
boolean supportsBatch = false;
final boolean finalSupportsBatch = supportsBatch;
final DatabaseType thisRef = this;
return (connection, undo, batch, outputQueryResults) -> new DefaultSqlScriptExecutor(new JdbcTemplate(connection, thisRef), callbackExecutor, undo, finalSupportsBatch && batch, outputQueryResults, statementInterceptor);
}
use of org.flywaydb.core.internal.database.DatabaseType in project flyway by flyway.
the class SqlMigrationExecutor method execute.
@Override
public void execute(final Context context) throws SQLException {
DatabaseType databaseType = DatabaseTypeRegister.getDatabaseTypeForConnection(context.getConnection());
DatabaseExecutionStrategy strategy = databaseType.createExecutionStrategy(context.getConnection());
strategy.execute(() -> {
executeOnce(context);
return true;
});
}
use of org.flywaydb.core.internal.database.DatabaseType in project flyway by flyway.
the class FlywayExecutor method execute.
/**
* Executes this command with proper resource handling and cleanup.
*
* @param command The command to execute.
* @param <T> The type of the result.
* @return The result of the command.
*/
public <T> T execute(Command<T> command, boolean scannerRequired) {
T result;
configurationValidator.validate(configuration);
StatementInterceptor statementInterceptor = null;
final Pair<ResourceProvider, ClassProvider<JavaMigration>> resourceProviderClassProviderPair = createResourceAndClassProviders(scannerRequired);
final ResourceProvider resourceProvider = resourceProviderClassProviderPair.getLeft();
final ClassProvider<JavaMigration> classProvider = resourceProviderClassProviderPair.getRight();
final ParsingContext parsingContext = new ParsingContext();
resourceNameValidator.validateSQLMigrationNaming(resourceProvider, configuration);
JdbcConnectionFactory jdbcConnectionFactory = new JdbcConnectionFactory(configuration.getDataSource(), configuration, statementInterceptor);
final DatabaseType databaseType = jdbcConnectionFactory.getDatabaseType();
final SqlScriptFactory sqlScriptFactory = databaseType.createSqlScriptFactory(configuration, parsingContext);
RetryStrategy.setNumberOfRetries(configuration.getLockRetryCount());
final SqlScriptExecutorFactory noCallbackSqlScriptExecutorFactory = databaseType.createSqlScriptExecutorFactory(jdbcConnectionFactory, NoopCallbackExecutor.INSTANCE, null);
jdbcConnectionFactory.setConnectionInitializer((jdbcConnectionFactory1, connection) -> {
if (configuration.getInitSql() == null) {
return;
}
StringResource resource = new StringResource(configuration.getInitSql());
SqlScript sqlScript = sqlScriptFactory.createSqlScript(resource, true, resourceProvider);
boolean outputQueryResults = false;
noCallbackSqlScriptExecutorFactory.createSqlScriptExecutor(connection, false, false, outputQueryResults).execute(sqlScript);
});
Database database = null;
try {
VersionPrinter.printVersion();
database = databaseType.createDatabase(configuration, !dbConnectionInfoPrinted, jdbcConnectionFactory, statementInterceptor);
databaseType.printMessages();
dbConnectionInfoPrinted = true;
LOG.debug("DDL Transactions Supported: " + database.supportsDdlTransactions());
Pair<Schema, List<Schema>> schemas = SchemaHistoryFactory.prepareSchemas(configuration, database);
Schema defaultSchema = schemas.getLeft();
parsingContext.populate(database, configuration);
database.ensureSupported();
DefaultCallbackExecutor callbackExecutor = new DefaultCallbackExecutor(configuration, database, defaultSchema, prepareCallbacks(database, resourceProvider, jdbcConnectionFactory, sqlScriptFactory, statementInterceptor, defaultSchema, parsingContext));
SqlScriptExecutorFactory sqlScriptExecutorFactory = databaseType.createSqlScriptExecutorFactory(jdbcConnectionFactory, callbackExecutor, statementInterceptor);
SchemaHistory schemaHistory = SchemaHistoryFactory.getSchemaHistory(configuration, noCallbackSqlScriptExecutorFactory, sqlScriptFactory, database, defaultSchema, statementInterceptor);
result = command.execute(createMigrationResolver(resourceProvider, classProvider, sqlScriptExecutorFactory, sqlScriptFactory, parsingContext), schemaHistory, database, defaultSchema, schemas.getRight().toArray(new Schema[0]), callbackExecutor, statementInterceptor);
} finally {
IOUtils.close(database);
showMemoryUsage();
}
return result;
}
use of org.flywaydb.core.internal.database.DatabaseType in project flyway by flyway.
the class JavaMigrationExecutor method execute.
@Override
public void execute(final Context context) throws SQLException {
DatabaseType databaseType = DatabaseTypeRegister.getDatabaseTypeForConnection(context.getConnection());
DatabaseExecutionStrategy strategy = databaseType.createExecutionStrategy(context.getConnection());
strategy.execute(() -> {
executeOnce(context);
return true;
});
}
Aggregations