Search in sources :

Example 1 with Results

use of org.flywaydb.core.internal.jdbc.Results in project flyway by flyway.

the class InsertRowLock method insertLockingRow.

private boolean insertLockingRow(String insertStatementTemplate, String booleanTrue) {
    String insertStatement = String.format(insertStatementTemplate.replace("?", "%s"), -100, "'" + tableLockString + "'", "'flyway-lock'", "''", "''", 0, "''", 0, booleanTrue);
    // Insert the locking row - the primary key-ness of 'installed_rank' will prevent us having two
    Results results = jdbcTemplate.executeStatement(insertStatement);
    // Succeed if there were no errors
    return results.getException() == null;
}
Also used : Results(org.flywaydb.core.internal.jdbc.Results)

Example 2 with Results

use of org.flywaydb.core.internal.jdbc.Results in project flyway by flyway.

the class SybaseASEDatabase method getDdlInTranOption.

boolean getDdlInTranOption() {
    try {
        // http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc36273.1600/doc/html/san1393052037182.html
        String databaseName = getDatabaseName();
        // The Sybase driver (v7.07) concatenates "null" to this query and we can't see why. By adding a one-line
        // comment marker we can at least prevent this causing us problems until we get a resolution.
        String getDatabaseMetadataQuery = "sp_helpdb " + databaseName + " -- ";
        Results results = getMainConnection().getJdbcTemplate().executeStatement(getDatabaseMetadataQuery);
        for (int resultsIndex = 0; resultsIndex < results.getResults().size(); resultsIndex++) {
            List<String> columns = results.getResults().get(resultsIndex).getColumns();
            if (columns != null) {
                int statusIndex = getStatusIndex(columns);
                if (statusIndex > -1) {
                    String options = results.getResults().get(resultsIndex).getData().get(0).get(statusIndex);
                    return options.contains("ddl in tran");
                }
            }
        }
        return false;
    } catch (Exception e) {
        throw new FlywayException(e);
    }
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) Results(org.flywaydb.core.internal.jdbc.Results) SQLException(java.sql.SQLException) FlywayException(org.flywaydb.core.api.FlywayException)

Example 3 with Results

use of org.flywaydb.core.internal.jdbc.Results in project flyway by flyway.

the class DefaultSqlScriptExecutor method executeStatement.

protected void executeStatement(JdbcTemplate jdbcTemplate, SqlScript sqlScript, SqlStatement sqlStatement) {
    logStatementExecution(sqlStatement);
    String sql = sqlStatement.getSql() + sqlStatement.getDelimiter();
    Results results = sqlStatement.execute(jdbcTemplate);
    if (results.getException() != null) {
        printWarnings(results);
        handleException(results, sqlScript, sqlStatement);
        return;
    }
    printWarnings(results);
    handleResults(results);
}
Also used : Results(org.flywaydb.core.internal.jdbc.Results)

Example 4 with Results

use of org.flywaydb.core.internal.jdbc.Results in project flyway by flyway.

the class PostgreSQLCopyParsedStatement method execute.

@Override
public Results execute(JdbcTemplate jdbcTemplate) {
    // #2355: Use reflection to ensure this works in cases where the PostgreSQL driver classes were loaded in a
    // child URLClassLoader instead of the system classloader.
    Object baseConnection;
    Object copyManager;
    Method copyManagerCopyInMethod;
    try {
        Connection connection = jdbcTemplate.getConnection();
        ClassLoader classLoader = connection.getClass().getClassLoader();
        Class<?> baseConnectionClass = classLoader.loadClass("org.postgresql.core.BaseConnection");
        baseConnection = connection.unwrap(baseConnectionClass);
        Class<?> copyManagerClass = classLoader.loadClass("org.postgresql.copy.CopyManager");
        Constructor<?> copyManagerConstructor = copyManagerClass.getConstructor(baseConnectionClass);
        copyManagerCopyInMethod = copyManagerClass.getMethod("copyIn", String.class, Reader.class);
        copyManager = copyManagerConstructor.newInstance(baseConnection);
    } catch (Exception e) {
        throw new FlywayException("Unable to find PostgreSQL CopyManager class", e);
    }
    Results results = new Results();
    try {
        try {
            Long updateCount = (Long) copyManagerCopyInMethod.invoke(copyManager, getSql(), new StringReader(copyData));
            results.addResult(new Result(updateCount, null, null, getSql()));
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new SQLException("Unable to execute COPY operation", e);
        }
    } catch (SQLException e) {
        jdbcTemplate.extractErrors(results, e);
    }
    return results;
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Reader(java.io.Reader) StringReader(java.io.StringReader) Method(java.lang.reflect.Method) FlywayException(org.flywaydb.core.api.FlywayException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Result(org.flywaydb.core.internal.jdbc.Result) Results(org.flywaydb.core.internal.jdbc.Results) StringReader(java.io.StringReader)

Example 5 with Results

use of org.flywaydb.core.internal.jdbc.Results in project flyway by flyway.

the class SpannerSchema method doAllForeignKeys.

private List<String[]> doAllForeignKeys() {
    List<String[]> foreignKeyAndTableList = new ArrayList<>();
    Results foreignKeyRs = jdbcTemplate.executeStatement("SELECT CONSTRAINT_NAME, TABLE_NAME " + "FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS " + "WHERE CONSTRAINT_TYPE='FOREIGN KEY'");
    for (Result result : foreignKeyRs.getResults()) {
        for (List<String> row : result.getData()) {
            String[] foreignKeyAndTable = { row.get(0), row.get(1) };
            foreignKeyAndTableList.add(foreignKeyAndTable);
        }
    }
    return foreignKeyAndTableList;
}
Also used : Results(org.flywaydb.core.internal.jdbc.Results) ArrayList(java.util.ArrayList) Result(org.flywaydb.core.internal.jdbc.Result)

Aggregations

Results (org.flywaydb.core.internal.jdbc.Results)5 SQLException (java.sql.SQLException)2 FlywayException (org.flywaydb.core.api.FlywayException)2 Result (org.flywaydb.core.internal.jdbc.Result)2 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1