Skip to content

Commit bba9dce

Browse files
authored
Merge pull request #288 from domaframework/example
Put example code in README.md
2 parents bf54468 + 9e7f60c commit bba9dce

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

README.md

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,70 @@ Doma [![Build Status](https://travis-ci.org/domaframework/doma.svg?branch=master
33

44
[![Join the chat at https://gitter.im/domaframework/doma](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/domaframework/doma?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
55

6-
Doma is a Database access framework for Java.
6+
Doma is a database access framework for Java.
7+
Doma uses [Pluggable Annotation Processing API][apt] to generate source code and validate sql mappings **at compile time**.
78

8-
Doma uses [Pluggable Annotation Processing API][apt] to generate source code and validate sql mappings at **compile time**.
9+
Example
10+
---------------------
11+
12+
Define an entity class:
13+
```java
14+
@Entity
15+
public class Employee {
16+
@Id
17+
@GeneratedValue(strategy = GenerationType.SEQUENCE)
18+
@SequenceGenerator(sequence = "EMPLOYEE_SEQ")
19+
public Integer id;
20+
public String name;
21+
public Integer age;
22+
@Version
23+
public Integer version;
24+
}
25+
```
26+
27+
Define a DAO interface:
28+
```java
29+
@Dao(config = AppConfig.class)
30+
public interface EmployeeDao {
31+
@Select
32+
List<Employee> selectAll();
33+
@Update
34+
int update(Employee employee);
35+
}
36+
```
937

10-
![doma](https://github.com/domaframework/doma/blob/master/docs/images/doma.png)
38+
Execute queries:
39+
```java
40+
public class App {
41+
public static void main(String[] args) {
42+
TransactionManager tm = AppConfig.singleton().getTransactionManager();
43+
tm.required(() -> {
44+
EmployeeDao dao = new EmployeeDaoImpl();
45+
Employee employee = dao.selectById(1);
46+
employee.age++;
47+
dao.update(employee);
48+
});
49+
}
50+
}
51+
```
52+
53+
54+
Documentation
55+
---------------------
56+
57+
https://doma.readthedocs.io/
1158

1259
Major versions
1360
---------------------
1461

62+
### Status and Repository
63+
1564
| Version | Status | Repository | Branch |
1665
| -------------------------------------- | ----------------- | -------------------------------------- | ------ |
1766
| [Doma 1](http://doma.seasar.org/) | stable | https://github.com/seasarorg/doma/ | master |
1867
| [Doma 2](http://doma.readthedocs.org/) | stable | https://github.com/domaframework/doma/ | master |
1968

20-
21-
Compatibility matrix
22-
-------------------------
69+
### Compatibility matrix
2370

2471
| | Doma 1 | Doma 2 |
2572
| ------- | ------ | ------ |

0 commit comments

Comments
 (0)