From bd3aac83423856040d84c5366942d94a9045e0ac Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 18 Apr 2013 10:11:06 +0200 Subject: [PATCH] DATAMONGO-658 - Pull forward changes made to README in 1.2.x branch. --- README.md | 133 +++++++++++++++++++++++++++--------------------------- 1 file changed, 66 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 977db51fd..686119af9 100644 --- a/README.md +++ b/README.md @@ -29,19 +29,13 @@ For those in a hurry: * Download the jar through Maven: - - org.springframework.data - spring-data-mongodb - 1.2.0.BUILD-SNAPSHOT - - - - - spring-maven-snapshot - true - Springframework Maven SNAPSHOT Repository - http://maven.springframework.org/snapshot - +```xml + + org.springframework.data + spring-data-mongodb + 1.2.1.RELEASE + +``` ### MongoTemplate MongoTemplate is the central support class for Mongo database operations. It provides @@ -54,93 +48,98 @@ Future plans are to support optional logging and/or exception throwing based on ### Easy Data Repository generation -To simplify the creation of Data Repositories a generic Repository interface and default implementation is provided. Furthermore, Spring will automatically create a Repository implementation for you that adds implementations of finder methods you specify on an interface. +To simplify the creation of data repositories a generic `Repository` interface and default implementation is provided. Furthermore, Spring will automatically create a Repository implementation for you that adds implementations of finder methods you specify on an interface. The Repository interface is - public interface Repository { +```java +public interface Repository { - T save(T entity); + T save(T entity); - List save(Iterable entities); + List save(Iterable entities); - T findById(ID id); + T findById(ID id); - boolean exists(ID id); + boolean exists(ID id); - List findAll(); + List findAll(); - Long count(); + Long count(); - void delete(T entity); + void delete(T entity); - void delete(Iterable entities); + void delete(Iterable entities); - void deleteAll(); - } + void deleteAll(); +} +``` -The MongoRepository extends Repository and will in future add more Mongo specific methods. +The `MongoRepository` extends `Repository` and will in future add more Mongo specific methods. - public interface MongoRepository extends - Repository { - } +```java +public interface MongoRepository extends Repository { +} +``` -SimpleMongoRepository is the out of the box implementation of the MongoRepository you can use for basid CRUD operations. +`SimpleMongoRepository` is the out of the box implementation of the `MongoRepository` you can use for basid CRUD operations. -To go beyond basic CRUD, extend the MongoRepository interface and supply your own finder methods that follow simple naming conventions such that they can be easily converted into queries. +To go beyond basic CRUD, extend the `MongoRepository` interface and supply your own finder methods that follow simple naming conventions such that they can be easily converted into queries. -For example, given a Person class with first and last name properties, a PersonRepository interface that can query for Person by last name and when the first name matches a regular expression is shown below +For example, given a `Person` class with first and last name properties, a `PersonRepository` interface that can query for `Person` by last name and when the first name matches a regular expression is shown below - public interface PersonRepository extends MongoRepository { +```java +public interface PersonRepository extends MongoRepository { - List findByLastname(String lastname); + List findByLastname(String lastname); - List findByFirstnameLike(String firstname); - } + List findByFirstnameLike(String firstname); +} +``` -You can have Spring automatically generate the implemention as shown below +You can have Spring automatically create a proxy for the interface as shown below: - - - - - - - - - - +```xml + + + + + + + + + + - - - - + +``` -This will register an object in the container named PersonRepository. You can use it as shown below +This will find the repository interface and register a proxy object in the container. You can use it as shown below: - @Service - public class MyService { +``java +@Service +public class MyService { - @Autowired - PersonRepository repository; + @Autowired + private final PersonRepository repository; + public void doWork() { - public void doWork() { + repository.deleteAll(); - repository.deleteAll(); + Person person = new Person(); + person.setFirstname("Oliver"); + person.setLastname("Gierke"); + person = repository.save(person); - Person person = new Person(); - person.setFirstname("Oliver"); - person.setLastname("Gierke"); - person = repository.save(person); + List lastNameResults = repository.findByLastname("Gierke"); - List lastNameResults = repository.findByLastname("Gierke"); + List firstNameResults = repository.findByFirstnameLike("Oli*"); - List firstNameResults = repository.findByFirstnameLike("Oli*"); - - } - } + } +} +``` Contributing to Spring Data