public void add(@NotNull String... commands) { for (String command : commands) { SqlCommand cmd = new SqlCommand(command); myStatements.add(cmd); } }
@NotNull private static SqlStatement[] makeStatementsFromStrings(final @NotNull String[] statements) { int n = statements.length; SqlStatement[] r = new SqlStatement[n]; for (int i = 0; i < n; i++) r[i] = new SqlCommand(statements[i]); return r; }
@NotNull @Override public SqlCommand rewrite(@NotNull final StringOperator operator) { String transformedSourceTex = operator.apply(mySourceText); return new SqlCommand(myRow, transformedSourceTex, myName, myDescription); }
@Override public void performCommand(@NotNull final String commandText) { final SqlCommand command = new SqlCommand(commandText); performCommand(command); }
@Override public void performCommand(@NotNull final DBTransaction transaction, @NotNull final String commandText) { final SqlCommand command = new SqlCommand(commandText); performCommand(transaction, command); }
@NotNull public final SqlCommand command(@NotNull final String name) { TextFileFragment fragment = getText(name); fragment = stripSingleStatement(fragment); return new SqlCommand(fragment); }
private void extractPLBlock(@NotNull TextWalker walker) { final TextPointer begin = walker.getPointer(); int position; while (true) { position = walker.getOffset(); if (walker.isEOT()) break; String row = walker.popRow().trim(); if (row.equals("/")) break; } String plText = rtrim(walker.getText().substring(begin.offset, position)); SqlCommand command = new SqlCommand(plText, begin.row, null); myStatements.add(command); }
private void extractSQLCommand(@NotNull TextWalker walker) { skipEmptySpace(walker); final TextPointer begin = walker.getPointer(); final Matcher matcher = walker.skipToPattern(SQL_END_MARKER); final String sqlText = rtrim(walker.getText().substring(begin.offset, walker.getOffset())); SqlCommand command = new SqlCommand(sqlText, begin.row, null); myStatements.add(command); if (matcher != null) { walker.skipToOffset(matcher.end()); } }
@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(); } }); }
@Test public void basic_create_drop() { TH.ensureNoTableOrView("Tab1"); final SqlCommand command1 = new SqlCommand("create table Tab1 (ColA char(1))"); final SqlCommand command2 = new SqlCommand("drop table Tab1"); DB.inSession(new InSessionNoResult() { @Override public void run(@NotNull final DBSession session) { session.command(command1).run(); session.command(command2).run(); } }); }
@Test public void rewrite_basic() { SqlCommand cmd1 = new SqlCommand("AAA BBB CCC", 33, "name"); SqlCommand cmd2 = cmd1.rewrite(Rewriters.replace("BBB", "XXX")); assertThat(cmd2.getSourceText()).isEqualTo("AAA XXX CCC"); assertThat(cmd2.getRow()).isEqualTo(33); assertThat(cmd2.getName()).isEqualTo("name"); }