protected Binding getBinding() { return getContext().getBinding(); }
void applyCustomizers(final StatementType stmt, Object[] args) { statementCustomizers.forEach(b -> { try { b.apply(stmt, args); } catch (SQLException e) { throw new UnableToExecuteStatementException(e, stmt.getContext()); } }); }
void beforeExecution() { callCustomizers(c -> c.beforeExecution(stmt, getContext())); }
void afterExecution() { callCustomizers(c -> c.afterExecution(stmt, getContext())); } }
void beforeTemplating() { callCustomizers(c -> c.beforeTemplating(stmt, getContext())); }
void beforeBinding() { callCustomizers(c -> c.beforeBinding(stmt, getContext())); }
SqlStatement(Handle handle, String sql) { super(handle); this.handle = handle; this.sql = sql; getContext() .setConnection(handle.getConnection()) .setRawSql(sql); }
final StatementContext ctx = getContext(); for (int valueIndex = 0; valueIter.hasNext(); valueIndex++) { if (valueIndex > 0) {
StatementContext ctx = getContext(); for (int valueIndex = 0; valueIndex < values.size(); valueIndex++) { if (valueIndex > 0) {
/** * Binds named parameters from object properties on the bean argument, with the given prefix. * The type must have been registered with pojo type mapping functionality first, usually * by a plugin or configuration. * * @param prefix a prefix to apply to all property names. * @param pojo source of named parameter values to use as arguments * * @return modified statement * @see JdbiImmutables an example method of registering a type */ @Beta public This bindPojo(String prefix, Object pojo) { return bindNamedArgumentFinder(new PojoPropertyArguments(prefix, pojo, getContext())); }
names.append(','); String paramName = getConfig().get(SqlStatements.class).getSqlParser().nameParameter(name, getContext()); names.append(paramName);
@Override public SqlStatementParameterCustomizer createForParameter(Annotation annotation, Class<?> sqlObjectType, Method method, Parameter param, int index, Type type) { return (stmt, arg) -> { final QualifiedType<?> mapTo; if (arg instanceof QualifiedType) { mapTo = (QualifiedType<?>) arg; } else if (arg instanceof GenericType) { mapTo = QualifiedType.of(((GenericType<?>) arg).getType()); } else if (arg instanceof Type) { mapTo = QualifiedType.of((Type) arg); } else { throw new UnsupportedOperationException("@MapTo must take a GenericType, QualifiedType, or Type, but got a " + arg.getClass().getName()); } ResultReturner returner = ResultReturner.forMethod(sqlObjectType, method); stmt.getConfig(SqlObjectStatementConfiguration.class).setReturner( () -> returner.mappedResult(((ResultBearing) stmt).mapTo(mapTo), stmt.getContext())); }; } }
PreparedStatement internalExecute() { final StatementContext ctx = getContext();
protected Binding getBinding() { return getContext().getBinding(); }
SqlStatement(Handle handle, String sql) { super(handle); this.handle = handle; this.sql = sql; getContext() .setConnection(handle.getConnection()) .setRawSql(sql); }
StatementContext ctx = getContext(); for (int valueIndex = 0; valueIndex < values.size(); valueIndex++) { if (valueIndex > 0) {
.render(sql, getContext()); getContext().setRenderedSql(renderedSql); .parse(renderedSql, getContext()); String sql = parsedSql.getSql(); ParsedParameters parsedParameters = parsedSql.getParameters(); getContext().setParsedSql(sql); stmt = handle.getStatementBuilder().createCall(handle.getConnection(), sql, getContext()); stmt = handle.getStatementBuilder().create(handle.getConnection(), sql, getContext()); throw new UnableToCreateStatementException(e, getContext()); getContext().setStatement(stmt); ArgumentBinder.bind(parsedParameters, getBinding(), stmt, getContext()); getConfig(SqlStatements.class) .getTimingCollector() .collect(elapsedTime, getContext()); e.addSuppressed(e1); throw new UnableToExecuteStatementException(e, getContext());