spring-projects / spring-projects/spring-data-relational

Provide a naming strategy for Mybatis method/statement names. [DATAJDBC-418]

Open
#639 1 comment 0 reactions 1 assignee View on GitHub

@schauder is already working on this.

Since Dec 31, 2020.

in: statement-builder type: enhancement
Dominant language
Java
Stars
827
Forks
394
PR merge metrics
No merged PRs in 30d

Description

Tyler K Van Gorder opened DATAJDBC-418 and commented

In our traditional Mybatis applications, we had a common pattern where our DataAcccess objects were co-located with our Mapper Interfaces & any associated Mapper.xml files: 

As an example, if "AttributeDefinition" is the aggregate root:

com.example.model.attribute:
  AttributeDefinition
  UnitOfMeasure
  AttributeDefinitionEnumeratedValue

And the data access for all three of those domain types ends up looking like this: 

 

com.example.dao.attribute: 

  AttributeDefinitionDao.java
  AttributeDefinitionDaoImpl.java
  AttributeDefinitionMapper.java
  AttributeDefinitionMapper.xml

And the mapper has queries for the aggregate root AND its associated domain types.

 

I am prototyping some work with Spring Data JDBC + Mybatis and I would like to group the mappers with the repository that is ultimately going to be using those mappers:

com.example.dao.attribute

  AttributeDefinitionRepository.java
  AttributeDefinitionMapper.java
  AttributeDefinitionMapper.xml
  

Where the queries for all domain types connected to the aggregate root are in the same mapper. 

I can use the NamespaceStrategy to map a domain type into the correct namespace, however, the statements are hard-coded and assume each domain type is mapped one-to-one with a corresponding mapper. 

Can we expand the NamespaceStrategy such that it can be passed both the domain type AND the method name?

Another really nice feature would be to have an out-of-the-box configuration strategy (annotation-based or Spring environment-based) that can be used to map a domain type to a Mybatis mapper namespace.

 


Affects: 1.1 RC3 (Moore)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.