@Test public void should_execute_script_with_begin_and_end() throws Exception { ArgumentCaptor<String> statementsCaptor = ArgumentCaptor.forClass(String.class); scriptExecutor = spy(new ScriptExecutor(connection, scriptingConfiguration, new DefaultStatementSplitter(ScriptingConfiguration.NEW_LINE_SYMBOL))); scriptingConfiguration.setSqlStatementDelimiter(ScriptingConfiguration.NEW_LINE_SYMBOL); scriptExecutor.execute(FileLoader.loadAsString("scripts/new-line-delimiter-begin-end.sql")); verify(connection, times(8)).createStatement(); verify(connection.createStatement(), times(8)).execute(statementsCaptor.capture()); assertThat(statementsCaptor.getAllValues()) .containsSequence( "BEGIN", "create table address (id bigint not null, city varchar(255) not null, houseNumber integer, streetName varchar(255) not null, version bigint, zipCode integer not null, primary key (id))", "create table useraccount (id bigint generated by default as identity, firstname varchar(128) not null, lastname varchar(128) not null, nickname varchar(128), password varchar(255) not null, openDate date, username varchar(32) not null, primary key (id))", "create table useraccount_address (useraccount_id bigint not null, addresses_id bigint not null, primary key (useraccount_id, addresses_id), unique (addresses_id))", "alter table useraccount_address add constraint FK538F4B7EC498202 foreign key (useraccount_id) references useraccount", "alter table useraccount_address add constraint FK538F4B757E57A74 foreign key (addresses_id) references address", "create sequence hibernate_sequence start with 1 increment by 1", "END"); }
public void execute(String script) { final List<String> statements = statementSplitter.splitStatements(script); for (String statement : statements) { executeStatement(statement); } }
ScriptExecutor { public void execute(String script) { final List<String> statements = statementSplitter.splitStatements(script); for (String statement : statements) { executeStatement(statement); } } }
ScriptExecutor { public void execute(String script) { final List<String> statements = statementSplitter.splitStatements(script); for (String statement : statements) { executeStatement(statement); } } ScriptExecutor(final Connection connection, final ScriptingConfiguration scriptingConfiguration,
        final StatementSplitter statementSplitter); }
ScriptExecutor { public void execute(String script) { final List<String> statements = statementSplitter.splitStatements(script); for (String statement : statements) { executeStatement(statement); } } ScriptExecutor(final Connection connection, final ScriptingConfiguration scriptingConfiguration,
        final StatementSplitter statementSplitter); void execute(String script); }
ScriptExecutor { public void execute(String script) { final List<String> statements = statementSplitter.splitStatements(script); for (String statement : statements) { executeStatement(statement); } } ScriptExecutor(final Connection connection, final ScriptingConfiguration scriptingConfiguration,
        final StatementSplitter statementSplitter); void execute(String script);  }