From fe5bdc97492b51643f439a98655e9bd694bfcf02 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 11 Jan 2012 18:56:04 +0000 Subject: [PATCH] [#1051] Add Factory.execute(String, Object...) as a convenience method for Factory.query(...).execute(); --- .../org/jooq/util/spring/FactoryProxy.java | 10 ++++++ .../main/java/org/jooq/FactoryOperations.java | 33 +++++++++++++++++++ jOOQ/src/main/java/org/jooq/impl/Factory.java | 16 +++++++++ 3 files changed, 59 insertions(+) diff --git a/jOOQ-spring/src/main/java/org/jooq/util/spring/FactoryProxy.java b/jOOQ-spring/src/main/java/org/jooq/util/spring/FactoryProxy.java index 39a7640d12..2e7faf4f6d 100644 --- a/jOOQ-spring/src/main/java/org/jooq/util/spring/FactoryProxy.java +++ b/jOOQ-spring/src/main/java/org/jooq/util/spring/FactoryProxy.java @@ -381,6 +381,16 @@ public class FactoryProxy implements FactoryOperations, MethodInterceptor { return getDelegate().fetchOne(sql, bindings); } + @Override + public final int execute(String sql) throws DataAccessException { + return getDelegate().execute(sql); + } + + @Override + public final int execute(String sql, Object... bindings) throws DataAccessException { + return getDelegate().execute(sql, bindings); + } + @Override public final ResultQuery resultQuery(String sql) throws DataAccessException { return getDelegate().resultQuery(sql); diff --git a/jOOQ/src/main/java/org/jooq/FactoryOperations.java b/jOOQ/src/main/java/org/jooq/FactoryOperations.java index 3fc9c5f331..f1ce63e610 100644 --- a/jOOQ/src/main/java/org/jooq/FactoryOperations.java +++ b/jOOQ/src/main/java/org/jooq/FactoryOperations.java @@ -1034,6 +1034,39 @@ public interface FactoryOperations extends Configuration { @Support Record fetchOne(String sql, Object... bindings) throws DataAccessException; + /** + * Execute a query holding plain SQL. + *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @param sql The SQL + * @return The results from the executed query + * @throws DataAccessException if something went wrong executing the query + */ + @Support + int execute(String sql) throws DataAccessException; + + /** + * Execute a new query holding plain SQL. There must be as many binding + * variables contained in the SQL, as passed in the bindings parameter + *

+ *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @param sql The SQL + * @param bindings The bindings + * @return The results from the executed query + * @throws DataAccessException if something went wrong executing the query + */ + @Support + int execute(String sql, Object... bindings) throws DataAccessException; + /** * Create a new query holding plain SQL. There must not be any binding * variables contained in the SQL diff --git a/jOOQ/src/main/java/org/jooq/impl/Factory.java b/jOOQ/src/main/java/org/jooq/impl/Factory.java index 725ad365ef..22d3aa08e6 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Factory.java +++ b/jOOQ/src/main/java/org/jooq/impl/Factory.java @@ -841,6 +841,22 @@ public class Factory implements FactoryOperations { return new SQLResultQuery(this, sql, bindings).fetchOne(); } + /** + * {@inheritDoc} + */ + @Override + public final int execute(String sql) throws DataAccessException { + return query(sql).execute(); + } + + /** + * {@inheritDoc} + */ + @Override + public final int execute(String sql, Object... bindings) throws DataAccessException { + return query(sql, bindings).execute(); + } + /** * {@inheritDoc} */