Estou paginando umas funcionalidades do meu sistema e uma delas está me dando trabalho.
[code] Criteria query = HibernateSessionProvider.getSession().createCriteria( PackageFilter.class );
query.setProjection( Projections.projectionList()
.add( Projections.groupProperty( "source.ip.ip" ) )
.add( Projections.property( "source.port.port" ) )
.add( Projections.groupProperty( "action" ) )
.add( Projections.groupProperty( "target.ip.ip" ) )
.add( Projections.groupProperty( "target.port.port" ) )
.add( Projections.property( "protocol" ) )
.add( Projections.count( "source.ip.ip" ) ) );
query.add( Restrictions.eq( "server.idServer", idServer ) );
Criterion sourceCriterion = Restrictions.like( "source.ip.ip", host, MatchMode.END );
Criterion targetCriterion = Restrictions.like( "target.ip.ip", host, MatchMode.END );
query.add( Restrictions.or( sourceCriterion, targetCriterion ) );
query.add( Restrictions.between( "date", initialDate, finalDate ) );
[/code]
Essa é minha query e gostaria de fazer uma projeção de qts linhas são produzidas por ela.
Query gerada (rs formatado!):
select
this_.source as y0_,
this_.sourcePort as y1_,
this_.action as y2_,
this_.target as y3_,
this_.targetPort as y4_,
this_.protocol as y5_,
count(this_.source) as y6_
from
PackageFilter this_
where
this_.idServer=?
and
(this_.source like ? or this_.target like ?)
and
this_.date between ? and ?
group by
this_.source,
this_.action,
this_.target,
this_.targetPort
Se eu inserir Projections.rowCount( ) o resultado retornado não é o número de linhas, mas sim o total do agrupamento criado.
[code] Criteria query = HibernateSessionProvider.getSession().createCriteria( PackageFilter.class );
query.setProjection( Projections.projectionList()
.add( Projections.rowCount( )
.add( Projections.groupProperty( "source.ip.ip" ) )
.add( Projections.property( "source.port.port" ) )
.add( Projections.groupProperty( "action" ) )
.add( Projections.groupProperty( "target.ip.ip" ) )
.add( Projections.groupProperty( "target.port.port" ) )
.add( Projections.property( "protocol" ) )
.add( Projections.count( "source.ip.ip" ) ) );
query.add( Restrictions.eq( "server.idServer", idServer ) );
Criterion sourceCriterion = Restrictions.like( "source.ip.ip", host, MatchMode.END );
Criterion targetCriterion = Restrictions.like( "target.ip.ip", host, MatchMode.END );
query.add( Restrictions.or( sourceCriterion, targetCriterion ) );
query.add( Restrictions.between( "date", initialDate, finalDate ) );
[/code]
O q eu faço para retornar a qtd de linhas geradas?