commit 274e26fd6f960c5ca8e477154d5fc132f7e66daf Author: Simon Baslé Date: Mon Jun 15 14:58:25 2015 +0200 initial v2 from scratch commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..14faa42b --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +### Maven template +target/ + +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion +*.iml +.idea/ +*.ipr +*.iws + +### Eclipse template +.classpath +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +.settings/ +.loadpath + +### OS specifics +.DS_Store +Thumbs.db +ehthumbs.db +Desktop.ini +$RECYCLE.BIN/ + +### Java template +*.class +hs_err_pid* \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 00000000..b068acb1 --- /dev/null +++ b/README.md @@ -0,0 +1,203 @@ +# Spring Data Couchbase - v2 +This branch is a work in progress, it will contain the do-over of the `Spring-Data Couchbase` connector +for the `Couchbase Java SDK 2.x` generation. + +Below is the v1 README as of `75bce39`: + +# Spring Data Couchbase + +The primary goal of the [Spring Data](http://www.springsource.org/spring-data) project is to make it easier to build +Spring-powered applications that use new data access technologies such as non-relational databases, map-reduce +frameworks, and cloud based data services. + +The Spring Data Couchbase project aims to provide a familiar and consistent Spring-based programming model for Couchbase +Server as a document database and cache while retaining store-specific features and capabilities. Key functional areas +of Spring Data Couchbase are a POJO centric model for interacting with a Couchbase Server Bucket and easily writing a +repository style data access layer. + +## Getting Help + +For a comprehensive treatment of all the Spring Data Couchbase features, please refer to: + +* the [User Guide](http://static.springsource.org/spring-data/couchbase/docs/current/reference/html/) +* the [JavaDocs](http://static.springsource.org/spring-data/couchbase/docs/current/api/) have extensive comments + in them as well. +* for more detailed questions, use the [forum](http://forum.springsource.org/forumdisplay.php?f=80). + +If you are new to Spring as well as to Spring Data, look for information about +[Spring projects](http://www.springsource.org/projects). + + +## Quick Start + +### Maven configuration + +Add the Maven dependency: + +```xml + + org.springframework.data + spring-data-couchbase + 1.2.2.RELEASE + +``` + +If you'd rather like the latest snapshots of the upcoming major version, use our Maven snapshot repository and declare +the appropriate dependency version. + +```xml + + org.springframework.data + spring-data-couchbase + 1.3.0.BUILD-SNAPSHOT + + + + spring-libs-snapshot + Spring Snapshot Repository + http://repo.spring.io/libs-snapshot + +``` + +### CouchbaseTemplate + +CouchbaseTemplate is the central support class for Couchbase database operations. It provides: + +* Basic POJO mapping support to and from JSON (by default through Jackson) +* Convenience methods to interact with the store (insert object, update objects) and Couchbase specific ones +* Exception translation into Spring's [technology agnostic DAO exception hierarchy](http://docs.spring.io/spring/docs/current/spring-framework-reference/html/dao.html#dao-exceptions). + +### Spring Data Repositories + +To simplify the creation of data repositories Spring Data COUCHBASE provides a generic repository programming model. It +will automatically create a repository proxy for you that adds implementations of finder methods you specify on an +interface. + +To create a repository on top of a `User` entity, all you need to write is: + +```java +public interface UserRepository extends CrudRepository { + + /** + * Additional custom finder method. + */ + List findByLastname(Query query); + +} +``` + +Once you get a reference to that repository bean, you'll find a lot of methods that make it very easy o work with this +entity. In addition to the ones provided through the `CrudRepository`, you can add your own methods as well. + +In general, every finder method that does not depend on a single key (like `findById`) needs a backing View on the +server side. In the example above, it assumes you have a view named `findByLastname` in the `user` design document. You +can customize the view and design document name through the `@View` annotation. Also make sure you publish them into +production before accessing it. + +This is an example view for the `findByLastname` method: + +```javascript +function (doc, meta) { + if(doc._class == "com.example.entity.User" && doc.lastname) { + emit(doc.lastname, null); + } +} +``` + +You can pass in custom runtime parameters through the `Query` param. + +To make the `findAll()` and `count` view work, it needs to look like this (and do not forget the `_count` reduce +function): + +```javascript +function (doc, meta) { + if(doc._class == "com.example.entity.User") { + emit(null, null); + } +} +``` + +The queries issued on execution will be derived from the method name. Extending `CrudRepository` causes CRUD methods +being pulled into the interface so that you can easily save and find single entities and collections of them. + +You can have Spring automatically create a proxy for the interface by using the following JavaConfig: + +```java +@Configuration +@EnableCouchbaseRepositories +public class Config extends AbstractCouchbaseConfiguration { + + @Override + protected List bootstrapHosts() { + return Arrays.asList("host1", "host2"); + } + + @Override + protected String getBucketName() { + return "default"; + } + + @Override + protected String getBucketPassword() { + return ""; + } +} +``` + +This sets up a connection to a Couchbase cluster and enables the detection of Spring Data repositories (through +`@EnableCouchbaseRepositories). The same configuration would look like this in XML: + +```xml + + + +``` + +This will find the repository interface and register a proxy object in the container. You can use it as shown below: + +```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); + + } +} +``` + + +## Contributing to Spring Data + +Here are some ways for you to get involved in the community: + +* Get involved with the Spring community on the Spring Community Forums. Please help out on the + [forum](http://forum.springsource.org/forumdisplay.php?f=80) by responding to questions and joining the debate. +* Create [JIRA](https://jira.springframework.org/browse/DATACOUCH) tickets for bugs and new features and comment and + vote on the ones that you are interested in. +* Github is for social coding: if you want to write code, we encourage contributions through pull requests from + [forks of this repository](http://help.github.com/forking/). If you want to contribute code this way, please reference + a JIRA ticket as well covering the specific issue you are addressing. +* Watch for upcoming articles on Spring by [subscribing](http://www.springsource.org/node/feed) to springframework.org + +Before we accept a non-trivial patch or pull request we will need you to sign the +[contributor's agreement](https://support.springsource.com/spring_committer_signup). Signing the contributor's agreement +does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and +you will get an author credit if we do. Active contributors might be asked to join the core team, and given the ability +to merge pull requests. diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..b75fd33b --- /dev/null +++ b/pom.xml @@ -0,0 +1,155 @@ + + + + 4.0.0 + + org.springframework.data + spring-data-couchbase + 1.4.0.BUILD-SNAPSHOT + + Spring Data Couchbase + Spring Data integration for Couchbase + https://github.com/SpringSource/spring-data-couchbase + + + org.springframework.data.build + spring-data-parent + 1.7.0.BUILD-SNAPSHOT + + + + + DATACOUCH + + 2.1.3 + 2.3.2 + 1.11.0.BUILD-SNAPSHOT + 1.0.0.GA + + + + + + org.springframework + spring-context + + + org.springframework + spring-web + + + org.springframework + spring-tx + + + + ${project.groupId} + spring-data-commons + ${springdata.commons} + + + + com.couchbase.client + java-client + ${couchbase} + + + + org.springframework + spring-test + ${spring} + test + + + + org.hibernate + hibernate-validator + 4.2.0.Final + test + + + + org.apache.httpcomponents + httpclient + 4.3.3 + test + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson} + + + + joda-time + joda-time + ${jodatime} + true + + + + + javax.validation + validation-api + ${validation} + true + + + + + javax.enterprise + cdi-api + ${cdi} + provided + true + + + + org.apache.openwebbeans.test + cditest-owb + ${webbeans} + test + + + + javax.servlet + servlet-api + 3.0-alpha-1 + test + + + + + + + spring-libs-snapshot + https://repo.spring.io/libs-snapshot + + + + + + spring-plugins-release + https://repo.spring.io/plugins-release + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + org.codehaus.mojo + wagon-maven-plugin + + + org.asciidoctor + asciidoctor-maven-plugin + + + + + \ No newline at end of file diff --git a/template.mf b/template.mf new file mode 100644 index 00000000..caed27c3 --- /dev/null +++ b/template.mf @@ -0,0 +1,21 @@ +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: org.springframework.data.couchbase +Bundle-Name: ${project.name} +Bundle-Vendor: Pivotal Software, Inc. +Bundle-Version: ${project.version} +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Export-Template: + org.springframework.data.couchbase.*;version="${project.version}" +Import-Template: + javax.enterprise.*;version="${cdi:[=.=.=,+1.0.0)}";resolution:=optional, + com.couchbase.client.*;version="${couchbase:[=.=.=,+2.1.3)}", + net.spy.memcached.*;version="[2.8.0,3.0.0)", + com.fasterxml.jackson.*;version="${jackson:[=.=.=,+1.0.0)}", + org.springframework.*;version="${spring:[=.=.=.=,+1.1.0)}", + org.springframework.data.*;version="${springdata.commons:[=.=.=.=,+1.0.0)}", + org.w3c.*;version="0.0.0", + org.aopalliance.*;version="[1.0.0, 2.0.0)";resolution:=optional, + org.slf4j.*;version="${slf4j:[=.=.=,+1.0.0)}", + org.joda.time.*;version="${jodatime:[=.=.=,+1.0.0)}";resolution:=optional, + javax.validation.*;version="${validation:[=.=.=.=,+1.0.0)}";resolution:=optional +