Skip to content

Commit a2e385f

Browse files
committed
Add entities, DAO, and SQL scripts for orders
1 parent f4aa10d commit a2e385f

File tree

16 files changed

+753
-19
lines changed

16 files changed

+753
-19
lines changed

README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,112 @@ This repository includes the following examples:
1010
* [example-criteria](example-criteria) - Uses the Criteria API.
1111
* [example-jpms](example-jpms) - Uses the Java Platform Module System (JPMS).
1212

13+
ER diagram
14+
---------------------
15+
16+
The ER diagram for the database used in the example projects is shown below.
17+
18+
```mermaid
19+
erDiagram
20+
DEPARTMENT {
21+
INTEGER id PK "not null"
22+
VARCHAR name "not null"
23+
INTEGER version "not null"
24+
}
25+
EMPLOYEE {
26+
INTEGER id PK "not null"
27+
VARCHAR name "not null"
28+
INTEGER age "not null"
29+
INTEGER salary
30+
VARCHAR job_type
31+
TIMESTAMP hiredate
32+
INTEGER department_id
33+
INTEGER version "not null"
34+
TIMESTAMP inserttimestamp
35+
TIMESTAMP updatetimestamp
36+
}
37+
USER {
38+
INT id PK "auto_increment"
39+
VARCHAR name "not null"
40+
VARCHAR email "unique not null"
41+
TIMESTAMP created_at "default current_timestamp"
42+
INT version "default 0 not null"
43+
}
44+
ROLE {
45+
INT id PK "auto_increment"
46+
VARCHAR name "unique not null"
47+
INT version "default 0 not null"
48+
}
49+
USER_ROLE {
50+
INT id PK "auto_increment"
51+
INT user_id "not null"
52+
INT role_id "not null"
53+
INT version "default 0 not null"
54+
}
55+
PRODUCT {
56+
INT id PK "auto_increment"
57+
VARCHAR name "not null"
58+
DECIMAL price "not null"
59+
INT stock_quantity "not null"
60+
TIMESTAMP created_at "default current_timestamp"
61+
INT version "default 0 not null"
62+
}
63+
CATEGORY {
64+
INT id PK "auto_increment"
65+
VARCHAR name "unique not null"
66+
INT version "default 0 not null"
67+
}
68+
PRODUCT_CATEGORY {
69+
INT id PK "auto_increment"
70+
INT product_id "not null"
71+
INT category_id "not null"
72+
INT version "default 0 not null"
73+
}
74+
ORDER {
75+
INT id PK "auto_increment"
76+
INT user_id "not null"
77+
TIMESTAMP order_date "default current_timestamp"
78+
VARCHAR status "not null"
79+
INT version "default 0 not null"
80+
}
81+
ORDER_ITEM {
82+
INT id PK "auto_increment"
83+
INT order_id "not null"
84+
INT product_id "not null"
85+
INT quantity "not null"
86+
DECIMAL price "not null"
87+
INT version "default 0 not null"
88+
}
89+
PAYMENT {
90+
INT id PK "auto_increment"
91+
INT order_id "unique not null"
92+
DECIMAL amount "not null"
93+
TIMESTAMP payment_date "default current_timestamp"
94+
INT version "default 0 not null"
95+
}
96+
REVIEW {
97+
INT id PK "auto_increment"
98+
INT user_id "not null"
99+
INT product_id "not null"
100+
INT rating "check: 1-5"
101+
TEXT comment
102+
TIMESTAMP created_at "default current_timestamp"
103+
INT version "default 0 not null"
104+
}
105+
106+
EMPLOYEE }|..|| DEPARTMENT : belongs_to
107+
USER_ROLE }|..|| USER : "user_id"
108+
USER_ROLE }|..|| ROLE : "role_id"
109+
PRODUCT_CATEGORY }|..|| PRODUCT : "product_id"
110+
PRODUCT_CATEGORY }|..|| CATEGORY : "category_id"
111+
ORDER }|..|| USER : "user_id"
112+
ORDER_ITEM }|..|| ORDER : "order_id"
113+
ORDER_ITEM }|..|| PRODUCT : "product_id"
114+
PAYMENT ||--|| ORDER : "order_id"
115+
REVIEW }|..|| USER : "user_id"
116+
REVIEW }|..|| PRODUCT : "product_id"
117+
```
118+
13119
Clone this repository
14120
---------------------
15121

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package example.common.entity;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import org.seasar.doma.Association;
6+
import org.seasar.doma.Entity;
7+
import org.seasar.doma.GeneratedValue;
8+
import org.seasar.doma.GenerationType;
9+
import org.seasar.doma.Id;
10+
import org.seasar.doma.Version;
11+
import org.seasar.doma.jdbc.entity.NamingType;
12+
13+
@Entity(naming = NamingType.SNAKE_LOWER_CASE)
14+
public class Category {
15+
@Id
16+
@GeneratedValue(strategy = GenerationType.IDENTITY)
17+
public Integer id;
18+
19+
public String name;
20+
21+
@Version public Integer version;
22+
23+
@Association public List<Product> productList = new ArrayList<>();
24+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package example.common.entity;
2+
3+
import java.time.LocalDateTime;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import org.seasar.doma.Association;
7+
import org.seasar.doma.Entity;
8+
import org.seasar.doma.GeneratedValue;
9+
import org.seasar.doma.GenerationType;
10+
import org.seasar.doma.Id;
11+
import org.seasar.doma.Table;
12+
import org.seasar.doma.Version;
13+
import org.seasar.doma.jdbc.entity.NamingType;
14+
15+
@Entity(naming = NamingType.SNAKE_LOWER_CASE)
16+
@Table(quote = true)
17+
public class Order {
18+
@Id
19+
@GeneratedValue(strategy = GenerationType.IDENTITY)
20+
public Integer id;
21+
22+
public Integer userId;
23+
public LocalDateTime orderDate;
24+
public String status;
25+
26+
@Version public Integer version;
27+
28+
@Association public List<OrderItem> orderItemList = new ArrayList<>();
29+
@Association public Payment payment;
30+
@Association public User user;
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package example.common.entity;
2+
3+
import java.math.BigDecimal;
4+
import org.seasar.doma.Association;
5+
import org.seasar.doma.Entity;
6+
import org.seasar.doma.GeneratedValue;
7+
import org.seasar.doma.GenerationType;
8+
import org.seasar.doma.Id;
9+
import org.seasar.doma.Table;
10+
import org.seasar.doma.Version;
11+
import org.seasar.doma.jdbc.entity.NamingType;
12+
13+
@Entity(naming = NamingType.SNAKE_LOWER_CASE)
14+
@Table(name = "order_item")
15+
public class OrderItem {
16+
@Id
17+
@GeneratedValue(strategy = GenerationType.IDENTITY)
18+
public Integer id;
19+
20+
public Integer orderId;
21+
public Integer productId;
22+
public Integer quantity;
23+
public BigDecimal price;
24+
25+
@Version public Integer version;
26+
27+
@Association public Order order;
28+
@Association public Product product;
29+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package example.common.entity;
2+
3+
import java.math.BigDecimal;
4+
import java.time.LocalDateTime;
5+
import org.seasar.doma.Association;
6+
import org.seasar.doma.Entity;
7+
import org.seasar.doma.GeneratedValue;
8+
import org.seasar.doma.GenerationType;
9+
import org.seasar.doma.Id;
10+
import org.seasar.doma.Version;
11+
import org.seasar.doma.jdbc.entity.NamingType;
12+
13+
@Entity(naming = NamingType.SNAKE_LOWER_CASE)
14+
public class Payment {
15+
@Id
16+
@GeneratedValue(strategy = GenerationType.IDENTITY)
17+
public Integer id;
18+
19+
public Integer orderId;
20+
public BigDecimal amount;
21+
public LocalDateTime paymentDate;
22+
23+
@Version public Integer version;
24+
25+
@Association public Order order;
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package example.common.entity;
2+
3+
import java.math.BigDecimal;
4+
import java.time.LocalDateTime;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
import org.seasar.doma.Association;
8+
import org.seasar.doma.Entity;
9+
import org.seasar.doma.GeneratedValue;
10+
import org.seasar.doma.GenerationType;
11+
import org.seasar.doma.Id;
12+
import org.seasar.doma.Version;
13+
import org.seasar.doma.jdbc.entity.NamingType;
14+
15+
@Entity(naming = NamingType.SNAKE_LOWER_CASE)
16+
public class Product {
17+
@Id
18+
@GeneratedValue(strategy = GenerationType.IDENTITY)
19+
public Integer id;
20+
21+
public String name;
22+
public BigDecimal price;
23+
public Integer stockQuantity;
24+
public LocalDateTime createdAt;
25+
26+
@Version public Integer version;
27+
28+
@Association public List<Category> categoryList = new ArrayList<>();
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package example.common.entity;
2+
3+
import org.seasar.doma.Association;
4+
import org.seasar.doma.Entity;
5+
import org.seasar.doma.GeneratedValue;
6+
import org.seasar.doma.GenerationType;
7+
import org.seasar.doma.Id;
8+
import org.seasar.doma.Version;
9+
import org.seasar.doma.jdbc.entity.NamingType;
10+
11+
@Entity(naming = NamingType.SNAKE_LOWER_CASE)
12+
public class ProductCategory {
13+
@Id
14+
@GeneratedValue(strategy = GenerationType.IDENTITY)
15+
public Integer id;
16+
17+
public Integer productId;
18+
public Integer categoryId;
19+
20+
@Version public Integer version;
21+
22+
@Association public Product product;
23+
@Association public Category category;
24+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package example.common.entity;
2+
3+
import java.time.LocalDateTime;
4+
import org.seasar.doma.Association;
5+
import org.seasar.doma.Entity;
6+
import org.seasar.doma.GeneratedValue;
7+
import org.seasar.doma.GenerationType;
8+
import org.seasar.doma.Id;
9+
import org.seasar.doma.Version;
10+
import org.seasar.doma.jdbc.entity.NamingType;
11+
12+
@Entity(naming = NamingType.SNAKE_LOWER_CASE)
13+
public class Review {
14+
@Id
15+
@GeneratedValue(strategy = GenerationType.IDENTITY)
16+
public Integer id;
17+
18+
public Integer userId;
19+
public Integer productId;
20+
public Integer rating;
21+
public String comment;
22+
public LocalDateTime createdAt;
23+
24+
@Version public Integer version;
25+
26+
@Association public User user;
27+
@Association public Product product;
28+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package example.common.entity;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import org.seasar.doma.*;
6+
import org.seasar.doma.jdbc.entity.NamingType;
7+
8+
@Entity(naming = NamingType.SNAKE_LOWER_CASE)
9+
public class Role {
10+
@Id
11+
@GeneratedValue(strategy = GenerationType.IDENTITY)
12+
public Integer id;
13+
14+
public String name;
15+
16+
@Version public Integer version;
17+
18+
@Association public List<User> userList = new ArrayList<>();
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package example.common.entity;
2+
3+
import java.time.LocalDateTime;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import org.seasar.doma.*;
7+
import org.seasar.doma.jdbc.entity.NamingType;
8+
9+
@Entity(naming = NamingType.SNAKE_LOWER_CASE)
10+
@Table(quote = true)
11+
public class User {
12+
@Id
13+
@GeneratedValue(strategy = GenerationType.IDENTITY)
14+
public Integer id;
15+
16+
public String name;
17+
public String email;
18+
19+
public LocalDateTime createdAt;
20+
21+
@Version public Integer version;
22+
23+
@Association public List<Role> roleList = new ArrayList<>();
24+
}

0 commit comments

Comments
 (0)