Search in sources :

Example 1 with Result

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

the class DefaultSqlScriptExecutor method handleResults.

protected void handleResults(Results results) {
    for (Result result : results.getResults()) {
        long updateCount = result.getUpdateCount();
        if (updateCount != -1) {
            handleUpdateCount(updateCount);
        }
        outputQueryResult(result);
    }
}
Also used : Result(org.flywaydb.core.internal.jdbc.Result)

Example 2 with Result

use of org.flywaydb.core.internal.jdbc.Result 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 3 with Result

use of org.flywaydb.core.internal.jdbc.Result 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

Result (org.flywaydb.core.internal.jdbc.Result)3 Results (org.flywaydb.core.internal.jdbc.Results)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 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 FlywayException (org.flywaydb.core.api.FlywayException)1