You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+45-1Lines changed: 45 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,10 +9,13 @@ We prepared some common scenarios, which you typically need to implement data-ce
9
9
- as a template of common framework usage scenarios (see scenarios below)
10
10
- to document best practices of such common usages (**comments are welcomed!**)
11
11
12
+
**Use code in the repository as you like (MIT License)**
13
+
12
14
## Frameworks compared
13
15
14
16
* Spring JDBCTemplate (see [implementation](src/main/java/com/clevergang/dbtests/repository/impl/jdbctemplate/JDBCDataRepositoryImpl.java))
15
17
* jOOQ (see [implementation](src/main/java/com/clevergang/dbtests/repository/impl/jooq/JooqDataRepositoryImpl.java))
18
+
* MyBatis (see [implementation](src/main/java/com/clevergang/dbtests/repository/impl/mybatis/MyBatisDataRepositoryImpl.java) and [mapper](src/main/resources/mybatis/mappers/DataRepositoryMapper.xml))
16
19
17
20
We tried to find optimal (== most readable) implementation in every framework, but comments are welcomed! There are lot of comments explaining why we chose to such implementation and some FIXMEs on places which we do not like, but which cannot be implemented differently or which we have troubles to improve...
18
21
@@ -54,4 +57,45 @@ So we dropped JPA completely, started using JDBCTemplate and discovered that we
54
57
55
58
This project aims to explore other options in the SQL mapping area than just JDBCTemplate.
56
59
57
-
**Use code in the repository as you like (MIT License)**
60
+
## Conclusions/Notes
61
+
62
+
I was able to implement all of the scenarios with all of the tested frameworks -
63
+
with only difference in how comfortable or inconvenient it was. Please note that following remarks
64
+
are very subjective and does not have to necessarily apply to you.
65
+
66
+
#### What would I choose
67
+
68
+
1. If project manager is ok with additional cost of a licence or the project uses one of open source databases (like PostgreSQL) then definitely go with **jOOQ**.
69
+
2. If project uses Oracle, DB2, MSSQL or any other commercial database and additional cost for jOOQ licence is not acceptable, then go with **JDBCTemplate**
70
+
71
+
#### Subjective pros/cons of each framework
72
+
73
+
**JDBC Template**
74
+
* Pros
75
+
* Feels like you are very close to JDBC itself
76
+
* Implemented all of the scenarios without bigger issues - there were no hidden surprises
77
+
* Very easy batch operations
78
+
* Easy setup
79
+
* Cons
80
+
* Methods in JDBCDataRepositoryImpl are not much readable - that's because you have to inline SQL in Java code. It would have been better if Java supported multiline strings.
81
+
* Debug logging could be better
82
+
83
+
**jOOQ**
84
+
* Pros
85
+
* Very fluent, very easy to write new queries, code is very readable
86
+
* Once setup it's very easy to use, excellent for simple queries
87
+
* Awesome logger debug output
88
+
* Cons
89
+
* Paid licence for certain databases - it'll be difficult to persuade managers that it's worth it :)
90
+
* Not so much usable for big queries - it's better to use native SQL (see scenario 9.)
91
+
* Weird syntax for performing batch operations (in case that you do not use UpdatableRecord). But it's not a big deal...
92
+
93
+
94
+
**MyBatis**
95
+
* Pros
96
+
* Writing SQL statements in XML mapper file feels good - it's easy to work with parameters.
97
+
* Cons
98
+
* quite a lot of files for single DAO imlementation (MyBatisDataRepositoryImpl, DataRepositoryMapper and DataRepositoryMapper.xml), though navigation is not such a big deal
99
+
* at version 3.4.0 unable to work with Java8 DateTime types (LocalDate etc.), support possible through 3rd party library (mybatis-types), see build.gradle and <typeHandlers> configuration in mybatis-config.xml
100
+
* can't run batch and non-batch operations in single SqlSession, but have to create completely new SqlSession instead (see configuration in DbTestsApplication class). Surprisingly, this does not necessarily mean that the batch and non-batch operations will be executed in different transactions (as we would expect), so at the end this is not a total drawback, but just inconvenience
101
+
* expected that localCacheScope=STATEMENT is default MyBatis behavior, which is not... I know this is questionable drawback, but it was kind of surprise for me, see mybatis-config.xml
0 commit comments