どのエンティティでも件数を数えるのは要件としてあるので,getCountByConditionを作ってみました.
追記:
小林さんご指摘のとおり
hogeService.select().where("prefId = ?", 1).getCount();
で件数取得できました... or2 ヘタコイタ...
JdbcManagerってよくできてるねーwww
public abstract class AbstractService<E> extends S2AbstractService<E> { public JdbcManagerImplementor jdbcManagerImplementor; public long getCountByCondition(String criteria, Object... params) { EntityMeta entityMeta = getEntityMeta(); String tableName = entityMeta.getTableMeta().getName(); StringBuilder physicalCriteria = new StringBuilder(); StringTokenizer st = new StringTokenizer(criteria); while (st.hasMoreTokens()) { String token = st.nextToken(); if (entityMeta.hasPropertyMeta(token)) { PropertyMeta pm = entityMeta.getPropertyMeta(token); newCriteria.append(pm.getColumnMeta().getName()); } else { newCriteria.append(" ").append(token); } } String sql = String.format("SELECT COUNT(*) AS COUNT FROM %s WHERE %s", tableName, physicalCriteria.toString()); BeanMap bm = jdbcManager.selectBySql(BeanMap.class, sql, params) .getSingleResult(); long count = 0L; Class<?> clazz = bm.get("count").getClass(); if (Long.class.equals(clazz)) { count = (Long) bm.get("count"); } if (BigDecimal.class.equals(clazz)) { count = ((BigDecimal) bm.get("count")).longValue(); } return count; } public long getCountByCondition(SimpleWhere simpleWhere) { long count = getCountByCondition(simpleWhere.getCriteria(), simpleWhere .getParams()); return count; } private EntityMeta getEntityMeta() { EntityMetaFactory entityMetaFactory = jdbcManagerImplementor .getEntityMetaFactory(); EntityMeta entityMeta = entityMetaFactory.getEntityMeta(entityClass); return entityMeta; } }