Skip to content

Commit 45095f9

Browse files
authored
Move db-table-prefix and db-table-suffix to runtime configurations (#478)
1 parent 0a9c3e6 commit 45095f9

File tree

8 files changed

+80
-182
lines changed

8 files changed

+80
-182
lines changed

core/deployment/src/main/java/io/quarkiverse/jberet/deployment/JBeretProcessor.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import java.util.ServiceLoader;
1616
import java.util.Set;
1717
import java.util.function.Consumer;
18-
import java.util.function.Predicate;
1918
import java.util.stream.Collectors;
2019
import java.util.stream.Stream;
2120

@@ -298,19 +297,27 @@ ServiceStartBuildItem init(JBeretRecorder recorder,
298297
}
299298

300299
@BuildStep
301-
void nativeImage(BuildProducer<NativeImageResourceBuildItem> resources,
300+
void nativeImage(
301+
BuildProducer<NativeImageResourceBuildItem> resources,
302302
BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
303303
JBeretConfig config) {
304304
resources.produce(new NativeImageResourceBuildItem("sql/jberet-sql.properties"));
305305
resources.produce(new NativeImageResourceBuildItem("sql/jberet.ddl"));
306-
if (JdbcJobRepositorySupplier.TYPE.equals(config.repository().type())) {
307-
config.repository().jdbc().ddlFileName().map(String::trim)
308-
.filter(Predicate.not(String::isEmpty))
309-
.ifPresent(v -> resources.produce(new NativeImageResourceBuildItem(v)));
310-
config.repository().jdbc().sqlFileName().map(String::trim)
311-
.filter(Predicate.not(String::isEmpty))
312-
.ifPresent(v -> resources.produce(new NativeImageResourceBuildItem(v)));
313-
}
306+
// See org.jberet.repository.JdbcRepository.getDDLLocation
307+
resources.produce(new NativeImageResourceBuildItem("sql/jberet-mysql.ddl"));
308+
resources.produce(new NativeImageResourceBuildItem("sql/jberet-oracle.ddl"));
309+
resources.produce(new NativeImageResourceBuildItem("sql/jberet-postgresql.ddl"));
310+
resources.produce(new NativeImageResourceBuildItem("sql/jberet-mssqlserver.ddl"));
311+
resources.produce(new NativeImageResourceBuildItem("sql/jberet-db2.ddl"));
312+
resources.produce(new NativeImageResourceBuildItem("sql/jberet-sybase.ddl"));
313+
resources.produce(new NativeImageResourceBuildItem("sql/jberet-derby.ddl"));
314+
resources.produce(new NativeImageResourceBuildItem("sql/jberet-firebird.ddl"));
315+
316+
config.repository().jdbc().ddlFileName()
317+
.ifPresent(v -> resources.produce(new NativeImageResourceBuildItem(v)));
318+
config.repository().jdbc().sqlFileName()
319+
.ifPresent(v -> resources.produce(new NativeImageResourceBuildItem(v)));
320+
314321
reflectiveClasses
315322
.produce(ReflectiveClassBuildItem.builder(JobInstanceImpl.class).constructors().methods().fields().build());
316323
reflectiveClasses

core/runtime/src/main/java/io/quarkiverse/jberet/runtime/JBeretConfig.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.quarkus.runtime.annotations.ConfigDocSection;
2121
import io.quarkus.runtime.annotations.ConfigPhase;
2222
import io.quarkus.runtime.annotations.ConfigRoot;
23+
import io.quarkus.runtime.configuration.TrimmedStringConverter;
2324
import io.smallrye.config.ConfigMapping;
2425
import io.smallrye.config.WithConverter;
2526
import io.smallrye.config.WithDefault;
@@ -43,7 +44,7 @@ public interface JBeretConfig {
4344
/**
4445
* The JBeret Repository configuration.
4546
*/
46-
@ConfigDocSection(generated = true)
47+
@ConfigDocSection
4748
Repository repository();
4849

4950
interface JobConfig {
@@ -111,9 +112,10 @@ interface Jdbc {
111112

112113
/**
113114
* Custom DDL file resource for JBeret tables creation; if using <b>custom table names</b> please
114-
* also set <code>sql-filename</code> property to propagate table names.
115+
* also set <code>sql-file</code> property to propagate table names.
115116
*/
116117
@WithName("ddl-file")
118+
@WithConverter(TrimmedStringConverter.class)
117119
Optional<String> ddlFileName();
118120

119121
/**
@@ -125,19 +127,8 @@ interface Jdbc {
125127
* "https://raw.githubusercontent.com/jberet/jsr352/refs/tags/3.1.0.Final/jberet-core/src/main/resources/sql/jberet-sql.properties">jberet.properties</a>
126128
*/
127129
@WithName("sql-file")
130+
@WithConverter(TrimmedStringConverter.class)
128131
Optional<String> sqlFileName();
129-
130-
/**
131-
* JBeret tables name prefix.
132-
*/
133-
@WithName("db-table-prefix")
134-
Optional<String> dbTablePrefix();
135-
136-
/**
137-
* JBeret tables name suffix.
138-
*/
139-
@WithName("db-table-suffix")
140-
Optional<String> dbTableSuffix();
141132
}
142133
}
143134
}

core/runtime/src/main/java/io/quarkiverse/jberet/runtime/JBeretRuntimeConfig.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
import java.util.Optional;
55
import java.util.Properties;
66

7+
import io.quarkiverse.jberet.runtime.JBeretConfig.Repository;
8+
import io.quarkiverse.jberet.runtime.JBeretConfig.Repository.Jdbc;
79
import io.quarkus.runtime.annotations.ConfigDocMapKey;
10+
import io.quarkus.runtime.annotations.ConfigDocSection;
811
import io.quarkus.runtime.annotations.ConfigPhase;
912
import io.quarkus.runtime.annotations.ConfigRoot;
13+
import io.quarkus.runtime.configuration.TrimmedStringConverter;
1014
import io.smallrye.config.ConfigMapping;
15+
import io.smallrye.config.WithConverter;
1116
import io.smallrye.config.WithDefaults;
17+
import io.smallrye.config.WithName;
1218

1319
@ConfigMapping(prefix = JBeretConfig.PREFIX)
1420
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
@@ -25,6 +31,12 @@ public interface JBeretRuntimeConfig {
2531
@ConfigDocMapKey("job-name")
2632
Map<String, JobConfig> job();
2733

34+
/**
35+
* The JBeret Repository configuration.
36+
*/
37+
@ConfigDocSection
38+
Repository repository();
39+
2840
interface JobConfig {
2941
/**
3042
* The Job schedule in Cron format.
@@ -45,4 +57,27 @@ default Properties paramsAsProperties() {
4557
return properties;
4658
}
4759
}
60+
61+
interface Repository {
62+
/**
63+
* The JBeret JDBC Repository configuration.
64+
*/
65+
Jdbc jdbc();
66+
67+
interface Jdbc {
68+
/**
69+
* JBeret tables name prefix.
70+
*/
71+
@WithName("db-table-prefix")
72+
@WithConverter(TrimmedStringConverter.class)
73+
Optional<String> dbTablePrefix();
74+
75+
/**
76+
* JBeret tables name suffix.
77+
*/
78+
@WithName("db-table-suffix")
79+
@WithConverter(TrimmedStringConverter.class)
80+
Optional<String> dbTableSuffix();
81+
}
82+
}
4883
}

core/runtime/src/main/java/io/quarkiverse/jberet/runtime/repository/JdbcJobRepositorySupplier.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package io.quarkiverse.jberet.runtime.repository;
22

3+
import static org.jberet.repository.JdbcRepository.DB_TABLE_PREFIX_KEY;
4+
import static org.jberet.repository.JdbcRepository.DB_TABLE_SUFFIX_KEY;
5+
import static org.jberet.repository.JdbcRepository.DDL_FILE_NAME_KEY;
6+
import static org.jberet.repository.JdbcRepository.SQL_FILE_NAME_KEY;
7+
38
import java.util.Optional;
49
import java.util.Properties;
5-
import java.util.function.Predicate;
610

711
import jakarta.inject.Inject;
812
import jakarta.inject.Singleton;
@@ -12,7 +16,7 @@
1216

1317
import io.agroal.api.AgroalDataSource;
1418
import io.quarkiverse.jberet.runtime.JBeretConfig;
15-
import io.quarkiverse.jberet.runtime.JBeretConfig.Repository.Jdbc;
19+
import io.quarkiverse.jberet.runtime.JBeretRuntimeConfig;
1620
import io.quarkiverse.jberet.runtime.JobRepositorySupplier;
1721
import io.quarkus.agroal.runtime.AgroalDataSourceUtil;
1822

@@ -22,28 +26,29 @@ public class JdbcJobRepositorySupplier implements JobRepositorySupplier {
2226

2327
@Inject
2428
JBeretConfig config;
29+
@Inject
30+
JBeretRuntimeConfig runtimeConfig;
2531

2632
@Override
2733
public JobRepository get() {
2834
Properties configProperties = new Properties();
29-
Jdbc jdbc = config.repository().jdbc();
30-
addJdbcProperty(jdbc.sqlFileName(), JdbcRepository.SQL_FILE_NAME_KEY, configProperties);
31-
addJdbcProperty(jdbc.ddlFileName(), JdbcRepository.DDL_FILE_NAME_KEY, configProperties);
32-
addJdbcProperty(jdbc.dbTablePrefix(), JdbcRepository.DB_TABLE_PREFIX_KEY, configProperties);
33-
addJdbcProperty(jdbc.dbTableSuffix(), JdbcRepository.DB_TABLE_SUFFIX_KEY, configProperties);
35+
addJdbcProperty(config.repository().jdbc().sqlFileName(), SQL_FILE_NAME_KEY, configProperties);
36+
addJdbcProperty(config.repository().jdbc().ddlFileName(), DDL_FILE_NAME_KEY, configProperties);
37+
addJdbcProperty(runtimeConfig.repository().jdbc().dbTablePrefix(), DB_TABLE_PREFIX_KEY, configProperties);
38+
addJdbcProperty(runtimeConfig.repository().jdbc().dbTableSuffix(), DB_TABLE_SUFFIX_KEY, configProperties);
3439

35-
Optional<AgroalDataSource> dataSource = AgroalDataSourceUtil.dataSourceIfActive(jdbc.datasource());
40+
String datasource = config.repository().jdbc().datasource();
41+
Optional<AgroalDataSource> dataSource = AgroalDataSourceUtil.dataSourceIfActive(datasource);
3642
if (dataSource.isEmpty()) {
37-
throw new IllegalStateException("No configured datasource " + jdbc.datasource() + " could be found.");
43+
throw new IllegalArgumentException("The configured datasource " + datasource + " could not be found. " +
44+
"Available configured datasources: " + AgroalDataSourceUtil.activeDataSourceNames());
3845
}
3946
return new JdbcRepository(dataSource.get(), configProperties);
4047
}
4148

4249
private void addJdbcProperty(Optional<String> value, String jberetPropertyName,
4350
Properties jdbcRepositoryProperties) {
44-
value.map(String::trim)
45-
.filter(Predicate.not(String::isEmpty))
46-
.ifPresent(v -> jdbcRepositoryProperties.put(jberetPropertyName, v));
51+
value.ifPresent(v -> jdbcRepositoryProperties.put(jberetPropertyName, v));
4752
}
4853

4954
@Override

docs/modules/ROOT/pages/includes/quarkus-jberet.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ endif::add-copy-button-to-config-props[]
224224

225225
[.description]
226226
--
227-
Custom DDL file resource for JBeret tables creation; if using *custom table names* please also set `sql-filename` property to propagate table names.
227+
Custom DDL file resource for JBeret tables creation; if using *custom table names* please also set `sql-file` property to propagate table names.
228228

229229

230230
ifdef::add-copy-button-to-env-var[]
@@ -260,7 +260,7 @@ endif::add-copy-button-to-env-var[]
260260
|string
261261
|
262262

263-
a|icon:lock[title=Fixed at build time] [[quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-prefix]] [.property-path]##link:#quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-prefix[`quarkus.jberet.repository.jdbc.db-table-prefix`]##
263+
a| [[quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-prefix]] [.property-path]##link:#quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-prefix[`quarkus.jberet.repository.jdbc.db-table-prefix`]##
264264
ifdef::add-copy-button-to-config-props[]
265265
config_property_copy_button:+++quarkus.jberet.repository.jdbc.db-table-prefix+++[]
266266
endif::add-copy-button-to-config-props[]
@@ -281,7 +281,7 @@ endif::add-copy-button-to-env-var[]
281281
|string
282282
|
283283

284-
a|icon:lock[title=Fixed at build time] [[quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-suffix]] [.property-path]##link:#quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-suffix[`quarkus.jberet.repository.jdbc.db-table-suffix`]##
284+
a| [[quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-suffix]] [.property-path]##link:#quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-suffix[`quarkus.jberet.repository.jdbc.db-table-suffix`]##
285285
ifdef::add-copy-button-to-config-props[]
286286
config_property_copy_button:+++quarkus.jberet.repository.jdbc.db-table-suffix+++[]
287287
endif::add-copy-button-to-config-props[]

docs/modules/ROOT/pages/includes/quarkus-jberet_quarkus.jberet.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ endif::add-copy-button-to-config-props[]
224224

225225
[.description]
226226
--
227-
Custom DDL file resource for JBeret tables creation; if using *custom table names* please also set `sql-filename` property to propagate table names.
227+
Custom DDL file resource for JBeret tables creation; if using *custom table names* please also set `sql-file` property to propagate table names.
228228

229229

230230
ifdef::add-copy-button-to-env-var[]
@@ -260,7 +260,7 @@ endif::add-copy-button-to-env-var[]
260260
|string
261261
|
262262

263-
a|icon:lock[title=Fixed at build time] [[quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-prefix]] [.property-path]##link:#quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-prefix[`quarkus.jberet.repository.jdbc.db-table-prefix`]##
263+
a| [[quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-prefix]] [.property-path]##link:#quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-prefix[`quarkus.jberet.repository.jdbc.db-table-prefix`]##
264264
ifdef::add-copy-button-to-config-props[]
265265
config_property_copy_button:+++quarkus.jberet.repository.jdbc.db-table-prefix+++[]
266266
endif::add-copy-button-to-config-props[]
@@ -281,7 +281,7 @@ endif::add-copy-button-to-env-var[]
281281
|string
282282
|
283283

284-
a|icon:lock[title=Fixed at build time] [[quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-suffix]] [.property-path]##link:#quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-suffix[`quarkus.jberet.repository.jdbc.db-table-suffix`]##
284+
a| [[quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-suffix]] [.property-path]##link:#quarkus-jberet_quarkus-jberet-repository-jdbc-db-table-suffix[`quarkus.jberet.repository.jdbc.db-table-suffix`]##
285285
ifdef::add-copy-button-to-config-props[]
286286
config_property_copy_button:+++quarkus.jberet.repository.jdbc.db-table-suffix+++[]
287287
endif::add-copy-button-to-config-props[]

0 commit comments

Comments
 (0)