@Override void configureReturner(Script stmt, SqlObjectStatementConfiguration cfg) { cfg.setReturner(() -> stmt.execute()); }
@Test public void testScript() { // tag::script[] int[] results = handle.createScript( "INSERT INTO user VALUES(3, 'Charlie');" + "UPDATE user SET name='Bobby Tables' WHERE id=2;") .execute(); assertThat(results).containsExactly(1, 1); // end::script[] }
@Test public void testParamRight() { FooParamRight sqlObject = handle.attach(FooParamRight.class); handle.createScript(CREATE_INSERT).execute(); assertThat(sqlObject.bar(ROWS)).hasSize(ROWS); }
@Test public void testMethodRight() { FooMethodRight sqlObject = handle.attach(FooMethodRight.class); handle.createScript(CREATE_INSERT).execute(); assertThat(sqlObject.bar()).hasSize(ROWS); }
@Test public void testControlGroup() { NoMaxRows sqlObject = handle.attach(NoMaxRows.class); handle.createScript(CREATE_INSERT).execute(); assertThat(sqlObject.bar()).hasSize(3); }
@Test public void testParamNonsense() { FooParamRight sqlObject = handle.attach(FooParamRight.class); handle.createScript(CREATE_INSERT).execute(); assertThatThrownBy(() -> sqlObject.bar(0)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("is 0, which is negative or 0"); }
@Test public void testFetchSize() { h.createScript(findSqlOnClasspath("default-data")).execute(); ResultIterable<Something> ri = h.createQuery("select id, name from something order by id") .setFetchSize(1) .mapToBean(Something.class); ResultIterator<Something> r = ri.iterator(); assertThat(r.hasNext()).isTrue(); r.next(); assertThat(r.hasNext()).isTrue(); r.next(); assertThat(r.hasNext()).isFalse(); }
@Test public void testScriptStuff() { Handle h = dbRule.openHandle(); Script s = h.createScript(findSqlOnClasspath("default-data")); s.execute(); assertThat(h.select("select * from something").mapToMap()).hasSize(2); }
@Test public void testScriptWithComments() { Handle h = dbRule.openHandle(); Script script = h.createScript(getResourceOnClasspath("script/insert-script-with-comments.sql")); script.execute(); assertThat(h.select("select * from something").mapToMap()).hasSize(3); }
@Test public void testScriptWithStringSemicolon() { Handle h = dbRule.openHandle(); Script script = h.createScript(getResourceOnClasspath("script/insert-with-string-semicolons.sql")); script.execute(); assertThat(h.select("select * from something").mapToMap()).hasSize(3); }
@Test public void testMethodRight() { FooMethodRight sqlObject = handle.attach(FooMethodRight.class); handle.createScript(CREATE_INSERT).execute(); assertThat(sqlObject.bar()).hasSize(ROWS); }
@Test public void testControlGroup() { NoMaxRows sqlObject = handle.attach(NoMaxRows.class); handle.createScript(CREATE_INSERT).execute(); assertThat(sqlObject.bar()).hasSize(3); }
@Test public void testParamRight() { FooParamRight sqlObject = handle.attach(FooParamRight.class); handle.createScript(CREATE_INSERT).execute(); assertThat(sqlObject.bar(ROWS)).hasSize(ROWS); }
@Test public void testParamNonsense() { FooParamRight sqlObject = handle.attach(FooParamRight.class); handle.createScript(CREATE_INSERT).execute(); assertThatThrownBy(() -> sqlObject.bar(0)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("is 0, which is negative or 0"); }