@Override public Void withHandle(Handle handle) { Batch batch = handle.createBatch(); for (DataSegment segment : segments) { batch.add( StringUtils.format( "UPDATE %s SET used=true WHERE id = '%s'", getSegmentsTable(), segment.getId() ) ); } batch.execute(); return null; } }
@Override public Void withHandle(Handle handle) { if (tableExists(handle, tableName)) { log.info("Deleting all records from table[%s]", tableName); final Batch batch = handle.createBatch(); batch.add("DELETE FROM " + tableName); batch.execute(); } else { log.info("Table[%s] does not exit.", tableName); } return null; } }
@Override public Void withHandle(Handle handle) { if (!tableExists(handle, tableName)) { log.info("Creating table[%s]", tableName); final Batch batch = handle.createBatch(); for (String s : sql) { batch.add(s); } batch.execute(); } else { log.info("Table[%s] already exists", tableName); } return null; } }
Batch batch = handle.createBatch(); for (int i = 0; i < 10; i++) { String timestampSt = StringUtils.format("2011-01-12T00:0%s:00.000Z", i);
/** * 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 String[] statements = getStatements(); Batch b = handle.createBatch(); for (String s : statements) { if ( ! WHITESPACE_ONLY.matcher(s).matches() ) { b.add(s); } } return b.execute(); }
/** * 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 String script; final StatementContext ctx = new ConcreteStatementContext(globalStatementAttributes); try { script = locator.locate(name, ctx); } catch (Exception e) { throw new UnableToExecuteStatementException(String.format("Error while loading script [%s]", name), e, ctx); } final String[] statements = script.replaceAll("\n", " ").replaceAll("\r", "").split(";"); Batch b = handle.createBatch(); for (String s : statements) { if ( ! WHITESPACE_ONLY.matcher(s).matches() ) { b.add(s); } } return b.execute(); } }
@Override public Void withHandle(Handle handle) throws Exception { Batch batch = handle.createBatch(); for (DataSegment segment : segments) { batch.add( String.format( "UPDATE %s SET used=true WHERE id = '%s'", getSegmentsTable(), segment.getIdentifier() ) ); } batch.execute(); return null; } }
@Override public Void withHandle(Handle handle) throws Exception { Batch batch = handle.createBatch(); for (DataSegment segment : segments) { batch.add( StringUtils.format( "UPDATE %s SET used=true WHERE id = '%s'", getSegmentsTable(), segment.getIdentifier() ) ); } batch.execute(); return null; } }
@Override public Void withHandle(Handle handle) { Batch batch = handle.createBatch(); for (DataSegment segment : segments) { batch.add( StringUtils.format( "UPDATE %s SET used=true WHERE id = '%s'", getSegmentsTable(), segment.getIdentifier() ) ); } batch.execute(); return null; } }
@Override public Void withHandle(Handle handle) { if (tableExists(handle, tableName)) { log.info("Deleting all records from table[%s]", tableName); final Batch batch = handle.createBatch(); batch.add("DELETE FROM " + tableName); batch.execute(); } else { log.info("Table[%s] does not exit.", tableName); } return null; } }
@Override public Void withHandle(Handle handle) throws Exception { if (tableExists(handle, tableName)) { log.info("Deleting all records from table[%s]", tableName); final Batch batch = handle.createBatch(); batch.add("DELETE FROM " + tableName); batch.execute(); } else { log.info("Table[%s] does not exit.", tableName); } return null; } }
@Override public Void withHandle(Handle handle) throws Exception { if (!tableExists(handle, tableName)) { log.info("Creating table[%s]", tableName); final Batch batch = handle.createBatch(); for (String s : sql) { batch.add(s); } batch.execute(); } else { log.info("Table[%s] already exists", tableName); } return null; } }
@Override public Void withHandle(Handle handle) { if (!tableExists(handle, tableName)) { log.info("Creating table[%s]", tableName); final Batch batch = handle.createBatch(); for (String s : sql) { batch.add(s); } batch.execute(); } else { log.info("Table[%s] already exists", tableName); } return null; } }
@Test public void testBatch() throws Exception { String sql1 = "insert into something (id, name) values (1, 'Eric')"; String sql2 = "insert into something (id, name) values (2, 'Keith')"; h.createBatch().add(sql1).add(sql2).execute(); assertEquals(2, logged.size()); assertEquals(sql1, logged.get(0)); assertEquals(sql2, logged.get(1)); }
@Test public void testBatch() throws Exception { String sql1 = "insert into something (id, name) values (1, 'Eric')"; String sql2 = "insert into something (id, name) values (2, 'Keith')"; h.createBatch().add(sql1).add(sql2).execute(); assertEquals(2, logged.size()); assertEquals(sql1, logged.get(0)); assertEquals(sql2, logged.get(1)); }
@Test public void testLog4J() throws Exception { BasicConfigurator.configure(new AppenderSkeleton() { @Override protected void append(LoggingEvent loggingEvent) { logged.add(loggingEvent.getRenderedMessage()); } @Override public boolean requiresLayout() { return false; } @Override public void close() { } }); h.setSQLLog(new Log4JLog()); Logger.getLogger("org.skife.jdbi").setLevel(Level.DEBUG); String sql1 = "insert into something (id, name) values (1, 'Eric')"; String sql2 = "insert into something (id, name) values (2, 'Keith')"; h.createBatch().add(sql1).add(sql2).execute(); assertEquals(1, logged.size()); assertTrue(logged.get(0).matches("batch:\\[\\[insert into something \\(id, name\\) values \\(1, 'Eric'\\)\\], \\[insert into something \\(id, name\\) values \\(2, 'Keith'\\)\\]\\] took \\d+ millis")); }
@Test public void testLog4J() throws Exception { BasicConfigurator.configure(new AppenderSkeleton() { @Override protected void append(LoggingEvent loggingEvent) { logged.add(loggingEvent.getRenderedMessage()); } @Override public boolean requiresLayout() { return false; } @Override public void close() { } }); h.setSQLLog(new Log4JLog()); Logger.getLogger("org.skife.jdbi").setLevel(Level.DEBUG); String sql1 = "insert into something (id, name) values (1, 'Eric')"; String sql2 = "insert into something (id, name) values (2, 'Keith')"; h.createBatch().add(sql1).add(sql2).execute(); assertEquals(1, logged.size()); assertTrue(logged.get(0).matches("batch:\\[\\[insert into something \\(id, name\\) values \\(1, 'Eric'\\)\\], \\[insert into something \\(id, name\\) values \\(2, 'Keith'\\)\\]\\] took \\d+ millis")); }
@Test public void testBasics() throws Exception { Handle h = this.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").map(Something.class).list(); assertEquals(3, r.size()); } }
@Test public void testBasics() throws Exception { Handle h = this.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").map(Something.class).list(); assertEquals(3, r.size()); } }