DATADOC-78: Added code to MongoTemplate to check for overriden collection name when saving an entity without specifying a collection. Removed SLF4J from source code and reverted to commons-logging API for internal logging.
This commit is contained in:
@@ -82,45 +82,6 @@
|
|||||||
<version>1.6.1</version>
|
<version>1.6.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Logging -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>javax.mail</groupId>
|
|
||||||
<artifactId>mail</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>javax.jms</groupId>
|
|
||||||
<artifactId>jms</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.sun.jdmk</groupId>
|
|
||||||
<artifactId>jmxtools</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.sun.jmx</groupId>
|
|
||||||
<artifactId>jmxri</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.annotation</groupId>
|
<groupId>javax.annotation</groupId>
|
||||||
<artifactId>jsr250-api</artifactId>
|
<artifactId>jsr250-api</artifactId>
|
||||||
|
|||||||
@@ -26,45 +26,6 @@
|
|||||||
<artifactId>spring-web</artifactId>
|
<artifactId>spring-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Logging -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>javax.mail</groupId>
|
|
||||||
<artifactId>mail</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>javax.jms</groupId>
|
|
||||||
<artifactId>jms</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.sun.jdmk</groupId>
|
|
||||||
<artifactId>jmxtools</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.sun.jmx</groupId>
|
|
||||||
<artifactId>jmxri</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.annotation</groupId>
|
<groupId>javax.annotation</groupId>
|
||||||
<artifactId>jsr250-api</artifactId>
|
<artifactId>jsr250-api</artifactId>
|
||||||
@@ -95,34 +56,16 @@
|
|||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-core</artifactId>
|
<artifactId>spring-core</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>commons-logging</groupId>
|
|
||||||
<artifactId>commons-logging</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-web</artifactId>
|
<artifactId>spring-web</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>commons-logging</groupId>
|
|
||||||
<artifactId>commons-logging</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-webmvc</artifactId>
|
<artifactId>spring-webmvc</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>commons-logging</groupId>
|
|
||||||
<artifactId>commons-logging</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -103,12 +103,6 @@
|
|||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-core</artifactId>
|
<artifactId>spring-core</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>commons-logging</groupId>
|
|
||||||
<artifactId>commons-logging</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
@@ -169,6 +163,7 @@
|
|||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>${org.slf4j.version}</version>
|
<version>${org.slf4j.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.springframework.data.document.persistence.test;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.data.persistence.document.mongo.MongoDocumentBacking;
|
|
||||||
|
|
||||||
//@DocumentEntity
|
//@DocumentEntity
|
||||||
public class Resume {
|
public class Resume {
|
||||||
|
|||||||
@@ -62,45 +62,6 @@
|
|||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Logging -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>javax.mail</groupId>
|
|
||||||
<artifactId>mail</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>javax.jms</groupId>
|
|
||||||
<artifactId>jms</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.sun.jdmk</groupId>
|
|
||||||
<artifactId>jmxtools</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.sun.jmx</groupId>
|
|
||||||
<artifactId>jmxri</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mysema.querydsl</groupId>
|
<groupId>com.mysema.querydsl</groupId>
|
||||||
<artifactId>querydsl-mongodb</artifactId>
|
<artifactId>querydsl-mongodb</artifactId>
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ import org.springframework.data.document.mongodb.convert.MappingMongoConverter;
|
|||||||
import org.springframework.data.document.mongodb.convert.MongoConverter;
|
import org.springframework.data.document.mongodb.convert.MongoConverter;
|
||||||
import org.springframework.data.document.mongodb.convert.SimpleMongoConverter;
|
import org.springframework.data.document.mongodb.convert.SimpleMongoConverter;
|
||||||
import org.springframework.data.document.mongodb.index.IndexDefinition;
|
import org.springframework.data.document.mongodb.index.IndexDefinition;
|
||||||
|
import org.springframework.data.document.mongodb.mapping.Document;
|
||||||
|
import org.springframework.data.document.mongodb.mapping.MongoPersistentEntity;
|
||||||
import org.springframework.data.document.mongodb.mapping.event.AfterConvertEvent;
|
import org.springframework.data.document.mongodb.mapping.event.AfterConvertEvent;
|
||||||
import org.springframework.data.document.mongodb.mapping.event.AfterLoadEvent;
|
import org.springframework.data.document.mongodb.mapping.event.AfterLoadEvent;
|
||||||
import org.springframework.data.document.mongodb.mapping.event.AfterSaveEvent;
|
import org.springframework.data.document.mongodb.mapping.event.AfterSaveEvent;
|
||||||
@@ -65,6 +67,7 @@ import org.springframework.data.document.mongodb.mapping.event.BeforeSaveEvent;
|
|||||||
import org.springframework.data.document.mongodb.mapping.event.MongoMappingEvent;
|
import org.springframework.data.document.mongodb.mapping.event.MongoMappingEvent;
|
||||||
import org.springframework.data.document.mongodb.query.Query;
|
import org.springframework.data.document.mongodb.query.Query;
|
||||||
import org.springframework.data.document.mongodb.query.Update;
|
import org.springframework.data.document.mongodb.query.Update;
|
||||||
|
import org.springframework.data.mapping.model.MappingContext;
|
||||||
import org.springframework.jca.cci.core.ConnectionCallback;
|
import org.springframework.jca.cci.core.ConnectionCallback;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
@@ -505,11 +508,19 @@ public class MongoTemplate implements InitializingBean, MongoOperations, Applica
|
|||||||
// Find methods that take a Query to express the query and that return a List of objects.
|
// Find methods that take a Query to express the query and that return a List of objects.
|
||||||
|
|
||||||
public <T> List<T> find(Query query, Class<T> targetClass) {
|
public <T> List<T> find(Query query, Class<T> targetClass) {
|
||||||
return find(getDefaultCollectionName(), query, targetClass);
|
String collName = getEntityCollection(targetClass);
|
||||||
|
if (null == collName) {
|
||||||
|
collName = getRequiredDefaultCollectionName();
|
||||||
|
}
|
||||||
|
return find(collName, query, targetClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> List<T> find(Query query, Class<T> targetClass, MongoReader<T> reader) {
|
public <T> List<T> find(Query query, Class<T> targetClass, MongoReader<T> reader) {
|
||||||
return find(getDefaultCollectionName(), query, targetClass, reader);
|
String collName = getEntityCollection(targetClass);
|
||||||
|
if (null == collName) {
|
||||||
|
collName = getRequiredDefaultCollectionName();
|
||||||
|
}
|
||||||
|
return find(collName, query, targetClass, reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> List<T> find(String collectionName, final Query query, Class<T> targetClass) {
|
public <T> List<T> find(String collectionName, final Query query, Class<T> targetClass) {
|
||||||
@@ -574,7 +585,11 @@ public class MongoTemplate implements InitializingBean, MongoOperations, Applica
|
|||||||
* @see org.springframework.data.document.mongodb.MongoOperations#insert(java.lang.Object)
|
* @see org.springframework.data.document.mongodb.MongoOperations#insert(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
public void insert(Object objectToSave) {
|
public void insert(Object objectToSave) {
|
||||||
insert(getRequiredDefaultCollectionName(), objectToSave);
|
String collName = getEntityCollection(objectToSave);
|
||||||
|
if (null == collName) {
|
||||||
|
collName = getRequiredDefaultCollectionName();
|
||||||
|
}
|
||||||
|
insert(collName, objectToSave);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -588,7 +603,11 @@ public class MongoTemplate implements InitializingBean, MongoOperations, Applica
|
|||||||
* @see org.springframework.data.document.mongodb.MongoOperations#insert(T, org.springframework.data.document.mongodb.MongoWriter)
|
* @see org.springframework.data.document.mongodb.MongoOperations#insert(T, org.springframework.data.document.mongodb.MongoWriter)
|
||||||
*/
|
*/
|
||||||
public <T> void insert(T objectToSave, MongoWriter<T> writer) {
|
public <T> void insert(T objectToSave, MongoWriter<T> writer) {
|
||||||
insert(getDefaultCollectionName(), objectToSave, writer);
|
String collName = getEntityCollection(objectToSave);
|
||||||
|
if (null == collName) {
|
||||||
|
collName = getDefaultCollectionName();
|
||||||
|
}
|
||||||
|
insert(collName, objectToSave, writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -1084,6 +1103,36 @@ public class MongoTemplate implements InitializingBean, MongoOperations, Applica
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getEntityCollection(Object obj) {
|
||||||
|
if (null != obj) {
|
||||||
|
return getEntityCollection(obj.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getEntityCollection(Class<?> clazz) {
|
||||||
|
if (mongoConverter instanceof MappingMongoConverter) {
|
||||||
|
MappingContext ctx = ((MappingMongoConverter) mongoConverter).getMappingContext();
|
||||||
|
MongoPersistentEntity entity = (MongoPersistentEntity) ctx.getPersistentEntity(clazz);
|
||||||
|
if (null != entity) {
|
||||||
|
return entity.getCollection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Entity hasn't yet been added, try and figure it out anyway
|
||||||
|
if (clazz.isAnnotationPresent(Document.class)) {
|
||||||
|
Document doc = clazz.getAnnotation(Document.class);
|
||||||
|
if (!"".equals(doc.collection())) {
|
||||||
|
return doc.collection();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to simple name
|
||||||
|
return clazz.getSimpleName().toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks and handles any errors.
|
* Checks and handles any errors.
|
||||||
* <p/>
|
* <p/>
|
||||||
|
|||||||
@@ -41,7 +41,13 @@ public class MongoPersistentEntity<T> extends BasicPersistentEntity<T> {
|
|||||||
*/
|
*/
|
||||||
public MongoPersistentEntity(MappingContext mappingContext, TypeInformation typeInformation) {
|
public MongoPersistentEntity(MappingContext mappingContext, TypeInformation typeInformation) {
|
||||||
super(mappingContext, typeInformation);
|
super(mappingContext, typeInformation);
|
||||||
this.collection = typeInformation.getType().getSimpleName();
|
this.collection = typeInformation.getType().getSimpleName().toLowerCase();
|
||||||
|
if (typeInformation.getType().isAnnotationPresent(Document.class)) {
|
||||||
|
Document d = typeInformation.getType().getAnnotation(Document.class);
|
||||||
|
if (!"".equals(d.collection())) {
|
||||||
|
this.collection = d.collection();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ import com.mongodb.DBCollection;
|
|||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
import com.mongodb.MongoException;
|
import com.mongodb.MongoException;
|
||||||
import com.mongodb.util.JSON;
|
import com.mongodb.util.JSON;
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.data.document.mongodb.CollectionCallback;
|
import org.springframework.data.document.mongodb.CollectionCallback;
|
||||||
@@ -50,7 +50,7 @@ import org.springframework.util.Assert;
|
|||||||
*/
|
*/
|
||||||
public class MongoPersistentEntityIndexCreator implements ApplicationListener<MappingContextEvent> {
|
public class MongoPersistentEntityIndexCreator implements ApplicationListener<MappingContextEvent> {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(MongoPersistentEntityIndexCreator.class);
|
private static final Log log = LogFactory.getLog(MongoPersistentEntityIndexCreator.class);
|
||||||
|
|
||||||
private Set<Class<?>> classesSeen = Collections.newSetFromMap(new ConcurrentHashMap<Class<?>, Boolean>());
|
private Set<Class<?>> classesSeen = Collections.newSetFromMap(new ConcurrentHashMap<Class<?>, Boolean>());
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
package org.springframework.data.document.mongodb.mapping.event;
|
package org.springframework.data.document.mongodb.mapping.event;
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ import org.springframework.context.ApplicationListener;
|
|||||||
*/
|
*/
|
||||||
public abstract class AbstractMappingEventListener<T extends ApplicationEvent, E> implements ApplicationListener<T> {
|
public abstract class AbstractMappingEventListener<T extends ApplicationEvent, E> implements ApplicationListener<T> {
|
||||||
|
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
protected final Log log = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked"})
|
@SuppressWarnings({"unchecked"})
|
||||||
public void onApplicationEvent(T appEvent) {
|
public void onApplicationEvent(T appEvent) {
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ import java.util.Collection;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.data.document.mongodb.query.Criteria;
|
import org.springframework.data.document.mongodb.query.Criteria;
|
||||||
import org.springframework.data.document.mongodb.query.CriteriaDefinition;
|
import org.springframework.data.document.mongodb.query.CriteriaDefinition;
|
||||||
import org.springframework.data.document.mongodb.query.Query;
|
import org.springframework.data.document.mongodb.query.Query;
|
||||||
@@ -42,7 +42,7 @@ import org.springframework.data.repository.query.parser.PartTree;
|
|||||||
*/
|
*/
|
||||||
class MongoQueryCreator extends AbstractQueryCreator<Query, Query> {
|
class MongoQueryCreator extends AbstractQueryCreator<Query, Query> {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(MongoQueryCreator.class);
|
private static final Log LOG = LogFactory.getLog(MongoQueryCreator.class);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ package org.springframework.data.document.mongodb.repository;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.data.document.mongodb.MongoOperations;
|
import org.springframework.data.document.mongodb.MongoOperations;
|
||||||
import org.springframework.data.document.mongodb.MongoPropertyDescriptors.MongoPropertyDescriptor;
|
import org.springframework.data.document.mongodb.MongoPropertyDescriptors.MongoPropertyDescriptor;
|
||||||
import org.springframework.data.document.mongodb.MongoTemplate;
|
import org.springframework.data.document.mongodb.MongoTemplate;
|
||||||
@@ -55,8 +55,7 @@ public class MongoRepositoryFactoryBean<T extends MongoRepository<S, ID>, S, ID
|
|||||||
/**
|
/**
|
||||||
* Configures the {@link MongoTemplate} to be used.
|
* Configures the {@link MongoTemplate} to be used.
|
||||||
*
|
*
|
||||||
* @param template
|
* @param template the template to set
|
||||||
* the template to set
|
|
||||||
*/
|
*/
|
||||||
public void setTemplate(MongoTemplate template) {
|
public void setTemplate(MongoTemplate template) {
|
||||||
|
|
||||||
@@ -274,7 +273,7 @@ public class MongoRepositoryFactoryBean<T extends MongoRepository<S, ID>, S, ID
|
|||||||
*/
|
*/
|
||||||
private static class IndexEnsuringQueryCreationListener implements QueryCreationListener<PartTreeMongoQuery> {
|
private static class IndexEnsuringQueryCreationListener implements QueryCreationListener<PartTreeMongoQuery> {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(IndexEnsuringQueryCreationListener.class);
|
private static final Log LOG = LogFactory.getLog(IndexEnsuringQueryCreationListener.class);
|
||||||
private final MongoOperations operations;
|
private final MongoOperations operations;
|
||||||
|
|
||||||
public IndexEnsuringQueryCreationListener(MongoOperations operations) {
|
public IndexEnsuringQueryCreationListener(MongoOperations operations) {
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ package org.springframework.data.document.mongodb.repository;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.data.document.mongodb.MongoTemplate;
|
import org.springframework.data.document.mongodb.MongoTemplate;
|
||||||
import org.springframework.data.document.mongodb.query.BasicQuery;
|
import org.springframework.data.document.mongodb.query.BasicQuery;
|
||||||
import org.springframework.data.document.mongodb.query.Query;
|
import org.springframework.data.document.mongodb.query.Query;
|
||||||
@@ -33,7 +33,7 @@ import org.springframework.data.document.mongodb.query.Query;
|
|||||||
public class StringBasedMongoQuery extends AbstractMongoQuery {
|
public class StringBasedMongoQuery extends AbstractMongoQuery {
|
||||||
|
|
||||||
private static final Pattern PLACEHOLDER = Pattern.compile("\\?(\\d+)");
|
private static final Pattern PLACEHOLDER = Pattern.compile("\\?(\\d+)");
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(StringBasedMongoQuery.class);
|
private static final Log LOG = LogFactory.getLog(StringBasedMongoQuery.class);
|
||||||
|
|
||||||
private final String query;
|
private final String query;
|
||||||
private final String fieldSpec;
|
private final String fieldSpec;
|
||||||
@@ -71,7 +71,9 @@ public class StringBasedMongoQuery extends AbstractMongoQuery {
|
|||||||
query = new BasicQuery(queryString);
|
query = new BasicQuery(queryString);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug("Created query {}", query.getQueryObject());
|
if (LOG.isDebugEnabled()) {
|
||||||
|
LOG.debug(String.format("Created query {}", query.getQueryObject()));
|
||||||
|
}
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import org.bson.types.ObjectId;
|
|||||||
/**
|
/**
|
||||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||||
*/
|
*/
|
||||||
@Document
|
@Document(collection = "places")
|
||||||
public class Location {
|
public class Location {
|
||||||
|
|
||||||
private ObjectId id;
|
private ObjectId id;
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
package org.springframework.data.document.mongodb.mapping;
|
package org.springframework.data.document.mongodb.mapping;
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.data.document.mongodb.mapping.event.AbstractMappingEventListener;
|
import org.springframework.data.document.mongodb.mapping.event.AbstractMappingEventListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,7 +26,7 @@ import org.springframework.data.document.mongodb.mapping.event.AbstractMappingEv
|
|||||||
*/
|
*/
|
||||||
public class MappingEventsListener<MongoMappingEvent> extends AbstractMappingEventListener {
|
public class MappingEventsListener<MongoMappingEvent> extends AbstractMappingEventListener {
|
||||||
|
|
||||||
private Logger log = LoggerFactory.getLogger(getClass());
|
private Log log = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBeforeConvert(Object source) {
|
public void onBeforeConvert(Object source) {
|
||||||
|
|||||||
@@ -24,11 +24,12 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.mongodb.DB;
|
||||||
import com.mongodb.Mongo;
|
import com.mongodb.Mongo;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
import org.springframework.data.document.mongodb.MongoDbUtils;
|
import org.springframework.data.document.mongodb.MongoDbUtils;
|
||||||
@@ -41,7 +42,8 @@ import org.springframework.data.document.mongodb.query.Query;
|
|||||||
*/
|
*/
|
||||||
public class MappingTests {
|
public class MappingTests {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(MongoDbUtils.class);
|
private static final Log LOGGER = LogFactory.getLog(MongoDbUtils.class);
|
||||||
|
private final String[] collectionsToDrop = new String[]{"person", "personmapproperty", "personpojo", "personcustomidname", "account"};
|
||||||
|
|
||||||
ApplicationContext applicationContext;
|
ApplicationContext applicationContext;
|
||||||
MongoTemplate template;
|
MongoTemplate template;
|
||||||
@@ -50,7 +52,10 @@ public class MappingTests {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
Mongo mongo = new Mongo();
|
Mongo mongo = new Mongo();
|
||||||
mongo.getDB("database").getCollection("person").drop();
|
DB db = mongo.getDB("database");
|
||||||
|
for (String coll : collectionsToDrop) {
|
||||||
|
db.getCollection(coll).drop();
|
||||||
|
}
|
||||||
applicationContext = new ClassPathXmlApplicationContext("/mapping.xml");
|
applicationContext = new ClassPathXmlApplicationContext("/mapping.xml");
|
||||||
template = applicationContext.getBean(MongoTemplate.class);
|
template = applicationContext.getBean(MongoTemplate.class);
|
||||||
mappingContext = applicationContext.getBean(MongoMappingContext.class);
|
mappingContext = applicationContext.getBean(MongoMappingContext.class);
|
||||||
@@ -58,6 +63,9 @@ public class MappingTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersonPojo() throws Exception {
|
public void testPersonPojo() throws Exception {
|
||||||
|
// POJOs aren't auto-detected, have to add manually
|
||||||
|
mappingContext.addPersistentEntity(PersonPojo.class);
|
||||||
|
|
||||||
LOGGER.info("about to create new personpojo");
|
LOGGER.info("about to create new personpojo");
|
||||||
PersonPojo p = new PersonPojo(12345, "Person", "Pojo");
|
PersonPojo p = new PersonPojo(12345, "Person", "Pojo");
|
||||||
LOGGER.info("about to insert");
|
LOGGER.info("about to insert");
|
||||||
@@ -73,6 +81,9 @@ public class MappingTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersonWithCustomIdName() {
|
public void testPersonWithCustomIdName() {
|
||||||
|
// POJOs aren't auto-detected, have to add manually
|
||||||
|
mappingContext.addPersistentEntity(PersonCustomIdName.class);
|
||||||
|
|
||||||
PersonCustomIdName p = new PersonCustomIdName(123456, "Custom", "Id");
|
PersonCustomIdName p = new PersonCustomIdName(123456, "Custom", "Id");
|
||||||
template.insert(p);
|
template.insert(p);
|
||||||
|
|
||||||
@@ -163,15 +174,15 @@ public class MappingTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrimitives() {
|
public void testPrimitivesAndCustomCollectionName() {
|
||||||
Location loc = new Location(
|
Location loc = new Location(
|
||||||
new double[]{1.0, 2.0},
|
new double[]{1.0, 2.0},
|
||||||
new int[]{1, 2, 3, 4},
|
new int[]{1, 2, 3, 4},
|
||||||
new float[]{1.0f, 2.0f}
|
new float[]{1.0f, 2.0f}
|
||||||
);
|
);
|
||||||
template.insert("locations", loc);
|
template.insert(loc);
|
||||||
|
|
||||||
List<Location> result = template.find("locations", new Query(Criteria.where("_id").is(loc.getId())), Location.class);
|
List<Location> result = template.find("places", new Query(Criteria.where("_id").is(loc.getId())), Location.class);
|
||||||
assertThat(result.size(), is(1));
|
assertThat(result.size(), is(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,5 +33,4 @@ Import-Template:
|
|||||||
org.apache.commons.collections15.*;version="[4.0.0,5.0.0)",
|
org.apache.commons.collections15.*;version="[4.0.0,5.0.0)",
|
||||||
org.apache.commons.logging.*;version="[1.1.1, 2.0.0)",
|
org.apache.commons.logging.*;version="[1.1.1, 2.0.0)",
|
||||||
org.bson.*;version="0",
|
org.bson.*;version="0",
|
||||||
org.slf4j.*;version="[1.5.0,1.6.0)",
|
|
||||||
org.w3c.dom.*;version="0"
|
org.w3c.dom.*;version="0"
|
||||||
|
|||||||
Reference in New Issue
Block a user