A sample project demonstrating code generation using the Doma Codegen Plugin.
This project demonstrates how to use the Doma Codegen Plugin to automatically generate entity classes and DAO classes from database schemas.
It supports both MySQL and PostgreSQL databases and uses Testcontainers to automatically start databases during code generation.
example-codegen-plugin/
├── build.gradle.kts # Build configuration file
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── example/
│ │ │ └── generated/ # Auto-generated code
│ │ │ ├── mysql/
│ │ │ │ ├── dao/ # MySQL DAO classes
│ │ │ │ └── entity/ # MySQL entity classes
│ │ │ └── postgresql/
│ │ │ ├── dao/ # PostgreSQL DAO classes
│ │ │ └── entity/ # PostgreSQL entity classes
│ │ └── resources/
│ │ ├── META-INF/ # Auto-generated SQL files
│ │ ├── init_mysql.sql # MySQL initialization script
│ │ └── init_postgresql.sql # PostgreSQL initialization script
│ └── test/
│ └── java/
│ └── example/
│ └── generated/ # Auto-generated test code
Code is generated from the following four tables:
DEPARTMENT- Department informationADDRESS- Address informationEMPLOYEE- Employee information (with foreign key constraints to DEPARTMENT and ADDRESS)COMP_KEY_ADDRESS- Address information with composite primary key
./gradlew domaCodeGenMysqlAll./gradlew domaCodeGenPostgresqlAll./gradlew clean./gradlew testThe following configurations are set in build.gradle.kts:
- Uses Testcontainers MySQL
- Initialization script:
src/main/resources/init_mysql.sql - Generated packages:
- Entities:
example.generated.mysql.entity - DAOs:
example.generated.mysql.dao
- Entities:
- Uses Testcontainers PostgreSQL
- Initialization script:
src/main/resources/init_postgresql.sql - Generated packages:
- Entities:
example.generated.postgresql.entity - DAOs:
example.generated.postgresql.dao
- Entities:
- Java 17 or higher
- Docker (required for running Testcontainers)