/** * Executes the update, returning the result obtained from the given {@link ResultProducer}. * * @param <R> the result type * @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("Could not produce statement result", e, getContext()); } }
public SqlUpdateHandler(Class<?> sqlObjectType, Method method) { super(sqlObjectType, method); if (method.isAnnotationPresent(UseRowReducer.class)) { throw new UnsupportedOperationException("Cannot declare @UseRowReducer on a @SqlUpdate method."); } boolean isGetGeneratedKeys = method.isAnnotationPresent(GetGeneratedKeys.class); QualifiedType<?> returnType = QualifiedType.of( GenericTypes.resolveType(method.getGenericReturnType(), sqlObjectType)) .with(getQualifiers(method)); if (isGetGeneratedKeys) { ResultReturner magic = ResultReturner.forMethod(sqlObjectType, method); String[] columnNames = method.getAnnotation(GetGeneratedKeys.class).value(); this.returner = update -> { ResultBearing resultBearing = update.executeAndReturnGeneratedKeys(columnNames); UseRowMapper useRowMapper = method.getAnnotation(UseRowMapper.class); ResultIterable<?> iterable = useRowMapper == null ? resultBearing.mapTo(returnType) : resultBearing.map(rowMapperFor(useRowMapper)); return magic.mappedResult(iterable, update.getContext()); }; } else if (isNumeric(method.getReturnType())) { this.returner = update -> update.execute(); } else if (isBoolean(method.getReturnType())) { this.returner = update -> update.execute() > 0; } else { throw new UnableToCreateSqlObjectException(invalidReturnTypeMessage(method, returnType)); } }
/** * Executes the update, returning the result obtained from the given {@link ResultProducer}. * * @param <R> the result type * @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("Could not produce statement result", e, getContext()); } }