diff --git a/src/docbkx/introduction/getting-started.xml b/src/docbkx/introduction/getting-started.xml
index faeadc191..be8939d60 100644
--- a/src/docbkx/introduction/getting-started.xml
+++ b/src/docbkx/introduction/getting-started.xml
@@ -5,10 +5,10 @@
Additional Help Resources
Learning a new framework is not always straight forward. In this
- section, we (the Spring Data team) tried to provide, what we think is, an
- easy to follow guide for starting with Spring Data Document module. However,
- if you encounter issues or you are just looking for an advice, feel free to
- use one of the links below:
+ section, we try to provide what we think is an easy to follow guide for
+ starting with Spring Data Document module. However, if you encounter issues
+ or you are just looking for an advice, feel free to use one of the links
+ below:
Support
diff --git a/src/docbkx/introduction/introduction.xml b/src/docbkx/introduction/introduction.xml
index 0d51bbb1b..ec24086fa 100644
--- a/src/docbkx/introduction/introduction.xml
+++ b/src/docbkx/introduction/introduction.xml
@@ -11,22 +11,27 @@
Spring concepts.
Knowing Spring
- Spring Data uses heavily Spring framework's Spring Data uses Spring framework's core
functionality, such as the IoC
- container, resource
- abstract or AOP
- infrastructure. While it is not important to know the Spring
- APIs, understanding the concepts behind them is. At a minimum, the idea
- behind IoC should be familiar. These being said, the more knowledge one
- has about the Spring, the faster she will pick up Spring Data Document.
- Besides the very comprehensive (and sometimes disarming) documentation
- that explains in detail the Spring Framework, there are a lot of
- articles, blog entries and books on the matter - take a look at the
- Spring framework container and Data Access abstractions such as the portable
+ exception hierarchy. While it is not important to know the Spring APIs,
+ understanding the concepts behind them is. At a minimum, the idea behind
+ IoC should be familiar for whatever IoC container you choose to use.
+
+
+ The core functionality of the MongoDB and CouchDB support can be
+ used directly, with no references to the Spring Container, much like
+ JdbcTemplate can be used 'standalone' without any other services of the
+ Spring container. To leverage all the features of Spring Data document,
+ such as it's repository support, then you will need to configure the
+ container using Spring.
+
+ To learn more about Spring, you can refer to the comprehensive
+ (and sometimes disarming) documentation that explains in detail the
+ Spring Framework. There are a lot of articles, blog entries and books on
+ the matter - take a look at the Spring framework home page for
more information.
diff --git a/src/docbkx/reference/mongodb.xml b/src/docbkx/reference/mongodb.xml
index 2a2fb2a07..7bb10a048 100644
--- a/src/docbkx/reference/mongodb.xml
+++ b/src/docbkx/reference/mongodb.xml
@@ -39,11 +39,6 @@
Persistence and mapping lifecycle events
-
- Low-level mapping using MongoReader/MongoWriter
- abstractions
-
-
Java based Query, Criteria, and Update DSLs
@@ -71,15 +66,16 @@
- For most tasks you will find yourself using MongoTemplate or the
- Repository support that both leverage the rich mapping functionality.
- MongoTemplate is the place to look for accessing functionality such as
- incrementing counters or ad-hoc CRUD operations. MongoTemplate also provides
- callback methods so that it is easy for you to get a hold of the low level
- API artifacts such as org.mongo.DB to communicate
- directly with MongoDB. The goal with naming conventions on various API
- artifacts is to copy those in the base MongoDB Java driver so you can easily
- map your existing knowledge onto the Spring APIs.
+ For most tasks you will find yourself using
+ MongoTemplate or the Repository support that both
+ leverage the rich mapping functionality. MongoTemplate is the place to look
+ for accessing functionality such as incrementing counters or ad-hoc CRUD
+ operations. MongoTemplate also provides callback methods so that it is easy
+ for you to get a hold of the low level API artifacts such as
+ org.mongo.DB to communicate directly with MongoDB. The
+ goal with naming conventions on various API artifacts is to copy those in
+ the base MongoDB Java driver so you can easily map your existing knowledge
+ onto the Spring APIs.
Getting Started
@@ -110,21 +106,13 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
- <version>1.0.0.M2</version>
- </dependency>
-
- <dependency>
- <groupId>cglib</groupId>
- <artifactId>cglib</artifactId>
- <version>2.2</version>
+ <version>1.0.0.M3</version>
</dependency>
</dependencies>
- The cglib dependency is there as we will use Spring's Java
- configuration style. Also change the version of Spring in the pom.xml to
- be
+ Also change the version of Spring in the pom.xml to be
<spring.framework.version>3.0.5.RELEASE</spring.framework.version>
@@ -145,64 +133,57 @@
here.
You may also want to set the logging level to DEBUG to see some
- additional information, edit the log4j.properties file and add
+ additional information, edit the log4j.properties file to have
- log4j.category.org.springframework.data.document.mongodb=DEBUG
+ log4j.category.org.springframework.data.document.mongodb=DEBUG
+log4j.appender.stdout.layout.ConversionPattern=%-5p [%c{3}]: %m%n
- Next, in the org.spring.mongodb package in the
- src/test/java directory create a class as shown
- below.
+ Create a simple Person class to persist
- package org.spring.mongodb;
-
-import org.springframework.context.annotation.Configuration;
-import org.springframework.data.document.mongodb.MongoTemplate;
-import org.springframework.data.document.mongodb.config.AbstractMongoConfiguration;
+ package org.spring.mongodb;
-import com.mongodb.Mongo;
+public class Person {
-@Configuration
-public class MongoConfig extends AbstractMongoConfiguration {
+ private String id;
+ private String firstName;
+ private String lastName;
+ private int age;
- @Override
- public Mongo mongo() throws Exception {
- return new Mongo("localhost");
+ public Person(String firstName, String lastName, int age) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.age = age;
}
-
- @Override
- public MongoTemplate mongoTemplate() throws Exception {
- return new MongoTemplate(mongo() , "database", "mongoexample");
+ public String getFirstName() {
+ return firstName;
}
-}
-
- Then create a simple Person class to persist
-
- package org.spring.mongodb;
-
-public class Person {
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
- private String id;
-
- private String name;
+ public String getLastName() {
+ return lastName;
+ }
- public Person(String id, String name) {
- this.id = id;
- this.name = name;
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
}
-
- public String getId() {
- return id;
+
+ public int getAge() {
+ return age;
}
- public String getName() {
- return name;
+ public void setAge(int age) {
+ this.age = age;
}
@Override
public String toString() {
- return "Person [id=" + id + ", name=" + name + "]";
+ return "Person [id=" + id + ", firstName=" + firstName + ", lastName="
+ + lastName + ", age=" + age + "]";
}
+
}
@@ -210,40 +191,40 @@ public class Person {
package org.spring.mongodb;
+import static org.springframework.data.document.mongodb.query.Criteria.where;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.document.mongodb.MongoOperations;
-import org.springframework.data.document.mongodb.query.Criteria;
+import org.springframework.data.document.mongodb.MongoTemplate;
import org.springframework.data.document.mongodb.query.Query;
+import org.spring.mongodb.Person;
+
public class MongoApp {
private static final Log log = LogFactory.getLog(MongoApp.class);
public static void main(String[] args) {
- ApplicationContext ctx = new AnnotationConfigApplicationContext(MongoConfig.class);
- MongoOperations mongoOps = ctx.getBean(MongoOperations.class);
-
- mongoOps.insert(new Person("1234", "Joe"));
- log.info(mongoOps.findOne(new Query(Criteria.where("name").is("Joe")), Person.class));
+ MongoOperations mongoOps = new MongoTemplate(new Mongo(), "database");
+
+ mongoOps.insert(new Person("Joe", "Swanson", 34));
+
+ log.info( mongoOps.findOne(new Query(where("firstName").is("Joe")), Person.class) );
+
+ mongoOps.dropCollection("person");
}
}
This will produce the following output
- MongoPersistentEntityIndexCreator] - <Analyzing class class org.spring.mongodb.Person for index information.>
-LoggingEventListener] - <onBeforeConvert: Person [id=1234, name=Joe]>
-LoggingEventListener] - <onBeforeSave: Person [id=1234, name=Joe], { "_id" : "1234" , "name" : "Joe"}>
-MongoTemplate] - <insert DBObject: { "_id" : "1234" , "name" : "Joe"}>
-LoggingEventListener] - <onAfterSave: Person [id=1234, name=Joe], { "_id" : "1234" , "name" : "Joe"}>
-MongoTemplate] - <findOne using query: { "name" : "Joe"} in db.collection: database.person>
-LoggingEventListener] - <onAfterLoad: { "_id" : "1234" , "name" : "Joe"}>
-LoggingEventListener] - <onAfterConvert: { "_id" : "1234" , "name" : "Joe"}, Person [id=1234, name=Joe]>
-MongoApp] - <Person [id=1234, name=Joe]>
+ DEBUG [mongodb.mapping.MongoPersistentEntityIndexCreator]: Analyzing class class org.mongo.demo2.domain.Person for index information.
+DEBUG [document.mongodb.MongoTemplate]: insert DBObject containing fields: [_class, lastName, age, firstName] in collection: Person
+DEBUG [document.mongodb.MongoTemplate]: findOne using query: { "firstName" : "Joe"} in db.collection: database.Person
+INFO [spring.mongodb.MongoApp]: Person [id=4ddb2f629e60ab6a21da5fdb, firstName=Joe, lastName=Swanson, age=34]
+DEBUG [document.mongodb.MongoTemplate]: Dropped collection [database.person]
If you are not using Maven then you would need to include the
@@ -299,13 +280,7 @@ MongoApp] - <Person [id=1234, name=Joe]>
spring-expression-3.0.5.RELEASE.jar
-
-
- spring-tx-3.0.5.RELEASE.jar
-
-
-
@@ -319,7 +294,7 @@ MongoApp] - <Person [id=1234, name=Joe]>
- Connecting to MongoDB
+ Connecting to MongoDB
One of the first tasks when using MongoDB and Spring is to create a
com.mongodb.Mongo object using the IoC container.