Browse files

add query which returns limited number of results

  • Loading branch information...
2 parents 0bfe37e + cd2868e commit 44ed20abd4bb08aaf9ff9581cc15d56bae3c3065 @grze grze committed Nov 30, 2011
View
2 clc/modules/msgs/src/main/java/com/eucalyptus/component/Faults.java
@@ -492,7 +492,7 @@ public CheckException apply( final ServiceStatusType input ) {
public static Collection<CheckException> lookup( final ServiceConfiguration config ) {
final EntityTransaction db = Entities.get( CheckException.class );
try {
- final List<CheckException> res = Entities.query( new CheckException( config.getName( ) ) );
+ final List<CheckException> res = Entities.query( new CheckException( config.getName( ) ), true, 1 );
db.commit( );
return res;
} catch ( final Exception ex ) {
View
15 clc/modules/msgs/src/main/java/com/eucalyptus/entities/Entities.java
@@ -233,6 +233,21 @@ public static EntityTransaction get( final Object obj ) {
return Lists.newArrayList( Sets.newHashSet( resultList ) );
}
+ @SuppressWarnings( { "unchecked", "cast" } )
+ public static <T> List<T> query( final T example, final boolean readOnly, final int maxResults ) {
+ final Example qbe = Example.create( example ).enableLike( MatchMode.EXACT );
+ final List<T> resultList = ( List<T> ) getTransaction( example ).getTxState( ).getSession( )
+ .createCriteria( example.getClass( ) )
+ .setReadOnly( readOnly )
+ .setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY )
+ .setCacheable( true )
+ .add( qbe )
+ .setMaxResults( maxResults )
+ .setFetchSize( maxResults )
+ .list( );
+ return Lists.newArrayList( Sets.newHashSet( resultList ) );
+ }
+
public static <T> T uniqueResult( final T example ) throws TransactionException, NoSuchElementException {
try {
final Object pk = resolvePrimaryKey( example );

0 comments on commit 44ed20a

Please sign in to comment.