Skip to content

Commit 22d8edb

Browse files
author
bwajtr
committed
Improved documentation
1 parent ad2ac3b commit 22d8edb

7 files changed

Lines changed: 47 additions & 9 deletions

File tree

README.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,51 @@ Comparison of usage of non-JPA SQL mapping frameworks for Java (Jooq, Spring JDB
33

44
We are not comparing performance (that'll be maybe added later), but rather how are these frameworks used for everyday tasks.
55

6-
We prepared some common scenarios, which you typically need to implement data-centric application, and then we implemented these scenarios using various non-JPA frameworks.
6+
We prepared some common scenarios, which you typically need to implement data-centric application, and then we implemented these scenarios using various non-JPA DB layer frameworks.
7+
8+
## Frameworks compared
9+
10+
* Spring JDBCTemplate (see [implementation](src/main/java/com/clevergang/dbtests/repository/impl/jdbctemplate/JDBCDataRepositoryImpl.java))
11+
* jOOQ (see [implementation](src/main/java/com/clevergang/dbtests/repository/impl/jooq/JooqDataRepositoryImpl.java))
12+
13+
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 do not know how to improve...
14+
15+
## Scenarios implemented
16+
17+
These are the scenarios:
18+
1. Fetch single entity based on primary key
19+
2. Fetch list of entities based on condition
20+
3. Save new single entity and return primary key
21+
4. Batch insert multiple entities of same type and return generated keys
22+
5. Update single existing entity - update all fields of entity at once
23+
6. Fetch entity and it's many-to-one relation (Company for Department)
24+
7. Fetch entity and it's one-to-many relation (Departments for Company)
25+
8. Update entities one-to-many relation - add two items, update two items and delete one item
26+
9. Complex select - construct select where conditions based on some boolean conditions + throw in some joins
27+
10. Call stored procedure/function and process results
28+
11. Execute query using JDBC simple Statement (not PreparedStatement)
29+
30+
See javadoc of [Scenarios](src/main/java/com/clevergang/dbtests/Scenarios.java) class for description of each scenario.
731

832
## Model used
933

1034
![Simple company database model](/SimpleCompanyModel.png?raw=true "Simple company database model")
1135

1236
## Why only non-JPA?
13-
Well, we were trying to "stick with standard" in our projects in the past, but after many years of JPA usage
14-
(Hibernate mostly), we realized it's counterproductive. In most of our projects it caused more problems then
37+
Well, we were trying to "stick with standard" in our projects so we used JPA in the past, but after many years of JPA usage
38+
(Hibernate mostly), we realized it's counterproductive. In most of our projects it caused more problems than
1539
it helped to solve - especially in big projects (with lots of tables and relations).
16-
There are many reasons of those failures - but the biggest issues are that JPA implementations simply turned into bloatware,
17-
lot of strange magic is happening inside and the complexity is so high, that you need a high-class Hibernate uberexpert
18-
in every team so the app actually shows some performance and the code is managable...
40+
There are many reasons of those failures - but the biggest issue is that JPA implementations simply turned into bloatware.
41+
Lot of strange magic is happening inside and the complexity is so high, that you need a high-class Hibernate uberexpert
42+
in every team so the app actually shows some performance and the code is manageable...
1943

2044
So we dropped JPA completely, started using JDBCTemplate and discovered that we can deliver apps sooner
21-
(which was kind of surprising), they are god damn faster (thanks to effective use of DB) and much more robust...
45+
(which was kind of surprising), they are a lot faster (thanks to effective use of DB) and much more robust...
46+
This was really relaxing and we do not plan to return to JPA at all... (yes, even for CRUD applications!)
2247

2348
This project aims to explore other options in the SQL mapping area than just JDBCTemplate. It should serve us
2449
- as point of reference when deciding for SQL mapping framework
2550
- as a template of common DB usage scenarios
2651
- to document best practices of such common usages (**comments are welcomed!**)
2752

28-
2953
Use code in the repository as you like (MIT License)

src/main/java/com/clevergang/dbtests/DbTestsApplication.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import org.springframework.context.annotation.Configuration;
1111
import org.springframework.context.annotation.Primary;
1212

13+
/**
14+
* This whole thing is based on Spring Boot as we plan to use these frameworks with SpringBoot
15+
*/
1316
@SpringBootApplication
1417
@Configuration
1518
public class DbTestsApplication {

src/main/java/com/clevergang/dbtests/Scenarios.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
import static java.util.stream.Collectors.toList;
1717

1818
/**
19-
* Common scenarios
19+
* Implementation of the scenarios. Note that the scenarios are always the same, what changes is the
20+
* DB API implementation. To make things little bit easier for us we do not autowire the
21+
* DB API implementation, but we pass it to the constructor of the Scenarios class instead - this
22+
* isn't typical pattern we use in production code.
2023
*
2124
* @author Bretislav Wajtr <bretislav.wajtr@clevergang.com>
2225
*/

src/main/java/com/clevergang/dbtests/repository/api/data/ProjectsWithCostsGreaterThanOutput.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.util.Objects;
55

66
/**
7+
* This data class represents output of of complex query executed in DataRepository#getProjectsWithCostsGreaterThan
8+
*
79
* @author Bretislav Wajtr <bretislav.wajtr@ibacz.eu>
810
*/
911
public class ProjectsWithCostsGreaterThanOutput {

src/main/java/com/clevergang/dbtests/repository/api/data/RegisterEmployeeOutput.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.Objects;
44

55
/**
6+
* Output of DB procedure call in DataRepository#callRegisterEmployee
7+
*
68
* @author Bretislav Wajtr <bretislav.wajtr@ibacz.eu>
79
*/
810
public class RegisterEmployeeOutput {

src/main/java/com/clevergang/dbtests/repository/impl/jdbctemplate/JDBCDataRepositoryImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.stream.Collectors;
2222

2323
/**
24+
* Spring JDBCTemplate implementation of the DataRepository
25+
*
2426
* @author Bretislav Wajtr <bretislav.wajtr@clevergang.com>
2527
*/
2628
@Repository

src/main/java/com/clevergang/dbtests/repository/impl/jooq/JooqDataRepositoryImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434

3535
/**
36+
* jOOQ implementation of the DataRepository
37+
*
3638
* @author Bretislav Wajtr <bretislav.wajtr@clevergang.com>
3739
*/
3840
@Repository

0 commit comments

Comments
 (0)