Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FMWK-261 Align find APIs to use Query instead of Qualifier #652

Merged
merged 21 commits into from
Nov 9, 2023

Conversation

agrgr
Copy link

@agrgr agrgr commented Nov 5, 2023

findUsingQuery() instead of findByQualifier(), deprecate AerospikeCriteria, Qualifier implements CriteriaDefinition

…ate AerospikeCriteria, Qualifier implements CriteriaDefinition
@agrgr agrgr requested review from roimenashe and reugn November 5, 2023 13:43
agrgr added 3 commits November 6, 2023 15:15
# Conflicts:
#	src/main/java/org/springframework/data/aerospike/query/KeyQualifier.java
#	src/main/java/org/springframework/data/aerospike/repository/support/SimpleAerospikeRepository.java
#	src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java
@agrgr agrgr marked this pull request as ready for review November 6, 2023 13:34
@roimenashe
Copy link
Member

@agrgr What about Operations/Template (for both reactive and non-reactive) changes? we need to replace all findUsingQualifier methods with findUsingQuery alternatives and still need to decide what to do with existing find() variations that accepts Query (should add new method and mark as deprecated or just remove).

We shouldn't have any find..Qualifier (ById, Using, findAll...) exposed in our interfaces/implementations after migrating to Query.

@agrgr
Copy link
Author

agrgr commented Nov 6, 2023

We shouldn't have any find..Qualifier (ById, Using, findAll...) exposed in our interfaces/implementations after migrating to Query.

Right, there was findByQualifier() in reactive flow which is now updated.

@roimenashe
Copy link
Member

roimenashe commented Nov 6, 2023

We shouldn't have any find..Qualifier (ById, Using, findAll...) exposed in our interfaces/implementations after migrating to Query.

Right, there was findByQualifier() in reactive flow which is now updated.

We still have bunch of Qualifier usages in AerospikeOperations/AerospikeTemplate and also in reactive AerospikeReactiveOperations/AerospikeReactiveTemplate, I think we should get rid of Qualifier completely at these levels (repository and operations/template) we should use Query in API everywhere and translate it into qualifiers only internally (private methods of the implementations [templates]).

Let's talk about it tomorrow.

@agrgr
Copy link
Author

agrgr commented Nov 6, 2023

I think we should get rid of Qualifier completely at these levels (repository and operations/template) we should use Query in API everywhere

Ok, firstly I thought this PR would handle just replacing findByQualifier. Went back to your description, makes sense. Will add an update aligning methods.

* @return Stream of entities.
*/
<T, S> Stream<?> findUsingQualifier(Class<T> entityClass, Class<S> targetClass, @Nullable Filter filter,
Qualifier qualifier);
<T, S> Stream<?> find(Query query, Class<T> entityClass, Class<S> targetClass, @Nullable Filter filter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Stream<S>

* @param filter Secondary index filter.
* @return Stream of entities.
*/
<T, S> Flux<?> find(Query query, Class<T> entityClass, Class<S> targetClass, @Nullable Filter filter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Flux<S>

if (criteria == null) {
return null;
} else if (criteria.getQualifiers() == null) {
return new Qualifier[]{(criteria)};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(criteria) -> criteria

@@ -712,11 +712,11 @@ public interface AerospikeOperations {
* @param id The id of the document to find. Must not be {@literal null}.
* @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
* @param targetClass The class to map the document to.
* @param qualifiers {@link Qualifier}s provided to build a filter Expression for the query. Optional argument.
* @param query {@link Query} provided to build a filter expression. Optional argument.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...to build a filter expression is not accurate, filters could also lead to statement filters and Query might also contain sorting and limiting options (same for other query param descriptions in javadocs)

* @return Stream of entities.
*/
<T> Stream<T> findUsingQualifier(Class<T> entityClass, @Nullable Filter filter, Qualifier qualifier);
<T> Stream<T> find(Query query, Class<T> entityClass, @Nullable Filter filter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the filter? filtering (both statement and expressions) comes from the Qualifier within the Query, consult with @reugn wether we should still expose Filter as a param.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, having the Query parameter only should be enough.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. For future: there in an opportunity to add a condition in StatementBuilder to check Filter first and not build Qualifier-constructed Filter if it already exists

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this might be a breaking change if we had Filter exposed in Template/Operations/Repository, talked with @agrgr and agreed to verify that, if its a breaking change it might be the first one for this release (which may require major version release).

try {
AerospikePersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(entityClass);
Key key = getKey(id, setName);

if (targetClass != null && targetClass != entityClass) {
return getRecordMapToTargetClass(entity, key, targetClass, qualifiers);
return getRecordMapToTargetClass(entity, key, targetClass, criteria);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only used in one place and we are passing criteria now so no need for this method to accept Qualifier... (varargs) but a single Qualifier object, try to see how deep it goes, wherever you can - use Qualifier instead of Qualifier... (varargs).

List<Object> ids;
if (criteria.hasSingleId()) {
ids = getIdValue(criteria);
return operations.findByIdsUsingQuery(ids, entityClass, targetClass, (Query) null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant (Query) casting

@@ -62,8 +60,8 @@ protected Query prepareQuery(Object[] parameters, ParametersParameterAccessor ac
PartTree tree = new PartTree(queryMethod.getName(), entityClass);
Query baseQuery = createQuery(accessor, tree);

AerospikeCriteria criteria = baseQuery.getAerospikeCriteria();
Query query = new Query(criteria);
Qualifier qualifiers = baseQuery.getCriteria().getCriteriaObject();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qualifier instead of qualifiers

* Find all entities that have primary key in the given list.
*
* @param ids List of primary keys
*/
List<P> findById(List<String> ids);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why findById and not findByIds if it gets a list of ids? same for many methods in this class

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is in repository, so it needs the exact name of the field

@agrgr agrgr changed the title FMWK-261 Add support for findUsingQuery instead of findByQualifier FMWK-261 Align find APIs to use Query instead of Qualifier Nov 8, 2023
@agrgr agrgr merged commit 579a204 into main Nov 9, 2023
5 checks passed
@agrgr agrgr deleted the FMWK-261-findUsingQuery branch November 9, 2023 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants