@ -418,8 +418,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
* @see org . springframework . data . mongodb . core . MongoOperations # executeAsStream ( org . springframework . data . mongodb . core . query . Query , java . lang . Class )
* @see org . springframework . data . mongodb . core . MongoOperations # executeAsStream ( org . springframework . data . mongodb . core . query . Query , java . lang . Class )
* /
* /
@Override
@Override
public < T > CloseableIterator < T > stream ( final Query query , final Class < T > entityType ) {
public < T > CloseableIterator < T > stream ( Query query , Class < T > entityType ) {
return stream ( query , entityType , getCollectionName ( entityType ) ) ;
return stream ( query , entityType , getCollectionName ( entityType ) ) ;
}
}
@ -428,12 +427,12 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
* @see org . springframework . data . mongodb . core . MongoOperations # stream ( org . springframework . data . mongodb . core . query . Query , java . lang . Class , java . lang . String )
* @see org . springframework . data . mongodb . core . MongoOperations # stream ( org . springframework . data . mongodb . core . query . Query , java . lang . Class , java . lang . String )
* /
* /
@Override
@Override
public < T > CloseableIterator < T > stream ( final Query query , final Class < T > entityType , final String collectionName ) {
public < T > CloseableIterator < T > stream ( Query query , Class < T > entityType , String collectionName ) {
return doStream ( query , entityType , collectionName , entityType ) ;
return doStream ( query , entityType , collectionName , entityType ) ;
}
}
@SuppressWarnings ( "ConstantConditions" )
@SuppressWarnings ( "ConstantConditions" )
protected < T > CloseableIterator < T > doStream ( final Query query , final Class < ? > entityType , final String collectionName ,
protected < T > CloseableIterator < T > doStream ( Query query , final Class < ? > entityType , String collectionName ,
Class < T > returnType ) {
Class < T > returnType ) {
Assert . notNull ( query , "Query must not be null!" ) ;
Assert . notNull ( query , "Query must not be null!" ) ;
@ -443,7 +442,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
return execute ( collectionName , ( CollectionCallback < CloseableIterator < T > > ) collection - > {
return execute ( collectionName , ( CollectionCallback < CloseableIterator < T > > ) collection - > {
MongoPersistentEntity < ? > persistentEntity = mappingContext . getRequired PersistentEntity ( entityType ) ;
MongoPersistentEntity < ? > persistentEntity = mappingContext . getPersistentEntity ( entityType ) ;
Document mappedFields = getMappedFieldsObject ( query . getFieldsObject ( ) , persistentEntity , returnType ) ;
Document mappedFields = getMappedFieldsObject ( query . getFieldsObject ( ) , persistentEntity , returnType ) ;
Document mappedQuery = queryMapper . getMappedObject ( query . getQueryObject ( ) , persistentEntity ) ;
Document mappedQuery = queryMapper . getMappedObject ( query . getQueryObject ( ) , persistentEntity ) ;
@ -2523,7 +2522,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
< S , T > List < T > doFind ( String collectionName , Document query , Document fields , Class < S > sourceClass ,
< S , T > List < T > doFind ( String collectionName , Document query , Document fields , Class < S > sourceClass ,
Class < T > targetClass , CursorPreparer preparer ) {
Class < T > targetClass , CursorPreparer preparer ) {
MongoPersistentEntity < ? > entity = mappingContext . getRequired PersistentEntity ( sourceClass ) ;
MongoPersistentEntity < ? > entity = mappingContext . getPersistentEntity ( sourceClass ) ;
Document mappedFields = getMappedFieldsObject ( fields , entity , targetClass ) ;
Document mappedFields = getMappedFieldsObject ( fields , entity , targetClass ) ;
Document mappedQuery = queryMapper . getMappedObject ( query , entity ) ;
Document mappedQuery = queryMapper . getMappedObject ( query , entity ) ;
@ -2860,7 +2859,12 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
return queryMapper . getMappedSort ( query . getSortObject ( ) , mappingContext . getPersistentEntity ( type ) ) ;
return queryMapper . getMappedSort ( query . getSortObject ( ) , mappingContext . getPersistentEntity ( type ) ) ;
}
}
private Document getMappedFieldsObject ( Document fields , MongoPersistentEntity < ? > entity , Class < ? > targetType ) {
private Document getMappedFieldsObject ( Document fields , @Nullable MongoPersistentEntity < ? > entity ,
Class < ? > targetType ) {
if ( entity = = null ) {
return fields ;
}
Document projectedFields = propertyOperations . computeFieldsForProjection ( projectionFactory , fields ,
Document projectedFields = propertyOperations . computeFieldsForProjection ( projectionFactory , fields ,
entity . getType ( ) , targetType ) ;
entity . getType ( ) , targetType ) ;