From c1cf946f62d6f59c118e233155c2f5cc8a66b1ef Mon Sep 17 00:00:00 2001 From: lukaseder Date: Mon, 8 Oct 2018 12:02:47 +0200 Subject: [PATCH] [#7914] Overload fetchXYZ(T, Collection) and fetchXYZ(T, Condition...) --- jOOQ/src/main/java/org/jooq/DSLContext.java | 375 ++++++++++++++++++ .../java/org/jooq/impl/DefaultDSLContext.java | 120 +++++- 2 files changed, 490 insertions(+), 5 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java index 9a98cd6901..232cb690ad 100644 --- a/jOOQ/src/main/java/org/jooq/DSLContext.java +++ b/jOOQ/src/main/java/org/jooq/DSLContext.java @@ -10822,11 +10822,44 @@ public interface DSLContext extends Scope , AutoCloseable { * This executes
SELECT COUNT(*) FROM table WHERE condition
* * @param table The table whose records to count + * @param condition The condition to apply * @return The number of records in the table that satisfy a condition * @throws DataAccessException if something went wrong executing the query */ int fetchCount(Table table, Condition condition) throws DataAccessException; + /** + * Count the number of records in a table that satisfy a condition. + *

+ * This executes + *

SELECT COUNT(*) FROM table WHERE condition
+ *

+ * Convenience API for calling {@link #fetchCount(Table, Condition)} with + * {@link DSL#and(Condition...)}. + * + * @param table The table whose records to count + * @param conditions The conditions to apply + * @return The number of records in the table that satisfy a condition + * @throws DataAccessException if something went wrong executing the query + */ + int fetchCount(Table table, Condition... conditions) throws DataAccessException; + + /** + * Count the number of records in a table that satisfy a condition. + *

+ * This executes + *

SELECT COUNT(*) FROM table WHERE condition
+ *

+ * Convenience API for calling {@link #fetchCount(Table, Condition)} with + * {@link DSL#and(Collection)}. + * + * @param table The table whose records to count + * @param conditions The conditions to apply + * @return The number of records in the table that satisfy a condition + * @throws DataAccessException if something went wrong executing the query + */ + int fetchCount(Table table, Collection conditions) throws DataAccessException; + /** * Check if a {@link Select} would return any records, if it were executed. *

@@ -10870,6 +10903,34 @@ public interface DSLContext extends Scope , AutoCloseable { */ boolean fetchExists(Table table, Condition condition) throws DataAccessException; + /** + * Check if a table has any records that satisfy a condition. + *

+ * This executes

SELECT EXISTS(SELECT * FROM table WHERE condition)
+ *

+ * Convenience API for calling {@link #fetchExists(Table, Condition)} with + * {@link DSL#and(Condition...)}. + * + * @param table The table whose records to count + * @return Whether the table contains any records that satisfy a condition + * @throws DataAccessException if something went wrong executing the query + */ + boolean fetchExists(Table table, Condition... conditions) throws DataAccessException; + + /** + * Check if a table has any records that satisfy a condition. + *

+ * This executes

SELECT EXISTS(SELECT * FROM table WHERE condition)
+ *

+ * Convenience API for calling {@link #fetchExists(Table, Condition)} with + * {@link DSL#and(Collection)}. + * + * @param table The table whose records to count + * @return Whether the table contains any records that satisfy a condition + * @throws DataAccessException if something went wrong executing the query + */ + boolean fetchExists(Table table, Collection conditions) throws DataAccessException; + /** * Execute a {@link Query} in the context of this DSLContext. * @@ -10914,6 +10975,42 @@ public interface DSLContext extends Scope , AutoCloseable { @Support Result fetch(Table table, Condition condition) throws DataAccessException; + /** + * Execute and return all records for + *

SELECT * FROM [table] WHERE [condition] 
. + *

+ * The result and its contained records are attached to this + * {@link Configuration} by default. Use {@link Settings#isAttachRecords()} + * to override this behaviour. + *

+ * Convenience API for calling {@link #fetch(Table, Condition)} with + * {@link DSL#and(Condition...)}. + * + * @return The results from the executed query. This will never be + * null. + * @throws DataAccessException if something went wrong executing the query + */ + @Support + Result fetch(Table table, Condition... conditions) throws DataAccessException; + + /** + * Execute and return all records for + *

SELECT * FROM [table] WHERE [condition] 
. + *

+ * The result and its contained records are attached to this + * {@link Configuration} by default. Use {@link Settings#isAttachRecords()} + * to override this behaviour. + *

+ * Convenience API for calling {@link #fetch(Table, Condition)} with + * {@link DSL#and(Collection)}. + * + * @return The results from the executed query. This will never be + * null. + * @throws DataAccessException if something went wrong executing the query + */ + @Support + Result fetch(Table table, Collection conditions) throws DataAccessException; + /** * Execute and return zero or one record for *

SELECT * FROM [table]
. @@ -10944,6 +11041,42 @@ public interface DSLContext extends Scope , AutoCloseable { @Support R fetchOne(Table table, Condition condition) throws DataAccessException, TooManyRowsException; + /** + * Execute and return zero or one record for + *
SELECT * FROM [table] WHERE [condition] 
. + *

+ * The resulting record is attached to this {@link Configuration} by + * default. Use {@link Settings#isAttachRecords()} to override this + * behaviour. + *

+ * Convenience API for calling {@link #fetchOne(Table, Condition)} with + * {@link DSL#and(Condition...)}. + * + * @return The record or null, if no record was found. + * @throws DataAccessException if something went wrong executing the query + * @throws TooManyRowsException if the query returned more than one record + */ + @Support + R fetchOne(Table table, Condition... conditions) throws DataAccessException, TooManyRowsException; + + /** + * Execute and return zero or one record for + *

SELECT * FROM [table] WHERE [condition] 
. + *

+ * The resulting record is attached to this {@link Configuration} by + * default. Use {@link Settings#isAttachRecords()} to override this + * behaviour. + *

+ * Convenience API for calling {@link #fetchOne(Table, Condition)} with + * {@link DSL#and(Collection)}. + * + * @return The record or null, if no record was found. + * @throws DataAccessException if something went wrong executing the query + * @throws TooManyRowsException if the query returned more than one record + */ + @Support + R fetchOne(Table table, Collection conditions) throws DataAccessException, TooManyRowsException; + /** * Execute and return exactly one record for *

SELECT * FROM [table]
. @@ -10976,6 +11109,44 @@ public interface DSLContext extends Scope , AutoCloseable { @Support R fetchSingle(Table table, Condition condition) throws DataAccessException, NoDataFoundException, TooManyRowsException; + /** + * Execute and return exactly one record for + *
SELECT * FROM [table] WHERE [condition] 
. + *

+ * The resulting record is attached to this {@link Configuration} by + * default. Use {@link Settings#isAttachRecords()} to override this + * behaviour. + *

+ * Convenience API for calling {@link #fetchSingle(Table, Condition)} with + * {@link DSL#and(Condition...)}. + * + * @return The record. This is never null. + * @throws DataAccessException if something went wrong executing the query + * @throws NoDataFoundException if the query returned now rows + * @throws TooManyRowsException if the query returned more than one record + */ + @Support + R fetchSingle(Table table, Condition... conditions) throws DataAccessException, NoDataFoundException, TooManyRowsException; + + /** + * Execute and return exactly one record for + *

SELECT * FROM [table] WHERE [condition] 
. + *

+ * The resulting record is attached to this {@link Configuration} by + * default. Use {@link Settings#isAttachRecords()} to override this + * behaviour. + *

+ * Convenience API for calling {@link #fetchSingle(Table, Condition)} with + * {@link DSL#and(Collection)}. + * + * @return The record. This is never null. + * @throws DataAccessException if something went wrong executing the query + * @throws NoDataFoundException if the query returned now rows + * @throws TooManyRowsException if the query returned more than one record + */ + @Support + R fetchSingle(Table table, Collection conditions) throws DataAccessException, NoDataFoundException, TooManyRowsException; + /** * Execute and return zero or one record for @@ -11007,6 +11178,42 @@ public interface DSLContext extends Scope , AutoCloseable { @Support Optional fetchOptional(Table table, Condition condition) throws DataAccessException, TooManyRowsException; + /** + * Execute and return zero or one record for + *

SELECT * FROM [table] WHERE [condition] 
. + *

+ * The resulting record is attached to this {@link Configuration} by + * default. Use {@link Settings#isAttachRecords()} to override this + * behaviour. + *

+ * Convenience API for calling {@link #fetchOptional(Table, Condition)} with + * {@link DSL#and(Condition...)}. + * + * @return The record + * @throws DataAccessException if something went wrong executing the query + * @throws TooManyRowsException if the query returned more than one record + */ + @Support + Optional fetchOptional(Table table, Condition... conditions) throws DataAccessException, TooManyRowsException; + + /** + * Execute and return zero or one record for + *

SELECT * FROM [table] WHERE [condition] 
. + *

+ * The resulting record is attached to this {@link Configuration} by + * default. Use {@link Settings#isAttachRecords()} to override this + * behaviour. + *

+ * Convenience API for calling {@link #fetchOptional(Table, Condition)} with + * {@link DSL#and(Collection)}. + * + * @return The record + * @throws DataAccessException if something went wrong executing the query + * @throws TooManyRowsException if the query returned more than one record + */ + @Support + Optional fetchOptional(Table table, Collection conditions) throws DataAccessException, TooManyRowsException; + /** * Execute and return zero or one record for @@ -11036,6 +11243,40 @@ public interface DSLContext extends Scope , AutoCloseable { @Support R fetchAny(Table table, Condition condition) throws DataAccessException; + /** + * Execute and return zero or one record for + *

SELECT * FROM [table] WHERE [condition] LIMIT 1
. + *

+ * The resulting record is attached to this {@link Configuration} by + * default. Use {@link Settings#isAttachRecords()} to override this + * behaviour. + *

+ * Convenience API for calling {@link #fetchAny(Table, Condition)} with + * {@link DSL#and(Condition...)}. + * + * @return The record or null if no record was returned + * @throws DataAccessException if something went wrong executing the query + */ + @Support + R fetchAny(Table table, Condition... conditions) throws DataAccessException; + + /** + * Execute and return zero or one record for + *

SELECT * FROM [table] WHERE [condition] LIMIT 1
. + *

+ * The resulting record is attached to this {@link Configuration} by + * default. Use {@link Settings#isAttachRecords()} to override this + * behaviour. + *

+ * Convenience API for calling {@link #fetchAny(Table, Condition)} with + * {@link DSL#and(Collection)}. + * + * @return The record or null if no record was returned + * @throws DataAccessException if something went wrong executing the query + */ + @Support + R fetchAny(Table table, Collection conditions) throws DataAccessException; + /** * Execute and return all records lazily for *

SELECT * FROM [table]
. @@ -11064,6 +11305,40 @@ public interface DSLContext extends Scope , AutoCloseable { @Support Cursor fetchLazy(Table table, Condition condition) throws DataAccessException; + /** + * Execute and return all records lazily for + *
SELECT * FROM [table] WHERE [condition] 
. + *

+ * The result and its contained records are attached to this + * {@link Configuration} by default. Use {@link Settings#isAttachRecords()} + * to override this behaviour. + *

+ * Convenience API for calling {@link #fetchLazy(Table, Condition)} with + * {@link DSL#and(Condition...)}. + * + * @return The cursor. This will never be null. + * @throws DataAccessException if something went wrong executing the query + */ + @Support + Cursor fetchLazy(Table table, Condition... conditions) throws DataAccessException; + + /** + * Execute and return all records lazily for + *

SELECT * FROM [table] WHERE [condition] 
. + *

+ * The result and its contained records are attached to this + * {@link Configuration} by default. Use {@link Settings#isAttachRecords()} + * to override this behaviour. + *

+ * Convenience API for calling {@link #fetchLazy(Table, Condition)} with + * {@link DSL#and(Collection)}. + * + * @return The cursor. This will never be null. + * @throws DataAccessException if something went wrong executing the query + */ + @Support + Cursor fetchLazy(Table table, Collection conditions) throws DataAccessException; + /** @@ -11094,6 +11369,40 @@ public interface DSLContext extends Scope , AutoCloseable { @Support CompletionStage> fetchAsync(Table table, Condition condition); + /** + * Execute and return all records asynchronously for + *

SELECT * FROM [table] WHERE [condition] 
. + *

+ * The result and its contained records are attached to this + * {@link Configuration} by default. Use {@link Settings#isAttachRecords()} + * to override this behaviour. + *

+ * Convenience API for calling {@link #fetchAsync(Table, Condition)} with + * {@link DSL#and(Condition...)}. + * + * @return The completion stage. The completed result will never be + * null. + */ + @Support + CompletionStage> fetchAsync(Table table, Condition... condition); + + /** + * Execute and return all records asynchronously for + *

SELECT * FROM [table] WHERE [condition] 
. + *

+ * The result and its contained records are attached to this + * {@link Configuration} by default. Use {@link Settings#isAttachRecords()} + * to override this behaviour. + *

+ * Convenience API for calling {@link #fetchAsync(Table, Condition)} with + * {@link DSL#and(Collection)}. + * + * @return The completion stage. The completed result will never be + * null. + */ + @Support + CompletionStage> fetchAsync(Table table, Collection condition); + /** * Execute and return all records asynchronously for *

SELECT * FROM [table]
. @@ -11122,6 +11431,40 @@ public interface DSLContext extends Scope , AutoCloseable { @Support CompletionStage> fetchAsync(Executor executor, Table table, Condition condition); + /** + * Execute and return all records asynchronously for + *
SELECT * FROM [table] WHERE [condition] 
. + *

+ * The result and its contained records are attached to this + * {@link Configuration} by default. Use {@link Settings#isAttachRecords()} + * to override this behaviour. + *

+ * Convenience API for calling {@link #fetchAsync(Executor, Table, Condition)} with + * {@link DSL#and(Condition...)}. + * + * @return The completion stage. The completed result will never be + * null. + */ + @Support + CompletionStage> fetchAsync(Executor executor, Table table, Condition... conditions); + + /** + * Execute and return all records asynchronously for + *

SELECT * FROM [table] WHERE [condition] 
. + *

+ * The result and its contained records are attached to this + * {@link Configuration} by default. Use {@link Settings#isAttachRecords()} + * to override this behaviour. + *

+ * Convenience API for calling {@link #fetchAsync(Executor, Table, Condition)} with + * {@link DSL#and(Collection)}. + * + * @return The completion stage. The completed result will never be + * null. + */ + @Support + CompletionStage> fetchAsync(Executor executor, Table table, Collection conditions); + /** * Execute and return all records lazily for *

SELECT * FROM [table]
. @@ -11148,6 +11491,38 @@ public interface DSLContext extends Scope , AutoCloseable { @Support Stream fetchStream(Table table, Condition condition) throws DataAccessException; + /** + * Execute and return all records lazily for + *
SELECT * FROM [table] WHERE [condition] 
. + *

+ * The result and its contained records are attached to this + * {@link Configuration} by default. Use {@link Settings#isAttachRecords()} + * to override this behaviour. + *

+ * Convenience API for calling {@link #fetchStream(Table, Condition)} with + * {@link DSL#and(Condition...)}. + * + * @throws DataAccessException if something went wrong executing the query + */ + @Support + Stream fetchStream(Table table, Condition... conditions) throws DataAccessException; + + /** + * Execute and return all records lazily for + *

SELECT * FROM [table] WHERE [condition] 
. + *

+ * The result and its contained records are attached to this + * {@link Configuration} by default. Use {@link Settings#isAttachRecords()} + * to override this behaviour. + *

+ * Convenience API for calling {@link #fetchStream(Table, Condition)} with + * {@link DSL#and(Collection)}. + * + * @throws DataAccessException if something went wrong executing the query + */ + @Support + Stream fetchStream(Table table, Collection conditions) throws DataAccessException; + /** * Insert one record. diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index 85d2d6bc38..5d83d1009f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -3685,7 +3685,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri } @Override - public BigInteger currval(Name sequence) throws DataAccessException { + public BigInteger currval(Name sequence) { return currval(sequence(sequence)); } @@ -4135,7 +4135,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri @Override - public List fetchValues(Table> table) throws DataAccessException { + public List fetchValues(Table> table) { return fetchValues(selectFrom(table)); } @@ -4182,20 +4182,40 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri } @Override - public boolean fetchExists(Select query) throws DataAccessException { + public int fetchCount(Table table, Condition... conditions) { + return fetchCount(table, DSL.and(conditions)); + } + + @Override + public int fetchCount(Table table, Collection conditions) { + return fetchCount(table, DSL.and(conditions)); + } + + @Override + public boolean fetchExists(Select query) { return selectOne().whereExists(query).fetchOne() != null; } @Override - public boolean fetchExists(Table table) throws DataAccessException { + public boolean fetchExists(Table table) { return fetchExists(selectOne().from(table)); } @Override - public boolean fetchExists(Table table, Condition condition) throws DataAccessException { + public boolean fetchExists(Table table, Condition condition) { return fetchExists(selectOne().from(table).where(condition)); } + @Override + public boolean fetchExists(Table table, Condition... conditions) { + return fetchExists(table, DSL.and(conditions)); + } + + @Override + public boolean fetchExists(Table table, Collection conditions) { + return fetchExists(table, DSL.and(conditions)); + } + @Override public int execute(Query query) { final Configuration previous = Tools.getConfiguration(query); @@ -4223,6 +4243,16 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return selectFrom(table).where(condition).fetch(); } + @Override + public Result fetch(Table table, Condition... conditions) { + return fetch(table, DSL.and(conditions)); + } + + @Override + public Result fetch(Table table, Collection conditions) { + return fetch(table, DSL.and(conditions)); + } + @Override public R fetchOne(Table table) { return Tools.fetchOne(fetchLazy(table)); @@ -4233,6 +4263,16 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return Tools.fetchOne(fetchLazy(table, condition)); } + @Override + public R fetchOne(Table table, Condition... conditions) { + return fetchOne(table, DSL.and(conditions)); + } + + @Override + public R fetchOne(Table table, Collection conditions) { + return fetchOne(table, DSL.and(conditions)); + } + @Override public R fetchSingle(Table table) { return Tools.fetchSingle(fetchLazy(table)); @@ -4243,6 +4283,16 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return Tools.fetchSingle(fetchLazy(table, condition)); } + @Override + public R fetchSingle(Table table, Condition... conditions) { + return fetchSingle(table, DSL.and(conditions)); + } + + @Override + public R fetchSingle(Table table, Collection conditions) { + return fetchSingle(table, DSL.and(conditions)); + } + @Override public Optional fetchOptional(Table table) { @@ -4254,6 +4304,16 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return Optional.ofNullable(fetchOne(table, condition)); } + @Override + public Optional fetchOptional(Table table, Condition... conditions) { + return fetchOptional(table, DSL.and(conditions)); + } + + @Override + public Optional fetchOptional(Table table, Collection conditions) { + return fetchOptional(table, DSL.and(conditions)); + } + @Override public R fetchAny(Table table) { @@ -4265,6 +4325,16 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return Tools.filterOne(selectFrom(table).where(condition).limit(1).fetch()); } + @Override + public R fetchAny(Table table, Condition... conditions) { + return fetchAny(table, DSL.and(conditions)); + } + + @Override + public R fetchAny(Table table, Collection conditions) { + return fetchAny(table, DSL.and(conditions)); + } + @Override public Cursor fetchLazy(Table table) { return selectFrom(table).fetchLazy(); @@ -4275,6 +4345,16 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return selectFrom(table).where(condition).fetchLazy(); } + @Override + public Cursor fetchLazy(Table table, Condition... conditions) { + return fetchLazy(table, DSL.and(conditions)); + } + + @Override + public Cursor fetchLazy(Table table, Collection conditions) { + return fetchLazy(table, DSL.and(conditions)); + } + @Override @@ -4287,6 +4367,16 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return selectFrom(table).where(condition).fetchAsync(); } + @Override + public CompletionStage> fetchAsync(Table table, Condition... conditions) { + return fetchAsync(table, DSL.and(conditions)); + } + + @Override + public CompletionStage> fetchAsync(Table table, Collection conditions) { + return fetchAsync(table, DSL.and(conditions)); + } + @Override public CompletionStage> fetchAsync(Executor executor, Table table) { return selectFrom(table).fetchAsync(executor); @@ -4297,6 +4387,16 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return selectFrom(table).where(condition).fetchAsync(executor); } + @Override + public CompletionStage> fetchAsync(Executor executor, Table table, Condition... conditions) { + return fetchAsync(executor, table, DSL.and(conditions)); + } + + @Override + public CompletionStage> fetchAsync(Executor executor, Table table, Collection conditions) { + return fetchAsync(executor, table, DSL.and(conditions)); + } + @Override public Stream fetchStream(Table table) { return selectFrom(table).stream(); @@ -4307,6 +4407,16 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return selectFrom(table).where(condition).stream(); } + @Override + public Stream fetchStream(Table table, Condition... conditions) { + return fetchStream(table, DSL.and(conditions)); + } + + @Override + public Stream fetchStream(Table table, Collection conditions) { + return fetchStream(table, DSL.and(conditions)); + } + @Override