Browse Source

DATADOC-118 removed methods that take a MongoReader

pull/1/head
Thomas Risberg 15 years ago
parent
commit
c9fe785c32
  1. 130
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoOperations.java
  2. 63
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoTemplate.java
  3. 2
      spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/MongoOperationsUnitTests.java
  4. 37
      spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/analytics/MvcAnalyticsTests.java

130
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoOperations.java

@ -196,18 +196,6 @@ public interface MongoOperations { @@ -196,18 +196,6 @@ public interface MongoOperations {
*/
<T> List<T> getCollection(String collectionName, Class<T> targetClass);
/**
* Query for a list of objects of type T from the specified collection, mapping the DBObject using
* the provided MongoReader.
*
* @param collectionName name of the collection to retrieve the objects from
* @param targetClass the parameterized type of the returned list.
* @param reader the MongoReader to convert from DBObject to an object.
* @return the converted collection
*/
<T> List<T> getCollection(String collectionName, Class<T> targetClass,
MongoReader<T> reader);
/**
* Ensure that an index for the provided {@link IndexDefinition} exists for the default collection.
* If not it will be created.
@ -243,25 +231,6 @@ public interface MongoOperations { @@ -243,25 +231,6 @@ public interface MongoOperations {
*/
<T> T findOne(Query query, Class<T> targetClass);
/**
* Map the results of an ad-hoc query on the default MongoDB collection to a single instance of an object
* of the specified type.
* <p/>
* The object is converted from the MongoDB native representation using an instance of
* {@see MongoConverter}. Unless configured otherwise, an
* instance of SimpleMongoConverter will be used.
* <p/>
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
* feature rich {@link Query}.
*
* @param query the query class that specifies the criteria used to find a record and also an optional fields specification
* @param targetClass the parameterized type of the returned list.
* @param reader the MongoReader to convert from DBObject to an object.
* @return the converted object
*/
<T> T findOne(Query query, Class<T> targetClass,
MongoReader<T> reader);
/**
* Map the results of an ad-hoc query on the specified collection to a single instance of an object
* of the specified type.
@ -281,26 +250,6 @@ public interface MongoOperations { @@ -281,26 +250,6 @@ public interface MongoOperations {
<T> T findOne(String collectionName, Query query,
Class<T> targetClass);
/**
* Map the results of an ad-hoc query on the specified collection to a single instance of an object
* of the specified type.
* <p/>
* The object is converted from the MongoDB native representation using an instance of
* {@see MongoConverter}. Unless configured otherwise, an
* instance of SimpleMongoConverter will be used.
* <p/>
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
* feature rich {@link Query}.
*
* @param collectionName name of the collection to retrieve the objects from
* @param query the query class that specifies the criteria used to find a record and also an optional fields specification
* @param targetClass the parameterized type of the returned list.
* @param reader the MongoReader to convert from DBObject to an object.
* @return the converted object
*/
<T> T findOne(String collectionName, Query query,
Class<T> targetClass, MongoReader<T> reader);
/**
* Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type.
* <p/>
@ -317,24 +266,6 @@ public interface MongoOperations { @@ -317,24 +266,6 @@ public interface MongoOperations {
*/
<T> List<T> find(Query query, Class<T> targetClass);
/**
* Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type.
* <p/>
* The object is converted from the MongoDB native representation using an instance of
* {@see MongoConverter}. Unless configured otherwise, an
* instance of SimpleMongoConverter will be used.
* <p/>
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
* feature rich {@link Query}.
*
* @param query the query class that specifies the criteria used to find a record and also an optional fields specification
* @param targetClass the parameterized type of the returned list.
* @param reader the MongoReader to convert from DBObject to an object.
* @return the List of converted objects
*/
<T> List<T> find(Query query, Class<T> targetClass,
MongoReader<T> reader);
/**
* Map the results of an ad-hoc query on the specified collection to a List of the specified type.
* <p/>
@ -353,26 +284,6 @@ public interface MongoOperations { @@ -353,26 +284,6 @@ public interface MongoOperations {
<T> List<T> find(String collectionName, Query query,
Class<T> targetClass);
/**
* Map the results of an ad-hoc query on the specified collection to a List of the specified type.
* <p/>
* The object is converted from the MongoDB native representation using an instance of
* {@see MongoConverter}. Unless configured otherwise, an
* instance of SimpleMongoConverter will be used.
* <p/>
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
* feature rich {@link Query}.
*
* @param collectionName name of the collection to retrieve the objects from
* @param query the query class that specifies the criteria used to find a record and also an optional fields specification
* @param targetClass the parameterized type of the returned list.
* @param reader the MongoReader to convert from DBObject to an object.
* @return the List of converted objects
*/
<T> List<T> find(String collectionName, Query query,
Class<T> targetClass, MongoReader<T> reader);
/**
* Map the results of an ad-hoc query on the specified collection to a List of the specified type.
* <p/>
@ -410,26 +321,6 @@ public interface MongoOperations { @@ -410,26 +321,6 @@ public interface MongoOperations {
*/
<T> T findAndRemove(Query query, Class<T> targetClass);
/**
* Map the results of an ad-hoc query on the default MongoDB collection to a single instance of an object
* of the specified type. The first document that matches the query is returned and also removed from the
* collection in the database.
* <p/>
* The object is converted from the MongoDB native representation using an instance of
* {@see MongoConverter}. Unless configured otherwise, an
* instance of SimpleMongoConverter will be used.
* <p/>
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
* feature rich {@link Query}.
*
* @param query the query class that specifies the criteria used to find a record and also an optional fields specification
* @param targetClass the parameterized type of the returned list.
* @param reader the MongoReader to convert from DBObject to an object.
* @return the converted object
*/
<T> T findAndRemove(Query query, Class<T> targetClass,
MongoReader<T> reader);
/**
* Map the results of an ad-hoc query on the specified collection to a single instance of an object
* of the specified type. The first document that matches the query is returned and also removed from the
@ -450,27 +341,6 @@ public interface MongoOperations { @@ -450,27 +341,6 @@ public interface MongoOperations {
<T> T findAndRemove(String collectionName, Query query,
Class<T> targetClass);
/**
* Map the results of an ad-hoc query on the specified collection to a single instance of an object
* of the specified type. The first document that matches the query is returned and also removed from the
* collection in the database.
* <p/>
* The object is converted from the MongoDB native representation using an instance of
* {@see MongoConverter}. Unless configured otherwise, an
* instance of SimpleMongoConverter will be used.
* <p/>
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
* feature rich {@link Query}.
*
* @param collectionName name of the collection to retrieve the objects from
* @param query the query class that specifies the criteria used to find a record and also an optional fields specification
* @param targetClass the parameterized type of the returned list.
* @param reader the MongoReader to convert from DBObject to an object.
* @return the converted object
*/
<T> T findAndRemove(String collectionName, Query query,
Class<T> targetClass, MongoReader<T> reader);
/**
* Insert the object into the default collection.
* <p/>

63
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoTemplate.java

@ -438,19 +438,9 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher @@ -438,19 +438,9 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher
return findOne(determineCollectionName(targetClass), query, targetClass);
}
public <T> T findOne(Query query, Class<T> targetClass,
MongoReader<T> reader) {
return findOne(determineCollectionName(targetClass), query, targetClass, reader);
}
public <T> T findOne(String collectionName, Query query,
Class<T> targetClass) {
return findOne(collectionName, query, targetClass, null);
}
public <T> T findOne(String collectionName, Query query,
Class<T> targetClass, MongoReader<T> reader) {
return doFindOne(collectionName, query.getQueryObject(), query.getFieldsObject(), targetClass, reader);
return doFindOne(collectionName, query.getQueryObject(), query.getFieldsObject(), targetClass);
}
// Find methods that take a Query to express the query and that return a List of objects.
@ -459,10 +449,6 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher @@ -459,10 +449,6 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher
return find(determineCollectionName(targetClass), query, targetClass);
}
public <T> List<T> find(Query query, Class<T> targetClass, MongoReader<T> reader) {
return find(determineCollectionName(targetClass), query, targetClass, reader);
}
public <T> List<T> find(String collectionName, final Query query, Class<T> targetClass) {
CursorPreparer cursorPreparer = null;
if (query.getSkip() > 0 || query.getLimit() > 0 || query.getSortObject() != null) {
@ -490,10 +476,6 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher @@ -490,10 +476,6 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher
return doFind(collectionName, query.getQueryObject(), query.getFieldsObject(), targetClass, cursorPreparer);
}
public <T> List<T> find(String collectionName, Query query, Class<T> targetClass, MongoReader<T> reader) {
return doFind(collectionName, query.getQueryObject(), query.getFieldsObject(), targetClass, reader);
}
public <T> List<T> find(String collectionName, Query query,
Class<T> targetClass, CursorPreparer preparer) {
return doFind(collectionName, query.getQueryObject(), query.getFieldsObject(), targetClass, preparer);
@ -506,19 +488,9 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher @@ -506,19 +488,9 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher
return findAndRemove(determineCollectionName(targetClass), query, targetClass);
}
public <T> T findAndRemove(Query query, Class<T> targetClass,
MongoReader<T> reader) {
return findAndRemove(determineCollectionName(targetClass), query, targetClass, reader);
}
public <T> T findAndRemove(String collectionName, Query query,
Class<T> targetClass) {
return findAndRemove(collectionName, query, targetClass, null);
}
public <T> T findAndRemove(String collectionName, Query query,
Class<T> targetClass, MongoReader<T> reader) {
return doFindAndRemove(collectionName, query.getQueryObject(), query.getFieldsObject(), query.getSortObject(), targetClass, reader);
return doFindAndRemove(collectionName, query.getQueryObject(), query.getFieldsObject(), query.getSortObject(), targetClass);
}
/* (non-Javadoc)
@ -904,11 +876,6 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher @@ -904,11 +876,6 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher
});
}
public <T> List<T> getCollection(String collectionName, Class<T> targetClass, MongoReader<T> reader) {
return executeEach(new FindCallback(null), null, new ReadDbObjectCallback<T>(reader, targetClass),
collectionName);
}
public DB getDb() {
return MongoDbUtils.getDB(mongo, databaseName, username, password == null ? null : password.toCharArray());
}
@ -937,7 +904,7 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher @@ -937,7 +904,7 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher
}
/**
* Map the results of an ad-hoc query on the default MongoDB collection to an object using the provided MongoReader
* Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter
* <p/>
* The query document is specified as a standard DBObject and so is the fields specification.
*
@ -945,14 +912,10 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher @@ -945,14 +912,10 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher
* @param query the query document that specifies the criteria used to find a record
* @param fields the document that specifies the fields to be returned
* @param targetClass the parameterized type of the returned list.
* @param reader the MongoReader to convert from DBObject to an object.
* @return the List of converted objects.
*/
protected <T> T doFindOne(String collectionName, DBObject query, DBObject fields, Class<T> targetClass, MongoReader<T> reader) {
MongoReader<? super T> readerToUse = reader;
if (readerToUse == null) {
readerToUse = this.mongoConverter;
}
protected <T> T doFindOne(String collectionName, DBObject query, DBObject fields, Class<T> targetClass) {
MongoReader<? super T> readerToUse = this.mongoConverter;
PersistentEntity<?> entity = mappingContext.getPersistentEntity(targetClass);
DBObject mappedQuery = mapper.getMappedObject(query, entity);
@ -992,7 +955,7 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher @@ -992,7 +955,7 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher
}
/**
* Map the results of an ad-hoc query on the default MongoDB collection to a List using the provided MongoReader
* Map the results of an ad-hoc query on the default MongoDB collection to a List using the template's converter.
* <p/>
* The query document is specified as a standard DBObject and so is the fields specification.
*
@ -1003,14 +966,15 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher @@ -1003,14 +966,15 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher
* @param reader the MongoReader to convert from DBObject to an object.
* @return the List of converted objects.
*/
protected <T> List<T> doFind(String collectionName, DBObject query, DBObject fields, Class<T> targetClass, MongoReader<T> reader) {
protected <T> List<T> doFind(String collectionName, DBObject query, DBObject fields, Class<T> targetClass) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("find using query: " + query + " fields: " + fields + " for class: " + targetClass + " in collection: " + collectionName);
}
MongoReader<? super T> readerToUse = this.mongoConverter;
PersistentEntity<?> entity = mappingContext.getPersistentEntity(targetClass);
return executeEach(new FindCallback(mapper.getMappedObject(query, entity), fields),
null,
new ReadDbObjectCallback<T>(reader, targetClass),
new ReadDbObjectCallback<T>(readerToUse, targetClass),
collectionName);
}
@ -1031,7 +995,7 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher @@ -1031,7 +995,7 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher
}
/**
* Map the results of an ad-hoc query on the default MongoDB collection to an object using the provided MongoReader
* Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter.
* The first document that matches the query is returned and also removed from the collection in the database.
* <p/>
* The query document is specified as a standard DBObject and so is the fields specification.
@ -1042,11 +1006,8 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher @@ -1042,11 +1006,8 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher
* @param reader the MongoReader to convert from DBObject to an object.
* @return the List of converted objects.
*/
protected <T> T doFindAndRemove(String collectionName, DBObject query, DBObject fields, DBObject sort, Class<T> targetClass, MongoReader<T> reader) {
MongoReader<? super T> readerToUse = reader;
if (readerToUse == null) {
readerToUse = this.mongoConverter;
}
protected <T> T doFindAndRemove(String collectionName, DBObject query, DBObject fields, DBObject sort, Class<T> targetClass) {
MongoReader<? super T> readerToUse = this.mongoConverter;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("findAndRemove using query: " + query + " fields: " + fields + " sort: " + sort + " for class: " + targetClass + " in collection: " + collectionName);
}

2
spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/MongoOperationsUnitTests.java

@ -238,7 +238,7 @@ public abstract class MongoOperationsUnitTests { @@ -238,7 +238,7 @@ public abstract class MongoOperationsUnitTests {
new Execution() {
@Override
public void doWith(MongoOperations operations) {
operations.getCollection("collection", Object.class, converter);
operations.getCollection("collection", Object.class);
}
}.assertDataAccessException();
}

37
spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/analytics/MvcAnalyticsTests.java

@ -5,6 +5,8 @@ import java.util.Date; @@ -5,6 +5,8 @@ import java.util.Date;
import java.util.List;
import com.mongodb.*;
import org.bson.types.ObjectId;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -13,17 +15,45 @@ import org.springframework.data.document.analytics.MvcEvent; @@ -13,17 +15,45 @@ import org.springframework.data.document.analytics.MvcEvent;
import org.springframework.data.document.analytics.Parameters;
import org.springframework.data.document.mongodb.MongoReader;
import org.springframework.data.document.mongodb.MongoTemplate;
import org.springframework.data.document.mongodb.convert.MongoConverter;
import org.springframework.data.document.mongodb.mapping.MongoPersistentEntity;
import org.springframework.data.document.mongodb.query.BasicQuery;
import org.springframework.data.mapping.model.MappingContext;
public class MvcAnalyticsTests {
private MongoTemplate mongoTemplate;
private MongoTemplate mongoDummyTemplate;
@Before
public void setUp() throws Exception {
Mongo m = new Mongo();
mongoTemplate = new MongoTemplate(m, "mvc");
mongoDummyTemplate = new MongoTemplate(
m,
"mvc",
new MongoConverter() {
public void write(Object t, DBObject dbo) {
}
public <S> S read(Class<S> clazz, DBObject dbo) {
return null;
}
public <T> T convertObjectId(ObjectId id, Class<T> targetType) {
return null;
}
public ObjectId convertObjectId(Object id) {
return null;
}
public MappingContext<? extends MongoPersistentEntity<?>> getMappingContext() {
return null;
}
});
}
@Test
@ -49,12 +79,7 @@ public class MvcAnalyticsTests { @@ -49,12 +79,7 @@ public class MvcAnalyticsTests {
MvcEvent.class);
Assert.assertEquals(22, mvcEvents.size());
mongoTemplate.getCollection("mvc", MvcEvent.class,
new MongoReader<MvcEvent>() {
public <S extends MvcEvent> S read(Class<S> clazz, DBObject dbo) {
return null;
}
});
mongoDummyTemplate.getCollection("mvc", MvcEvent.class);
}

Loading…
Cancel
Save