/** * Execute this script in a batch statement * * @return an array of ints which are the results of each statement in the script */ public int[] execute() { final List<String> statements = getStatements(); Batch b = handle.createBatch(); statements.forEach(b::add); return b.execute(); }
@Test public void testBatch() { h.createBatch().add(CREATE).define("x", "foo").execute(); assertThat(logger.getAttributes()) .hasSize(2) .allMatch(x -> x.get("x").equals("foo")) .allMatch(x -> x.size() == 1); }
@Test public void testBatch() { h.execute(CREATE); h.createBatch().add(INSERT).execute(); // unfortunately... assertThat(logger.getRawSql()).containsExactly(CREATE, CREATE, null, null); assertThat(logger.getTimings()).hasSize(2).allMatch(IS_POSITIVE); assertThat(logger.getExceptions()).isEmpty(); }
@Test public void testSimpleBatch() { // tag::simpleBatch[] Batch batch = handle.createBatch(); batch.add("INSERT INTO fruit VALUES(0, 'apple')"); batch.add("INSERT INTO fruit VALUES(1, 'banana')"); int[] rowsModified = batch.execute(); // end::simpleBatch[] assertThat(rowsModified).containsExactly(1, 1); assertThat(handle.createQuery("SELECT count(1) FROM fruit") .mapTo(int.class) .findOnly() .intValue()) .isEqualTo(2); }
@Test public void testBasics() { Handle h = dbRule.openHandle(); Batch b = h.createBatch(); b.add("insert into something (id, name) values (0, 'Keith')"); b.add("insert into something (id, name) values (1, 'Eric')"); b.add("insert into something (id, name) values (2, 'Brian')"); b.execute(); List<Something> r = h.createQuery("select * from something order by id").mapToBean(Something.class).list(); assertThat(r).hasSize(3); }
/** * Execute this script in a batch statement * * @return an array of ints which are the results of each statement in the script */ public int[] execute() { final List<String> statements = getStatements(); Batch b = handle.createBatch(); statements.forEach(b::add); return b.execute(); }