public <T> T asSingleResult() {
		T javaObject = null;
		String cacheKey = getCacheKey();
		if (isCacheable() && transaction == null) {
			Collection<Key> keys = getCacheManager().get(cacheNamespace, cacheKey);
			if (keys != null && keys.size() > 0) {
				Key key = keys.iterator().next();
				try {
					javaObject = (T) entityManager.get(key);
				} catch (EntityNotFoundException e) {
					throw new InconsistentCacheException("Entity Key " + key + " found in the cache but not in the Datastore");
				}
			}
		}
		if (javaObject == null) {
			Entity entity = getDatastoreService().prepare(query).asSingleEntity();
			if (entity == null) {
				throw new org.simpleds.exception.EntityNotFoundException("No " + getKind() + " found with " + getFilterPredicates());
			}
			javaObject = (T) entityManager.datastoreToJava(entity);
			if (isCacheable()) {
                populateCache(cacheKey, ImmutableList.of(entity.getKey()));
			}
		}
		return javaObject;

	}
public < T > T asSingleResult ( ) { T javaObject = null ; String cacheKey = getCacheKey ( ) ; if ( isCacheable ( ) && transaction == null ) { Collection < Key > keys = getCacheManager ( ) . get ( cacheNamespace , cacheKey ) ; if ( keys != null && keys . size ( ) > 0 ) { Key key = keys . iterator ( ) . next ( ) ; try { javaObject = ( T ) entityManager . get ( key ) ; } catch ( EntityNotFoundException e ) { throw new InconsistentCacheException ( "Entity Key " + key + " found in the cache but not in the Datastore" ) ; } } } if ( javaObject == null ) { Entity entity = getDatastoreService ( ) . prepare ( query ) . asSingleEntity ( ) ; if ( entity == null ) { throw new org . simpleds . exception . EntityNotFoundException ( "No " + getKind ( ) + " found with " + getFilterPredicates ( ) ) ; } javaObject = ( T ) entityManager . datastoreToJava ( entity ) ; if ( isCacheable ( ) ) { populateCache ( cacheKey , ImmutableList . of ( entity . getKey ( ) ) ) ; } } return javaObject ; }
Execute the query and return a single result
@return the first result of the query
@throws EntityNotFoundException if the query did not return any result