diff --git a/src/main/java/org/springframework/data/aerospike/core/AerospikeOperations.java b/src/main/java/org/springframework/data/aerospike/core/AerospikeOperations.java index c35b37f90..7346f085b 100644 --- a/src/main/java/org/springframework/data/aerospike/core/AerospikeOperations.java +++ b/src/main/java/org/springframework/data/aerospike/core/AerospikeOperations.java @@ -581,7 +581,7 @@ public interface AerospikeOperations { /** * Find a record by id, set name will be determined by the given entityClass. *

- * The resulting The record will be mapped to the given entityClass. + * The matching record will be mapped to the given entityClass. * * @param id The id of the record to find. Must not be {@literal null}. * @param entityClass The class to extract set name from and to map the record to. Must not be @@ -593,7 +593,7 @@ public interface AerospikeOperations { /** * Find a record by id within the given set. *

- * The record will be mapped to the given entityClass. + * The matching record will be mapped to the given entityClass. * * @param id The id of the record to find. Must not be {@literal null}. * @param entityClass The class to map the record to and to get entity properties from (such as expiration). Must not @@ -606,7 +606,7 @@ public interface AerospikeOperations { /** * Find a record by id, set name will be determined by the given entityClass. *

- * The record will be mapped to the given entityClass. + * The matching record will be mapped to the given entityClass. * * @param id The id of the record to find. Must not be {@literal null}. * @param entityClass The class to extract set name from. Must not be {@literal null}. @@ -619,7 +619,7 @@ public interface AerospikeOperations { /** * Find a record by id within the given set. *

- * The record will be mapped to the given entityClass. + * The matching record will be mapped to the given entityClass. * * @param id The id of the record to find. Must not be {@literal null}. * @param entityClass The class to get entity properties from (such as expiration). Must not be {@literal null}. diff --git a/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeOperations.java b/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeOperations.java index f39b4bcde..91ea6ff84 100644 --- a/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeOperations.java +++ b/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeOperations.java @@ -562,7 +562,7 @@ public interface ReactiveAerospikeOperations { /** * Reactively find a record by id, set name will be determined by the given entityClass. *

- * The record will be mapped to the given entityClass. + * The matching record will be mapped to the given entityClass. * * @param id The id of the record to find. Must not be {@literal null}. * @param entityClass The class to extract set name from and to map the document to. Must not be @@ -574,7 +574,7 @@ public interface ReactiveAerospikeOperations { /** * Reactively find a record by id within the given set. *

- * The record will be mapped to the given entityClass. + * The matching record will be mapped to the given entityClass. * * @param id The id of the record to find. Must not be {@literal null}. * @param entityClass The class to map the record to and to get entity properties from (such expiration). Must not @@ -587,7 +587,7 @@ public interface ReactiveAerospikeOperations { /** * Reactively find a record by id, set name will be determined by the given entityClass. *

- * The record will be mapped to the given targetClass. + * The matching record will be mapped to the given targetClass. * * @param id The id of the record to find. Must not be {@literal null}. * @param entityClass The class to extract set name from. Must not be {@literal null}. @@ -599,7 +599,7 @@ public interface ReactiveAerospikeOperations { /** * Reactively find a record by id within the given set. *

- * The record will be mapped to the given targetClass. + * The matching record will be mapped to the given targetClass. * * @param id The id of the record to find. Must not be {@literal null}. * @param entityClass The class to map the record to and to get entity properties from (such expiration). Must not diff --git a/src/test/java/org/springframework/data/aerospike/convert/AerospikeReadDataIntegrationTests.java b/src/test/java/org/springframework/data/aerospike/convert/AerospikeReadDataIntegrationTests.java new file mode 100644 index 000000000..2d89a81be --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/convert/AerospikeReadDataIntegrationTests.java @@ -0,0 +1,99 @@ +package org.springframework.data.aerospike.convert; + +import com.aerospike.client.Bin; +import com.aerospike.client.Key; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.junit.jupiter.api.Test; +import org.springframework.data.aerospike.BaseBlockingIntegrationTests; +import org.springframework.data.aerospike.sample.Address; +import org.springframework.data.annotation.Id; + +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +class AerospikeReadDataIntegrationTests extends BaseBlockingIntegrationTests { + + long longId = 10L; + String name = "John"; + int age = 74; + Map map = Map.of(10, "100"); + Address address = new Address("Street", 20, "ZipCode", "City"); + Map addressMap = Map.of( + "street", address.getStreet(), + "apartment", address.getApartment(), + "zipCode", address.getZipCode(), + "city", address.getCity()); + + @AllArgsConstructor + @Getter + static class User { + + @Id + long id; + String name; + int age; + Map map; + Address address; + } + + @Test + void readDocumentWithLongId() { + template.getAerospikeClient().put(null, + new Key(namespace, template.getSetName(User.class), longId), + new Bin("name", name), + new Bin("age", 74), + new Bin("map", map), + new Bin("address", addressMap) + ); + // we can read the record into a User document because its class is given + List users = template.findAll(User.class).toList(); + User user; + if (template.getAerospikeConverter().getAerospikeDataSettings().isKeepOriginalKeyTypes()) { + // we need isKeepOriginalKeyTypes == true because id is of type long, otherwise findById() returns null + // isKeepOriginalKeyTypes parameter would be unimportant if id were of type String + user = template.findById(longId, User.class); + assertThat(users.get(0).getId()).isEqualTo(user.getId()); + assertThat(users.get(0).getName()).isEqualTo(user.getName()); + } else { + user = users.get(0); + } + assertThat(user.getId()).isEqualTo(longId); + assertThat(user.getName()).isEqualTo(name); + assertThat(user.getAge()).isEqualTo(age); + assertThat(user.getMap()).isEqualTo(map); + assertThat(user.getAddress()).isEqualTo(address); + } + + @AllArgsConstructor + @Getter + static class Document { + + @Id + String id; + int number; + } + + @Test + void readLongIdAsString() { + template.getAerospikeClient().put(null, + new Key(namespace, template.getSetName(Document.class), longId), + new Bin("number", age) + ); + // we can read the record into a Document because its class is given + List users = template.findAll(Document.class).toList(); + Document document; + if (template.getAerospikeConverter().getAerospikeDataSettings().isKeepOriginalKeyTypes()) { + // original id has type long + document = template.findById(longId, Document.class); + assertThat(users.get(0).getId()).isEqualTo(document.getId()); + assertThat(users.get(0).getNumber()).isEqualTo(document.getNumber()); + } else { + document = users.get(0); + } + assertThat(document.getId()).isEqualTo(String.valueOf(longId)); + assertThat(document.getNumber()).isEqualTo(age); + } +}