Browse Source

DATADOC-18 - Let Repository subsystem use MongoOperations instead of MongoTemplate.

pull/1/head
Oliver Gierke 15 years ago
parent
commit
95ac7e638c
  1. 20
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoQuery.java
  2. 18
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoRepositoryFactoryBean.java
  3. 30
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/SimpleMongoRepository.java
  4. 2
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/config/MongoRepositoryConfigDefinitionParser.java
  5. 2
      spring-data-mongodb/src/test/resources/org/springframework/data/document/mongodb/repository/PersonRepositoryIntegrationTests-context.xml
  6. 33
      src/docbkx/index.xml

20
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 @@ -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; @@ -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 { @@ -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 { @@ -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 { @@ -156,7 +156,7 @@ public class MongoQuery implements RepositoryQuery {
private DBCursor getCollectionCursor(final DBObject query) {
return template.execute(new CollectionCallback<DBCursor>() {
return operations.execute(new CollectionCallback<DBCursor>() {
public DBCursor doInCollection(DBCollection collection) {

18
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoRepositoryFactoryBean.java

@ -19,7 +19,7 @@ import java.io.Serializable; @@ -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; @@ -39,17 +39,17 @@ import org.springframework.util.Assert;
public class MongoRepositoryFactoryBean extends
RepositoryFactoryBeanSupport<Repository<?, ?>> {
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 @@ -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 @@ -92,7 +92,7 @@ public class MongoRepositoryFactoryBean extends
protected <T, ID extends Serializable> RepositorySupport<T, ID> getTargetRepository(
Class<T> domainClass) {
return new SimpleMongoRepository<T, ID>(domainClass, template);
return new SimpleMongoRepository<T, ID>(domainClass, operations);
}
@ -119,7 +119,7 @@ public class MongoRepositoryFactoryBean extends @@ -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);
}
}
}

30
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/SimpleMongoRepository.java

@ -21,7 +21,7 @@ import java.io.Serializable; @@ -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; @@ -43,20 +43,20 @@ import com.mongodb.QueryBuilder;
public class SimpleMongoRepository<T, ID extends Serializable> extends
RepositorySupport<T, ID> implements PagingAndSortingRepository<T, ID> {
private final MongoTemplate template;
private final MongoOperations operations;
private MongoEntityInformation entityInformation;
/**
* @param domainClass
* @param template
* @param operations
*/
public SimpleMongoRepository(Class<T> domainClass, MongoTemplate template) {
public SimpleMongoRepository(Class<T> domainClass, MongoOperations operations) {
super(domainClass);
Assert.notNull(template);
this.template = template;
Assert.notNull(operations);
this.operations = operations;
}
@ -68,7 +68,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends @@ -68,7 +68,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends
*/
public T save(T entity) {
template.save(entity);
operations.save(entity);
return entity;
}
@ -84,7 +84,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends @@ -84,7 +84,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends
List<T> result = new ArrayList<T>();
for (T entity : entities) {
template.save(entity);
operations.save(entity);
result.add(entity);
}
@ -102,7 +102,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends @@ -102,7 +102,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends
public T findById(ID id) {
List<T> 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<T, ID extends Serializable> extends @@ -129,7 +129,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends
*/
public List<T> findAll() {
return template.getCollection(getDomainClass());
return operations.getCollection(getDomainClass());
}
@ -140,7 +140,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends @@ -140,7 +140,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends
*/
public Long count() {
return template.getCollection(template.getDefaultCollectionName())
return operations.getCollection(operations.getDefaultCollectionName())
.count();
}
@ -156,7 +156,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends @@ -156,7 +156,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> 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<T, ID extends Serializable> extends @@ -181,7 +181,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends
*/
public void deleteAll() {
template.dropCollection(template.getDefaultCollectionName());
operations.dropCollection(operations.getDefaultCollectionName());
}
@ -197,7 +197,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends @@ -197,7 +197,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends
Long count = count();
List<T> list =
template.query(new BasicDBObject(), getDomainClass(),
operations.query(new BasicDBObject(), getDomainClass(),
withPagination(pageable));
return new PageImpl<T>(list, pageable, count);
@ -213,7 +213,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends @@ -213,7 +213,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends
*/
public List<T> findAll(final Sort sort) {
return template.query(new BasicDBObject(), getDomainClass(),
return operations.query(new BasicDBObject(), getDomainClass(),
withSorting(sort));
}

2
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/config/MongoRepositoryConfigDefinitionParser.java

@ -46,6 +46,6 @@ public class MongoRepositoryConfigDefinitionParser @@ -46,6 +46,6 @@ public class MongoRepositoryConfigDefinitionParser
MongoRepositoryConfiguration context,
BeanDefinitionBuilder builder, Object beanSource) {
builder.addPropertyReference("template", context.getMongoTemplateRef());
builder.addPropertyReference("operations", context.getMongoTemplateRef());
}
}

2
spring-data-mongodb/src/test/resources/org/springframework/data/document/mongodb/repository/PersonRepositoryIntegrationTests-context.xml

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
<import resource="infrastructure.xml" />
<bean class="org.springframework.data.document.mongodb.repository.MongoRepositoryFactoryBean">
<property name="template" ref="mongoTemplate" />
<property name="operations" ref="mongoTemplate" />
<property name="repositoryInterface" value="org.springframework.data.document.mongodb.repository.PersonRepository" />
</bean>

33
src/docbkx/index.xml

@ -1,43 +1,52 @@ @@ -1,43 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
<book xmlns:xi="http://www.w3.org/2001/XInclude">
<bookinfo>
<title>Spring Datastore Document - Reference Documentation</title>
<releaseinfo>&version;</releaseinfo>
<releaseinfo>version;</releaseinfo>
<authorgroup>
<author>
<firstname>Mark</firstname>
<surname>Pollack</surname>
</author>
<author>
<firstname>Thomas</firstname>
<surname>Risberg</surname>
</author>
<author>
<firstname>Oliver</firstname>
<surname>Gierke</surname>
</author>
</authorgroup>
<legalnotice>
<para>
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.
</para>
<para>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.</para>
</legalnotice>
</bookinfo>
<toc />
<xi:include href="preface.xml" />
<xi:include href="mongo.xml" />
<part>
<title>Reference</title>
<partintro>
<para>
This part of the reference documentation details the ...
</para>
<para>This part of the reference documentation details the ...</para>
</partintro>
<!-- <xi:include href="amqp.xml"/> -->
</part>
</book>
Loading…
Cancel
Save