@NotNull public SqlScript build() { return new SqlScript(myStatements); }
@NotNull public final SqlScript script(@NotNull final String name) { TextFragment fragment = getText(name); SqlScriptBuilder b = new SqlScriptBuilder(); b.parse(fragment.text); return new SqlScript(b.build()); }
@Test public void construct_2() { SqlScript script1 = new SqlScript("command1"), script2 = new SqlScript("command2"); SqlScript script = new SqlScript(script1, script2); assertThat((Integer)script.getStatements().size()).isEqualTo((Integer)2); assertThat(script.getStatements().get(0).getSourceText()).isEqualTo("command1"); assertThat(script.getStatements().get(1).getSourceText()).isEqualTo("command2"); }
@Test public void basic_2() { final SqlScript script = new SqlScript("create table TT2(X1 integer)", "drop table TT2"); myFacade.inSession(new InSessionNoResult() { @Override public void run(@NotNull final DBSession session) { session.script(script).run(); } }); }
@Test public void basic_4() { final SqlScript script = new SqlScript("create table TT4(X1 integer)", "insert into TT4 values (44)", "select * from TT4", "drop table TT4"); myFacade.inSession(new InSessionNoResult() { @Override public void run(@NotNull final DBSession session) { session.script(script).run(); } }); }
@Test public void toString_contains_all_commands() { SqlScript script = new SqlScript("command 1", "command 2"); final String text = script.toString(); assertThat(text).contains("command 1") .contains("command 2"); }
@Test public void basic_4_with_query() { final SqlScript script = new SqlScript(new SqlCommand("create table TT4a(X1 integer)"), new SqlCommand("insert into TT4a values (44)"), new SqlQuery<Boolean>("select * from TT4a", Layouts.existence()), new SqlCommand("drop table TT4a")); myFacade.inSession(new InSessionNoResult() { @Override public void run(@NotNull final DBSession session) { session.script(script).run(); } }); }