Skip to content

Commit

Permalink
FMWK-195 Override Set Name from Operations/Template (#646)
Browse files Browse the repository at this point in the history
* Override set name in the AerospikeTemplate (initial commit)

* Align new qualifier changes with the new set name injection.

* Fix ambiguous overloading, use different method names (BREAKING CHANGE), add tests for set name injection.

* Extract override set name to the base class.

* Refactor and add set name tests for FindByQueryProjections

* Rename test classes, address warnings and add more tests for set name injection

* Add more tests with set name

* Add more set name tests (find by ids, queries and indexes)

* Add reactive insert and insertAll tests with a given set name

* More reactive tests, align exists naming with new format

* Fix count and save tests

* Increase test coverage for both reactive and non-reactive set name tests

* Add missing tests for reactive operations with set name

* Re-add deprecated delete variations with deprecated warning message to use the new ones "deleteAll" and "deleteById".
  • Loading branch information
roimenashe authored Oct 29, 2023
1 parent e30e7c4 commit b9f1091
Show file tree
Hide file tree
Showing 47 changed files with 2,555 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class AerospikeWriteData {
private Key key;
@Getter
private final String namespace;
@Getter
private String setName;
private Collection<Bin> bins;
@Getter
private int expiration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ public Optional<Key> getNewKey(AerospikeWriteData data,
if (idProperty != null) {
String id = accessor.getProperty(idProperty, String.class); // currently id can only be a String
Assert.notNull(id, "Id must not be null!");
return Optional.of(new Key(data.getNamespace(), entity.getSetName(), id));
String setName;
if (data.getSetName() != null) {
setName = data.getSetName();
} else {
setName = entity.getSetName();
}
return Optional.of(new Key(data.getNamespace(), setName, id));
} else {
// id is mandatory
throw new AerospikeException(OP_NOT_APPLICABLE, "Id has not been provided");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ public interface AerospikeInternalOperations {
*/
<T, S> Object findByIdInternal(Object id, Class<T> entityClass, Class<S> targetClass, Qualifier... qualifiers);

/**
* Find document by providing id with a given set name.
* <p>
* Documents will be mapped to the given targetClass.
*
* @param id The id of the document to find. Must not be {@literal null}.
* @param entityClass The class to get the entity properties from (such as expiration). Must not be
* {@literal null}.
* @param targetClass The class to map the document to.
* @param setName Set name to find the document from.
* @param qualifiers {@link Qualifier}s provided to build a filter Expression for the query. Optional argument.
* @return The document from Aerospike, returned document will be mapped to targetClass's type.
*/
<T, S> Object findByIdInternal(Object id, Class<T> entityClass, Class<S> targetClass, String setName,
Qualifier... qualifiers);

/**
* Find documents by providing multiple ids, set name will be determined by the given entityClass.
* <p>
Expand All @@ -36,6 +52,23 @@ public interface AerospikeInternalOperations {
<T, S> List<?> findByIdsInternal(Collection<?> ids, Class<T> entityClass, Class<S> targetClass,
Qualifier... qualifiers);

/**
* Find documents by providing multiple ids with a given set name.
* <p>
* Documents will be mapped to the given targetClass.
*
* @param ids The ids of the documents to find. Must not be {@literal null}.
* @param entityClass The class to get the entity properties from (such as expiration). Must not be
* {@literal null}.
* @param targetClass The class to map the document to.
* @param setName Set name to find the document from.
* @param qualifiers {@link Qualifier}s provided to build a filter Expression for the query. Optional argument.
* @return The documents from Aerospike, returned documents will be mapped to targetClass's type, if no document
* exists, an empty list is returned.
*/
<T, S> List<?> findByIdsInternal(Collection<?> ids, Class<T> entityClass, Class<S> targetClass,
String setName, Qualifier... qualifiers);

/**
* Batch delete documents by providing their ids. Set name will be determined by the given entityClass.
* <p>
Expand All @@ -46,4 +79,15 @@ <T, S> List<?> findByIdsInternal(Collection<?> ids, Class<T> entityClass, Class<
* @throws AerospikeException.BatchRecordArray if batch delete results contain errors or null records
*/
<T> void deleteByIdsInternal(Collection<?> ids, Class<T> entityClass);

/**
* Batch delete documents by providing their ids with a given set name.
* <p>
* This operation requires Server version 6.0+.
*
* @param ids The ids of the documents to delete. Must not be {@literal null}.
* @param setName Set name to delete the documents from.
* @throws AerospikeException.BatchRecordArray if batch delete results contain errors or null records
*/
void deleteByIdsInternal(Collection<?> ids, String setName);
}
Loading

0 comments on commit b9f1091

Please sign in to comment.