[#2931] Add DSLContext.fetchCount(Table<?>) and fetchCount(Table<?>, Condition)
This commit is contained in:
parent
6eae4d769d
commit
b2b5482765
@ -5191,6 +5191,28 @@ public interface DSLContext {
|
||||
*/
|
||||
int fetchCount(Select<?> query) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Count the number of records in a table.
|
||||
* <p>
|
||||
* This executes <code><pre>SELECT COUNT(*) FROM table</pre></code>
|
||||
*
|
||||
* @param table The table whose records to count
|
||||
* @return The number or records in the table
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
int fetchCount(Table<?> table) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Count the number of records in a table.
|
||||
* <p>
|
||||
* This executes <code><pre>SELECT COUNT(*) FROM table WHERE condition</pre></code>
|
||||
*
|
||||
* @param table The table whose records to count
|
||||
* @return The number or records in the table
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
int fetchCount(Table<?> table, Condition condition) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a {@link Query} in the context of this <code>DSLContext</code>.
|
||||
*
|
||||
|
||||
@ -1807,6 +1807,16 @@ public class DefaultDSLContext implements DSLContext, Serializable {
|
||||
return new FetchCount(configuration(), query).fetchOne().value1();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fetchCount(Table<?> table) {
|
||||
return fetchCount(table, trueCondition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fetchCount(Table<?> table, Condition condition) {
|
||||
return selectCount().from(table).where(condition).fetchOne(0, int.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int execute(Query query) {
|
||||
final Configuration previous = Utils.getConfiguration(query);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user