Javadoc cleanups and a few code cleanups.

This commit is contained in:
Oliver Gierke
2011-07-20 18:46:14 +02:00
parent eebe973209
commit 4324ed8231
6 changed files with 296 additions and 706 deletions

View File

@@ -23,7 +23,6 @@ import com.mongodb.MongoInternalException;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
@@ -35,10 +34,7 @@ import org.springframework.data.mongodb.UncategorizedMongoDbException;
* exception from the {@code org.springframework.dao} hierarchy. Return {@literal null} if no translation is
* appropriate: any other exception may have resulted from user code, and should not be translated.
*
* @param ex
* runtime exception that occurred
* @author Oliver Gierke
* @return the corresponding DataAccessException instance, or {@literal null} if the exception should not be translated
*/
public class MongoExceptionTranslator implements PersistenceExceptionTranslator {

View File

@@ -24,6 +24,7 @@ import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.WriteResult;
import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.data.mongodb.core.index.IndexDefinition;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
@@ -256,7 +257,7 @@ public interface MongoOperations {
<T> List<T> findAll(Class<T> entityClass, String collectionName);
/**
* Ensure that an index for the provided {@link IndexDefinition} exists for the collection indicated by the entity class.
* Ensure that an index for the provided {@link IndexDefinition} exists for the collection indicated by the entity class.
* If not it will be created.
*
* @param indexDefinition
@@ -274,7 +275,7 @@ public interface MongoOperations {
void ensureIndex(IndexDefinition indexDefinition, String collectionName);
/**
* Map the results of an ad-hoc query on the collection for the entity class to a single instance of an object
* Map the results of an ad-hoc query on the collection for the entity class 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
@@ -397,13 +398,13 @@ public interface MongoOperations {
<T> T findById(Object id, Class<T> entityClass, String collectionName);
/**
* Map the results of an ad-hoc query on the collection for the entity type to a single instance of an
* Map the results of an ad-hoc query on the collection for the entity type 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}.
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}.
* <p/>
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
* 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
@@ -489,7 +490,7 @@ public interface MongoOperations {
void insert(Collection<? extends Object> batchToSave, String collectionName);
/**
* Insert a mixed Collection of objects into a database collection determining the
* Insert a mixed Collection of objects into a database collection determining the
* collection name to use based on the class.
*
* @param collectionToSave
@@ -498,7 +499,7 @@ public interface MongoOperations {
void insertAll(Collection<? extends Object> objectsToSave);
/**
* Save the object to the collection for the entity type of the object to save. This will perform an
* Save the object to the collection for the entity type of the object to save. This will perform an
* insert if the object is not already present, that is an 'upsert'.
* <p/>
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}. Unless
@@ -535,7 +536,7 @@ public interface MongoOperations {
void save(Object objectToSave, String collectionName);
/**
* Updates the first object that is found in the collection of the entity class that matches the query document with
* Updates the first object that is found in the collection of the entity class that matches the query document with
* the provided update document.
* @param query
* the query document that specifies the criteria used to select a record to be updated
@@ -559,7 +560,7 @@ public interface MongoOperations {
WriteResult updateFirst(Query query, Update update, String collectionName);
/**
* Updates all objects that are found in the collection for the entity class that matches the query document criteria
* Updates all objects that are found in the collection for the entity class that matches the query document criteria
* with the provided updated document.
* @param query
* the query document that specifies the criteria used to select a record to be updated
@@ -611,4 +612,10 @@ public interface MongoOperations {
*/
void remove(Query query, String collectionName);
/**
* Returns the underlying {@link MongoConverter}.
*
* @return
*/
MongoConverter getConverter();
}

View File

@@ -104,7 +104,7 @@ public class QueryMapper {
// $or/$nor
BasicBSONList conditions = (BasicBSONList) value;
BasicBSONList newConditions = new BasicBSONList();
Iterator iter = conditions.iterator();
Iterator<Object> iter = conditions.iterator();
while (iter.hasNext()) {
newConditions.add(getMappedObject((DBObject) iter.next(), entity));
}

View File

@@ -40,6 +40,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.mongodb.InvalidMongoDbApiUsageException;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.CollectionCallback;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.WriteResultChecking;
@@ -68,10 +69,9 @@ public class MongoTemplateTests {
@Autowired
MongoTemplate template;
MongoTemplate mappingTemplate;
MongoTemplate simpleTemplate;
@Autowired
MongoDbFactory factory;
MongoTemplate mappingTemplate, simpleTemplate;
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -88,13 +88,13 @@ public class MongoTemplateTests {
PersonWithIdPropertyOfPrimitiveLong.class)));
mappingContext.afterPropertiesSet();
MappingMongoConverter mappingConverter = new MappingMongoConverter(template.getDbFactory(), mappingContext);
MappingMongoConverter mappingConverter = new MappingMongoConverter(factory, mappingContext);
mappingConverter.afterPropertiesSet();
this.mappingTemplate = new MongoTemplate(template.getDbFactory(), mappingConverter);
this.mappingTemplate = new MongoTemplate(factory, mappingConverter);
SimpleMongoConverter simpleConverter = new SimpleMongoConverter();
simpleConverter.afterPropertiesSet();
this.simpleTemplate = new MongoTemplate(template.getDbFactory(), simpleConverter);
this.simpleTemplate = new MongoTemplate(factory, simpleConverter);
}
@Before
@@ -128,7 +128,7 @@ public class MongoTemplateTests {
@Test
public void updateFailure() throws Exception {
MongoTemplate mongoTemplate = new MongoTemplate(template.getDbFactory());
MongoTemplate mongoTemplate = new MongoTemplate(factory);
mongoTemplate.setWriteResultChecking(WriteResultChecking.EXCEPTION);
Person person = new Person("Oliver2");
@@ -746,7 +746,7 @@ public class MongoTemplateTests {
return null;
}
});
MongoTemplate slaveTemplate = new MongoTemplate(this.template.getDbFactory());
MongoTemplate slaveTemplate = new MongoTemplate(factory);
slaveTemplate.setSlaveOk(true);
slaveTemplate.execute("slaveOkTest", new CollectionCallback<Object>() {
public Object doInCollection(DBCollection collection)

View File

@@ -47,6 +47,7 @@ import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Order;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.util.ReflectionTestUtils;
/**
* @author Jon Brisbin <jbrisbin@vmware.com>
@@ -84,7 +85,7 @@ public class MappingTests {
}
applicationContext = new ClassPathXmlApplicationContext("/mapping.xml");
template = applicationContext.getBean(MongoTemplate.class);
mappingContext = (MongoMappingContext) template.getMappingContext();
mappingContext = (MongoMappingContext) ReflectionTestUtils.getField(template, "mappingContext");
}
@Test