[#2931] Add DSLContext.fetchCount(Table<?>) and fetchCount(Table<?>, Condition)

This commit is contained in:
Lukas Eder 2014-01-06 15:23:46 +01:00
parent 6eae4d769d
commit b2b5482765
2 changed files with 32 additions and 0 deletions

View File

@ -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>.
*

View File

@ -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);