From b7c710bed09bf40897688cab3db02ed90243b397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Basl=C3=A9?= Date: Mon, 22 Feb 2016 12:33:02 +0100 Subject: [PATCH] Updated features/examples for 2.0.0 --- index.html | 126 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 84 insertions(+), 42 deletions(-) diff --git a/index.html b/index.html index b1e49eee..13122d6b 100644 --- a/index.html +++ b/index.html @@ -41,30 +41,32 @@ badges: {% capture billboard_description %} -Spring Data for [Couchbase](http://www.couchbase.com) is part of the umbrella -Spring Data project which aims to provide a familiar and consistent Spring-based -programming model for new datastores while retaining store-specific features and +Spring Data for [Couchbase](http://www.couchbase.com) is part of the umbrella +Spring Data project which aims to provide a familiar and consistent Spring-based +programming model for new datastores while retaining store-specific features and capabilities. {% endcapture %} {% capture main_content %} -The Spring Data Couchbase project provides integration with the Couchbase Server -database. Key functional areas of Spring Data Couchbase are a POJO centric model -for interacting with Couchbase Buckets and easily writing a Repository style data +The Spring Data Couchbase project provides integration with the Couchbase Server +database. Key functional areas of Spring Data Couchbase are a POJO centric model +for interacting with Couchbase Buckets and easily writing a Repository style data access layer. ## Features -* Spring configuration support using Java based @Configuration classes or an XML namespace for the Couchbase driver. -* CouchbaseTemplate helper class that increases productivity performing common Couchbase operations. Includes integrated object mapping between documents and POJOs. +* Spring configuration support using Java based `@Configuration` classes or an XML namespace for the Couchbase driver (Java SDK version `2.x`). +* `CouchbaseTemplate` helper class that increases productivity performing common Couchbase operations. Includes integrated object mapping between documents and POJOs. * Exception translation into Spring's portable Data Access Exception hierarchy. * Feature Rich Object Mapping integrated with Spring's Conversion Service. * Annotation based mapping metadata but extensible to support other metadata formats. -* Automatic implementation of Repository interfaces including support for custom finder methods (backed by Couchbase Views). +* Automatic implementation of `Repository` interfaces including support for custom finder methods (backed by Couchbase's query language, `N1QL`) and `PagingAndSortingRepository`. +* For Couchbase server versions < 4.0, repositories can still be backed by Couchbase Views. +* Support for geospatial and multidimensional querying (backed by Couchbase Spatial Views) * JMX administration and monitoring -* Transparent @Cacheable support to cache any objects you need for high performance access. +* Can serve as the backend for `@Cacheable` support, to cache any objects you need for high performance access (see sibling Spring Cache project in Couchbase's github, [couchbaselabs/couchbase-spring-cache](https://github.com/couchbaselabs/couchbase-spring-cache)). ## Quick Start @@ -72,6 +74,10 @@ access layer. {% include download_widget.md %} ## Configuration +The minimal configuration requires you to set the name and password of the main `Bucket` into which Spring Data Couchbase will store the data: `getBucketName()` and `getBucketPassword()`. + +The other required information is a list of IPs or hostnames to bootstrap from (at least one, preferably two): `getBootstrapHosts()`. These are just used to initiate connection to the cluster, after which the client will discover all nodes and keep the cluster map up to date. + ```java package foo; @@ -82,7 +88,7 @@ import foo; public class Config extends AbstractCouchbaseConfiguration { @Override - protected List bootstrapHosts() { + protected List getBootstrapHosts() { return Arrays.asList("host1", "host2"); } @@ -103,42 +109,31 @@ public class Config extends AbstractCouchbaseConfiguration { public interface UserRepository extends CrudRepository { /** - * Additional custom finder method. + * Additional custom finder method, backed by an auto-generated + * N1QL query. */ - List findByLastname(Query query); + List findByLastnameAndAgeBetween(String lastName, int minAge, + int maxAge); + /** + * Additional custom finder method, backed by a View that indexes + * the names. + */ + @View(designDocument = "user", viewName = "byName") + List findByLastname(String lastName); + + /** + * Additional custom finder method, backed by a geospatial view and + * allowing multi-dimensional queries. + * You can also query within a Circle or a Polygon. + */ + @Dimensional(designDocument = "userGeo", spatialViewName = "byLocation") + List findByLocationWithin(Box cityBoundingBox); } ``` -## Usage -```java -@Service -public class MyService { - - private final UserRepository userRepository; - - @Autowired - public MyService(UserRepository userRepository) { - this.userRepository = userRepository; - } - - public void doWork() { - userRepository.deleteAll(); - - User user = new User(); - user.setLastname("Jackson"); - - user = userRepository.save(user); - - Query query = new Query(); - query.setKey(ComplexKey.of("Jackson")); - List allUsers = userRepository.findByLastname(query); - - } -} -``` - -Note that to back the custom finders, you need to set up two Views on the server: +## Server-side Setup +Note that some CRUD operations like `findAll` and `count`, as well as view-based custom finders each require you to set up a corresponding View on the server side: For `findByLastname`: @@ -160,6 +155,53 @@ function (doc, meta) { } ``` +For `findByLocationWithin`: + +```javascript +function (doc, meta) { + if(doc._class == "com.example.entity.User" && doc.location) { + emit([doc.location.x, doc.location.y], null); + } +} +``` + +For more information on server side setup and how it can be partially automated in development environments, see the [Backing Views](http://docs.spring.io/spring-data/couchbase/docs/current/reference/html/#couchbase.repository.views) and [Automatic Index Management](http://docs.spring.io/spring-data/couchbase/docs/current/reference/html/#couchbase.repository.indexing) sections of the documentation. + +## Usage +```java +@Service +public class MyService { + + private final UserRepository userRepository; + + @Autowired + public MyService(UserRepository userRepository) { + this.userRepository = userRepository; + } + + public void doWork() { + userRepository.deleteAll(); + + User user = new User(); + user.setLastname("Jackson"); + user.setLocation(new Point(123, 456)); + + user = userRepository.save(user); + + List jacksonChildren = + userRepository.findByLastNameAndAgeBetween("Jackson", 0, 18); + + List jacksonFamily = + userRepository.findByLastName("Jackson"); + + //bounding box is lower-left, upper-right corners + Box cityBounds = new Box(new Point(100, 100), new Point(150, 500)); + List jacksonsInSomeCity = + userRepository.findByLocationWithin(cityBounds); + } +} +``` + {% endcapture %} {% capture related_resources %}