https://github.com/jloisel/reactive-couchbase
Observable Couchbase Repository
https://github.com/jloisel/reactive-couchbase
Last synced: 10 months ago
JSON representation
Observable Couchbase Repository
- Host: GitHub
- URL: https://github.com/jloisel/reactive-couchbase
- Owner: jloisel
- License: apache-2.0
- Created: 2015-02-16T19:47:23.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-02-17T07:32:28.000Z (about 11 years ago)
- Last Synced: 2025-04-08T16:39:10.626Z (about 1 year ago)
- Language: Java
- Homepage:
- Size: 180 KB
- Stars: 5
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# reactive-couchbase
Spring Data Couchbase is currently using the synchronous Couchbase Java SDK 1.x. Java SDK 2 offers batching which greatly improves the performances:
http://docs.couchbase.com/developer/java-2.1/documents-bulk.html
But the Java SDK 2.x is pretty low level. It lakes a high level repository like Spring Data, while Spring Data lakes Asynchronous operations on Observables. This Couchbase repository implementation tries to fit both worlds:
- Asynchronous through RxJava,
- High level API which is easy to use.
Pre-requisites:
- Maven
- Java JDK 8
- Lombok (see http://projectlombok.org/)
Observable Couchbase repository made easy:
```java
final AsyncRepositoryFactory factory = ...;
final AsyncRepository repository = factory.create(Person.class);
// findAll() returns Observable
repository.findAll().forEach(person -> System.out.println(person.getFirstname()));
```
As well as sequential repository:
```java
final SyncRepositoryFactory factory = ...;
final SyncRepository repository = factory.create(Person.class);
final List persons = repository.findAll();
```
Person entity using Jackson Json processor:
```java
@Value
@Builder
public class Person implements ReactiveEntity {
String id;
String firstname;
String lastname;
@JsonCreator
Person(
@JsonProperty("id") final String id,
@JsonProperty("firstname") final String firstname,
@JsonProperty("lastname") final String lastname) {
super();
this.id = checkNotNull(id);
this.firstname = checkNotNull(firstname);
this.lastname = checkNotNull(lastname);
}
}
```
Spring Configuration:
```java
@Configuration
public class CouchbaseConfig {
@Bean
@Autowired
ASyncRepository asyncPersonRepository(final ASyncRepositoryFactory factory) {
return factory.create(Person.class);
}
@Bean
@Autowired
SyncRepository syncPersonRepository(final SyncRepositoryFactory factory) {
return factory.create(Person.class);
}
}
```