GithubHelp home page GithubHelp logo

mindis / reactive-couchbase Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jloisel/reactive-couchbase

0.0 3.0 0.0 184 KB

Observable Couchbase Repository

License: Apache License 2.0

Java 99.44% JavaScript 0.56%

reactive-couchbase's Introduction

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:

Observable Couchbase repository made easy:

final AsyncRepositoryFactory factory = ...;
final AsyncRepository<Person> repository = factory.create(Person.class);

// findAll() returns Observable<Person>
repository.findAll().forEach(person -> System.out.println(person.getFirstname()));

As well as sequential repository:

final SyncRepositoryFactory factory = ...;
final SyncRepository<Person> repository = factory.create(Person.class);

final List<Person> persons = repository.findAll();

Person entity using Jackson Json processor:

@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:

@Configuration
public class CouchbaseConfig {

  @Bean
  @Autowired
  ASyncRepository<Person> asyncPersonRepository(final ASyncRepositoryFactory factory) {
    return factory.create(Person.class);
  }
  
  @Bean
  @Autowired
  SyncRepository<Person> syncPersonRepository(final SyncRepositoryFactory factory) {
    return factory.create(Person.class);
  }
}

reactive-couchbase's People

Contributors

jloisel avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.