List of usage examples for org.apache.commons.dbutils.handlers LimitedMapListHandler LimitedMapListHandler
public LimitedMapListHandler(int limit)
From source file:com.bloidonia.vertx.mods.JdbcProcessor.java
private void doSelect(Message<JsonObject> message, Connection connection, TransactionalHandler transaction) throws SQLException { new BatchHandler(connection, message, transaction) { public JsonObject process() throws SQLException { JsonObject reply = new JsonObject(); ArrayList<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); // processing while ((resultSet != null || valueIterator.hasNext()) && (batchSize == -1 || result.size() < batchSize)) { LimitedMapListHandler handler = new LimitedMapListHandler( batchSize == -1 ? -1 : batchSize - result.size()); if (resultSet == null) { List<Object> params = valueIterator.next(); statementFiller.fill(statement, params); resultSet = statement.executeQuery(); }/*w w w. ja v a2 s . c om*/ store(result, handler); } reply.putArray("result", JsonUtils.listOfMapsToJsonArray(result)); return reply; } }.handle(message); }
From source file:com.bloidonia.vertx.mods.JdbcProcessor.java
private void doUpdate(Message<JsonObject> message, Connection connection, final boolean insert, TransactionalHandler transaction) throws SQLException { new BatchHandler(connection, message, transaction) { void initialiseStatement(Message<JsonObject> initial) throws SQLException { if (insert) { this.statement = connection.prepareStatement(initial.body().getString("stmt"), Statement.RETURN_GENERATED_KEYS); } else { this.statement = connection.prepareStatement(initial.body().getString("stmt")); }//from ww w . j a va 2s . c o m } public JsonObject process() throws SQLException { JsonObject reply = new JsonObject(); ArrayList<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); // processing int nRows = 0; if (insert) { while ((resultSet != null || valueIterator.hasNext()) && (batchSize == -1 || result.size() < batchSize)) { LimitedMapListHandler handler = new LimitedMapListHandler( batchSize == -1 ? -1 : batchSize - result.size()); if (resultSet == null) { List<Object> params = valueIterator.next(); statementFiller.fill(statement, params); nRows += statement.executeUpdate(); resultSet = statement.getGeneratedKeys(); } store(result, handler); } reply.putArray("result", JsonUtils.listOfMapsToJsonArray(result)); } else { while (valueIterator.hasNext()) { List<Object> params = valueIterator.next(); statementFiller.fill(statement, params); nRows += statement.executeUpdate(); } } reply.putNumber("updated", nRows); return reply; } }.handle(message); }