@Test public void connectionMadeIllegalPath() { final FilePathInitializationPlugin filePathInitializationPlugin = new FilePathInitializationPlugin( "classpath:nonexisting.sql", StandardCharsets.UTF_8); assertNotNull(filePathInitializationPlugin); assertThrows(IllegalArgumentException.class, () -> filePathInitializationPlugin.connectionMade("name", connection)); verifyNoMoreInteractions(connection, statement); }
@Override public void connectionMade(final String name, final Connection connection) { final FilePath filePath = FilePath.get(resource); try (final InputStream inputStream = filePath.newInputStream(); final Statement statement = connection.createStatement(); final ByteArrayOutputStream out = new ByteArrayOutputStream(Math.max(32, inputStream.available())); ) { copyToOutputStream(inputStream, out); statement.execute(convertToString(out.toByteArray())); } catch (IOException e) { throw new IllegalArgumentException(String.format("Could not read SQL from file path \"%s\"", filePath.getName()), e); } catch (SQLException e) { throw new IllegalArgumentException(String.format("Could not run SQL script from file path \"%s\"", filePath.getName()), e); } }
FilePathInitializationPlugin implements InitializationPlugin { @Override public void connectionMade(final String name, final Connection connection) { final FilePath filePath = FilePath.get(resource); try (final InputStream inputStream = filePath.newInputStream(); final Statement statement = connection.createStatement(); final ByteArrayOutputStream out = new ByteArrayOutputStream(Math.max(32, inputStream.available())); ) { copyToOutputStream(inputStream, out); statement.execute(convertToString(out.toByteArray())); } catch (IOException e) { throw new IllegalArgumentException(String.format("Could not read SQL from file path \"%s\"", filePath.getName()), e); } catch (SQLException e) { throw new IllegalArgumentException(String.format("Could not run SQL script from file path \"%s\"", filePath.getName()), e); } } }
FilePathInitializationPlugin implements InitializationPlugin { @Override public void connectionMade(final String name, final Connection connection) { final FilePath filePath = FilePath.get(resource); try (final InputStream inputStream = filePath.newInputStream(); final Statement statement = connection.createStatement(); final ByteArrayOutputStream out = new ByteArrayOutputStream(Math.max(32, inputStream.available())); ) { copyToOutputStream(inputStream, out); statement.execute(convertToString(out.toByteArray())); } catch (IOException e) { throw new IllegalArgumentException(String.format("Could not read SQL from file path \"%s\"", filePath.getName()), e); } catch (SQLException e) { throw new IllegalArgumentException(String.format("Could not run SQL script from file path \"%s\"", filePath.getName()), e); } } FilePathInitializationPlugin(final String resource, final Charset charset); }
FilePathInitializationPlugin implements InitializationPlugin { @Override public void connectionMade(final String name, final Connection connection) { final FilePath filePath = FilePath.get(resource); try (final InputStream inputStream = filePath.newInputStream(); final Statement statement = connection.createStatement(); final ByteArrayOutputStream out = new ByteArrayOutputStream(Math.max(32, inputStream.available())); ) { copyToOutputStream(inputStream, out); statement.execute(convertToString(out.toByteArray())); } catch (IOException e) { throw new IllegalArgumentException(String.format("Could not read SQL from file path \"%s\"", filePath.getName()), e); } catch (SQLException e) { throw new IllegalArgumentException(String.format("Could not run SQL script from file path \"%s\"", filePath.getName()), e); } } FilePathInitializationPlugin(final String resource, final Charset charset); @Override void connectionMade(final String name, final Connection connection); }
FilePathInitializationPlugin implements InitializationPlugin { @Override public void connectionMade(final String name, final Connection connection) { final FilePath filePath = FilePath.get(resource); try (final InputStream inputStream = filePath.newInputStream(); final Statement statement = connection.createStatement(); final ByteArrayOutputStream out = new ByteArrayOutputStream(Math.max(32, inputStream.available())); ) { copyToOutputStream(inputStream, out); statement.execute(convertToString(out.toByteArray())); } catch (IOException e) { throw new IllegalArgumentException(String.format("Could not read SQL from file path \"%s\"", filePath.getName()), e); } catch (SQLException e) { throw new IllegalArgumentException(String.format("Could not run SQL script from file path \"%s\"", filePath.getName()), e); } } FilePathInitializationPlugin(final String resource, final Charset charset); @Override void connectionMade(final String name, final Connection connection);  }