|
44 | 44 | import io.quarkus.arc.deployment.AutoAddScopeBuildItem;
|
45 | 45 | import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
|
46 | 46 | import io.quarkus.arc.processor.BuiltinScope;
|
47 |
| -import io.quarkus.datasource.common.runtime.DatabaseKind; |
48 | 47 | import io.quarkus.deployment.Capabilities;
|
49 | 48 | import io.quarkus.deployment.Capability;
|
50 | 49 | import io.quarkus.deployment.Feature;
|
|
65 | 64 | import io.quarkus.quartz.runtime.QuartzRuntimeConfig;
|
66 | 65 | import io.quarkus.quartz.runtime.QuartzSchedulerImpl;
|
67 | 66 | import io.quarkus.quartz.runtime.QuartzSupport;
|
| 67 | +import io.quarkus.quartz.runtime.jdbc.JDBCDataSource; |
68 | 68 | import io.quarkus.quartz.runtime.jdbc.QuarkusDBv8Delegate;
|
69 | 69 | import io.quarkus.quartz.runtime.jdbc.QuarkusHSQLDBDelegate;
|
70 | 70 | import io.quarkus.quartz.runtime.jdbc.QuarkusMSSQLDelegate;
|
@@ -122,8 +122,8 @@ QuartzJDBCDriverDialectBuildItem driver(List<JdbcDataSourceBuildItem> jdbcDataSo
|
122 | 122 | if (config.clustered()) {
|
123 | 123 | throw new ConfigurationException("Clustered jobs configured with unsupported job store option");
|
124 | 124 | }
|
125 |
| - |
126 |
| - return new QuartzJDBCDriverDialectBuildItem(Optional.empty()); |
| 125 | + // No DB storage, the driver can stay empty, and we don't need data sources either |
| 126 | + return new QuartzJDBCDriverDialectBuildItem(Optional.empty(), null); |
127 | 127 | }
|
128 | 128 |
|
129 | 129 | if (capabilities.isMissing(Capability.AGROAL)) {
|
@@ -162,43 +162,17 @@ QuartzJDBCDriverDialectBuildItem driver(List<JdbcDataSourceBuildItem> jdbcDataSo
|
162 | 162 | throw new ConfigurationException(message);
|
163 | 163 | }
|
164 | 164 | }
|
| 165 | + // A custom delegate implementation, we don't need to check datasources |
| 166 | + return new QuartzJDBCDriverDialectBuildItem(driverDelegate, null); |
165 | 167 | } else {
|
166 |
| - Optional<JdbcDataSourceBuildItem> selectedJdbcDataSourceBuildItem = jdbcDataSourceBuildItems.stream() |
167 |
| - .filter(i -> config.dataSourceName().isPresent() ? config.dataSourceName().get().equals(i.getName()) |
168 |
| - : i.isDefault()) |
169 |
| - .findFirst(); |
170 |
| - |
171 |
| - if (!selectedJdbcDataSourceBuildItem.isPresent()) { |
172 |
| - String message = String.format( |
173 |
| - "JDBC Store configured but the '%s' datasource is not configured properly. You can configure your datasource by following the guide available at: https://quarkus.io/guides/datasource", |
174 |
| - config.dataSourceName().isPresent() ? config.dataSourceName().get() : "default"); |
175 |
| - throw new ConfigurationException(message); |
| 168 | + List<JDBCDataSource> dataSources = new ArrayList<>(); |
| 169 | + for (JdbcDataSourceBuildItem jdbcDataSourceBuildItem : jdbcDataSourceBuildItems) { |
| 170 | + dataSources.add(new JDBCDataSource(jdbcDataSourceBuildItem.getName(), jdbcDataSourceBuildItem.isDefault(), |
| 171 | + jdbcDataSourceBuildItem.getDbKind())); |
176 | 172 | }
|
177 |
| - driverDelegate = Optional.of(guessDriver(selectedJdbcDataSourceBuildItem)); |
| 173 | + // Defer driver determination to runtime |
| 174 | + return new QuartzJDBCDriverDialectBuildItem(Optional.empty(), dataSources); |
178 | 175 | }
|
179 |
| - return new QuartzJDBCDriverDialectBuildItem(driverDelegate); |
180 |
| - } |
181 |
| - |
182 |
| - private String guessDriver(Optional<JdbcDataSourceBuildItem> jdbcDataSource) { |
183 |
| - if (!jdbcDataSource.isPresent()) { |
184 |
| - return QuarkusStdJDBCDelegate.class.getName(); |
185 |
| - } |
186 |
| - |
187 |
| - String dataSourceKind = jdbcDataSource.get().getDbKind(); |
188 |
| - if (DatabaseKind.isPostgreSQL(dataSourceKind)) { |
189 |
| - return QuarkusPostgreSQLDelegate.class.getName(); |
190 |
| - } |
191 |
| - if (DatabaseKind.isH2(dataSourceKind)) { |
192 |
| - return QuarkusHSQLDBDelegate.class.getName(); |
193 |
| - } |
194 |
| - if (DatabaseKind.isMsSQL(dataSourceKind)) { |
195 |
| - return QuarkusMSSQLDelegate.class.getName(); |
196 |
| - } |
197 |
| - if (DatabaseKind.isDB2(dataSourceKind)) { |
198 |
| - return QuarkusDBv8Delegate.class.getName(); |
199 |
| - } |
200 |
| - |
201 |
| - return QuarkusStdJDBCDelegate.class.getName(); |
202 | 176 | }
|
203 | 177 |
|
204 | 178 | @BuildStep
|
@@ -250,7 +224,20 @@ List<ReflectiveClassBuildItem> reflectiveClasses(QuartzBuildTimeConfig config,
|
250 | 224 | reflectiveClasses.add(ReflectiveClassBuildItem.builder(Connection.class)
|
251 | 225 | .reason(getClass().getName()).methods()
|
252 | 226 | .fields().build());
|
253 |
| - reflectiveClasses.add(ReflectiveClassBuildItem.builder(driverDialect.getDriver().get()) |
| 227 | + // Since we determine driver delegate at runtime, we need to register all of them |
| 228 | + reflectiveClasses.add(ReflectiveClassBuildItem.builder(QuarkusDBv8Delegate.class.getName()) |
| 229 | + .reason(getClass().getName()) |
| 230 | + .methods().build()); |
| 231 | + reflectiveClasses.add(ReflectiveClassBuildItem.builder(QuarkusHSQLDBDelegate.class.getName()) |
| 232 | + .reason(getClass().getName()) |
| 233 | + .methods().build()); |
| 234 | + reflectiveClasses.add(ReflectiveClassBuildItem.builder(QuarkusMSSQLDelegate.class.getName()) |
| 235 | + .reason(getClass().getName()) |
| 236 | + .methods().build()); |
| 237 | + reflectiveClasses.add(ReflectiveClassBuildItem.builder(QuarkusPostgreSQLDelegate.class.getName()) |
| 238 | + .reason(getClass().getName()) |
| 239 | + .methods().build()); |
| 240 | + reflectiveClasses.add(ReflectiveClassBuildItem.builder(QuarkusStdJDBCDelegate.class.getName()) |
254 | 241 | .reason(getClass().getName())
|
255 | 242 | .methods().build());
|
256 | 243 | reflectiveClasses.add(ReflectiveClassBuildItem.builder("io.quarkus.quartz.runtime.QuartzSchedulerImpl$InvokerJob")
|
@@ -348,6 +335,7 @@ public void quartzSupportBean(QuartzRuntimeConfig runtimeConfig, QuartzBuildTime
|
348 | 335 | .scope(Singleton.class) // this should be @ApplicationScoped but it fails for some reason
|
349 | 336 | .setRuntimeInit()
|
350 | 337 | .supplier(recorder.quartzSupportSupplier(runtimeConfig, buildTimeConfig, driverDialect.getDriver(),
|
| 338 | + driverDialect.getDataSources(), |
351 | 339 | nonconcurrentMethods))
|
352 | 340 | .done());
|
353 | 341 | }
|
|
0 commit comments