An open API service indexing awesome lists of open source software.

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

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);
}
}
```