/spring-data-aerospike

Spring Data Aerospike

Primary LanguageJavaApache License 2.0Apache-2.0

Spring Data Aerospike

maven ci javadoc

The Spring Data Aerospike project aims to provide a familiar and consistent Spring-based programming model for new data stores while retaining store-specific features and capabilities. It provides integration with the Aerospike database. Key functional areas of Spring Data Aerospike are a POJO centric model for interacting with Aerospike DB and easily writing a repository style data access layer.

Documentation

Examples

  1. Demo project example with a step-by-step tutorial can be found here

  2. Demo project with detailed guides is located here

Getting Started Blog Posts

Spring Data Aerospike Compatibility

Compatibility Table
Spring Data Aerospike Spring Boot Aerospike Client Aerospike Reactor Client Aerospike Server

4.8.x

3.3.x

7.2.x

7.1.x

5.2.x.x

4.7.x

3.2.x

7.2.x

7.1.x

5.2.x.x

4.6.x

3.2.x

7.2.x

7.1.x

5.2.x.x

4.5.x

3.1.x

7.1.x

7.0.x

5.2.x.x

4.4.x

3.1.x

7.0.x

7.0.x

5.2.x.x

4.3.x

3.1.x

6.1.x

6.1.x

5.2.x.x

4.2.x

3.0.x

6.1.x

6.1.x

5.2.x.x

4.1.x

3.0.x

6.1.x

6.1.x

5.2.x.x

3.5.x

2.7.x

6.1.x

6.1.x

5.2.x.x

3.4.x

2.6.x

5.1.x

5.1.x

5.2.x.x

3.3.x

2.5.x

5.1.x

5.1.x

5.2.x.x

3.2.x

2.5.x

5.1.x

5.0.x

5.2.x.x

3.0.x, 3.1.x

2.5.x

5.1.x

5.0.x

2.5.x

2.5.x

4.4.x

4.4.x

2.4.2.RELEASE

2.3.x

4.4.x

4.4.x

2.3.5.RELEASE

2.2.x

4.4.x

4.4.x

2.1.1.RELEASE

2.1.x, 2.0.x

4.4.x

3.2.x

1.2.1.RELEASE

1.5.x

4.1.x

Quick Start

1. Maven configuration

Add the spring-data-aerospike Maven dependency:

<dependency>
  <groupId>com.aerospike</groupId>
  <artifactId>spring-data-aerospike</artifactId>
  <version>${spring-data-aerospike.version}</version>
</dependency>

Notes:

2. AerospikeRepository

AerospikeRepository is the simplest way to interact with Aerospike using Spring Data Aerospike.

Create your own custom repository that extends AerospikeRepository which will provide out-of-the-box CRUD operations and query implementations, so you can easily save, find, delete and query single entities and collections of them.

Implementation will be determined by the method names automatically, no need to write any implementation.

For example, given a Person class with first and last name properties, a PersonRepository interface that can query for Person by last name and when the first name matches a like expression is shown below:

public interface PersonRepository extends AerospikeRepository<Person, Long> {

    List<Person> findByLastname(String lastname);

    List<Person> findByFirstnameLike(String firstname);
}

For non-blocking reactive API use ReactiveAerospikeRepository.

3. Configuration

In order to configure Spring Data Aerospike you will need to create a configuration class that extends AbstractAerospikeDataConfiguration and defines the relevant Spring Data Repositories via @EnableAerospikeRepositories annotation.

To set the connection details you can either override getHosts() and nameSpace() methods of the AbstractAerospikeDataConfiguration class or define spring-data-aerospike.connection.hosts and spring-data-aerospike.connection.namespace in application.properties file.

Note
You can further customize your configuration by changing other settings.

Here is a simple example of a configuration class that sets up a connection to a local Aerospike DB instance:

@Configuration
@EnableAerospikeRepositories(basePackageClasses = PersonRepository.class)
class ApplicationConfig extends AbstractAerospikeDataConfiguration {

    @Override
    protected Collection<Host> getHosts() {
        return Collections.singleton(new Host("localhost", 3000));
    }

    @Override
    protected String nameSpace() {
        return "test";
    }
}

Usage

Below is an example of a service that uses PersonRepository operations.

  • deleteAll and save are provided automatically by extending AerospikeRepository interface

  • findByFirstnameLike and findByLastname methods were defined in PersonRepository but there was no need to write the actual implementation, it is determined automatically from the method names

@Service
public class PersonService {

    private final PersonRepository personRepository;

    @Autowired
    public PersonService(PersonRepository personRepository) {
        this.personRepository = personRepository;
    }

    public void example() {
        // Delete all existing persons
        personRepository.deleteAll();

        Person person = new Person();
        person.setFirstname("John");
        person.setLastname("Smith");
        // Save the new created person
        personRepository.save(person);

        // Get all persons whose first name starts with "Jo"
        List<Person> firstNameResults = personRepository.findByFirstnameLike("Jo*");
        // Get all persons whose last name is equal to "Smith"
        List<Person> lastNameResults = personRepository.findByLastname("Smith");
    }
}

AerospikeOperations

AerospikeOperations is the base interface for Aerospike database operations. It is implemented by AerospikeTemplate class.

As a lower-level alternative to AerospikeRepository, AerospikeOperations supports wider variety of operations and greater flexibility, but requires a bit more code writing and less out-of-the-box functionality.

Features supported by AerospikeOperations:

  • Basic support for mapping POJOs to and from Aerospike bins

  • Convenience CRUD (Create, Read, Update and Delete) methods for interacting with Aerospike

  • Rich query API

  • Access to the native Aerospike Java Client (reactive and non-reactive)

  • Translating exceptions into Spring’s technology-agnostic DAO exception hierarchy

For non-blocking reactive API use ReactiveAerospikeOperations.

Getting Help

Contributing to Spring Data Aerospike

Here are some ways you can get involved:

  • Help out on the StackOverflow spring-data-aerospike tag by responding to questions and joining the debate

  • Create a GitHub issue for a feature request or bug fixing, comment and vote on the ones that you are interested in

  • GitHub is for social coding: we encourage contributions through pull requests from forks of this repository. When contributing code, please reference a specific GitHub issue you are addressing

  • Watch for upcoming articles by subscribing to Aerospike Stand-Up