Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
merged from eee
  • Loading branch information
dmitrii committed Dec 1, 2011
2 parents 2078f58 + 44ed20a commit cfdc10d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Expand Up @@ -167,6 +167,11 @@ public static class CheckException extends RuntimeException implements Iterable<
@Transient
private CheckException other;

@SuppressWarnings( "unused" )
public CheckException( ) {
this( null );
}

private CheckException( final String serviceName ) {
this.serviceName = serviceName;
this.severity = null;
Expand Down Expand Up @@ -429,7 +434,7 @@ private static CheckException chain( final ServiceConfiguration config, final Se
return last;
} catch ( Exception ex ) {
LOG.error( "Faults: error in processing previous error: " + ex );
Logs.extreme( ).error( ex , ex );
Logs.extreme( ).error( ex, ex );
return new CheckException( config, Severity.ERROR, ex );
}
}
Expand Down Expand Up @@ -487,14 +492,14 @@ public static Function<ServiceStatusType, CheckException> transformToExceptions(
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 ) {
LOG.error( "Failed to lookup error information for: " + config.getFullName( ), ex );
db.rollback( );
}
return null;
return Lists.newArrayList( );
}

public static void persist( final CheckException errors ) {
Expand All @@ -512,7 +517,7 @@ public static void persist( final CheckException errors ) {
}
} catch ( Exception ex ) {
LOG.error( "Faults: error in processing previous error: " + errors );
Logs.extreme( ).error( ex , ex );
Logs.extreme( ).error( ex, ex );
}
}
}
Expand Down
Expand Up @@ -233,6 +233,21 @@ public static <T> List<T> query( final T example, final boolean readOnly ) {
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 );
Expand Down

0 comments on commit cfdc10d

Please sign in to comment.