Skip to content

Commit 8ec833f

Browse files
author
Dennis Labordus
committed
Refactoring setup project to build two docker images (basex and postgresql). Flyway is now configured using Quarkus.
Signed-off-by: Dennis Labordus <[email protected]>
1 parent bd82677 commit 8ec833f

File tree

7 files changed

+170
-57
lines changed

7 files changed

+170
-57
lines changed

app/src/main/resources/application-test.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
# Test common configuration.
5+
# Test configuration.
66

77
# Datasource configuration for BaseX (none)
88
quarkus.datasource.jdbc = false
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-FileCopyrightText: 2021 Alliander N.V.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
package org.lfenergy.compas.scl.data.rest;
5+
6+
import org.junit.jupiter.api.Test;
7+
import org.lfenergy.compas.scl.data.basex.client.BaseXClientFactory;
8+
import org.lfenergy.compas.scl.data.util.SclDataModelMarshaller;
9+
10+
import static org.junit.jupiter.api.Assertions.assertNotNull;
11+
import static org.mockito.Mockito.mock;
12+
13+
class CompasSclDataServiceBaseXConfigurationTest {
14+
@Test
15+
void createBaseXClientFactoryProduction_WhenCalled_ThenObjectReturned() {
16+
assertNotNull(new CompasSclDataServiceBaseXConfiguration()
17+
.createBaseXClientFactoryProduction("host", 8898, "admin", ""));
18+
}
19+
20+
@Test
21+
void creatCompasSclDataRepositoryProduction_WhenCalled_ThenObjectReturned() {
22+
var baseXClientFactory = mock(BaseXClientFactory.class);
23+
;
24+
var sclDataModelMarshaller = mock(SclDataModelMarshaller.class);
25+
26+
assertNotNull(new CompasSclDataServiceBaseXConfiguration()
27+
.creatCompasSclDataRepositoryProduction(baseXClientFactory, sclDataModelMarshaller));
28+
}
29+
30+
@Test
31+
void createBaseXClientFactoryDevelopment_WhenCalled_ThenObjectReturned() {
32+
assertNotNull(new CompasSclDataServiceBaseXConfiguration()
33+
.createBaseXClientFactoryDevelopment("host", 8898, "admin", ""));
34+
}
35+
36+
@Test
37+
void creatCompasSclDataRepositoryDevelopment_WhenCalled_ThenObjectReturned() {
38+
var baseXClientFactory = mock(BaseXClientFactory.class);
39+
;
40+
var sclDataModelMarshaller = mock(SclDataModelMarshaller.class);
41+
42+
assertNotNull(new CompasSclDataServiceBaseXConfiguration()
43+
.creatCompasSclDataRepositoryDevelopment(baseXClientFactory, sclDataModelMarshaller));
44+
}
45+
}

app/src/test/java/org/lfenergy/compas/scl/data/rest/CompasSclDataServiceCommonConfigurationTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
package org.lfenergy.compas.scl.data.rest;
55

66
import org.junit.jupiter.api.Test;
7+
import org.lfenergy.compas.core.commons.ElementConverter;
8+
import org.lfenergy.compas.scl.data.repository.CompasSclDataRepository;
9+
import org.lfenergy.compas.scl.data.util.SclElementProcessor;
710

811
import static org.junit.jupiter.api.Assertions.assertNotNull;
12+
import static org.mockito.Mockito.mock;
913

1014
class CompasSclDataServiceCommonConfigurationTest {
1115
@Test
@@ -22,4 +26,14 @@ void creatSclElementProcessor_WhenCalled_ThenObjectReturned() {
2226
void createSclDataModelMarshaller_WhenCalled_ThenObjectReturned() {
2327
assertNotNull(new CompasSclDataServiceCommonConfiguration().createSclDataModelMarshaller());
2428
}
29+
30+
@Test
31+
void createCompasSclDataService_WhenCalled_ThenObjectReturned() {
32+
var repository = mock(CompasSclDataRepository.class);
33+
var converter = mock(ElementConverter.class);
34+
var sclElementProcessor = mock(SclElementProcessor.class);
35+
36+
assertNotNull(new CompasSclDataServiceCommonConfiguration()
37+
.createCompasSclDataService(repository, converter, sclElementProcessor));
38+
}
2539
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-FileCopyrightText: 2021 Alliander N.V.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
package org.lfenergy.compas.scl.data.rest;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import javax.sql.DataSource;
9+
10+
import static org.junit.jupiter.api.Assertions.assertNotNull;
11+
import static org.mockito.Mockito.mock;
12+
13+
class CompasSclDataServicePostgreSQLConfigurationTest {
14+
@Test
15+
void creatCompasSclDataRepositoryProduction_WhenCalled_ThenObjectReturned() {
16+
var datasource = mock(DataSource.class);
17+
18+
assertNotNull(new CompasSclDataServicePostgreSQLConfiguration().creatCompasSclDataRepositoryProduction(datasource));
19+
}
20+
21+
@Test
22+
void creatCompasSclDataRepositoryDevelopment_WhenCalled_ThenObjectReturned() {
23+
var datasource = mock(DataSource.class);
24+
25+
assertNotNull(new CompasSclDataServicePostgreSQLConfiguration().creatCompasSclDataRepositoryDevelopment(datasource));
26+
}
27+
}

doc/basex.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ You can run the following command to build the BaseX version of the application.
5050
You can run your application in dev mode that enables live coding using:
5151

5252
```shell script
53-
./mvnw -Dquarkus.profile=dev,prod-basex package io.quarkus:quarkus-maven-plugin::dev
53+
./mvnw -DskipTests=true -Dquarkus.profile=dev-basex package io.quarkus:quarkus-maven-plugin::dev
5454
```
5555

5656
### Creating a native executable
@@ -61,9 +61,10 @@ You can create a native executable using:
6161
./mvnw -P native package
6262
```
6363

64-
This will run the native executable build in a container, because in the native profile the property
64+
This will run the native executable build in a container. In the native profile the property
6565
"quarkus.native.container-build" is set to 'true'.
6666

67-
You can then execute your native executable with: `./app/target/app-local-SNAPSHOT-runner`
67+
You can then execute your native executable with: `./app/target/basex-quarkus-app/app-local-SNAPSHOT-runner`
6868

69-
If you want to learn more about building native executables, please see https://quarkus.io/guides/maven-tooling.html.
69+
If you want to learn more about building native executables, please see https://quarkus.io/guides/maven-tooling.html
70+
and https://quarkus.io/guides/writing-native-applications-tips.

doc/postgresql.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,32 @@ docker run --rm --name compas_postgresql \
4444
4545
### Building the application
4646

47-
You can run the following command to build the BaseX version of the application.
47+
You can run the following command to build the PostgreSQL version of the application.
4848

4949
```shell script
50-
./mvnw -P postgres clean verify
50+
./mvnw clean verify
5151
```
5252

5353
### Running the application in dev mode
5454

5555
You can run your application in dev mode that enables live coding using:
5656

5757
```shell script
58-
./mvnw -P postgres -DskipTests=true -Dquarkus.profile=dev,prod-postgres package io.quarkus:quarkus-maven-plugin::dev
58+
./mvnw -DskipTests=true -Dquarkus.profile=dev-postgres package io.quarkus:quarkus-maven-plugin::dev
5959
```
6060

61+
### Creating a native executable
62+
63+
You can create a native executable using:
64+
65+
```shell script
66+
./mvnw -P native package
67+
```
68+
69+
This will run the native executable build in a container. In the native profile the property
70+
"quarkus.native.container-build" is set to 'true'.
71+
72+
You can then execute your native executable with: `./app/target/postgresql-quarkus-app/app-local-SNAPSHOT-runner`
73+
74+
If you want to learn more about building native executables, please see https://quarkus.io/guides/maven-tooling.html
75+
and https://quarkus.io/guides/writing-native-applications-tips.

repository-postgresql/src/main/java/org/lfenergy/compas/scl/data/repository/postgresql/CompasSclDataPostgreSQLRepository.java

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@
2525
import static org.lfenergy.compas.scl.data.exception.CompasSclDataServiceErrorCode.*;
2626

2727
public class CompasSclDataPostgreSQLRepository implements CompasSclDataRepository {
28+
private static final String SElECT_METADATA_CLAUSE = "select id, name, major_version, minor_version, patch_version ";
29+
private static final String FROM_CLAUSE = " from scl_file ";
30+
private static final String DELETE_FROM_CLAUSE = "delete " + FROM_CLAUSE;
31+
private static final String WHERE_CLAUSE = " where ";
32+
private static final String AND_CLAUSE = " and ";
33+
private static final String ORDER_BY_CLAUSE = " order by id, major_version, minor_version, patch_version";
34+
35+
private static final String FILTER_ON_TYPE = "type = ?";
36+
private static final String FILTER_ON_ID = "id = ?";
37+
private static final String FILTER_ON_VERSION = "major_version = ? and minor_version = ? and patch_version = ? ";
38+
2839
private static final String ID_FIELD = "id";
2940
private static final String MAJOR_VERSION_FIELD = "major_version";
3041
private static final String MINOR_VERSION_FIELD = "minor_version";
@@ -41,31 +52,31 @@ public CompasSclDataPostgreSQLRepository(DataSource dataSource) {
4152
@Override
4253
@Transactional(SUPPORTS)
4354
public List<Item> list(SclType type) {
44-
var sql = "select id, name, major_version, minor_version, patch_version" +
45-
" from scl_file outer_scl" +
46-
" where type = ?" +
47-
" and (id, major_version, minor_version, patch_version) in (" +
48-
// Last select the maximum patch version with the major/minor version per id.
49-
" select id, major_version, minor_version, max(patch_version)" +
50-
" from scl_file patch_scl" +
51-
" where patch_scl.type = outer_scl.type" +
52-
" and (id, major_version, minor_version) in (" +
53-
// Next select the maximum minor version with the major version per id.
54-
" select id, major_version, max(minor_version)" +
55-
" from scl_file minor_scl" +
56-
" where minor_scl.type = outer_scl.type" +
57-
" and (id, major_version) in (" +
58-
// First select the maximum major version per id.
59-
" select id, max(major_version)" +
60-
" from scl_file major_scl" +
61-
" where major_scl.type = outer_scl.type" +
62-
" group by id" +
63-
" )" +
64-
" group by id, major_version" +
65-
" )" +
66-
" group by id, major_version, minor_version" +
67-
" )" +
68-
" order by id, major_version, minor_version, patch_version";
55+
var sql = SElECT_METADATA_CLAUSE
56+
+ FROM_CLAUSE
57+
+ WHERE_CLAUSE + FILTER_ON_TYPE
58+
+ " and (id, major_version, minor_version, patch_version) in ("
59+
// Last select the maximum patch version with the major/minor version per id.
60+
+ " select id, major_version, minor_version, max(patch_version)"
61+
+ " from scl_file patch_scl"
62+
+ " where patch_scl.type = scl_file.type"
63+
+ " and (id, major_version, minor_version) in ("
64+
// Next select the maximum minor version with the major version per id.
65+
+ " select id, major_version, max(minor_version)"
66+
+ " from scl_file minor_scl"
67+
+ " where minor_scl.type = scl_file.type"
68+
+ " and (id, major_version) in ("
69+
// First select the maximum major version per id.
70+
+ " select id, max(major_version)"
71+
+ " from scl_file major_scl"
72+
+ " where major_scl.type = scl_file.type"
73+
+ " group by id"
74+
+ " )"
75+
+ " group by id, major_version"
76+
+ " )"
77+
+ " group by id, major_version, minor_version"
78+
+ " )"
79+
+ ORDER_BY_CLAUSE;
6980

7081
var items = new ArrayList<Item>();
7182
try (var connection = dataSource.getConnection();
@@ -88,11 +99,11 @@ public List<Item> list(SclType type) {
8899
@Override
89100
@Transactional(SUPPORTS)
90101
public List<Item> listVersionsByUUID(SclType type, UUID id) {
91-
var sql = "select id, name, major_version, minor_version, patch_version"
92-
+ " from scl_file"
93-
+ " where id = ?"
94-
+ " and type = ?"
95-
+ " order by major_version, minor_version, patch_version";
102+
var sql = SElECT_METADATA_CLAUSE
103+
+ FROM_CLAUSE
104+
+ WHERE_CLAUSE + FILTER_ON_ID
105+
+ AND_CLAUSE + FILTER_ON_TYPE
106+
+ ORDER_BY_CLAUSE;
96107

97108
var items = new ArrayList<Item>();
98109
try (var connection = dataSource.getConnection();
@@ -126,12 +137,11 @@ public String findByUUID(SclType type, UUID id) {
126137
@Transactional(SUPPORTS)
127138
public String findByUUID(SclType type, UUID id, Version version) {
128139
var sql = "select scl_data "
129-
+ " from scl_file "
130-
+ " where id = ?"
131-
+ " and type = ?"
132-
+ " and major_version = ? "
133-
+ " and minor_version = ? "
134-
+ " and patch_version = ? ";
140+
+ FROM_CLAUSE
141+
+ WHERE_CLAUSE + FILTER_ON_ID
142+
+ AND_CLAUSE + FILTER_ON_TYPE
143+
+ AND_CLAUSE + FILTER_ON_VERSION;
144+
135145
try (var connection = dataSource.getConnection();
136146
var stmt = connection.prepareStatement(sql)) {
137147
stmt.setObject(1, id);
@@ -155,11 +165,12 @@ public String findByUUID(SclType type, UUID id, Version version) {
155165
@Override
156166
@Transactional(SUPPORTS)
157167
public SclMetaInfo findMetaInfoByUUID(SclType type, UUID id) {
158-
var sql = "select id, name, major_version, minor_version, patch_version"
159-
+ " from scl_file"
160-
+ " where id = ?"
161-
+ " and type = ?"
168+
var sql = SElECT_METADATA_CLAUSE
169+
+ FROM_CLAUSE
170+
+ WHERE_CLAUSE + FILTER_ON_ID
171+
+ AND_CLAUSE + FILTER_ON_TYPE
162172
+ " order by major_version desc, minor_version desc, patch_version desc";
173+
163174
try (var connection = dataSource.getConnection();
164175
var stmt = connection.prepareStatement(sql)) {
165176
stmt.setObject(1, id);
@@ -205,9 +216,10 @@ public void create(SclType type, UUID id, String name, String scl, Version versi
205216
@Override
206217
@Transactional(REQUIRED)
207218
public void delete(SclType type, UUID id) {
208-
var sql = "delete from scl_file "
209-
+ " where id = ?"
210-
+ " and type = ?";
219+
var sql = DELETE_FROM_CLAUSE
220+
+ WHERE_CLAUSE + FILTER_ON_ID
221+
+ AND_CLAUSE + FILTER_ON_TYPE;
222+
211223
try (var connection = dataSource.getConnection();
212224
var stmt = connection.prepareStatement(sql)) {
213225
stmt.setObject(1, id);
@@ -221,12 +233,11 @@ public void delete(SclType type, UUID id) {
221233
@Override
222234
@Transactional(REQUIRED)
223235
public void delete(SclType type, UUID id, Version version) {
224-
var sql = "delete from scl_file "
225-
+ " where id = ?"
226-
+ " and type = ?"
227-
+ " and major_version = ? "
228-
+ " and minor_version = ? "
229-
+ " and patch_version = ? ";
236+
var sql = DELETE_FROM_CLAUSE
237+
+ WHERE_CLAUSE + FILTER_ON_ID
238+
+ AND_CLAUSE + FILTER_ON_TYPE
239+
+ AND_CLAUSE + FILTER_ON_VERSION;
240+
230241
try (var connection = dataSource.getConnection();
231242
var stmt = connection.prepareStatement(sql)) {
232243
stmt.setObject(1, id);

0 commit comments

Comments
 (0)