[#7914] Overload fetchXYZ(T, Collection<? extends Condition>) and fetchXYZ(T, Condition...)

This commit is contained in:
lukaseder 2018-10-08 12:02:47 +02:00
parent 17ec69fd78
commit c1cf946f62
2 changed files with 490 additions and 5 deletions

View File

@ -10822,11 +10822,44 @@ public interface DSLContext extends Scope , AutoCloseable {
* This executes <code><pre>SELECT COUNT(*) FROM table WHERE condition</pre></code>
*
* @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.
* <p>
* This executes
* <code><pre>SELECT COUNT(*) FROM table WHERE condition</pre></code>
* <p>
* 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.
* <p>
* This executes
* <code><pre>SELECT COUNT(*) FROM table WHERE condition</pre></code>
* <p>
* 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<? extends Condition> conditions) throws DataAccessException;
/**
* Check if a {@link Select} would return any records, if it were executed.
* <p>
@ -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.
* <p>
* This executes <code><pre>SELECT EXISTS(SELECT * FROM table WHERE condition)</pre></code>
* <p>
* 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.
* <p>
* This executes <code><pre>SELECT EXISTS(SELECT * FROM table WHERE condition)</pre></code>
* <p>
* 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<? extends Condition> conditions) throws DataAccessException;
/**
* Execute a {@link Query} in the context of this <code>DSLContext</code>.
*
@ -10914,6 +10975,42 @@ public interface DSLContext extends Scope , AutoCloseable {
@Support
<R extends Record> Result<R> fetch(Table<R> table, Condition condition) throws DataAccessException;
/**
* Execute and return all records for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The result and its contained records are attached to this
* {@link Configuration} by default. Use {@link Settings#isAttachRecords()}
* to override this behaviour.
* <p>
* Convenience API for calling {@link #fetch(Table, Condition)} with
* {@link DSL#and(Condition...)}.
*
* @return The results from the executed query. This will never be
* <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
*/
@Support
<R extends Record> Result<R> fetch(Table<R> table, Condition... conditions) throws DataAccessException;
/**
* Execute and return all records for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The result and its contained records are attached to this
* {@link Configuration} by default. Use {@link Settings#isAttachRecords()}
* to override this behaviour.
* <p>
* Convenience API for calling {@link #fetch(Table, Condition)} with
* {@link DSL#and(Collection)}.
*
* @return The results from the executed query. This will never be
* <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
*/
@Support
<R extends Record> Result<R> fetch(Table<R> table, Collection<? extends Condition> conditions) throws DataAccessException;
/**
* Execute and return zero or one record for
* <code><pre>SELECT * FROM [table]</pre></code>.
@ -10944,6 +11041,42 @@ public interface DSLContext extends Scope , AutoCloseable {
@Support
<R extends Record> R fetchOne(Table<R> table, Condition condition) throws DataAccessException, TooManyRowsException;
/**
* Execute and return zero or one record for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The resulting record is attached to this {@link Configuration} by
* default. Use {@link Settings#isAttachRecords()} to override this
* behaviour.
* <p>
* Convenience API for calling {@link #fetchOne(Table, Condition)} with
* {@link DSL#and(Condition...)}.
*
* @return The record or <code>null</code>, 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 extends Record> R fetchOne(Table<R> table, Condition... conditions) throws DataAccessException, TooManyRowsException;
/**
* Execute and return zero or one record for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The resulting record is attached to this {@link Configuration} by
* default. Use {@link Settings#isAttachRecords()} to override this
* behaviour.
* <p>
* Convenience API for calling {@link #fetchOne(Table, Condition)} with
* {@link DSL#and(Collection)}.
*
* @return The record or <code>null</code>, 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 extends Record> R fetchOne(Table<R> table, Collection<? extends Condition> conditions) throws DataAccessException, TooManyRowsException;
/**
* Execute and return exactly one record for
* <code><pre>SELECT * FROM [table]</pre></code>.
@ -10976,6 +11109,44 @@ public interface DSLContext extends Scope , AutoCloseable {
@Support
<R extends Record> R fetchSingle(Table<R> table, Condition condition) throws DataAccessException, NoDataFoundException, TooManyRowsException;
/**
* Execute and return exactly one record for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The resulting record is attached to this {@link Configuration} by
* default. Use {@link Settings#isAttachRecords()} to override this
* behaviour.
* <p>
* Convenience API for calling {@link #fetchSingle(Table, Condition)} with
* {@link DSL#and(Condition...)}.
*
* @return The record. This is never <code>null</code>.
* @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 extends Record> R fetchSingle(Table<R> table, Condition... conditions) throws DataAccessException, NoDataFoundException, TooManyRowsException;
/**
* Execute and return exactly one record for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The resulting record is attached to this {@link Configuration} by
* default. Use {@link Settings#isAttachRecords()} to override this
* behaviour.
* <p>
* Convenience API for calling {@link #fetchSingle(Table, Condition)} with
* {@link DSL#and(Collection)}.
*
* @return The record. This is never <code>null</code>.
* @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 extends Record> R fetchSingle(Table<R> table, Collection<? extends Condition> conditions) throws DataAccessException, NoDataFoundException, TooManyRowsException;
/**
* Execute and return zero or one record for
@ -11007,6 +11178,42 @@ public interface DSLContext extends Scope , AutoCloseable {
@Support
<R extends Record> Optional<R> fetchOptional(Table<R> table, Condition condition) throws DataAccessException, TooManyRowsException;
/**
* Execute and return zero or one record for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The resulting record is attached to this {@link Configuration} by
* default. Use {@link Settings#isAttachRecords()} to override this
* behaviour.
* <p>
* 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
<R extends Record> Optional<R> fetchOptional(Table<R> table, Condition... conditions) throws DataAccessException, TooManyRowsException;
/**
* Execute and return zero or one record for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The resulting record is attached to this {@link Configuration} by
* default. Use {@link Settings#isAttachRecords()} to override this
* behaviour.
* <p>
* 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
<R extends Record> Optional<R> fetchOptional(Table<R> table, Collection<? extends Condition> conditions) throws DataAccessException, TooManyRowsException;
/**
* Execute and return zero or one record for
@ -11036,6 +11243,40 @@ public interface DSLContext extends Scope , AutoCloseable {
@Support
<R extends Record> R fetchAny(Table<R> table, Condition condition) throws DataAccessException;
/**
* Execute and return zero or one record for
* <code><pre>SELECT * FROM [table] WHERE [condition] LIMIT 1</pre></code>.
* <p>
* The resulting record is attached to this {@link Configuration} by
* default. Use {@link Settings#isAttachRecords()} to override this
* behaviour.
* <p>
* Convenience API for calling {@link #fetchAny(Table, Condition)} with
* {@link DSL#and(Condition...)}.
*
* @return The record or <code>null</code> if no record was returned
* @throws DataAccessException if something went wrong executing the query
*/
@Support
<R extends Record> R fetchAny(Table<R> table, Condition... conditions) throws DataAccessException;
/**
* Execute and return zero or one record for
* <code><pre>SELECT * FROM [table] WHERE [condition] LIMIT 1</pre></code>.
* <p>
* The resulting record is attached to this {@link Configuration} by
* default. Use {@link Settings#isAttachRecords()} to override this
* behaviour.
* <p>
* Convenience API for calling {@link #fetchAny(Table, Condition)} with
* {@link DSL#and(Collection)}.
*
* @return The record or <code>null</code> if no record was returned
* @throws DataAccessException if something went wrong executing the query
*/
@Support
<R extends Record> R fetchAny(Table<R> table, Collection<? extends Condition> conditions) throws DataAccessException;
/**
* Execute and return all records lazily for
* <code><pre>SELECT * FROM [table]</pre></code>.
@ -11064,6 +11305,40 @@ public interface DSLContext extends Scope , AutoCloseable {
@Support
<R extends Record> Cursor<R> fetchLazy(Table<R> table, Condition condition) throws DataAccessException;
/**
* Execute and return all records lazily for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The result and its contained records are attached to this
* {@link Configuration} by default. Use {@link Settings#isAttachRecords()}
* to override this behaviour.
* <p>
* Convenience API for calling {@link #fetchLazy(Table, Condition)} with
* {@link DSL#and(Condition...)}.
*
* @return The cursor. This will never be <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
*/
@Support
<R extends Record> Cursor<R> fetchLazy(Table<R> table, Condition... conditions) throws DataAccessException;
/**
* Execute and return all records lazily for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The result and its contained records are attached to this
* {@link Configuration} by default. Use {@link Settings#isAttachRecords()}
* to override this behaviour.
* <p>
* Convenience API for calling {@link #fetchLazy(Table, Condition)} with
* {@link DSL#and(Collection)}.
*
* @return The cursor. This will never be <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
*/
@Support
<R extends Record> Cursor<R> fetchLazy(Table<R> table, Collection<? extends Condition> conditions) throws DataAccessException;
/**
@ -11094,6 +11369,40 @@ public interface DSLContext extends Scope , AutoCloseable {
@Support
<R extends Record> CompletionStage<Result<R>> fetchAsync(Table<R> table, Condition condition);
/**
* Execute and return all records asynchronously for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The result and its contained records are attached to this
* {@link Configuration} by default. Use {@link Settings#isAttachRecords()}
* to override this behaviour.
* <p>
* Convenience API for calling {@link #fetchAsync(Table, Condition)} with
* {@link DSL#and(Condition...)}.
*
* @return The completion stage. The completed result will never be
* <code>null</code>.
*/
@Support
<R extends Record> CompletionStage<Result<R>> fetchAsync(Table<R> table, Condition... condition);
/**
* Execute and return all records asynchronously for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The result and its contained records are attached to this
* {@link Configuration} by default. Use {@link Settings#isAttachRecords()}
* to override this behaviour.
* <p>
* Convenience API for calling {@link #fetchAsync(Table, Condition)} with
* {@link DSL#and(Collection)}.
*
* @return The completion stage. The completed result will never be
* <code>null</code>.
*/
@Support
<R extends Record> CompletionStage<Result<R>> fetchAsync(Table<R> table, Collection<? extends Condition> condition);
/**
* Execute and return all records asynchronously for
* <code><pre>SELECT * FROM [table]</pre></code>.
@ -11122,6 +11431,40 @@ public interface DSLContext extends Scope , AutoCloseable {
@Support
<R extends Record> CompletionStage<Result<R>> fetchAsync(Executor executor, Table<R> table, Condition condition);
/**
* Execute and return all records asynchronously for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The result and its contained records are attached to this
* {@link Configuration} by default. Use {@link Settings#isAttachRecords()}
* to override this behaviour.
* <p>
* Convenience API for calling {@link #fetchAsync(Executor, Table, Condition)} with
* {@link DSL#and(Condition...)}.
*
* @return The completion stage. The completed result will never be
* <code>null</code>.
*/
@Support
<R extends Record> CompletionStage<Result<R>> fetchAsync(Executor executor, Table<R> table, Condition... conditions);
/**
* Execute and return all records asynchronously for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The result and its contained records are attached to this
* {@link Configuration} by default. Use {@link Settings#isAttachRecords()}
* to override this behaviour.
* <p>
* Convenience API for calling {@link #fetchAsync(Executor, Table, Condition)} with
* {@link DSL#and(Collection)}.
*
* @return The completion stage. The completed result will never be
* <code>null</code>.
*/
@Support
<R extends Record> CompletionStage<Result<R>> fetchAsync(Executor executor, Table<R> table, Collection<? extends Condition> conditions);
/**
* Execute and return all records lazily for
* <code><pre>SELECT * FROM [table]</pre></code>.
@ -11148,6 +11491,38 @@ public interface DSLContext extends Scope , AutoCloseable {
@Support
<R extends Record> Stream<R> fetchStream(Table<R> table, Condition condition) throws DataAccessException;
/**
* Execute and return all records lazily for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The result and its contained records are attached to this
* {@link Configuration} by default. Use {@link Settings#isAttachRecords()}
* to override this behaviour.
* <p>
* Convenience API for calling {@link #fetchStream(Table, Condition)} with
* {@link DSL#and(Condition...)}.
*
* @throws DataAccessException if something went wrong executing the query
*/
@Support
<R extends Record> Stream<R> fetchStream(Table<R> table, Condition... conditions) throws DataAccessException;
/**
* Execute and return all records lazily for
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
* <p>
* The result and its contained records are attached to this
* {@link Configuration} by default. Use {@link Settings#isAttachRecords()}
* to override this behaviour.
* <p>
* Convenience API for calling {@link #fetchStream(Table, Condition)} with
* {@link DSL#and(Collection)}.
*
* @throws DataAccessException if something went wrong executing the query
*/
@Support
<R extends Record> Stream<R> fetchStream(Table<R> table, Collection<? extends Condition> conditions) throws DataAccessException;
/**
* Insert one record.

View File

@ -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 <T> List<T> fetchValues(Table<? extends Record1<T>> table) throws DataAccessException {
public <T> List<T> fetchValues(Table<? extends Record1<T>> 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<? extends Condition> 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<? extends Condition> 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 <R extends Record> Result<R> fetch(Table<R> table, Condition... conditions) {
return fetch(table, DSL.and(conditions));
}
@Override
public <R extends Record> Result<R> fetch(Table<R> table, Collection<? extends Condition> conditions) {
return fetch(table, DSL.and(conditions));
}
@Override
public <R extends Record> R fetchOne(Table<R> 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 extends Record> R fetchOne(Table<R> table, Condition... conditions) {
return fetchOne(table, DSL.and(conditions));
}
@Override
public <R extends Record> R fetchOne(Table<R> table, Collection<? extends Condition> conditions) {
return fetchOne(table, DSL.and(conditions));
}
@Override
public <R extends Record> R fetchSingle(Table<R> 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 extends Record> R fetchSingle(Table<R> table, Condition... conditions) {
return fetchSingle(table, DSL.and(conditions));
}
@Override
public <R extends Record> R fetchSingle(Table<R> table, Collection<? extends Condition> conditions) {
return fetchSingle(table, DSL.and(conditions));
}
@Override
public <R extends Record> Optional<R> fetchOptional(Table<R> table) {
@ -4254,6 +4304,16 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
return Optional.ofNullable(fetchOne(table, condition));
}
@Override
public <R extends Record> Optional<R> fetchOptional(Table<R> table, Condition... conditions) {
return fetchOptional(table, DSL.and(conditions));
}
@Override
public <R extends Record> Optional<R> fetchOptional(Table<R> table, Collection<? extends Condition> conditions) {
return fetchOptional(table, DSL.and(conditions));
}
@Override
public <R extends Record> R fetchAny(Table<R> 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 extends Record> R fetchAny(Table<R> table, Condition... conditions) {
return fetchAny(table, DSL.and(conditions));
}
@Override
public <R extends Record> R fetchAny(Table<R> table, Collection<? extends Condition> conditions) {
return fetchAny(table, DSL.and(conditions));
}
@Override
public <R extends Record> Cursor<R> fetchLazy(Table<R> 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 <R extends Record> Cursor<R> fetchLazy(Table<R> table, Condition... conditions) {
return fetchLazy(table, DSL.and(conditions));
}
@Override
public <R extends Record> Cursor<R> fetchLazy(Table<R> table, Collection<? extends Condition> 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 <R extends Record> CompletionStage<Result<R>> fetchAsync(Table<R> table, Condition... conditions) {
return fetchAsync(table, DSL.and(conditions));
}
@Override
public <R extends Record> CompletionStage<Result<R>> fetchAsync(Table<R> table, Collection<? extends Condition> conditions) {
return fetchAsync(table, DSL.and(conditions));
}
@Override
public <R extends Record> CompletionStage<Result<R>> fetchAsync(Executor executor, Table<R> 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 <R extends Record> CompletionStage<Result<R>> fetchAsync(Executor executor, Table<R> table, Condition... conditions) {
return fetchAsync(executor, table, DSL.and(conditions));
}
@Override
public <R extends Record> CompletionStage<Result<R>> fetchAsync(Executor executor, Table<R> table, Collection<? extends Condition> conditions) {
return fetchAsync(executor, table, DSL.and(conditions));
}
@Override
public <R extends Record> Stream<R> fetchStream(Table<R> 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 <R extends Record> Stream<R> fetchStream(Table<R> table, Condition... conditions) {
return fetchStream(table, DSL.and(conditions));
}
@Override
public <R extends Record> Stream<R> fetchStream(Table<R> table, Collection<? extends Condition> conditions) {
return fetchStream(table, DSL.and(conditions));
}
@Override