Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 110 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,116 @@ Simple examples for [Doma](https://github.com/domaframework/doma).

This repository includes the following examples:

* [dao-style-basic](dao-style-basic) - Shows basic DAO style.
* [dao-style-file](dao-style-file) - Uses files to store SQL templates.
* [dao-style-text](dao-style-text) - Uses Text Blocks to store SQL templates.
* [dsl-style-java](dsl-style-java) - Uses the Criteria API.
* [jpms-java](jpms-java) - Uses the Java Platform Module System (JPMS).
* [example-sql-file](example-sql-file) - Uses SQL files to store SQL templates.
* [example-sql-annotation](example-sql-annotation) - Uses SQL annotations to store SQL templates.
* [example-criteria](example-criteria) - Uses the Criteria API.
* [example-jpms](example-jpms) - Uses the Java Platform Module System (JPMS).

ER diagram
---------------------

The ER diagram for the database used in the example projects is shown below.

```mermaid
erDiagram
DEPARTMENT {
INTEGER id PK "not null"
VARCHAR name "not null"
INTEGER version "not null"
}
EMPLOYEE {
INTEGER id PK "not null"
VARCHAR name "not null"
INTEGER age "not null"
INTEGER salary
VARCHAR job_type
TIMESTAMP hiredate
INTEGER department_id
INTEGER version "not null"
TIMESTAMP inserttimestamp
TIMESTAMP updatetimestamp
}
USER {
INT id PK "auto_increment"
VARCHAR name "not null"
VARCHAR email "unique not null"
TIMESTAMP created_at "default current_timestamp"
INT version "default 0 not null"
}
ROLE {
INT id PK "auto_increment"
VARCHAR name "unique not null"
INT version "default 0 not null"
}
USER_ROLE {
INT id PK "auto_increment"
INT user_id "not null"
INT role_id "not null"
INT version "default 0 not null"
}
PRODUCT {
INT id PK "auto_increment"
VARCHAR name "not null"
DECIMAL price "not null"
INT stock_quantity "not null"
TIMESTAMP created_at "default current_timestamp"
INT version "default 0 not null"
}
CATEGORY {
INT id PK "auto_increment"
VARCHAR name "unique not null"
INT version "default 0 not null"
}
PRODUCT_CATEGORY {
INT id PK "auto_increment"
INT product_id "not null"
INT category_id "not null"
INT version "default 0 not null"
}
ORDER {
INT id PK "auto_increment"
INT user_id "not null"
TIMESTAMP order_date "default current_timestamp"
VARCHAR status "not null"
INT version "default 0 not null"
}
ORDER_ITEM {
INT id PK "auto_increment"
INT order_id "not null"
INT product_id "not null"
INT quantity "not null"
DECIMAL price "not null"
INT version "default 0 not null"
}
PAYMENT {
INT id PK "auto_increment"
INT order_id "unique not null"
DECIMAL amount "not null"
TIMESTAMP payment_date "default current_timestamp"
INT version "default 0 not null"
}
REVIEW {
INT id PK "auto_increment"
INT user_id "not null"
INT product_id "not null"
INT rating "check: 1-5"
TEXT comment
TIMESTAMP created_at "default current_timestamp"
INT version "default 0 not null"
}

EMPLOYEE }|..|| DEPARTMENT : belongs_to
USER_ROLE }|..|| USER : "user_id"
USER_ROLE }|..|| ROLE : "role_id"
PRODUCT_CATEGORY }|..|| PRODUCT : "product_id"
PRODUCT_CATEGORY }|..|| CATEGORY : "category_id"
ORDER }|..|| USER : "user_id"
ORDER_ITEM }|..|| ORDER : "order_id"
ORDER_ITEM }|..|| PRODUCT : "product_id"
PAYMENT ||--|| ORDER : "order_id"
REVIEW }|..|| USER : "user_id"
REVIEW }|..|| PRODUCT : "product_id"
```

Clone this repository
---------------------
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions common-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id("java")
}

dependencies {
implementation(project(":common"))
implementation(libs.junit.jupiter.api)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package example.dao_style_basic.dao;
package example.common.test;

import example.dao_style_basic.DbConfig;
import example.common.DbConfig;
import example.common.dao.ScriptDao;
import example.common.dao.ScriptDaoImpl;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tasks {
val aptOptions = extensions.getByType<com.diffplug.gradle.eclipse.apt.AptPlugin.AptOptions>()
aptOptions.processorArgs =
mapOf(
"doma.domain.converters" to "example.dao_style_text.domain.DomainConverterProvider",
"doma.domain.converters" to "example.common.domain.DomainConverterProvider",
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package __.example.common.domain;

/** */
@javax.annotation.processing.Generated(value = { "Doma", "3.4.0" }, date = "2025-02-15T08:06:59.349+0900")
@org.seasar.doma.DomainTypeImplementation
public final class _Age extends org.seasar.doma.jdbc.domain.AbstractDomainType<java.lang.Integer, example.common.domain.Age> {

static {
org.seasar.doma.internal.Artifact.validateVersion("3.4.0");
}

private static final example.common.domain.AgeConverter converter = new example.common.domain.AgeConverter();

private static final _Age singleton = new _Age();

private _Age() {
super(org.seasar.doma.internal.wrapper.WrapperSuppliers.ofInteger());
}

@Override
protected example.common.domain.Age newDomain(java.lang.Integer value) {
return converter.fromValueToDomain(value);
}

@Override
protected java.lang.Integer getBasicValue(example.common.domain.Age domain) {
if (domain == null) {
return null;
}
return converter.fromDomainToValue(domain);
}

@Override
public Class<?> getBasicClass() {
return java.lang.Integer.class;
}

@Override
public Class<example.common.domain.Age> getDomainClass() {
return example.common.domain.Age.class;
}

/**
* @return the singleton
*/
public static _Age getSingletonInternal() {
return singleton;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package example.common.domain;

/** */
@javax.annotation.processing.Generated(value = { "Doma", "3.4.0" }, date = "2025-02-15T08:39:41.857+0900")
@org.seasar.doma.DomainTypeImplementation
public final class _Salary extends org.seasar.doma.jdbc.domain.AbstractDomainType<java.lang.Integer, example.common.domain.Salary> {

static {
org.seasar.doma.internal.Artifact.validateVersion("3.4.0");
}

private static final _Salary singleton = new _Salary();

private _Salary() {
super(org.seasar.doma.internal.wrapper.WrapperSuppliers.ofInteger());
}

@Override
protected example.common.domain.Salary newDomain(java.lang.Integer value) {
if (value == null) {
return null;
}
return new example.common.domain.Salary(value);
}

@Override
protected java.lang.Integer getBasicValue(example.common.domain.Salary domain) {
if (domain == null) {
return null;
}
return domain.value();
}

@Override
public Class<?> getBasicClass() {
return java.lang.Integer.class;
}

@Override
public Class<example.common.domain.Salary> getDomainClass() {
return example.common.domain.Salary.class;
}

/**
* @return the singleton
*/
public static _Salary getSingletonInternal() {
return singleton;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package example.common.entity;

/** */
@javax.annotation.processing.Generated(value = { "Doma", "3.4.0" }, date = "2025-02-15T08:44:03.573+0900")
public final class Department_ implements org.seasar.doma.jdbc.criteria.metamodel.EntityMetamodel<example.common.entity.Department> {

static {
org.seasar.doma.internal.Artifact.validateVersion("3.4.0");
}

private final String __qualifiedTableName;

private final example.common.entity._Department __entityType = example.common.entity._Department.getSingletonInternal();

private final java.util.List<org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<?>> __allPropertyMetamodels;

public final org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<java.lang.Integer> id = new org.seasar.doma.jdbc.criteria.metamodel.DefaultPropertyMetamodel<java.lang.Integer>(java.lang.Integer.class, __entityType, "id");

public final org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<java.lang.String> name = new org.seasar.doma.jdbc.criteria.metamodel.DefaultPropertyMetamodel<java.lang.String>(java.lang.String.class, __entityType, "name");

public final org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<java.lang.Integer> version = new org.seasar.doma.jdbc.criteria.metamodel.DefaultPropertyMetamodel<java.lang.Integer>(java.lang.Integer.class, __entityType, "version");

public Department_() {
this("");
}

public Department_(String qualifiedTableName) {
this.__qualifiedTableName = java.util.Objects.requireNonNull(qualifiedTableName);
java.util.ArrayList<org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<?>> __list = new java.util.ArrayList<>(3);
__list.add(id);
__list.add(name);
__list.add(version);
__allPropertyMetamodels = java.util.Collections.unmodifiableList(__list);
}

@Override
public org.seasar.doma.jdbc.entity.EntityType<example.common.entity.Department> asType() {
return __qualifiedTableName.isEmpty() ? __entityType : new org.seasar.doma.jdbc.criteria.metamodel.EntityTypeProxy<>(__entityType, __qualifiedTableName);
}

@Override
public java.util.List<org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<?>> allPropertyMetamodels() {
return __allPropertyMetamodels;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package example.common.entity;

/** */
@javax.annotation.processing.Generated(value = { "Doma", "3.4.0" }, date = "2025-02-15T08:44:03.603+0900")
public final class Employee_ implements org.seasar.doma.jdbc.criteria.metamodel.EntityMetamodel<example.common.entity.Employee> {

static {
org.seasar.doma.internal.Artifact.validateVersion("3.4.0");
}

private final String __qualifiedTableName;

private final example.common.entity._Employee __entityType = example.common.entity._Employee.getSingletonInternal();

private final java.util.List<org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<?>> __allPropertyMetamodels;

public final org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<java.lang.Integer> id = new org.seasar.doma.jdbc.criteria.metamodel.DefaultPropertyMetamodel<java.lang.Integer>(java.lang.Integer.class, __entityType, "id");

public final org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<java.lang.String> name = new org.seasar.doma.jdbc.criteria.metamodel.DefaultPropertyMetamodel<java.lang.String>(java.lang.String.class, __entityType, "name");

public final org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<example.common.domain.Age> age = new org.seasar.doma.jdbc.criteria.metamodel.DefaultPropertyMetamodel<example.common.domain.Age>(example.common.domain.Age.class, __entityType, "age");

public final org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<example.common.domain.Salary> salary = new org.seasar.doma.jdbc.criteria.metamodel.DefaultPropertyMetamodel<example.common.domain.Salary>(example.common.domain.Salary.class, __entityType, "salary");

public final org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<example.common.entity.JobType> jobType = new org.seasar.doma.jdbc.criteria.metamodel.DefaultPropertyMetamodel<example.common.entity.JobType>(example.common.entity.JobType.class, __entityType, "jobType");

public final org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<java.time.LocalDate> hiredate = new org.seasar.doma.jdbc.criteria.metamodel.DefaultPropertyMetamodel<java.time.LocalDate>(java.time.LocalDate.class, __entityType, "hiredate");

public final org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<java.lang.Integer> departmentId = new org.seasar.doma.jdbc.criteria.metamodel.DefaultPropertyMetamodel<java.lang.Integer>(java.lang.Integer.class, __entityType, "departmentId");

public final org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<java.lang.Integer> version = new org.seasar.doma.jdbc.criteria.metamodel.DefaultPropertyMetamodel<java.lang.Integer>(java.lang.Integer.class, __entityType, "version");

public final org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<java.time.LocalDateTime> insertTimestamp = new org.seasar.doma.jdbc.criteria.metamodel.DefaultPropertyMetamodel<java.time.LocalDateTime>(java.time.LocalDateTime.class, __entityType, "insertTimestamp");

public final org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<java.time.LocalDateTime> updateTimestamp = new org.seasar.doma.jdbc.criteria.metamodel.DefaultPropertyMetamodel<java.time.LocalDateTime>(java.time.LocalDateTime.class, __entityType, "updateTimestamp");

public Employee_() {
this("");
}

public Employee_(String qualifiedTableName) {
this.__qualifiedTableName = java.util.Objects.requireNonNull(qualifiedTableName);
java.util.ArrayList<org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<?>> __list = new java.util.ArrayList<>(10);
__list.add(id);
__list.add(name);
__list.add(age);
__list.add(salary);
__list.add(jobType);
__list.add(hiredate);
__list.add(departmentId);
__list.add(version);
__list.add(insertTimestamp);
__list.add(updateTimestamp);
__allPropertyMetamodels = java.util.Collections.unmodifiableList(__list);
}

@Override
public org.seasar.doma.jdbc.entity.EntityType<example.common.entity.Employee> asType() {
return __qualifiedTableName.isEmpty() ? __entityType : new org.seasar.doma.jdbc.criteria.metamodel.EntityTypeProxy<>(__entityType, __qualifiedTableName);
}

@Override
public java.util.List<org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel<?>> allPropertyMetamodels() {
return __allPropertyMetamodels;
}

}
Loading