Search in sources :

Example 81 with FlywayException

use of org.flywaydb.core.api.FlywayException in project dhis2-core by dhis2.

the class V2_34_6__Convert_systemsetting_value_column_from_bytea_to_string method fillNewColWithTransformedData.

private void fillNewColWithTransformedData(final Context context, Set<SystemSetting> systemSettingsToConvert) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper();
    ObjectMapper specialObjectMapper = new ObjectMapper();
    specialObjectMapper.setVisibility(specialObjectMapper.getSerializationConfig().getDefaultVisibilityChecker().withFieldVisibility(Visibility.ANY).withGetterVisibility(Visibility.NONE).withSetterVisibility(Visibility.NONE).withCreatorVisibility(Visibility.NONE));
    try (PreparedStatement ps = context.getConnection().prepareStatement("UPDATE systemsetting SET value_text = ? WHERE systemsettingid = ?")) {
        for (SystemSetting systemSetting : systemSettingsToConvert) {
            if (systemSetting.getName().equals(SMS_CONFIGURATION_SETTING_NAME)) {
                ps.setString(1, specialObjectMapper.writeValueAsString(systemSetting.getValue()));
            } else {
                ps.setString(1, objectMapper.writeValueAsString(systemSetting.getValue()));
            }
            ps.setLong(2, systemSetting.getId());
            ps.execute();
        }
    } catch (SQLException e) {
        log.error("Flyway java migration error:", e);
        throw new FlywayException(e);
    }
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 82 with FlywayException

use of org.flywaydb.core.api.FlywayException in project killbill by killbill.

the class DbMigrateWithDryRun method applyMigration.

private void applyMigration(final int installedRnk, final MigrationInfoImpl migration) {
    final MigrationVersion version = migration.getVersion();
    final String migrationText;
    if (version != null) {
        migrationText = "schema " + schema + " to version " + version + " - " + migration.getDescription();
    } else {
        migrationText = "schema " + schema + " with repeatable migration " + migration.getDescription();
    }
    LOG.info("Migrating " + migrationText);
    // PIERRE: override the executor to capture the SQL
    final FileSystemResource sqlScriptResource = new FileSystemResource(migration.getResolvedMigration().getPhysicalLocation());
    final MigrationExecutor migrationExecutor = new CapturingSqlMigrationExecutor(sqlStatements, dbSupport, sqlScriptResource, placeholderReplacer, encoding);
    try {
        doMigrate(migration, migrationExecutor, migrationText);
    } catch (final SQLException e) {
        throw new FlywayException("Unable to apply migration", e);
    }
    final AppliedMigration appliedMigration = new AppliedMigration(installedRnk, version, migration.getDescription(), migration.getType(), migration.getScript(), migration.getResolvedMigration().getChecksum(), null, null, -1, true);
    metaDataTableForDryRun.addAppliedMigration(appliedMigration);
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) MigrationVersion(org.flywaydb.core.api.MigrationVersion) SQLException(java.sql.SQLException) AppliedMigration(org.flywaydb.core.internal.metadatatable.AppliedMigration) MigrationExecutor(org.flywaydb.core.api.resolver.MigrationExecutor) FileSystemResource(org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource)

Aggregations

FlywayException (org.flywaydb.core.api.FlywayException)82 SQLException (java.sql.SQLException)22 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)14 PreparedStatement (java.sql.PreparedStatement)8 HashMap (java.util.HashMap)8 URL (java.net.URL)7 ResultSet (java.sql.ResultSet)7 Statement (java.sql.Statement)7 File (java.io.File)6 MigrationVersion (org.flywaydb.core.api.MigrationVersion)6 ResolvedMigrationImpl (org.flywaydb.core.internal.resolver.ResolvedMigrationImpl)6 Test (org.junit.Test)6 InputStreamReader (java.io.InputStreamReader)5 Method (java.lang.reflect.Method)5 BufferedReader (java.io.BufferedReader)4 FileInputStream (java.io.FileInputStream)4 Reader (java.io.Reader)4 StringReader (java.io.StringReader)4 URLClassLoader (java.net.URLClassLoader)4