private < T > ResultIterable < T > findByExample ( Class < ? > type , Map < PrimitivePropertyMethodMetadata < PropertyMetadata > , Object > entity ) { sessionContext . getCacheSynchronizationService ( ) . flush ( ) ; EntityTypeMetadata < EntityMetadata > entityTypeMetadata = sessionContext . getMetadataProvider ( ) . getEntityMetadata ( type ) ; EntityDiscriminator entityDiscriminator = entityTypeMetadata . getDatastoreMetadata ( ) . getDiscriminator ( ) ; if ( entityDiscriminator == null ) { throw new XOException ( "Type " + type . getName ( ) + " has no discriminator (i.e. cannot be identified in datastore)." ) ; } ResultIterator < Entity > iterator = sessionContext . getDatastoreSession ( ) . getDatastoreEntityManager ( ) . findEntity ( entityTypeMetadata , entityDiscriminator , entity ) ; AbstractInstanceManager < EntityId , Entity > entityInstanceManager = sessionContext . getEntityInstanceManager ( ) ; ResultIterator < T > resultIterator = new ResultIterator < T > ( ) { @ Override public boolean hasNext ( ) { return iterator . hasNext ( ) ; } @ Override public T next ( ) { Entity entity = iterator . next ( ) ; return entityInstanceManager . readInstance ( entity ) ; } @ Override public void remove ( ) { throw new UnsupportedOperationException ( "Cannot remove instance." ) ; } @ Override public void close ( ) { iterator . close ( ) ; } } ; XOTransaction xoTransaction = sessionContext . getXOTransaction ( ) ; final ResultIterator < T > transactionalIterator = xoTransaction != null ? new TransactionalResultIterator <> ( resultIterator , xoTransaction ) : resultIterator ; return sessionContext . getInterceptorFactory ( ) . addInterceptor ( new AbstractResultIterable < T > ( ) { @ Override public ResultIterator < T > iterator ( ) { return transactionalIterator ; } } , ResultIterable . class ) ; }
Find entities according to the given example entity .