diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java index 37531636a3..f2bb5ca908 100644 --- a/jOOQ/src/main/java/org/jooq/DSLContext.java +++ b/jOOQ/src/main/java/org/jooq/DSLContext.java @@ -5191,6 +5191,28 @@ public interface DSLContext { */ int fetchCount(Select query) throws DataAccessException; + /** + * Count the number of records in a table. + *

+ * This executes

SELECT COUNT(*) FROM table
+ * + * @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. + *

+ * This executes

SELECT COUNT(*) FROM table WHERE condition
+ * + * @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 DSLContext. * diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index bbfbfd53d2..55e381196a 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -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);