public SelectRootClauseBuilder < ? extends QueryForNumber > count ( ) { //TODO its hard to know whether or not to innerjoin to get an accurate count here. StringBuilder sb = new StringBuilder ( ) ; sb . append ( "SELECT count(*)" ) ; sb . append ( " FROM " ) . append ( definition . getSqlName ( ) ) ; //definition.innerJoin(sb); SelectRootClauseBuilder < ? extends QueryForNumber > r = SelectRootClauseBuilder . newInstance ( new RootClauseHandoff < CountBuilder < T > > ( sb . toString ( ) ) { @ Override protected CountBuilder < T > createBuilder ( String sql ) { return new CountBuilder < T > ( SelectBuilderFactory . this , sql ) ; } @ Override public CountBuilder < T > transform ( SelectRootClauseBuilder < CountBuilder < T > > clause ) { clause . where ( ) . limit ( 1 ) ; return super . transform ( clause ) ; } } ) ; return r ; }
FIXME This may not work .