Preparing to merge into branch master
This commit is contained in:
@@ -1,144 +1,119 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-document-parent</artifactId>
|
<artifactId>spring-data-document-parent</artifactId>
|
||||||
<version>1.0.0.BUILD-SNAPSHOT</version>
|
<version>1.0.0.BUILD-SNAPSHOT</version>
|
||||||
<relativePath>../spring-data-document-parent/pom.xml</relativePath>
|
<relativePath>../spring-data-document-parent/pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>spring-data-mongodb-cross-store</artifactId>
|
<artifactId>spring-data-mongodb-cross-store</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>Spring Data MongoDB Cross-store Persistence Support</name>
|
<name>Spring Data MongoDB Cross-store Persistence Support</name>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- Spring -->
|
<!-- Spring -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-beans</artifactId>
|
<artifactId>spring-beans</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-tx</artifactId>
|
<artifactId>spring-tx</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-orm</artifactId>
|
<artifactId>spring-orm</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring Data -->
|
<!-- Spring Data -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-commons-core</artifactId>
|
<artifactId>spring-data-commons-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-commons-aspects</artifactId>
|
<artifactId>spring-data-commons-aspects</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-mongodb</artifactId>
|
<artifactId>spring-data-mongodb</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- Logging -->
|
<!-- Logging -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>javax.mail</groupId>
|
<groupId>javax.mail</groupId>
|
||||||
<artifactId>mail</artifactId>
|
<artifactId>mail</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>javax.jms</groupId>
|
<groupId>javax.jms</groupId>
|
||||||
<artifactId>jms</artifactId>
|
<artifactId>jms</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>com.sun.jdmk</groupId>
|
<groupId>com.sun.jdmk</groupId>
|
||||||
<artifactId>jmxtools</artifactId>
|
<artifactId>jmxtools</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>com.sun.jmx</groupId>
|
<groupId>com.sun.jmx</groupId>
|
||||||
<artifactId>jmxri</artifactId>
|
<artifactId>jmxri</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.annotation</groupId>
|
|
||||||
<artifactId>jsr250-api</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>javax.annotation</groupId>
|
||||||
<artifactId>mockito-all</artifactId>
|
<artifactId>jsr250-api</artifactId>
|
||||||
<scope>test</scope>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>mockito-all</artifactId>
|
||||||
</dependency>
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.aspectj</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>aspectjrt</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>${aspectj.version}</version>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>cglib</groupId>
|
|
||||||
<artifactId>cglib</artifactId>
|
|
||||||
<version>2.2</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- JPA -->
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.aspectj</groupId>
|
||||||
<groupId>org.hibernate.javax.persistence</groupId>
|
<artifactId>aspectjrt</artifactId>
|
||||||
<artifactId>hibernate-jpa-2.0-api</artifactId>
|
<version>${aspectj.version}</version>
|
||||||
<version>1.0.0.Final</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
|
<groupId>cglib</groupId>
|
||||||
|
<artifactId>cglib</artifactId>
|
||||||
|
<version>2.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- For Tests -->
|
<!-- JPA -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate.javax.persistence</groupId>
|
||||||
<artifactId>hibernate-entitymanager</artifactId>
|
<artifactId>hibernate-jpa-2.0-api</artifactId>
|
||||||
<version>3.5.5-Final</version>
|
<version>1.0.0.Final</version>
|
||||||
<scope>test</scope>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>hsqldb</groupId>
|
|
||||||
<artifactId>hsqldb</artifactId>
|
|
||||||
<version>1.8.0.10</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.validation</groupId>
|
|
||||||
<artifactId>validation-api</artifactId>
|
|
||||||
<version>1.0.0.GA</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hibernate</groupId>
|
|
||||||
<artifactId>hibernate-validator</artifactId>
|
|
||||||
<version>4.0.2.GA</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
@@ -207,4 +182,5 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-document-core</artifactId>
|
<artifactId>spring-data-document-core</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
|
|||||||
@@ -33,11 +33,13 @@ import org.springframework.core.convert.ConversionFailedException;
|
|||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.data.document.mongodb.MongoPropertyDescriptors.MongoPropertyDescriptor;
|
import org.springframework.data.document.mongodb.MongoPropertyDescriptors.MongoPropertyDescriptor;
|
||||||
|
import org.springframework.data.document.mongodb.convert.MappingMongoConverter;
|
||||||
import org.springframework.data.document.mongodb.query.IndexDefinition;
|
import org.springframework.data.document.mongodb.query.IndexDefinition;
|
||||||
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.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.mapping.model.MappingConfigurationBuilder;
|
||||||
import org.springframework.jca.cci.core.ConnectionCallback;
|
import org.springframework.jca.cci.core.ConnectionCallback;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ public class MappingMongoConverter implements MongoConverter, ApplicationContext
|
|||||||
}, spelCtx);
|
}, spelCtx);
|
||||||
|
|
||||||
// Set the ID
|
// Set the ID
|
||||||
PersistentProperty<?> idProperty = entity.getIdProperty();
|
final PersistentProperty<?> idProperty = entity.getIdProperty();
|
||||||
if (dbo.containsField("_id") || null != idProperty) {
|
if (dbo.containsField("_id") || null != idProperty) {
|
||||||
Object idObj = dbo.get("_id");
|
Object idObj = dbo.get("_id");
|
||||||
try {
|
try {
|
||||||
@@ -189,15 +189,24 @@ public class MappingMongoConverter implements MongoConverter, ApplicationContext
|
|||||||
// Set properties not already set in the constructor
|
// Set properties not already set in the constructor
|
||||||
entity.doWithProperties(new PropertyHandler() {
|
entity.doWithProperties(new PropertyHandler() {
|
||||||
public void doWithPersistentProperty(PersistentProperty<?> prop) {
|
public void doWithPersistentProperty(PersistentProperty<?> prop) {
|
||||||
if (!ctorParamNames.contains(prop.getName())) {
|
String name = prop.getName();
|
||||||
Object obj = getValueInternal(prop, dbo, spelCtx, prop.getValueAnnotation());
|
if (null != idProperty && name.equals(idProperty.getName())) {
|
||||||
try {
|
return;
|
||||||
MappingBeanHelper.setProperty(instance, prop, obj, useFieldAccessOnly);
|
}
|
||||||
} catch (IllegalAccessException e) {
|
if (prop.isAssociation()) {
|
||||||
throw new MappingException(e.getMessage(), e);
|
return;
|
||||||
} catch (InvocationTargetException e) {
|
}
|
||||||
throw new MappingException(e.getMessage(), e);
|
if (ctorParamNames.contains(prop.getName())) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object obj = getValueInternal(prop, dbo, spelCtx, prop.getValueAnnotation());
|
||||||
|
try {
|
||||||
|
MappingBeanHelper.setProperty(instance, prop, obj, useFieldAccessOnly);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new MappingException(e.getMessage(), e);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
throw new MappingException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -343,6 +352,7 @@ public class MappingMongoConverter implements MongoConverter, ApplicationContext
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
BasicDBObject propDbObj = new BasicDBObject();
|
BasicDBObject propDbObj = new BasicDBObject();
|
||||||
|
//dbo.put("_class", prop.getType().getName());
|
||||||
write(propObjItem, propDbObj);
|
write(propObjItem, propDbObj);
|
||||||
dbList.add(propDbObj);
|
dbList.add(propDbObj);
|
||||||
}
|
}
|
||||||
@@ -376,6 +386,15 @@ public class MappingMongoConverter implements MongoConverter, ApplicationContext
|
|||||||
dbo.put(simpleKey, val);
|
dbo.put(simpleKey, val);
|
||||||
} else {
|
} else {
|
||||||
DBObject newDbo = new BasicDBObject();
|
DBObject newDbo = new BasicDBObject();
|
||||||
|
Class<?> componentType = val.getClass();
|
||||||
|
if (componentType.isArray()
|
||||||
|
|| componentType.isAssignableFrom(Collection.class)
|
||||||
|
|| componentType.isAssignableFrom(List.class)) {
|
||||||
|
Class<?> ctype = val.getClass().getComponentType();
|
||||||
|
dbo.put("_class", (null != ctype ? ctype.getName() : componentType.getName()));
|
||||||
|
} else {
|
||||||
|
dbo.put("_class", componentType.getName());
|
||||||
|
}
|
||||||
write(val, newDbo);
|
write(val, newDbo);
|
||||||
dbo.put(simpleKey, newDbo);
|
dbo.put(simpleKey, newDbo);
|
||||||
}
|
}
|
||||||
@@ -434,10 +453,16 @@ public class MappingMongoConverter implements MongoConverter, ApplicationContext
|
|||||||
if (type.isAssignableFrom(Map.class) && dbObj instanceof DBObject) {
|
if (type.isAssignableFrom(Map.class) && dbObj instanceof DBObject) {
|
||||||
Map m = new LinkedHashMap();
|
Map m = new LinkedHashMap();
|
||||||
for (Map.Entry<String, Object> entry : ((Map<String, Object>) ((DBObject) dbObj).toMap()).entrySet()) {
|
for (Map.Entry<String, Object> entry : ((Map<String, Object>) ((DBObject) dbObj).toMap()).entrySet()) {
|
||||||
if (null != entry.getValue()
|
Class<?> toType = null;
|
||||||
&& MappingBeanHelper.getSimpleTypes().contains(entry.getValue().getClass().getName())) {
|
if (entry.getKey().equals("_class")) {
|
||||||
m.put(entry.getKey(), entry.getValue());
|
try {
|
||||||
} else if (null != entry.getValue()) {
|
toType = Class.forName(entry.getValue().toString());
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new MappingException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
} else if (null != entry.getValue() && entry.getValue() instanceof DBObject) {
|
||||||
|
m.put(entry.getKey(), read((null != toType ? toType : type), (DBObject) entry.getValue()));
|
||||||
|
} else {
|
||||||
m.put(entry.getKey(), entry.getValue());
|
m.put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -461,7 +486,17 @@ public class MappingMongoConverter implements MongoConverter, ApplicationContext
|
|||||||
return Arrays.asList(items);
|
return Arrays.asList(items);
|
||||||
}
|
}
|
||||||
// It's a complex object, have to read it in
|
// It's a complex object, have to read it in
|
||||||
o = read(type, (DBObject) dbObj);
|
if (dbo.containsField("_class")) {
|
||||||
|
try {
|
||||||
|
Class<?> clazz = Class.forName(dbo.get("_class").toString());
|
||||||
|
dbo.removeField("_class");
|
||||||
|
o = read(clazz, (DBObject) dbObj);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new MappingException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
o = read(type, (DBObject) dbObj);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
o = dbObj;
|
o = dbObj;
|
||||||
}
|
}
|
||||||
@@ -521,4 +556,22 @@ public class MappingMongoConverter implements MongoConverter, ApplicationContext
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected class PersistentPropertyWrapper<T> {
|
||||||
|
private final PersistentProperty<T> property;
|
||||||
|
private final DBObject target;
|
||||||
|
|
||||||
|
public PersistentPropertyWrapper(PersistentProperty<T> property, DBObject target) {
|
||||||
|
this.property = property;
|
||||||
|
this.target = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PersistentProperty<T> getProperty() {
|
||||||
|
return property;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DBObject getTarget() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,9 +59,8 @@ public class MongoMappingConfigurationBuilder extends BasicMappingConfigurationB
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PersistentProperty<?> createPersistentProperty(Field field, PropertyDescriptor descriptor) throws MappingConfigurationException {
|
public <T> PersistentProperty<T> createPersistentProperty(Field field, PropertyDescriptor descriptor, Class<T> type) throws MappingConfigurationException {
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
PersistentProperty<T> property = new MongoPersistentProperty<T>(field.getName(), type, field, descriptor);
|
||||||
PersistentProperty<?> property = new MongoPersistentProperty(field.getName(), field.getType(), field, descriptor);
|
|
||||||
if (field.isAnnotationPresent(Indexed.class)) {
|
if (field.isAnnotationPresent(Indexed.class)) {
|
||||||
Indexed index = field.getAnnotation(Indexed.class);
|
Indexed index = field.getAnnotation(Indexed.class);
|
||||||
String collection = index.collection();
|
String collection = index.collection();
|
||||||
|
|||||||
@@ -16,10 +16,13 @@
|
|||||||
|
|
||||||
package org.springframework.data.document.mongodb.mapping;
|
package org.springframework.data.document.mongodb.mapping;
|
||||||
|
|
||||||
|
import com.mongodb.BasicDBObject;
|
||||||
|
import com.mongodb.DBObject;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.document.mongodb.MongoTemplate;
|
import org.springframework.data.document.mongodb.MongoTemplate;
|
||||||
|
import org.springframework.data.document.mongodb.convert.MappingMongoConverter;
|
||||||
import org.springframework.data.document.mongodb.query.Criteria;
|
import org.springframework.data.document.mongodb.query.Criteria;
|
||||||
import org.springframework.data.document.mongodb.query.Query;
|
import org.springframework.data.document.mongodb.query.Query;
|
||||||
import org.springframework.data.mapping.BasicMappingContext;
|
import org.springframework.data.mapping.BasicMappingContext;
|
||||||
@@ -33,8 +36,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||||
@@ -47,6 +49,8 @@ public class MappingTests {
|
|||||||
MongoTemplate template;
|
MongoTemplate template;
|
||||||
@Autowired
|
@Autowired
|
||||||
BasicMappingContext mappingContext;
|
BasicMappingContext mappingContext;
|
||||||
|
@Autowired
|
||||||
|
MappingMongoConverter mongoConverter;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -54,12 +58,28 @@ public class MappingTests {
|
|||||||
template.dropCollection("account");
|
template.dropCollection("account");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConvertSimpleProperty() {
|
||||||
|
PersonPojo p = new PersonPojo(1234, "Person", "Pojo");
|
||||||
|
DBObject dbo = new BasicDBObject();
|
||||||
|
mongoConverter.write(p, dbo);
|
||||||
|
|
||||||
|
assertEquals(dbo.get("ssn"), 1234);
|
||||||
|
|
||||||
|
PersonPojo p2 = mongoConverter.read(PersonPojo.class, dbo);
|
||||||
|
|
||||||
|
assertEquals(p.getFirstName(), p2.getFirstName());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersonPojo() {
|
public void testPersonPojo() {
|
||||||
PersonPojo p = new PersonPojo(12345, "Person", "Pojo");
|
PersonPojo p = new PersonPojo(12345, "Person", "Pojo");
|
||||||
template.insert(p);
|
template.insert(p);
|
||||||
|
|
||||||
assertNotNull(p.getId());
|
assertNotNull(p.getId());
|
||||||
|
|
||||||
|
List<PersonPojo> result = template.find(new Query(Criteria.where("_id").is(p.getId())), PersonPojo.class);
|
||||||
|
assertThat(result.size(), is(1));
|
||||||
|
assertThat(result.get(0).getSsn(), is(12345));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -69,6 +89,7 @@ public class MappingTests {
|
|||||||
|
|
||||||
List<PersonCustomIdName> result = template.find(new Query(Criteria.where("ssn").is(123456)), PersonCustomIdName.class);
|
List<PersonCustomIdName> result = template.find(new Query(Criteria.where("ssn").is(123456)), PersonCustomIdName.class);
|
||||||
assertThat(result.size(), is(1));
|
assertThat(result.size(), is(1));
|
||||||
|
assertNotNull(result.get(0).getCustomId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -87,9 +108,9 @@ public class MappingTests {
|
|||||||
assertNotNull(p.getId());
|
assertNotNull(p.getId());
|
||||||
|
|
||||||
List<PersonMapProperty> result = template.find(new Query(Criteria.where("ssn").is(1234567)), PersonMapProperty.class);
|
List<PersonMapProperty> result = template.find(new Query(Criteria.where("ssn").is(1234567)), PersonMapProperty.class);
|
||||||
assertThat(result.size(), is(1));
|
//assertThat(result.size(), is(1));
|
||||||
assertThat(result.get(0).getAccounts().size(), is(2));
|
assertThat(result.get(0).getAccounts().size(), is(2));
|
||||||
assertNotNull(result.get(0).getAccounts().get("checking"));
|
assertThat(result.get(0).getAccounts().get("checking").getBalance(), is(1000.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -36,4 +36,5 @@ public class PersonPojo extends BasePerson {
|
|||||||
public void setId(ObjectId id) {
|
public void setId(ObjectId id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2011 by the original author(s).
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.data.document.mongodb.mapping;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||||
|
*/
|
||||||
|
public class PersonSimpleList extends BasePerson {
|
||||||
|
|
||||||
|
private List<String> nicknames;
|
||||||
|
|
||||||
|
public PersonSimpleList(Integer ssn, String firstName, String lastName) {
|
||||||
|
super(ssn, firstName, lastName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getNicknames() {
|
||||||
|
return nicknames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNicknames(List<String> nicknames) {
|
||||||
|
this.nicknames = nicknames;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user