Skip to content

Add EntityMapper for SQLInsertClause.populate() - #5

Open
jojoldu wants to merge 6 commits into
eXsio:masterfrom
jojoldu:feature/add-EntityMapper
Open

Add EntityMapper for SQLInsertClause.populate()#5
jojoldu wants to merge 6 commits into
eXsio:masterfrom
jojoldu:feature/add-EntityMapper

Conversation

@jojoldu

@jojoldu jojoldu commented Jul 19, 2020

Copy link
Copy Markdown

Hi @eXsio

QClass created with Entityql as below will fail when using SQLInsertClause.populate().

    @Test
    void sqlPopulateInsert() throws Exception {
        //given
        Book entity = Book.builder()
                .bookNo(1)
                .bookType(BookType.IT)
                .build();

        //when
        sqlQueryFactory.insert(qBook)
                .populate(entity, BeanMapper.DEFAULT)
                .execute();

        //then
        List<Book> results = bookRepository.findAll();
        assertThat(results).hasSize(1);
        assertThat(results.get(0).getId()).isEqualTo(1L);
        assertThat(results.get(0).getBookType()).isEqualTo(BookType.IT);
    }

This is the insert query I intended,

insert into book (book_type, book_no) values (?, ?)

Actually, it works like this:

insert into book values ()

The reason was that the property key and the column name were different, and there was an issue that could not be recognized.

In BeanMapper supported by Querydsl-sql, the property key and the column name had to match.

This problem is also recognized in Querydsl-sql, so AnnotationMapper is supported.
However, AnnotationMapper uses the @column annotation of querydsl, so it cannot be used in QClass created with Entityql.

So I created a Mapper class that uses JPA's @column annotation.
I changed the test code above to EntityMapper and it worked fine.

Below is a link to the code I tested.

link

I'll ask for confirmation.

@codecov

codecov Bot commented Jul 19, 2020

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.75%. Comparing base (6532fd5) to head (248f5e4).
⚠️ Report is 42 commits behind head on master.

Files with missing lines Patch % Lines
...l/exsio/querydsl/entityql/mapper/EntityMapper.java 0.00% 24 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master       #5      +/-   ##
============================================
- Coverage     92.76%   88.75%   -4.01%     
- Complexity      300      344      +44     
============================================
  Files            27       36       +9     
  Lines           677      907     +230     
  Branches         37       56      +19     
============================================
+ Hits            628      805     +177     
- Misses           36       83      +47     
- Partials         13       19       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@eXsio eXsio left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hello, Thank you for the contribution!

Would you be so kind to provide an automated test that proves this code works and shows how to use it?

Please make sure that the overall code coverage is not decreased.

@jojoldu

jojoldu commented Jul 19, 2020

Copy link
Copy Markdown
Author

@eXsio
OK.
I will write the test code as soon as possible and commit it.

@jojoldu

jojoldu commented Jul 20, 2020

Copy link
Copy Markdown
Author

@eXsio Hello.
Added a test case where an issue occurs.

A successful test case using EntityMapper added as PR was also added.

Please confirm.

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