Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into FMWK-265-prepare-rele…
Browse files Browse the repository at this point in the history
…ase-4.6.0

# Conflicts:
#	src/main/asciidoc/reference/aerospike.adoc
#	src/main/asciidoc/reference/getting-started.adoc
  • Loading branch information
roimenashe committed Dec 17, 2023
2 parents 0ce8667 + 25316d6 commit a4571c3
Show file tree
Hide file tree
Showing 35 changed files with 1,174 additions and 1,161 deletions.
4 changes: 2 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ In order to configure Spring Data Aerospike you will need to create a configurat
`AbstractAerospikeDataConfiguration`, defines the relevant Spring Data Repositories via `@EnableAerospikeRepositories`
annotation and overrides `getHosts()` and `nameSpace()` methods with the required connection details.

You can optionally override other methods of `AbstractAerospikeDataConfiguration` to customize your configuration.
NOTE: You can optionally override xref:#configure-data-settings[`configureDataSettings`] method of `AbstractAerospikeDataConfiguration` to further customize your configuration.

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

Expand Down Expand Up @@ -215,7 +215,7 @@ 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
* Rich query API
* Access to the native Aerospike Java Client (reactive and non-reactive)
* Translating exceptions into Spring's
https://docs.spring.io/spring/docs/current/spring-framework-reference/html/dao.html#dao-exceptions[technology-agnostic
Expand Down
6 changes: 3 additions & 3 deletions src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ include::preface.adoc[]

:leveloffset: +1

include::reference/introduction.adoc[]
include::reference/aerospike.adoc[]
include::reference/getting-started.adoc[]
include::reference/functionality.adoc[]
include::reference/installation-and-usage.adoc[]
include::spring-data-commons-docs/repositories.adoc[]
include::reference/aerospike-repositories.adoc[]
include::reference/aerospike-reactive-repositories.adoc[]
Expand All @@ -40,6 +39,7 @@ include::reference/template.adoc[]
include::reference/secondary-indexes.adoc[]
include::reference/indexed-annotation.adoc[]
include::reference/caching.adoc[]
include::reference/configure-data-settings.adoc[]
include::spring-data-commons-docs/dependencies.adoc[]
include::spring-data-commons-docs/auditing.adoc[]

Expand Down
4 changes: 2 additions & 2 deletions src/main/asciidoc/preface.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ The jumping off ground for learning about Aerospike is https://www.aerospike.com
[[requirements]]
== Requirements

Spring Data Aerospike binaries require JDK level 17.0 and above, and https://spring.io/docs[Spring Framework] 5.3.x and above.
Spring Data Aerospike binaries require JDK level 17.0 and above.

In terms of server, https://www.aerospike.com/download/server/[Aerospike] version at least 5.2
In terms of server, it is required to use at least https://www.aerospike.com/download/server/[Aerospike server] version 5.2 (recommended to use the latest version when possible).

== Additional Help Resources

Expand Down
6 changes: 3 additions & 3 deletions src/main/asciidoc/reference/aerospike-object-mapping.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[[mapping-chapter]]
[[aerospike.object-mapping]]
= Aerospike Object Mapping

Rich mapping support is provided by the `AerospikeMappingConverter`. `AerospikeMappingConverter` has a rich metadata model that provides a full feature set of functionality to map domain objects to Aerospike clusters and objects.The mapping metadata model is populated using annotations on your domain objects. However, the infrastructure is not limited to using annotations as the only source of metadata information. The `AerospikeMappingConverter` also allows you to map objects without providing any additional metadata, by following a set of conventions.
Expand Down Expand Up @@ -49,8 +49,8 @@ The following outlines what field will be mapped to the '_id' document field:

The following outlines what type of conversion, if any, will be done on the property mapped to the _id document field.

* If a field named 'id' is declared as a String or BigInteger in the Java class it will be converted to and stored as a string.
* If no field named 'id' is present in the Java class then an implicit '_id' file will be generated by the driver but not mapped to a property or field of the Java class.
* By default, the type of the field annotated with `@id` is turned into a `String` to be stored in Aerospike database. If the original type cannot be persisted (see xref:#configure-data-settings.keep-original-key-types[keepOriginalKeyTypes] for details), it must be convertible to `String` and will be stored in the database as such, then converted back to the original type when the object is read. This is transparent to the application but needs to be considered if using external tools like `AQL` to view the data.
* If no field named "id" is present in the Java class then an implicit '_id' file will be generated by the driver but not mapped to a property or field of the Java class.

When querying and updating `AerospikeTemplate` will use the converter to handle conversions of the `Query` and `Update` objects that correspond to the above rules for saving documents so field names and types used in your queries will be able to match what is in your domain classes.

Expand Down
22 changes: 12 additions & 10 deletions src/main/asciidoc/reference/aerospike-repositories.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
[[aerospike-repo-intro]]
== Introduction

This chapter will point out the specialties for repository support for Aerospike. This builds on the <<repositories, Core SpringData Repository Support>>, so make sure you've got a sound understanding of the basic concepts explained there.
One of the main goals of the Spring Data is to significantly reduce the amount of boilerplate code required to implement data access layers for various persistence stores.

One of the core interfaces of Spring Data is `Repository`.
This interface acts primarily to capture the types to work with and to help user to discover interfaces that extend Repository.

In other words, it allows user to have basic and complicated queries without writing the implementation. This builds on the <<repositories, Core SpringData Repository Support>>, so make sure you've got a sound understanding of this concept.

[[aerospike-repo-usage]]
== Usage

To access domain entities stored in a Aerospike you can leverage our sophisticated repository support that eases implementing those quite significantly. To do so, simply create an interface for your repository:
To access entities stored in Aerospike you can leverage repository support that eases implementing those quite significantly. To do so, simply create an interface for your repository:

.Sample Person entity
====
Expand All @@ -30,7 +35,7 @@ public class Person {
}
----
====
We have a quite simple domain object here. The default serialization mechanism used in `AerospikeTemplate` (which is backing the repository support) regards properties named id as document id. Currently, we support`String` and `long` as id-types.
We have a quite simple domain object here. The default serialization mechanism used in `AerospikeTemplate` (which is backing the repository support) regards properties named "id" as document id. Currently we support `String` and `long` as id-types.

.Basic repository interface to persist Person entities
====
Expand All @@ -46,7 +51,7 @@ public interface PersonRepository extends AerospikeRepository<Person, String> {
----
====

Right now this interface simply serves typing purposes but we will add additional methods to it later. In your Spring configuration simply add
Right now this interface simply serves typing purposes, but we will add additional methods to it later. In your Spring configuration simply add

.General Aerospike repository Spring configuration
====
Expand Down Expand Up @@ -142,8 +147,8 @@ public interface PersonRepository extends PagingAndSortingRepository<Person, Str
}
----
<1> The method shows a query for all people with the given name. The query will be derived by parsing the method name for constraints that can be concatenated with `And` and `Or`.
<2> Applies pagination to a query. Just equip your method signature with a `Pageable` parameter and let the method return a `Page` instance and we will automatically page the query accordingly.
<3> Shows that you can query-based partial name searches.
<2> Applies pagination to a query. Just equip your method signature with a `Pageable` parameter and let the method return a `Page` instance, and it will automatically page the query accordingly (i.e. return the required part of results).
<3> Uses query-based partial name search.
====
[[aerospike.repositories.example]]

Expand All @@ -160,9 +165,6 @@ public class RepositoryExample {
@Autowired
AerospikeClient client;
/**
* @param ctx
*/
public RepositoryExample(ApplicationContext ctx) {
aerospikeOperations = ctx.getBean(AerospikeTemplate.class);
repository = (PersonRepository) ctx.getBean("personRepository");
Expand Down Expand Up @@ -196,7 +198,7 @@ public class RepositoryExample {
for (Person person : result) {
System.out.println(person.toString());
}
System.out.println("Results for name startting with letter 'M'");
System.out.println("Results for name starting with letter 'M'");
List<Person> resultPartial = repository.findByNameStartsWith("M");
for (Person person : resultPartial) {
System.out.println(person.toString());
Expand Down
177 changes: 0 additions & 177 deletions src/main/asciidoc/reference/aerospike.adoc
Original file line number Diff line number Diff line change
@@ -1,177 +0,0 @@
[[aerospike.functionality]]
= Aerospike Functionality

Aerospike supports a wide range of features summarized below:

* Feature Rich Object Mapping integrated with Spring's Conversion Service
* Automatic implementation of Repository interfaces including support for custom finder methods
* AerospikeTemplate helper class for performing common Aerospike operations
* Exceptions translation into Spring's portable Data Access Exception hierarchy
* Annotation-based mapping metadata but extensible to support other metadata formats

[[aerospike-getting-started]]
== Getting Started

Spring Data Aerospike uses Java Client, Aerospike’s Java client enables you to build applications in Java that store and retrieve data from an Aerospike cluster. It contains both synchronous and asynchronous calls to the database.

The Java Client runs on any platform with Java 1.8 version and above.

First, you need to set up a running Aerospike server.

To create a Spring project in STS go to File -> New -> Spring Template Project -> Simple Spring Utility Project -> press Yes when prompted. Then enter a project and a package name such as org.spring.aerospike.example.

Then add the following to `pom.xml` dependencies section.

[source,xml]
----
<dependencies>
<!-- other dependency elements omitted -->
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>spring-data-aerospike</artifactId>
<version>4.6.0</version>
</dependency>
</dependencies>
----

You can either set up Spring Boot or Spring application. Basic setup of Spring Boot application is described under the following link: https://projects.spring.io/spring-boot.

.Spring Boot compatibility
[width="100%",cols="<24%,<14%,<18%,<26%,<18%",options="header",]
|===
|Spring Data Aerospike |Spring Boot |Aerospike Client |Aerospike Reactor Client |Aerospike Server
|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 | |
|===

In case you do not want to use Spring Boot, the best way to manage Spring dependencies is to declare `spring-framework-bom` of the needed version in the `dependencyManagement` section of your `pom.xml`:

[source,xml]
----
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${place Spring version here}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
----

Create a simple Person class to persist.

[source,java]
----
package org.springframework.data.aerospike.example;
public class Person {
public final String id;
public final String name;
public final int age;
public Person(String id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
@Override
public String toString() {
return "Person [id=" + id + ", name=" + name + ", age=" + age + "]";
}
}
----

In the simplest case, your repository will extend the AerospikeRepository<T, String>, where T is the entity that you want to expose.

[source,java]
----
package org.springframework.data.aerospike.example.repo;
import org.springframework.data.aerospike.repository.AerospikeRepository;
public interface PersonRepository extends AerospikeRepository<Person, String> {
}
----
Please note that this is just an interface and not an actual class. In the background, when your context gets initialized, actual implementations for your repository descriptions get created and you can access them through regular beans.
This means you will save lots of boilerplate code while still exposing full CRUD semantics to your service layer and application.

To setup configuration for Aerospike you will need to subclass `AbstractAerospikeDataConfiguration`:

[source,java]
----
package org.springframework.data.aerospike.example.config;
import com.aerospike.client.Host;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.aerospike.repository.config.EnableAerospikeRepositories;
import org.springframework.data.aerospike.example.repo.PersonRepository;
import java.util.Collection;
import java.util.Collections;
@Configuration
@EnableAerospikeRepositories(basePackageClasses = PersonRepository.class)
public class AerospikeConfiguration extends AbstractAerospikeDataConfiguration {
@Override
protected Collection<Host> getHosts() {
return Collections.singleton(new Host("localhost", 3000));
}
@Override
protected String nameSpace() {
return "SAMPLE";
}
}
----

Now you are ready to inject and use `PersonRepository` in your application.

[[aerospike.auditing]]
== General auditing configuration

Auditing support is not available in the current version.

[[aerospike-template-intro]]
== Introduction to AerospikeTemplate

The template provides lower-level access to the database and also serves as the foundation for repositories.
For more information see xref:#aerospike.template[AerospikeTemplate] for more information.

Loading

0 comments on commit a4571c3

Please sign in to comment.