From 53e234af71899c5907c7f51e7e1a7cdecf544f0a Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Fri, 17 Aug 2012 14:51:30 +0200 Subject: [PATCH] [#1692] Replace Factory.executeInsert(), Factory.executeUpdate() and similar methods with more succinct variants - Added missing parts for executeDelete() --- .../org/jooq/test/_/testcases/CRUDTests.java | 4 +- .../main/java/org/jooq/FactoryOperations.java | 42 ++++++++++++- jOOQ/src/main/java/org/jooq/impl/Factory.java | 26 +++++++- .../main/java/org/jooq/impl/FactoryProxy.java | 61 +++++++++++-------- 4 files changed, 103 insertions(+), 30 deletions(-) diff --git a/jOOQ-test/src/org/jooq/test/_/testcases/CRUDTests.java b/jOOQ-test/src/org/jooq/test/_/testcases/CRUDTests.java index e539812c21..e7096b6a7d 100644 --- a/jOOQ-test/src/org/jooq/test/_/testcases/CRUDTests.java +++ b/jOOQ-test/src/org/jooq/test/_/testcases/CRUDTests.java @@ -227,7 +227,7 @@ extends BaseTest
UPDATE [table] SET [modified values in record] 
+ *
UPDATE [table] SET [modified values in record] WHERE [record is supplied record] 
* * @return The number of updated records * @throws DataAccessException if something went wrong executing the query @@ -1168,12 +1168,36 @@ public interface FactoryOperations extends Configuration { , T> int executeUpdate(R record, Condition condition) throws DataAccessException; /** - * Delete records from a table
DELETE FROM [table]
+ * Delete a record from a table + *
DELETE FROM [table] WHERE [record is supplied record]
* * @return The number of deleted records * @throws DataAccessException if something went wrong executing the query */ @Support + > int executeDelete(R record) throws DataAccessException; + + /** + * Delete a record from a table + *
DELETE FROM [table] WHERE [condition]
+ * + * @return The number of deleted records + * @throws DataAccessException if something went wrong executing the query + */ + @Support + , T> int executeDelete(R record, Condition condition) throws DataAccessException; + + /** + * Delete records from a table
DELETE FROM [table]
+ * + * @return The number of deleted records + * @throws DataAccessException if something went wrong executing the query + * @deprecated - 2.5.0 [#1692] - The semantics of + * {@link #executeDelete(TableRecord, Condition)} has changed. + * This method here is no longer necessary. + */ + @Deprecated + @Support > int executeDelete(Table table) throws DataAccessException; /** @@ -1181,8 +1205,12 @@ public interface FactoryOperations extends Configuration { *
DELETE FROM [table] WHERE [condition]
* * @return The number of deleted records - * @throws DataAccessException if something went wrong executing the query + * @throws DataAccessException if something went wrong executing the query. + * @deprecated - 2.5.0 [#1692] - The semantics of + * {@link #executeDelete(TableRecord, Condition)} has changed. + * This method here is no longer necessary. */ + @Deprecated @Support , T> int executeDelete(Table table, Condition condition) throws DataAccessException; @@ -1191,7 +1219,11 @@ public interface FactoryOperations extends Configuration { * * @return The number of deleted records * @throws DataAccessException if something went wrong executing the query + * @deprecated - 2.5.0 [#1692] - The semantics of + * {@link #executeDelete(TableRecord, Condition)} has changed. + * This method here is no longer necessary. */ + @Deprecated @Support > int executeDeleteOne(Table table) throws DataAccessException; @@ -1201,7 +1233,11 @@ public interface FactoryOperations extends Configuration { * * @return The number of deleted records * @throws DataAccessException if something went wrong executing the query + * @deprecated - 2.5.0 [#1692] - The semantics of + * {@link #executeDelete(TableRecord, Condition)} has changed. + * This method here is no longer necessary. */ + @Deprecated @Support , T> int executeDeleteOne(Table table, Condition condition) throws DataAccessException; diff --git a/jOOQ/src/main/java/org/jooq/impl/Factory.java b/jOOQ/src/main/java/org/jooq/impl/Factory.java index d631f6b597..5ee950060a 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Factory.java +++ b/jOOQ/src/main/java/org/jooq/impl/Factory.java @@ -6167,6 +6167,27 @@ public class Factory implements FactoryOperations { * {@inheritDoc} */ @Override + public final > int executeDelete(R record) { + DeleteQuery delete = deleteQuery(record.getTable()); + Util.addConditions(delete, record, record.getTable().getMainKey().getFieldsArray()); + return delete.execute(); + } + + /** + * {@inheritDoc} + */ + @Override + public final , T> int executeDelete(R record, Condition condition) { + DeleteQuery delete = deleteQuery(record.getTable()); + delete.addConditions(condition); + return delete.execute(); + } + + /** + * {@inheritDoc} + */ + @Override + @Deprecated public final > int executeDelete(Table table) { return executeDelete(table, trueCondition()); } @@ -6175,8 +6196,9 @@ public class Factory implements FactoryOperations { * {@inheritDoc} */ @Override + @Deprecated public final , T> int executeDelete(Table table, Condition condition) - { + throws DataAccessException{ DeleteQuery delete = deleteQuery(table); delete.addConditions(condition); return delete.execute(); @@ -6186,6 +6208,7 @@ public class Factory implements FactoryOperations { * {@inheritDoc} */ @Override + @Deprecated public final > int executeDeleteOne(Table table) { return executeDeleteOne(table, trueCondition()); } @@ -6194,6 +6217,7 @@ public class Factory implements FactoryOperations { * {@inheritDoc} */ @Override + @Deprecated public final , T> int executeDeleteOne(Table table, Condition condition) { DeleteQuery delete = deleteQuery(table); delete.addConditions(condition); diff --git a/jOOQ/src/main/java/org/jooq/impl/FactoryProxy.java b/jOOQ/src/main/java/org/jooq/impl/FactoryProxy.java index 4583608c07..a1be44d7cc 100644 --- a/jOOQ/src/main/java/org/jooq/impl/FactoryProxy.java +++ b/jOOQ/src/main/java/org/jooq/impl/FactoryProxy.java @@ -423,17 +423,17 @@ public final class FactoryProxy implements FactoryOperations { } @Override - public final Cursor fetchLazy(String sql) throws DataAccessException { + public final Cursor fetchLazy(String sql) { return getDelegate().fetchLazy(sql); } @Override - public final Cursor fetchLazy(String sql, Object... bindings) throws DataAccessException { + public final Cursor fetchLazy(String sql, Object... bindings) { return getDelegate().fetchLazy(sql, bindings); } @Override - public final Cursor fetchLazy(String sql, QueryPart... parts) throws DataAccessException { + public final Cursor fetchLazy(String sql, QueryPart... parts) { return getDelegate().fetchLazy(sql, parts); } @@ -468,27 +468,27 @@ public final class FactoryProxy implements FactoryOperations { } @Override - public final int execute(String sql) throws DataAccessException { + public final int execute(String sql) { return getDelegate().execute(sql); } @Override - public final int execute(String sql, Object... bindings) throws DataAccessException { + public final int execute(String sql, Object... bindings) { return getDelegate().execute(sql, bindings); } @Override - public final int execute(String sql, QueryPart... parts) throws DataAccessException { + public final int execute(String sql, QueryPart... parts) { return getDelegate().execute(sql, parts); } @Override - public final ResultQuery resultQuery(String sql) throws DataAccessException { + public final ResultQuery resultQuery(String sql) { return getDelegate().resultQuery(sql); } @Override - public final ResultQuery resultQuery(String sql, Object... bindings) throws DataAccessException { + public final ResultQuery resultQuery(String sql, Object... bindings) { return getDelegate().resultQuery(sql, bindings); } @@ -554,7 +554,7 @@ public final class FactoryProxy implements FactoryOperations { } @Override - public final > int executeInsert(R record) throws DataAccessException { + public final > int executeInsert(R record) { return getDelegate().executeInsert(record); } @@ -583,93 +583,106 @@ public final class FactoryProxy implements FactoryOperations { } @Override - public final > int executeUpdate(R record) throws DataAccessException { + public final > int executeUpdate(R record) { return getDelegate().executeUpdate(record); } @Override - public final , T> int executeUpdate(R record, Condition condition) - throws DataAccessException { + public final , T> int executeUpdate(R record, Condition condition) { return getDelegate().executeUpdate(record, condition); } @Override + public final > int executeDelete(R record) { + return getDelegate().executeDelete(record); + } + + @Override + public final , T> int executeDelete(R record, Condition condition) { + return getDelegate().executeDelete(record, condition); + } + + @Override + @Deprecated public final > int executeDelete(Table table) { return getDelegate().executeDelete(table); } @Override + @Deprecated public final , T> int executeDelete(Table table, Condition condition) { return getDelegate().executeDelete(table, condition); } @Override + @Deprecated public final > int executeDeleteOne(Table table) { return getDelegate().executeDeleteOne(table); } @Override + @Deprecated public final , T> int executeDeleteOne(Table table, Condition condition) { return getDelegate().executeDeleteOne(table, condition); } @Override - public final int getTransactionIsolation() throws DataAccessException { + public final int getTransactionIsolation() { return getDelegate().getTransactionIsolation(); } @Override - public final void setTransactionIsolation(int level) throws DataAccessException { + public final void setTransactionIsolation(int level) { getDelegate().setTransactionIsolation(level); } @Override - public final int getHoldability() throws DataAccessException { + public final int getHoldability() { return getDelegate().getHoldability(); } @Override - public final void setHoldability(int holdability) throws DataAccessException { + public final void setHoldability(int holdability) { getDelegate().setHoldability(holdability); } @Override - public final boolean getAutoCommit() throws DataAccessException { + public final boolean getAutoCommit() { return getDelegate().getAutoCommit(); } @Override - public final void setAutoCommit(boolean autoCommit) throws DataAccessException { + public final void setAutoCommit(boolean autoCommit) { getDelegate().setAutoCommit(autoCommit); } @Override - public final void releaseSavepoint(Savepoint savepoint) throws DataAccessException { + public final void releaseSavepoint(Savepoint savepoint) { getDelegate().releaseSavepoint(savepoint); } @Override - public final Savepoint setSavepoint(String name) throws DataAccessException { + public final Savepoint setSavepoint(String name) { return getDelegate().setSavepoint(name); } @Override - public final Savepoint setSavepoint() throws DataAccessException { + public final Savepoint setSavepoint() { return getDelegate().setSavepoint(); } @Override - public final void rollback(Savepoint savepoint) throws DataAccessException { + public final void rollback(Savepoint savepoint) { getDelegate().rollback(savepoint); } @Override - public final void rollback() throws DataAccessException { + public final void rollback() { getDelegate().rollback(); } @Override - public final void commit() throws DataAccessException { + public final void commit() { getDelegate().commit(); }