@Override public List<AuditEntry> withHandle(Handle handle) { Query<Map<String, Object>> query = handle.createQuery(theQueryString); if (key != null) { query.bind("audit_key", key); } return query.bind("type", type) .setMaxRows(theLimit) .map( new ResultSetMapper<AuditEntry>() { @Override public AuditEntry map(int index, ResultSet r, StatementContext ctx) throws SQLException { try { return jsonMapper.readValue(r.getBytes("payload"), AuditEntry.class); } catch (IOException e) { throw new SQLException(e); } } } ) .list(); } }
@Override public void apply(SQLStatement q) throws SQLException { assert q instanceof Query; ((Query)q).setMaxRows(va); } };
public void apply(SQLStatement q) throws SQLException { assert q instanceof Query; ((Query)q).setMaxRows(va); } };
@Override public void apply(SQLStatement q) throws SQLException { assert q instanceof Query; ((Query)q).setMaxRows(va); } };
@Override public void apply(SQLStatement q) throws SQLException { assert q instanceof Query; ((Query)q).setMaxRows(va); } };
public void apply(SQLStatement q) throws SQLException { assert q instanceof Query; ((Query)q).setMaxRows(va); } };
public void apply(SQLStatement q) throws SQLException { assert q instanceof Query; ((Query)q).setMaxRows(va); } };
public static int getInteger(final Handle handle, final String query) { return handle.createQuery(query) .map(IntegerMapper.FIRST) // Work around an *incredibly* obscure bug in hsqldb 1.8.0.x where setMaxRows(1) // (which first does) will only return 0 (no rows) or 1 (rows) for COUNT(*) .setMaxRows(0) .first(); } }
@Override public List<AuditEntry> withHandle(Handle handle) { Query<Map<String, Object>> query = handle.createQuery(theQueryString); if (key != null) { query.bind("audit_key", key); } return query.bind("type", type) .setMaxRows(theLimit) .map( new ResultSetMapper<AuditEntry>() { @Override public AuditEntry map(int index, ResultSet r, StatementContext ctx) throws SQLException { try { return jsonMapper.readValue(r.getBytes("payload"), AuditEntry.class); } catch (IOException e) { throw new SQLException(e); } } } ) .list(); } }
@Override public List<AuditEntry> withHandle(Handle handle) throws Exception { Query<Map<String, Object>> query = handle.createQuery(theQueryString); if (key != null) { query.bind("audit_key", key); } return query.bind("type", type) .setMaxRows(theLimit) .map( new ResultSetMapper<AuditEntry>() { @Override public AuditEntry map(int index, ResultSet r, StatementContext ctx) throws SQLException { try { return jsonMapper.readValue(r.getBytes("payload"), AuditEntry.class); } catch (IOException e) { throw new SQLException(e); } } } ) .list(); } }
@Test public void testStatementCustomizersPersistAfterMap() throws Exception { h.insert("insert into something (id, name) values (?, ?)", 1, "hello"); h.insert("insert into something (id, name) values (?, ?)", 2, "world"); List<Something> rs = h.createQuery("select id, name from something") .setMaxRows(1) .map(Something.class) .list(); assertEquals(1, rs.size()); }
@Test public void testStatementCustomizersPersistAfterMap() throws Exception { h.insert("insert into something (id, name) values (?, ?)", 1, "hello"); h.insert("insert into something (id, name) values (?, ?)", 2, "world"); List<Something> rs = h.createQuery("select id, name from something") .setMaxRows(1) .map(Something.class) .list(); assertEquals(1, rs.size()); }