Skip to content

DATACOUCH-588 - Refactoring part 1 of n. #278

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

Merged
merged 3 commits into from
Dec 21, 2020

Conversation

mikereiche
Copy link
Collaborator

This is part 1 of a multi-part refactoring effort.

The files below are the non-test files involved. The classes marked new and old are exactly that, and the files marked 'replace' are replacements for similar classes. To understand the changes, start with the resolveQuery() of the two repository factory classes, the *PartTeeCouchbaseQuery and StringBasedCouchbaseQuery that they created, then their execute() method ( AbstractCouchbaseQueryBase.execute() ) which calls the AbstractCouchbaseQuery.doExecute(), which creates a *CouchbaseQueryExecution and executes it.

org/springframework/data/couchbase/repository/query/AbstractCouchbaseQuery.java new
org/springframework/data/couchbase/repository/query/AbstractCouchbaseQueryBase.java new
org/springframework/data/couchbase/repository/query/AbstractReactiveCouchbaseQuery.java new
org/springframework/data/couchbase/repository/query/CouchbaseQueryExecution.java new
org/springframework/data/couchbase/repository/query/CouchbaseQueryMethod.java old
org/springframework/data/couchbase/repository/query/DtoInstantiatingConverter.java new
org/springframework/data/couchbase/repository/query/PartTreeCouchbaseQuery.java replace
org/springframework/data/couchbase/repository/query/ReactiveCouchbaseQueryExecution.java new
org/springframework/data/couchbase/repository/query/ReactiveCouchbaseQueryMethod.java new
org/springframework/data/couchbase/repository/query/ReactivePartTreeCouchbaseQuery.java replace
org/springframework/data/couchbase/repository/query/ReactiveStringBasedCouchbaseQuery.java replace
org/springframework/data/couchbase/repository/query/ResultProcessingConverter.java new
org/springframework/data/couchbase/repository/query/StringBasedCouchbaseQuery.java replace
org/springframework/data/couchbase/repository/query/StringN1qlQueryCreator.java old
org/springframework/data/couchbase/repository/support/CouchbaseRepositoryFactory.java old
org/springframework/data/couchbase/repository/support/ReactiveCouchbaseRepositoryFactory.java old

  • 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 November 12, 2020 06:50
Copy link
Contributor

@daschl daschl left a comment

Choose a reason for hiding this comment

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

Couple remarks. Also note that there are many "not yet implement" comments in the code - I'm okay with these as long as they are not degrading functionality we had before. If so, we should probably work on this in a feature branch until we are back to feature parity with the stable code, so we don't break folks.

@@ -39,6 +42,7 @@
Iterable<Airport> findAll();

@Override
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
Airport save(Airport airport);
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't that a KV method which does not need the scan consistency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

List<Airport> airports = airportRepository.findAllByIata("vie");
assertEquals(vie.getId(), airports.get(0).getId());
assertEquals(1, airports.size());
System.out.println("findAllByIata(0): " + airports.get(0));
Copy link
Contributor

Choose a reason for hiding this comment

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

are these printlns leftovers from debugging in the tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

vie = airportRepository.save(vie).block();
List<Airport> airports = airportRepository.findAllByIata("vie").collectList().block();
assertEquals(1, airports.size());
System.out.println("findAllByIata(0): " + airports.get(0));
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like some debugging leftovers - I'd recommend to remove all those prints from tests since they make them very noisy in logfiles

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

PageRequest pageable = PageRequest.of(page++, 2);
System.out.println("findAllByIataLike: " + "%S");
// java.lang.IndexOutOfBoundsException: Source emitted more than one item
// Flux<Airport> airportFlux = airportRepository.findAllByIataLike("S%");
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be removed or does this needs to be handled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed this to actually use the paging. Removed the commented-out lines and added assertions.

@@ -124,6 +143,23 @@ void count() {
airportRepository.save(airport).block();
}

int page = 0;
for (; page < 10;) {
Copy link
Contributor

Choose a reason for hiding this comment

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

a while(page < 10) is probably better here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've flattened out the loop to better verify the results.

* @author Michael Reiche
* @since 4.1
*/
public class ReactivePartTreeCouchbaseQuery extends AbstractReactiveCouchbaseQuery {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as with the string equivalent, is there a common base class for reactive and non-reactive that encapsulates the commonalities maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems there should be a way to make this tidier, but it eludes me.

* @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.

should we use Locale.ROOT in the toLowerCase?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done on exists, delete and count. Mark suggested an annotation. I will (eventually) see what mongo does.

* @return is this an 'exists' query?
*/
public boolean isExistsQuery() {
return getName().toLowerCase().startsWith("exists");
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use Locale.ROOT in the toLowerCase?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

*/
@Override
public Object execute(Query query, Class<?> type, String collection) {
return operations.removeByQuery(type)/*.inCollection(collection)*/.matching(query).all();
Copy link
Contributor

Choose a reason for hiding this comment

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

does the collection string needs to be handled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The do eventually. The support of an inCollection(collection) was one of the things I backed out to keep the (initial) changes to a minium.

*/
@Override
public Object execute(Query query, Class<?> type, String collection) {
return operations.removeByQuery(type).matching(query).all();
Copy link
Contributor

Choose a reason for hiding this comment

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

the collection string here is not handled at all - should we fail explicitly if it is present or even better handle it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As above - we are going to handle it, but I wanted to keep that out of the initial branch.

@mikereiche mikereiche force-pushed the datacouch_refactoring_part_1_of_n branch from e6ee57b to 0a72b4c Compare December 8, 2020 02:41
pom.xml Outdated
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
Copy link
Contributor

Choose a reason for hiding this comment

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

We are targeting java 8, not 9 right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I would think this is part of the parent pom?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I vaguely recall adding this when prompted by intellij to facilate some .of(...) call. Will check

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed. It was for Set.of(...) in a test.

* @author Christoph Strobl
* @since 1.10
*/
public enum CursorOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

we do not have cursors, does this apply at all to the impl?

* @return {@literal 0 (zero)} by default.
* @since 2.1
*/
int cursorBatchSize() default 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

there are many references to cursors, comments etc which are all very mongo-ish but do not apply to couchbase

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed cursor, comment etc. I left maxExecutionTimeMs just so Meta isn't empty.

}

if (meta.cursorBatchSize() != 0) {
metaAttributes.setCursorBatchSize(meta.cursorBatchSize());
Copy link
Contributor

Choose a reason for hiding this comment

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

does not apply? (see other comments)

@mikereiche mikereiche force-pushed the datacouch_refactoring_part_1_of_n branch from 0a72b4c to dfd7202 Compare December 16, 2020 17:13
public class Meta {

private enum MetaKey {
MAX_TIME_MS("$maxTimeMS"), MAX_SCAN("$maxScan"), COMMENT("$comment"), SNAPSHOT("$snapshot");
Copy link
Contributor

Choose a reason for hiding this comment

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

this stuff is mongo related, right? why do we keep this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I missed this when I cleaned out the Meta annotation. I've removed all the mongo-specific elements, I've left just an EXAMPLE in the enum because it can't be empty. I've also remove the mongo maxTimeMs from the Meta annotation.

@mikereiche mikereiche force-pushed the datacouch_refactoring_part_1_of_n branch from dfd7202 to b208391 Compare December 17, 2020 19:00
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)
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_refactoring_part_1_of_n branch 3 times, most recently from e1acbbb to fce318c Compare December 21, 2020 21:45
@mikereiche mikereiche force-pushed the datacouch_refactoring_part_1_of_n branch from fce318c to d9774a3 Compare December 21, 2020 21:47
@mikereiche mikereiche merged commit 3364e0f into master Dec 21, 2020
jorgerod pushed a commit to jorgerod/spring-data-couchbase that referenced this pull request Jan 15, 2021
* DATACOUCH-588 - Implement pageable and realign repo query

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)

* DATACOUCH-588 - Implement pageable and realign repo query

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)

* DATACOUCH-588 - Refactoring part 1 of n.

Co-authored-by: mikereiche <[email protected]>
mikereiche added a commit that referenced this pull request Feb 16, 2021
* DATACOUCH-588 - Implement pageable and realign repo query

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)

* DATACOUCH-588 - Implement pageable and realign repo query

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)

* DATACOUCH-588 - Refactoring part 1 of n.

Co-authored-by: mikereiche <[email protected]>
@mikereiche mikereiche deleted the datacouch_refactoring_part_1_of_n branch March 15, 2021 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants