Skip to content

DATAJDBC-318 - Add support for Query Derivation #209

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 6 commits into from

Conversation

mp911de
Copy link
Member

@mp911de mp911de commented Apr 21, 2020

We now support query derivation for repository query methods. Query methods support a wide range of keywords including support for embedded entities. Query derivation is limited to properties that can be used in a WHERE clause without involving joins.

interface PersonRepository extends PagingAndSortingRepository<Person, String> {

  List<Person> findByFirstname(String firstname);                                   

  List<Person> findByFirstnameOrderByLastname(String firstname, Pageable pageable); 

  Person findByFirstnameAndLastname(String firstname, String lastname);             

  Person findFirstByLastname(String lastname);
	
  Person findByAddress(Address address);
	
  Person findByAddressStreet(String street);
}

class Person {

  @Id String id;
  String firstname, lastname;
	@Embedded.Nullable Address address;	
}

class Address {
  String city, street;
}

Related ticket: DATAJDBC-318.

@schauder
Copy link
Contributor

One major complaint:

The select generation doesn't work properly for Entities that have 1:1 and 1:M relationships.

Iseeker pointed this out in a comment on the issue all ready https://jira.spring.io/browse/DATAJDBC-318?focusedCommentId=188768&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-188768

208cee4 adds two quick tests to demonstrate the problem.

The underlying problem is: We really shouldn't have two places where the base select gets constructed.
It is rather complex and will change in the future when we want to support more efficient ways of querying.

@mp911de mp911de force-pushed the issue/DATAJDBC-318 branch 2 times, most recently from e5964bc to b8d1fd3 Compare April 24, 2020 13:19
@schauder
Copy link
Contributor

Just using SELECT * doesn't work if there are 1:1 references in the aggregate, because these require a join and special aliases in order to avoid name clashes.

@schauder schauder force-pushed the issue/DATAJDBC-318 branch from b3faf36 to 498ba98 Compare April 27, 2020 18:44
schauder and others added 5 commits April 27, 2020 20:48
Without this change we see cyclic dependencies between modules (i.e. subpackages).
The following subpackages had a cycle:

repository.query and repository.query.parser

PartTreeJdbcQuery and JdbcQueryCreator(repository.query from jdbc) depend on PartTree (repository.query.parser)

AbstractQueryCreator (repository.query.parser) depends on ParameterAccessor (repository.query from commons)

This change changes the definition of a module, bundling all the modules above into one module (repository).

Alternative changes that should fix the problem:
1. Move ParameterAccessor to a different (probably new package)
2. Move AbstractQueryCreator to a different (probably new package)
3. org.springframework.data.jdbc.repository.query to e.g. org.springframework.data.jdbc.repository.query.jdbc

Original pull request: #209.
Move JdbcRepositoryQuery into repository.query package. Split JdbcRepositoryQuery into AbstractJdbcQuery and StringBasedJdbcQuery.
Add QueryMapper for mapping of Criteria.
Initial support for query derivation.

Emit events and issue entity callbacks only for default RowMapper.
Custom RowMapper/ResultSetExtractor are in full control of the mapping and can issue events/callbacks themselves.

Update reference documentation.

Original pull request: #209.
Added failing tests for entities with references.

Code deduplication.
Documentation wording.
Formatting.

Original pull request: #209.
We now reject criteria predicates for collections, maps and references. The select list selects all columns until DATAJDBC-523 is solved.

Original pull request: #209.
The select list must include columns for 1:1 relationships.

The implementation is copied from SqlGenerator and will be unified in the near future.

Original pull request: #209.
@schauder schauder force-pushed the issue/DATAJDBC-318 branch from 498ba98 to b02fdd9 Compare April 27, 2020 18:54
schauder added a commit that referenced this pull request Apr 28, 2020
Without this change we see cyclic dependencies between modules (i.e. subpackages).
The following subpackages had a cycle:

repository.query and repository.query.parser

PartTreeJdbcQuery and JdbcQueryCreator(repository.query from jdbc) depend on PartTree (repository.query.parser)

AbstractQueryCreator (repository.query.parser) depends on ParameterAccessor (repository.query from commons)

This change changes the definition of a module, bundling all the modules above into one module (repository).

Alternative changes that should fix the problem:
1. Move ParameterAccessor to a different (probably new package)
2. Move AbstractQueryCreator to a different (probably new package)
3. org.springframework.data.jdbc.repository.query to e.g. org.springframework.data.jdbc.repository.query.jdbc

Original pull request: #209.
schauder pushed a commit that referenced this pull request Apr 28, 2020
Move JdbcRepositoryQuery into repository.query package. Split JdbcRepositoryQuery into AbstractJdbcQuery and StringBasedJdbcQuery.
Add QueryMapper for mapping of Criteria.
Initial support for query derivation.

Emit events and issue entity callbacks only for default RowMapper.
Custom RowMapper/ResultSetExtractor are in full control of the mapping and can issue events/callbacks themselves.

Update reference documentation.

Original pull request: #209.
schauder added a commit that referenced this pull request Apr 28, 2020
Added failing tests for entities with references.

Code deduplication.
Documentation wording.
Formatting.

Original pull request: #209.
schauder pushed a commit that referenced this pull request Apr 28, 2020
We now reject criteria predicates for collections, maps and references. The select list selects all columns until DATAJDBC-523 is solved.

Original pull request: #209.
schauder added a commit that referenced this pull request Apr 28, 2020
The select list must include columns for 1:1 relationships.

The implementation is copied from SqlGenerator and will be unified in the near future.

Original pull request: #209.
@schauder
Copy link
Contributor

Merged to master.

@schauder schauder closed this Apr 28, 2020
@schauder schauder deleted the issue/DATAJDBC-318 branch April 28, 2020 07:29
mp911de pushed a commit that referenced this pull request Feb 21, 2022
The original extensions did not allow for executing fetch operations because they where on BindSpec.

Original pull request: #210.
mp911de added a commit that referenced this pull request Feb 21, 2022
Update ticket reference in test.

Original pull request: #210.
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.

2 participants