/** * Subclasses may override this for covariant result types * * <p>{@inheritDoc} */ @SuppressWarnings("deprecation") @Override public Query bind(int index, Object value) { Param<?>[] params = getParams().values().toArray(new Param[0]); if (index < 1 || index > params.length) throw new IllegalArgumentException("Index out of range for Query parameters : " + index); Param<?> param = params[index - 1]; param.setConverted(value); closeIfNecessary(param); return this; }
/** * Subclasses may override this for covariant result types * * <p>{@inheritDoc} */ @Override public Query bind(String param, Object value) { try { int index = Integer.valueOf(param); return bind(index, value); } catch (NumberFormatException e) { Param<?> p = getParam(param); if (p == null) { throw new IllegalArgumentException("No such parameter : " + param); } p.setConverted(value); closeIfNecessary(p); return this; } }
/** * Subclasses may override this for covariant result types * * <p>{@inheritDoc} */ @SuppressWarnings("deprecation") @Override public Query bind(String param, Object value) { try { int index = Integer.valueOf(param); return bind(index, value); } catch (NumberFormatException e) { ParamCollector collector = new ParamCollector(configuration(), true); collector.visit(this); List<Param<?>> params = collector.result.get(param); if (params == null || params.size() == 0) throw new IllegalArgumentException("No such parameter : " + param); for (Param<?> p : params) { p.setConverted(value); closeIfNecessary(p); } return this; } }
/** * Close the statement if necessary. * * <p>[#1886] If there is an open (cached) statement and its bind values are inlined due to a * {@link StatementType#STATIC_STATEMENT} setting, the statement should be closed. * * @param param The param that was changed */ private final void closeIfNecessary(Param<?> param) { // This is relevant when there is an open statement, only if (keepStatement() && statement != null) { // When an inlined param is being changed, the previous statement // has to be closed, regardless if variable binding is performed if (param.isInline()) { close(); } // If all params are inlined, the previous statement always has to // be closed else if (getParamType(configuration().settings()) == INLINED) { close(); } } }