final void callCustomizers(StatementCustomizerInvocation invocation) { for (StatementCustomizer customizer : getCustomizers()) { try { invocation.call(customizer); } catch (SQLException e) { throw new UnableToExecuteStatementException("Exception thrown in statement customization", e, ctx); } } }
/** * Locate the Script and split it into statements. * @return the split statements */ public List<String> getStatements() { return splitToStatements(getConfig(SqlStatements.class).getTemplateEngine().render(sql, getContext())); }
/** * Obtain the value of an attribute * * @param key the name of the attribute * @return the value of the attribute */ public Object getAttribute(String key) { return getConfig(SqlStatements.class).getAttribute(key); }
/** * 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; } }
/** * @return the finalized {@link ParsedSql} object. */ public ParsedSql build() { if (positional && named) { throw new UnableToExecuteStatementException( "Cannot mix named and positional parameters in a SQL statement: " + parameterNames); } ParsedParameters parameters = new ParsedParameters(positional, parameterNames); return new ParsedSql(sql.toString(), parameters); } }
/** * Register a positional output parameter * @param position the parameter position (zero-based) * @param sqlType an SQL type constant as defined by {@link java.sql.Types} or by the JDBC vendor. * @param mapper a mapper which converts the {@link CallableStatement} to a desired output type. * @return self */ public Call registerOutParameter(int position, int sqlType, CallableStatementMapper mapper) { getBinding().addPositional(position, new OutParamArgument(sqlType, mapper, null)); return this; }
/** * Register a named output parameter * @param name the parameter name * @param sqlType an SQL type constant as defined by {@link java.sql.Types} or by the JDBC vendor. * @param mapper a mapper which converts the {@link CallableStatement} to a desired output type. * @return self */ public Call registerOutParameter(String name, int sqlType, CallableStatementMapper mapper) { getBinding().addNamed(name, new OutParamArgument(sqlType, mapper, name)); return this; }
/** * Returns the attributes applied in this context. * * @return the defined attributes. */ public Map<String, Object> getAttributes() { return getConfig(SqlStatements.class).getAttributes(); }
static void bind(ParsedParameters parameters, Binding binding, PreparedStatement statement, StatementContext context) { if (parameters.isPositional()) { bindPositional(parameters, binding, statement, context); } else { bindNamed(parameters, binding, statement, context); } }
/** * Used if you need to have some exotic parameter bound. * * @param name name to bindBinaryStream this argument * @param argument exotic argument factory * * @return the same Query instance */ public This bind(String name, Argument argument) { getBinding().addNamed(name, argument); return typedThis; }
/** * Specify the maximum number of rows the query is to return. This uses the underlying JDBC * {@link Statement#setMaxRows(int)}}. * * @param maxRows maximum number of rows to return * * @return modified query */ public Query setMaxRows(final int maxRows) { return addCustomizer(StatementCustomizers.maxRows(maxRows)); }
/** * Specify the maximum field size in the result set. This uses the underlying JDBC * {@link Statement#setMaxFieldSize(int)} * * @param maxFields maximum field size * * @return modified query */ public Query setMaxFieldSize(final int maxFields) { return addCustomizer(StatementCustomizers.maxFieldSize(maxFields)); }
/** * Set the query timeout, in seconds, on the prepared statement * * @param seconds number of seconds before timing out * * @return the same Query instance */ public This setQueryTimeout(final int seconds) { return addCustomizer(StatementCustomizers.statementTimeout(seconds)); }
@Override public void logAfterExecution(StatementContext context) { timingCollector.collect(context.getElapsedTime(ChronoUnit.NANOS), context); } };
/** * Registers the given {@link Cleanable} to be executed when this statement is closed. * * @param cleanable the cleanable to register * @return this */ This addCleanable(Cleanable cleanable) { getContext().addCleanable(cleanable); return typedThis; }
@Override public void close() { getContext().close(); }
/** * Binds a new {@link NamedArgumentFinder}. * * @param namedArgumentFinder A NamedArgumentFinder to bind. Can be null. * * @return the same Query instance */ public This bindNamedArgumentFinder(final NamedArgumentFinder namedArgumentFinder) { if (namedArgumentFinder != null) { getBinding().addNamedArgumentFinder(namedArgumentFinder); } return typedThis; }
/** * Specify the fetch size for the query. This should cause the results to be * fetched from the underlying RDBMS in groups of rows equal to the number passed. * This is useful for doing chunked streaming of results when exhausting memory * could be a problem. * * @param fetchSize the number of rows to fetch in a bunch * * @return the modified query */ public Query setFetchSize(final int fetchSize) { return addCustomizer(StatementCustomizers.fetchSize(fetchSize)); }