Skip to content

Commit 6146936

Browse files
author
Adrien
committed
feat(dpp): add database provider plugins
1 parent 6d31224 commit 6146936

File tree

20 files changed

+2494
-0
lines changed

20 files changed

+2494
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: 'Check Pull Request for plugin: database provider'
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
paths:
7+
- 'dpp/**'
8+
9+
jobs:
10+
tests:
11+
name: Unit tests
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Set up JDK 21 for x64
16+
uses: actions/setup-java@v4
17+
with:
18+
java-version: '21'
19+
distribution: 'temurin'
20+
architecture: x64
21+
22+
- name: Start PostgreSQL test database
23+
working-directory: dpp/src/test/db
24+
run: |
25+
docker compose up -d
26+
sleep 5
27+
28+
- name: Install Pandoc
29+
run: sudo apt-get update && sudo apt-get install -y pandoc
30+
31+
- name: Execute unit tests
32+
run: mvn -ntp -pl dpp test
33+
34+
- name: Execute mutation tests
35+
run: mvn -ntp -pl dpp org.pitest:pitest-maven:mutationCoverage
36+
37+
- name: Extract summary from pitest
38+
run: |
39+
echo "<html><head></head><body><h1>Pit Test Coverage Report: database-provider</h1><h3>Project Summary</h3>" > pitest.html
40+
perl -0777 -ne 'print "$1\n" if /(<table>.*?<\/table>)/s' dpp/target/pit-reports/index.html >> pitest.html
41+
echo "</body></html>" >> pitest.html
42+
43+
- name: Convert pitest report to markdown
44+
run: pandoc --from html --to markdown_github --no-highlight pitest.html
45+
46+
- name: Post comment
47+
uses: luukkemp/pr-comment@2024.1
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
with:
51+
path: pitest.html

dpp/README.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# 📦 DPP - Database Provider Plugin
2+
3+
The Database Provider Plugin (DPP) is responsible for managing relational database access through configurable datasources within the LinID Identity Manager API ecosystem.
4+
5+
---
6+
7+
## 🚀 Overview
8+
9+
This plugin enables dynamic persistence of entities to PostgreSQL databases using **jOOQ** for SQL construction and execution. It supports configuration-driven entity mapping without requiring static entity definitions, allowing flexible database integration through YAML configuration.
10+
11+
⚠️ **Current Scope**: PostgreSQL only (extensible architecture for future)
12+
13+
---
14+
15+
## 📋 Configuration Model
16+
17+
The plugin integrates with the global YAML configuration:
18+
19+
```yaml
20+
providers:
21+
- name: ExampleDatabase
22+
type: database
23+
url: jdbc:postgresql://DATABASE_HOST:DATABASE_PORT/DATABASE_NAME
24+
username: DATABASE_USER
25+
password: DATABASE_PASSWORD
26+
27+
entities:
28+
- name: account
29+
route: accounts
30+
provider: ExampleDatabase
31+
tasks:
32+
# ... task definitions
33+
access:
34+
create:
35+
table: ACCOUNT_TABLE_NAME
36+
entityMapping:
37+
id: "{{ context.response.id }}"
38+
userName: "{{ context.response.userName }}"
39+
update:
40+
table: ACCOUNT_TABLE_NAME
41+
entityMapping:
42+
id: "{{ context.response.id }}"
43+
userName: "{{ context.response.userName }}"
44+
delete:
45+
table: ACCOUNT_TABLE_NAME
46+
entityMapping:
47+
id: "{{ context.response.id }}"
48+
userName: "{{ context.response.userName }}"
49+
select:
50+
table: ACCOUNT_TABLE_NAME
51+
entityMapping:
52+
id: "{{ context.response.id }}"
53+
userName: "{{ context.response.userName }}"
54+
attributes:
55+
- name: id
56+
type: String
57+
required: false
58+
input: Text
59+
access:
60+
primaryKey: true
61+
column: ID
62+
- name: username
63+
type: String
64+
required: true
65+
input: Text
66+
access:
67+
column: USERNAME
68+
```
69+
70+
### Configuration Fields
71+
72+
| Key | Required | Description |
73+
| ------------------------------------------- | -------- | ------------------------------------------------------------------------- |
74+
| `providers[].name` | ✅ | Unique identifier for the database provider |
75+
| `providers[].type` | ✅ | Must be `database` to activate this plugin |
76+
| `providers[].url` | ✅ | JDBC connection URL (PostgreSQL format: `jdbc:postgresql://host:port/db`) |
77+
| `providers[].username` | ✅ | Database authentication username |
78+
| `providers[].password` | ✅ | Database authentication password |
79+
| `entities[].provider` | ✅ | Reference to the database provider name |
80+
| `entities[].access.table` | ✅ | Target database table name for this entity |
81+
| `entities[].access.entityMapping` | ❌ | Maps fields from the SQL result to the dynamic entity |
82+
| `entities[].attributes[].access.column` | ✅ | Target database column name for this attribute |
83+
| `entities[].attributes[].access.primaryKey` | ✅ | Indicates if this attribute is a primary key |
84+
85+
---
86+
87+
## 🏗️ Architecture
88+
89+
### Connection Pooling
90+
91+
- **Pool Provider**: HikariCP
92+
- **Pool Scope**: One pool per configured database provider
93+
- **Configuration**:
94+
- Maximum pool size
95+
- Idle timeout
96+
- Connection timeout
97+
98+
### Dynamic Mapping
99+
100+
1. Entity → Table mapping via `entities[].access.table`
101+
2. Attribute → Column mapping via `entities[].attributes[].access.column`
102+
3. Only declared attributes are persisted
103+
4. No static JPA entities required
104+
105+
### jOOQ Integration
106+
107+
- All queries constructed via `DSLContext`
108+
- Dynamic table/field resolution using `DSL.name(...)`
109+
- Bind parameters for all values
110+
- Type-safe SQL construction
111+
112+
---
113+
114+
## 🛠 Building the Project
115+
116+
To compile and build the plugin:
117+
118+
```bash
119+
mvn clean install
120+
```
121+
122+
---
123+
124+
## 🧪 Running Tests
125+
126+
Run tests using:
127+
128+
```bash
129+
mvn test
130+
```
131+
132+
---

dpp/changelog.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Initialize plugin structure for Database Provider Plugin (DPP)
13+
14+
### Technical Details
15+
16+
### Planned
17+

dpp/pom.xml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>io.github.linagora.linid.im</groupId>
9+
<artifactId>linid-im-api-community-plugins</artifactId>
10+
<version>0.1.0</version>
11+
<relativePath>../pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>dpp</artifactId>
15+
<version>0.1.0</version>
16+
<name>Database Provider Plugin for linid-im-api</name>
17+
<description>A database provider plugin for handling database operations</description>
18+
<url>https://github.com/linagora/linid-im-api-community-plugins</url>
19+
20+
<licenses>
21+
<license>
22+
<name>GNU Affero General Public License v3.0</name>
23+
<url>https://www.gnu.org/licenses/agpl-3.0.html</url>
24+
<distribution>repo</distribution>
25+
<comments>This project is licensed under the GNU AGPL v3.0</comments>
26+
</license>
27+
</licenses>
28+
29+
<developers>
30+
<developer>
31+
<id>Hamilcar31</id>
32+
<name>Adrien CERE</name>
33+
<email>adrien.cere@gmail.com</email>
34+
</developer>
35+
</developers>
36+
37+
<scm>
38+
<connection>scm:git:git://github.com/linagora/linid-im-api-community-plugins.git</connection>
39+
<developerConnection>scm:git:ssh://git@github.com:linagora/linid-im-api-community-plugins.git</developerConnection>
40+
<url>https://github.com/linagora/linid-im-api-community-plugins</url>
41+
</scm>
42+
43+
<dependencies>
44+
<dependency>
45+
<groupId>org.springframework</groupId>
46+
<artifactId>spring-tx</artifactId>
47+
<version>7.0.6</version>
48+
<scope>compile</scope>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>org.jooq</groupId>
53+
<artifactId>jooq</artifactId>
54+
<version>3.20.11</version>
55+
<scope>compile</scope>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>com.zaxxer</groupId>
60+
<artifactId>HikariCP</artifactId>
61+
<version>7.0.2</version>
62+
<scope>compile</scope>
63+
</dependency>
64+
65+
<dependency>
66+
<groupId>org.postgresql</groupId>
67+
<artifactId>postgresql</artifactId>
68+
<version>42.7.10</version>
69+
<scope>compile</scope>
70+
</dependency>
71+
</dependencies>
72+
73+
</project>

0 commit comments

Comments
 (0)