We are delighted to announce that the eagerly awaited Spring Data Couchbase 4.0 is now available with enhanced capabilities. Built on top of Couchbase Java SDK 3.0, Spring Data Couchbase out-of-the-box comes with technology enhancements and leverages the latest Couchbase Server 6.5 capabilities. These improvements are targeted to maximize developer agility, offer reduced code impedance, enhance manageability, and provide quality developer experience.
Before getting into what’s changed in Spring Data Couchbase, let’s take a moment to step back and understand what Spring Data is, what problems it solves and why a developer should consider using it.
Most developers are familiar with a database, the de-facto standard for data persistence. Today, almost all applications rely on some type of technology that is responsible for persistent storage with more modern enterprise applications commonly adopting the use of a multi-model database.
Regardless of the technology used as a persistence store, operations performed on data have largely remained consistent. The consistency in operations comes from developers, over a period of time, writing thousands of lines of code over and over again to Create, Retrieve, Update and Delete data from their underlying persistence store. As a developer you always want to avoid writing such repetitive and monotonous code, rather you want to focus on writing business logic that brings in more value.
Over a decade, repository patterns have gained a lot of popularity and traction in the developer community. In its modern interpretation, a repository pattern abstracts the data store and enables your business logic to define, read and write operations on a logical level. These patterns are good from an abstractions point of view however it still doesn’t solve the core problem of a developer writing repetitive code. Implementing repository patterns and writing your own data access could leave you with a lot of spaghetti code making maintainability a nightmare, and could also be violating the D.R.Y principle. This is where Spring Data comes to our rescue.
Spring Data is a high-level Pivotal project whose purpose is to unify and ease the access to different kinds of persistence stores, both relational database systems and NoSQL data stores. Spring Data provides generic interfaces for these aspects (CrudRepository, PagingAndSortingRepository) as well as persistence store specific implementations.
With Spring Data’s repositories, you need only to write an interface with finder methods defined according to a given set of conventions (which may vary depending on the kind of persistence store you are using). Spring Data will provide an appropriate implementation of that interface at runtime.
Spring Data for Couchbase, on the other hand, is part of the umbrella Spring Data project that is maintained and fully supported by Couchbase to Enterprise subscribers. Spring Data for Couchbase aims to provide a familiar and consistent programming model for new data-stores while retaining store-specific features and capabilities. With Spring Data Couchbase you get the simplicity of Spring Data combined with the power of Couchbase!.
What’s changed in Spring Data Couchbase 4.0
Spring Data Couchbase 4.0 is built on top of Couchbase Java SDK 3.0.
Couchbase Java SDK 3.0 is a complete rethink of the 2.x API, providing a simpler surface area and adding support for future Couchbase Server features like Collections, Scopes and transactions (available since Couchbase Server 6.5 as a developer preview).
Couchbase Server Version Support
To stay in accordance with the feature support, the minimum Couchbase Server version requirement has been bumped up to 5.5 and later.
Going forward N1QL will be the primary implementation when it comes to working with custom repository methods as well as the built in ones. Because Spring Data pre-dated N1QL, it used older services by default. If you have used N1QL with Spring Data in the past, don’t worry, there are no significant behavioral changes when implementing N1QL queries with Spring Data Couchbase 4.0.
Although the concept of Automatic Index Management is not new, index management has been enhanced and is more N1QL centric. While some of the Index annotations like ViewIndexes are removed as they stand no more relevance, many new Index annotations are added to the annotations family that will provide enriched capabilities like field level indexing, composite field indexes and more.
Nothing has changed when it comes to dealing with entities, however switching between imports has become easier than ever. Any annotations that were a part of Couchbase SDK 2.x have now been dropped, which also means that developers get to stick to default spring data annotations.
ReactiveCouchbaseTemplate and CouchbaseTemplate have been overhauled in general, moving to a Fluent API instead of method overloads. In addition we moved from RxJava to Reactor for the reactive template which, in turn, provides seamless integration into the spring ecosystem.Template method names have been generalized for ease of use, and any view based methods have been removed. Also, new methods that leverage Couchbase analytics service and replicas have been introduced.
Developers can now natively use all transaction features that are available to them through Couchbase SDK 3.0. This way developers can have full programmatic control over transactions.
Previous versions of Spring-Data allowed configurations via both XML and Java-based annotations however, with this release XML based configuration has been removed.
Views existed prior to N1QL came into existence. Spring-Data 3.x emphasized use of View over N1QL for some aspects of the repositories which were then still evolving. Over the past few years there has been drastic advancement in N1QL with respect to performance, scalability and integration with search capabilities, in order to maximize the benefit out of N1QL, starting in Spring Data 4.0 support for Views has been removed.
So What’s Next ?
We would love to hear from you on how you liked the 4.0 features and how they will benefit your business going forward. You can also try some of the examples found here. Please don’t forget to share your feedback via the comments or in the forum.