diff --git a/src/docbkx/reference/mapping.xml b/src/docbkx/reference/mapping.xml
index 53a294ab8..e023ca77e 100644
--- a/src/docbkx/reference/mapping.xml
+++ b/src/docbkx/reference/mapping.xml
@@ -230,6 +230,8 @@ public class GeoSpatialAppConfig extends AbstractMongoConfiguration {
<!-- Default bean name is 'mongo' -->
<mongo:mongo host="localhost" port="27017"/>
+ <mongo:db-factory dbname="database" mongo-ref="mongo"/>
+
<!-- by default look for a Mongo object named 'mongo' - default name used for the converter is 'mappingConverter' -->
<mongo:mapping-converter base-package="com.bigbank.domain">
<mongo:custom-converters>
@@ -244,9 +246,7 @@ public class GeoSpatialAppConfig extends AbstractMongoConfiguration {
<!-- set the mapping converter to be used by the MongoTemplate -->
<bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate">
- <constructor-arg name="mongo" ref="mongo" />
- <constructor-arg name="databaseName" value="test" />
- <constructor-arg name="defaultCollectionName" value="myCollection" />
+ <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
<constructor-arg name="mongoConverter" ref="mappingConverter"/>
</bean>
@@ -382,52 +382,51 @@ public class Person {
@Document
@CompoundIndexes({
- @CompoundIndex(name = "age_idx", def = "{'lastName': 1, 'age': -1}")
+ @CompoundIndex(name = "age_idx", def = "{'lastName': 1, 'age': -1}")
})
public class Person<T extends Address> {
- @Id
- private String id;
- @Indexed(unique = true)
- private Integer ssn;
- private String firstName;
- @Indexed
- private String lastName;
- private Integer age;
- @Transient
- private Integer accountTotal;
- @DBRef
- private List<Account> accounts;
- private T address;
-
-
- public Person(Integer ssn) {
- this.ssn = ssn;
- }
-
- @PersistenceConstructor
- public Person(Integer ssn, String firstName, String lastName, Integer age, T address) {
- this.ssn = ssn;
- this.firstName = firstName;
- this.lastName = lastName;
- this.age = age;
- this.address = address;
- }
-
- public String getId() {
- return id;
- }
+ @Id
+ private String id;
+ @Indexed(unique = true)
+ private Integer ssn;
+ private String firstName;
+ @Indexed
+ private String lastName;
+ private Integer age;
+ @Transient
+ private Integer accountTotal;
+ @DBRef
+ private List<Account> accounts;
+ private T address;
+
+
+ public Person(Integer ssn) {
+ this.ssn = ssn;
+ }
+
+ @PersistenceConstructor
+ public Person(Integer ssn, String firstName, String lastName, Integer age, T address) {
+ this.ssn = ssn;
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.age = age;
+ this.address = address;
+ }
+
+ public String getId() {
+ return id;
+ }
// no setter for Id. (getter is only exposed for some unit testing)
- public Integer getSsn() {
- return ssn;
- }
+ public Integer getSsn() {
+ return ssn;
+ }
// other getters/setters ommitted
-
-}
+
@@ -436,7 +435,7 @@ public class Person<T extends Address> {
Compound IndexesCompound indexes are also supported. They are defined at the class
- level, rather than on indidvidual properties.
+ level, rather than on indidvidual properties.
Compound indexes are very important to improve the performance
@@ -540,7 +539,7 @@ public class Person {
mapping of all Java types to DBObjects. However, sometimes you may want
the MongoConverter's do most of the work
but allow you to selectivly handle the conversion for a particular type
- or to optimize performance.
+ or to optimize performance.
To selectivly handle the conversion yourself, register one or more
one or more
@@ -563,18 +562,18 @@ public class Person {
AbstractMongoConfiguration can be overriden to
configure a MappingMongoConverter. The examples here at the begining of this chapter show how to
- perform the configuration using Java and XML.
+ perform the configuration using Java and XML.
Below is an example of a Spring Converter implementation that
converts from a DBObject to a Person POJO.public class PersonReadConverter implements Converter<DBObject, Person> {
- public Person convert(DBObject source) {
- Person p = new Person((ObjectId) source.get("_id"), (String) source.get("name"));
- p.setAge((Integer) source.get("age"));
- return p;
- }
+ public Person convert(DBObject source) {
+ Person p = new Person((ObjectId) source.get("_id"), (String) source.get("name"));
+ p.setAge((Integer) source.get("age"));
+ return p;
+ }
}
@@ -583,13 +582,13 @@ public class Person {
public class PersonWriteConverter implements Converter<Person, DBObject> {
- public DBObject convert(Person source) {
- DBObject dbo = new BasicDBObject();
- dbo.put("_id", source.getId());
- dbo.put("name", source.getFirstName());
- dbo.put("age", source.getAge());
- return dbo;
- }
+ public DBObject convert(Person source) {
+ DBObject dbo = new BasicDBObject();
+ dbo.put("_id", source.getId());
+ dbo.put("name", source.getFirstName());
+ dbo.put("age", source.getAge());
+ return dbo;
+ }
}