Search in sources :

Example 1 with SqlScriptExecutorFactory

use of org.flywaydb.core.internal.sqlscript.SqlScriptExecutorFactory in project flyway by flyway.

the class FlywayExecutor method prepareCallbacks.

private List<Callback> prepareCallbacks(Database database, ResourceProvider resourceProvider, JdbcConnectionFactory jdbcConnectionFactory, SqlScriptFactory sqlScriptFactory, StatementInterceptor statementInterceptor, Schema schema, ParsingContext parsingContext) {
    List<Callback> effectiveCallbacks = new ArrayList<>();
    CallbackExecutor callbackExecutor = NoopCallbackExecutor.INSTANCE;
    effectiveCallbacks.addAll(Arrays.asList(configuration.getCallbacks()));
    if (!configuration.isSkipDefaultCallbacks()) {
        SqlScriptExecutorFactory sqlScriptExecutorFactory = jdbcConnectionFactory.getDatabaseType().createSqlScriptExecutorFactory(jdbcConnectionFactory, callbackExecutor, statementInterceptor);
        effectiveCallbacks.addAll(new SqlScriptCallbackFactory(resourceProvider, sqlScriptExecutorFactory, sqlScriptFactory, configuration).getCallbacks());
    }
    return effectiveCallbacks;
}
Also used : SqlScriptExecutorFactory(org.flywaydb.core.internal.sqlscript.SqlScriptExecutorFactory) Callback(org.flywaydb.core.api.callback.Callback) ArrayList(java.util.ArrayList)

Example 2 with SqlScriptExecutorFactory

use of org.flywaydb.core.internal.sqlscript.SqlScriptExecutorFactory 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);
}
Also used : java.sql(java.sql) CallbackExecutor(org.flywaydb.core.internal.callback.CallbackExecutor) DatabaseType(org.flywaydb.core.internal.database.DatabaseType) Connection(java.sql.Connection) Properties(java.util.Properties) ResourceProvider(org.flywaydb.core.api.ResourceProvider) DefaultExecutionStrategy(org.flywaydb.core.internal.database.DefaultExecutionStrategy) ParserSqlScript(org.flywaydb.core.internal.sqlscript.ParserSqlScript) CustomLog(lombok.CustomLog) DefaultSqlScriptExecutor(org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor) Configuration(org.flywaydb.core.api.configuration.Configuration) SqlScriptExecutorFactory(org.flywaydb.core.internal.sqlscript.SqlScriptExecutorFactory) Parser(org.flywaydb.core.internal.parser.Parser) SqlScriptMetadata.getMetadataResource(org.flywaydb.core.internal.sqlscript.SqlScriptMetadata.getMetadataResource) SqlScriptFactory(org.flywaydb.core.internal.sqlscript.SqlScriptFactory) Map(java.util.Map) org.flywaydb.core.internal.jdbc(org.flywaydb.core.internal.jdbc) DatabaseExecutionStrategy(org.flywaydb.core.internal.database.DatabaseExecutionStrategy) Pattern(java.util.regex.Pattern) ParsingContext(org.flywaydb.core.internal.parser.ParsingContext) DatabaseType(org.flywaydb.core.internal.database.DatabaseType) DefaultSqlScriptExecutor(org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor)

Example 3 with SqlScriptExecutorFactory

use of org.flywaydb.core.internal.sqlscript.SqlScriptExecutorFactory 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;
}
Also used : JdbcConnectionFactory(org.flywaydb.core.internal.jdbc.JdbcConnectionFactory) SqlScriptExecutorFactory(org.flywaydb.core.internal.sqlscript.SqlScriptExecutorFactory) ParsingContext(org.flywaydb.core.internal.parser.ParsingContext) DatabaseType(org.flywaydb.core.internal.database.DatabaseType) SqlScriptFactory(org.flywaydb.core.internal.sqlscript.SqlScriptFactory) Schema(org.flywaydb.core.internal.database.base.Schema) SchemaHistory(org.flywaydb.core.internal.schemahistory.SchemaHistory) StringResource(org.flywaydb.core.internal.resource.StringResource) ResourceProvider(org.flywaydb.core.api.ResourceProvider) NoopResourceProvider(org.flywaydb.core.internal.resource.NoopResourceProvider) ClassProvider(org.flywaydb.core.api.ClassProvider) NoopClassProvider(org.flywaydb.core.internal.clazz.NoopClassProvider) Database(org.flywaydb.core.internal.database.base.Database) SqlScript(org.flywaydb.core.internal.sqlscript.SqlScript) JavaMigration(org.flywaydb.core.api.migration.JavaMigration) ArrayList(java.util.ArrayList) List(java.util.List) StatementInterceptor(org.flywaydb.core.internal.jdbc.StatementInterceptor)

Aggregations

SqlScriptExecutorFactory (org.flywaydb.core.internal.sqlscript.SqlScriptExecutorFactory)3 ArrayList (java.util.ArrayList)2 ResourceProvider (org.flywaydb.core.api.ResourceProvider)2 DatabaseType (org.flywaydb.core.internal.database.DatabaseType)2 ParsingContext (org.flywaydb.core.internal.parser.ParsingContext)2 SqlScriptFactory (org.flywaydb.core.internal.sqlscript.SqlScriptFactory)2 java.sql (java.sql)1 Connection (java.sql.Connection)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Pattern (java.util.regex.Pattern)1 CustomLog (lombok.CustomLog)1 ClassProvider (org.flywaydb.core.api.ClassProvider)1 Callback (org.flywaydb.core.api.callback.Callback)1 Configuration (org.flywaydb.core.api.configuration.Configuration)1 JavaMigration (org.flywaydb.core.api.migration.JavaMigration)1 CallbackExecutor (org.flywaydb.core.internal.callback.CallbackExecutor)1 NoopClassProvider (org.flywaydb.core.internal.clazz.NoopClassProvider)1 DatabaseExecutionStrategy (org.flywaydb.core.internal.database.DatabaseExecutionStrategy)1