From 95ac7e638c57fa2a72075ef791608a61f41e7a71 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 16 Dec 2010 13:05:50 +0100 Subject: [PATCH] DATADOC-18 - Let Repository subsystem use MongoOperations instead of MongoTemplate. --- .../mongodb/repository/MongoQuery.java | 20 ++-- .../MongoRepositoryFactoryBean.java | 18 ++-- .../repository/SimpleMongoRepository.java | 30 +++--- ...MongoRepositoryConfigDefinitionParser.java | 2 +- ...rsonRepositoryIntegrationTests-context.xml | 2 +- src/docbkx/index.xml | 91 ++++++++++--------- 6 files changed, 86 insertions(+), 77 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoQuery.java b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoQuery.java index 5b3e1dbab..73059e200 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoQuery.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoQuery.java @@ -20,7 +20,7 @@ import static org.springframework.data.document.mongodb.repository.MongoCursorUt import java.util.List; import org.springframework.data.document.mongodb.CollectionCallback; -import org.springframework.data.document.mongodb.MongoTemplate; +import org.springframework.data.document.mongodb.MongoOperations; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.repository.query.QueryMethod; @@ -42,24 +42,24 @@ import com.mongodb.DBObject; public class MongoQuery implements RepositoryQuery { private final QueryMethod method; - private final MongoTemplate template; + private final MongoOperations operations; private final PartTree tree; /** * Creates a new {@link MongoQuery} from the given {@link QueryMethod} and - * {@link MongoTemplate}. + * {@link MongoOperations}. * * @param method - * @param template + * @param operations */ - public MongoQuery(QueryMethod method, MongoTemplate template) { + public MongoQuery(QueryMethod method, MongoOperations operations) { - Assert.notNull(template); + Assert.notNull(operations); Assert.notNull(method); this.method = method; - this.template = template; + this.operations = operations; this.tree = new PartTree(method.getName(), method.getDomainClass()); } @@ -95,7 +95,7 @@ public class MongoQuery implements RepositoryQuery { protected List readCollection(DBObject query) { - return template.query(template.getDefaultCollectionName(), query, + return operations.query(operations.getDefaultCollectionName(), query, method.getDomainClass()); } } @@ -147,7 +147,7 @@ public class MongoQuery implements RepositoryQuery { int count = getCollectionCursor(creator.createQuery()).count(); List result = - template.query(query, method.getDomainClass(), + operations.query(query, method.getDomainClass(), withPagination(pageable)); return new PageImpl(result, pageable, count); @@ -156,7 +156,7 @@ public class MongoQuery implements RepositoryQuery { private DBCursor getCollectionCursor(final DBObject query) { - return template.execute(new CollectionCallback() { + return operations.execute(new CollectionCallback() { public DBCursor doInCollection(DBCollection collection) { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoRepositoryFactoryBean.java b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoRepositoryFactoryBean.java index 71bc673f4..d1126f756 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoRepositoryFactoryBean.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoRepositoryFactoryBean.java @@ -19,7 +19,7 @@ import java.io.Serializable; import java.lang.reflect.Method; import org.springframework.beans.factory.FactoryBean; -import org.springframework.data.document.mongodb.MongoTemplate; +import org.springframework.data.document.mongodb.MongoOperations; import org.springframework.data.repository.Repository; import org.springframework.data.repository.query.QueryLookupStrategy; import org.springframework.data.repository.query.QueryLookupStrategy.Key; @@ -39,17 +39,17 @@ import org.springframework.util.Assert; public class MongoRepositoryFactoryBean extends RepositoryFactoryBeanSupport> { - private MongoTemplate template; + private MongoOperations operations; /** - * Configures the {@link MongoTemplate} to be used. + * Configures the {@link MongoOperations} to be used. * - * @param template the template to set + * @param operations the template to set */ - public void setTemplate(MongoTemplate template) { + public void setOperations(MongoOperations operations) { - this.template = template; + this.operations = operations; } @@ -78,7 +78,7 @@ public class MongoRepositoryFactoryBean extends public void afterPropertiesSet() { super.afterPropertiesSet(); - Assert.notNull(template, "MongoTemplate must not be null!"); + Assert.notNull(operations, "MongoTemplate must not be null!"); } /** @@ -92,7 +92,7 @@ public class MongoRepositoryFactoryBean extends protected RepositorySupport getTargetRepository( Class domainClass) { - return new SimpleMongoRepository(domainClass, template); + return new SimpleMongoRepository(domainClass, operations); } @@ -119,7 +119,7 @@ public class MongoRepositoryFactoryBean extends public RepositoryQuery resolveQuery(Method method) { - return new MongoQuery(new QueryMethod(method), template); + return new MongoQuery(new QueryMethod(method), operations); } } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/SimpleMongoRepository.java b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/SimpleMongoRepository.java index b02476287..801419abd 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/SimpleMongoRepository.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/SimpleMongoRepository.java @@ -21,7 +21,7 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; -import org.springframework.data.document.mongodb.MongoTemplate; +import org.springframework.data.document.mongodb.MongoOperations; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; @@ -43,20 +43,20 @@ import com.mongodb.QueryBuilder; public class SimpleMongoRepository extends RepositorySupport implements PagingAndSortingRepository { - private final MongoTemplate template; + private final MongoOperations operations; private MongoEntityInformation entityInformation; /** * @param domainClass - * @param template + * @param operations */ - public SimpleMongoRepository(Class domainClass, MongoTemplate template) { + public SimpleMongoRepository(Class domainClass, MongoOperations operations) { super(domainClass); - Assert.notNull(template); - this.template = template; + Assert.notNull(operations); + this.operations = operations; } @@ -68,7 +68,7 @@ public class SimpleMongoRepository extends */ public T save(T entity) { - template.save(entity); + operations.save(entity); return entity; } @@ -84,7 +84,7 @@ public class SimpleMongoRepository extends List result = new ArrayList(); for (T entity : entities) { - template.save(entity); + operations.save(entity); result.add(entity); } @@ -102,7 +102,7 @@ public class SimpleMongoRepository extends public T findById(ID id) { List result = - template.query(template.getDefaultCollectionName(), + operations.query(operations.getDefaultCollectionName(), QueryBuilder.start("_id").get(), getDomainClass()); return result.isEmpty() ? null : result.get(0); @@ -129,7 +129,7 @@ public class SimpleMongoRepository extends */ public List findAll() { - return template.getCollection(getDomainClass()); + return operations.getCollection(getDomainClass()); } @@ -140,7 +140,7 @@ public class SimpleMongoRepository extends */ public Long count() { - return template.getCollection(template.getDefaultCollectionName()) + return operations.getCollection(operations.getDefaultCollectionName()) .count(); } @@ -156,7 +156,7 @@ public class SimpleMongoRepository extends QueryBuilder builder = QueryBuilder.start(entityInformation.getFieldName()).is( entityInformation.getId(entity)); - template.remove(builder.get()); + operations.remove(builder.get()); } @@ -181,7 +181,7 @@ public class SimpleMongoRepository extends */ public void deleteAll() { - template.dropCollection(template.getDefaultCollectionName()); + operations.dropCollection(operations.getDefaultCollectionName()); } @@ -197,7 +197,7 @@ public class SimpleMongoRepository extends Long count = count(); List list = - template.query(new BasicDBObject(), getDomainClass(), + operations.query(new BasicDBObject(), getDomainClass(), withPagination(pageable)); return new PageImpl(list, pageable, count); @@ -213,7 +213,7 @@ public class SimpleMongoRepository extends */ public List findAll(final Sort sort) { - return template.query(new BasicDBObject(), getDomainClass(), + return operations.query(new BasicDBObject(), getDomainClass(), withSorting(sort)); } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/config/MongoRepositoryConfigDefinitionParser.java b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/config/MongoRepositoryConfigDefinitionParser.java index 38611907e..4429376e3 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/config/MongoRepositoryConfigDefinitionParser.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/config/MongoRepositoryConfigDefinitionParser.java @@ -46,6 +46,6 @@ public class MongoRepositoryConfigDefinitionParser MongoRepositoryConfiguration context, BeanDefinitionBuilder builder, Object beanSource) { - builder.addPropertyReference("template", context.getMongoTemplateRef()); + builder.addPropertyReference("operations", context.getMongoTemplateRef()); } } diff --git a/spring-data-mongodb/src/test/resources/org/springframework/data/document/mongodb/repository/PersonRepositoryIntegrationTests-context.xml b/spring-data-mongodb/src/test/resources/org/springframework/data/document/mongodb/repository/PersonRepositoryIntegrationTests-context.xml index 45d609dee..782f61b92 100644 --- a/spring-data-mongodb/src/test/resources/org/springframework/data/document/mongodb/repository/PersonRepositoryIntegrationTests-context.xml +++ b/spring-data-mongodb/src/test/resources/org/springframework/data/document/mongodb/repository/PersonRepositoryIntegrationTests-context.xml @@ -6,7 +6,7 @@ - + diff --git a/src/docbkx/index.xml b/src/docbkx/index.xml index dcb28ac0a..e41b48f26 100644 --- a/src/docbkx/index.xml +++ b/src/docbkx/index.xml @@ -1,43 +1,52 @@ - + + + + Spring Datastore Document - Reference Documentation - - Spring Datastore Document - Reference Documentation - &version; - - - - Mark - Pollack - - - Thomas - Risberg - - - - - - Copies of this document may be made for your own use and for distribution - to others, provided that you do not charge any fee for such copies and - further provided that each copy contains this Copyright Notice, whether - distributed in print or electronically. - - - - - - - - - - Reference - - - This part of the reference documentation details the ... - - - - - + version; + + + + Mark + + Pollack + + + + Thomas + + Risberg + + + + Oliver + + Gierke + + + + + Copies of this document may be made for your own use and for + distribution to others, provided that you do not charge any fee for such + copies and further provided that each copy contains this Copyright + Notice, whether distributed in print or electronically. + + + + + + + + + + Reference + + + This part of the reference documentation details the ... + + + + + \ No newline at end of file