Skip to content

DATACOUCH-588 - Implement pageable and realign repo query #249

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

Closed
wants to merge 4 commits into from

Conversation

mikereiche
Copy link
Collaborator

This is intended to be a preview for Michael Nitschinger.
The javadoc (especially author) is yet to be updated.

This implements pageable for non-reactive queries and
realigns reactive queries with other spring-data projects
to facilitate the implementaion of pageable (done) and other
types of queries such as projection and distinct (not yet
done)

  • You have read the Spring Data contribution guidelines.
  • There is a ticket in the bug tracker for the project in our JIRA.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

@mikereiche mikereiche requested a review from daschl July 24, 2020 00:49
Copy link
Contributor

@dnault dnault left a comment

Choose a reason for hiding this comment

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

Wow, you've been busy! Cool stuff. Sorry my comments are only superficial.

@@ -127,6 +137,27 @@ public Query with(final Pageable pageable) {
return with(pageable.getSort());
}

/**
* limit
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy & paste error?

* @return is this a 'delete'?
*/
public boolean isDeleteQuery() {
return getName().toLowerCase().startsWith("delete");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is spring-core guaranteed to be on the class path? Maybe you can use StringUtils.startsWithIgnoreCase(getName(), "delete");

query.limit(tree.getMaxResults());
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Created query %s for * fields.", query.export() /*, query.getFieldsObject()*/));
Copy link
Contributor

@dnault dnault Jul 24, 2020

Choose a reason for hiding this comment

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

Using String.format to build a log message is often a code smell. String.format is a very expensive to begin with, and we even might end up throwing away the result depending on the log level.

As an alternative, it's possible to take advantage of SLF4J placeholders:

LOG.debug("Created query {} for * fields.", query.export());

[Mike] Looks like I can only Edit your comment, not reply. I will fix this. It is guarded with isDebugEnabled() specifically so the query.export() won't be executed.

@mikereiche mikereiche force-pushed the datacouch_588_pageable_and_realign branch from 4b637d6 to df21147 Compare July 27, 2020 22:48
This implements pageable for non-reactive queries and
realigns reactive queries with other spring-data projects
to facilitate the implementaion of pageable (done) and other
types of queries such as projection and distinct (not yet
done)
@mikereiche mikereiche force-pushed the datacouch_588_pageable_and_realign branch from df21147 to 3aff13c Compare July 29, 2020 17:41
@daschl
Copy link
Contributor

daschl commented Sep 4, 2020

I'd like to get @mp911de on the overall approach and design, once that is "spring best practice" approved let's focus on reviewing all the bits (since this is a bigger change set)

@daschl daschl requested a review from mp911de September 4, 2020 14:28
Copy link
Member

@mp911de mp911de left a comment

Choose a reason for hiding this comment

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

This pull request is pretty cluttered with several types of changes which makes it a bit difficult to understand what's happening here. In general, it makes a lot of sense to align the Couchbase module with MongoDB/Cassandra as this simplifies the implementation approach.

The original authors aren't required to be retained on the copy since similar code patterns are available from the other store modules.

Please note that reactive pagination is limited to Flux<T> as there's no such thing like PageFlux. We're discussing right now, whether Mono<Page<T>> would make sense as return type. We did a first experiment in Cassandra that turned out to work well.

Let me know whether there are specific topics you need more feedback on.

*
* @return is this a 'delete'?
*/
public boolean isDeleteQuery() {
Copy link
Member

Choose a reason for hiding this comment

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

Those methods should go into the actual CouchbaseQuery (or AbstractCouchbaseQuery). Assuming the method name starts with a particular prefix is pretty risky especially when the query method uses an annotated query. MongoDB's @Query defines attributes such as delete or exists. PartTree (the source for query derivation) exposes similar information.

}

/*
final class ReactivePagedExecution<FindWithQuery> implements CouchbaseQueryExecution { // TODO ??
Copy link
Member

Choose a reason for hiding this comment

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

There's pretty much commented-out code blocks in here.

Reactive pagination returns typically a Flux<T>. An alternative approach can be Mono<Page<T>>.


return PageableExecutionUtils.getPage(matching.all().collectList().block(), pageable, () -> {

long count = operation.matching(query.skip(-1).limit(-1)).count().block();
Copy link
Member

Choose a reason for hiding this comment

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

While the code isn't active, please note that calling .block() methods is almost a guarantee to break the entire processing flow. Please refrain from calling .block().

* @see org.springframework.data.mongodb.repository.query.AbstractMongoQuery#isCountQuery()
*/
@Override
protected boolean isCountQuery() {
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -124,6 +133,15 @@ private String assembleEntityQuery(final boolean count) {
return query.toN1qlString(template, this.domainType, count);
}

@Override
public FindWithProjection<T> inCollection(String collection) {
Copy link
Member

Choose a reason for hiding this comment

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

inCollection/distinct methods are MongoDB-specific features. It makes only sense to re-apply the same pattern if Couchbase can provide such functionality.

This implements pageable for non-reactive queries and
realigns reactive queries with other spring-data projects
to facilitate the implementaion of pageable (done) and other
types of queries such as projection and distinct (not yet
done)
…g-projects/spring-data-couchbase into datacouch_588_pageable_and_realign
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants