/** * Specify that the result set should be concurrent updatable. * * This will allow the update methods to be called on the result set produced by this * Query. * * @return the modified query */ public Query concurrentUpdatable() { getContext().setConcurrentUpdatable(true); return this; } }
/** * Executes the query, returning the result obtained from the given {@link ResultProducer}. * * @param <R> the type of the result * @param producer the result producer. * @return value returned by the result producer. */ public <R> R execute(ResultProducer<R> producer) { try { return producer.produce(this::internalExecute, getContext()); } catch (SQLException e) { try { close(); } catch (Exception e1) { e.addSuppressed(e1); } throw new UnableToProduceResultException(e, getContext()); } }
@Override void configureReturner(Query q, SqlObjectStatementConfiguration cfg) { UseRowMapper useRowMapper = getMethod().getAnnotation(UseRowMapper.class); UseRowReducer useRowReducer = getMethod().getAnnotation(UseRowReducer.class); if (useRowReducer != null && useRowMapper != null) { throw new IllegalStateException("Cannot declare @UseRowMapper and @UseRowReducer on the same method."); } cfg.setReturner(() -> { StatementContext ctx = q.getContext(); QualifiedType<?> elementType = magic.elementType(ctx); if (useRowReducer != null) { return magic.reducedResult(q.reduceRows(rowReducerFor(useRowReducer)), ctx); } ResultIterable<?> iterable = useRowMapper == null ? q.mapTo(elementType) : q.map(rowMapperFor(useRowMapper)); return magic.mappedResult(iterable, ctx); }); }
default void check() throws Exception { Class<StatementContextExtensionMethodDao> extensionMethodDaoClass = StatementContextExtensionMethodDao.class; Method checkMethod = extensionMethodDaoClass.getMethod("check"); ExtensionMethod extensionMethod = getHandle().getExtensionMethod(); assertThat(extensionMethod.getType()).isEqualTo(extensionMethodDaoClass); assertThat(extensionMethod.getMethod()).isEqualTo(checkMethod); extensionMethod = getHandle().createQuery("select * from something").getContext().getExtensionMethod(); assertThat(extensionMethod.getType()).isEqualTo(extensionMethodDaoClass); assertThat(extensionMethod.getMethod()).isEqualTo(checkMethod); } }
@Test public void findNVarcharArgument() throws Exception { dbRule.getJdbi().useHandle(handle -> { String value = "foo"; PreparedStatement stmt = mock(PreparedStatement.class); handle.getConfig(Arguments.class) .findFor(NVARCHAR_STRING, value) .orElseThrow(IllegalStateException::new) .apply(1, stmt, null); verify(stmt).setNString(1, value); handle.createQuery("no execute") .getContext() .findArgumentFor(NVARCHAR_STRING, value) .orElseThrow(IllegalStateException::new) .apply(2, stmt, null); verify(stmt).setNString(2, value); }); }
/** * Specify that the result set should be concurrent updatable. * * This will allow the update methods to be called on the result set produced by this * Query. * * @return the modified query */ public Query concurrentUpdatable() { getContext().setConcurrentUpdatable(true); return this; } }
/** * Executes the query, returning the result obtained from the given {@link ResultProducer}. * * @param <R> the type of the result * @param producer the result producer. * @return value returned by the result producer. */ public <R> R execute(ResultProducer<R> producer) { try { return producer.produce(this::internalExecute, getContext()); } catch (SQLException e) { try { close(); } catch (Exception e1) { e.addSuppressed(e1); } throw new UnableToProduceResultException(e, getContext()); } }
default void check() throws Exception { Class<StatementContextExtensionMethodDao> extensionMethodDaoClass = StatementContextExtensionMethodDao.class; Method checkMethod = extensionMethodDaoClass.getMethod("check"); ExtensionMethod extensionMethod = getHandle().getExtensionMethod(); assertThat(extensionMethod.getType()).isEqualTo(extensionMethodDaoClass); assertThat(extensionMethod.getMethod()).isEqualTo(checkMethod); extensionMethod = getHandle().createQuery("select * from something").getContext().getExtensionMethod(); assertThat(extensionMethod.getType()).isEqualTo(extensionMethodDaoClass); assertThat(extensionMethod.getMethod()).isEqualTo(checkMethod); } }