Search in sources :

Example 1 with ToroRuntimeException

use of com.torodb.core.exceptions.ToroRuntimeException in project torodb by torodb.

the class AbstractSchemaUpdater method executeSql.

@SuppressFBWarnings(value = "UI_INHERITANCE_UNSAFE_GETRESOURCE", justification = "We want to read resources from the subclass")
protected void executeSql(DSLContext dsl, String resourcePath, SqlHelper sqlHelper) {
    try (InputStream resourceAsStream = getClass().getResourceAsStream(resourcePath)) {
        if (resourceAsStream == null) {
            throw new SystemException("Resource '" + resourcePath + "' does not exist");
        }
        String statementAsString = CharStreams.toString(new BufferedReader(new InputStreamReader(resourceAsStream, Charset.forName("UTF-8"))));
        sqlHelper.executeStatement(dsl, statementAsString, Context.UNKNOWN);
    } catch (IOException ex) {
        throw new ToroRuntimeException(ex);
    }
}
Also used : ToroRuntimeException(com.torodb.core.exceptions.ToroRuntimeException) SystemException(com.torodb.core.exceptions.SystemException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SystemException (com.torodb.core.exceptions.SystemException)1 ToroRuntimeException (com.torodb.core.exceptions.ToroRuntimeException)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1