|
12 | 12 | */
|
13 | 13 | package org.flowable.dmn.rest.conf.engine;
|
14 | 14 |
|
| 15 | +import javax.sql.DataSource; |
| 16 | + |
15 | 17 | import org.flowable.common.engine.impl.AbstractEngineConfiguration;
|
16 | 18 | import org.flowable.dmn.api.DmnDecisionService;
|
17 | 19 | import org.flowable.dmn.api.DmnHistoryService;
|
18 | 20 | import org.flowable.dmn.api.DmnRepositoryService;
|
19 | 21 | import org.flowable.dmn.engine.DmnEngine;
|
20 | 22 | import org.flowable.dmn.engine.DmnEngineConfiguration;
|
21 | 23 | import org.flowable.dmn.engine.impl.cfg.StandaloneInMemDmnEngineConfiguration;
|
| 24 | +import org.flowable.dmn.spring.DmnEngineFactoryBean; |
| 25 | +import org.flowable.dmn.spring.SpringDmnEngineConfiguration; |
| 26 | +import org.flowable.idm.spring.configurator.SpringIdmEngineConfigurator; |
| 27 | +import org.springframework.beans.factory.annotation.Value; |
22 | 28 | import org.springframework.context.annotation.Bean;
|
23 | 29 | import org.springframework.context.annotation.Configuration;
|
| 30 | +import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
| 31 | +import org.springframework.transaction.PlatformTransactionManager; |
| 32 | + |
| 33 | +import com.zaxxer.hikari.HikariDataSource; |
24 | 34 |
|
25 | 35 | /**
|
26 | 36 | * @author Yvo Swillens
|
27 | 37 | */
|
28 | 38 | @Configuration(proxyBeanMethods = false)
|
29 | 39 | public class FlowableDmnEngineConfiguration {
|
30 | 40 |
|
31 |
| - public DmnEngine ruleEngine() { |
32 |
| - DmnEngineConfiguration dmnEngineConfiguration = new StandaloneInMemDmnEngineConfiguration(); |
33 |
| - dmnEngineConfiguration.setDatabaseSchemaUpdate(AbstractEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); |
| 41 | + @Value("${jdbc.url:jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000}") |
| 42 | + protected String jdbcUrl; |
| 43 | + |
| 44 | + @Value("${jdbc.driver:org.h2.Driver}") |
| 45 | + protected String jdbcDriver; |
| 46 | + |
| 47 | + @Value("${jdbc.username:sa}") |
| 48 | + protected String jdbcUsername; |
| 49 | + |
| 50 | + @Value("${jdbc.password:}") |
| 51 | + protected String jdbcPassword; |
| 52 | + |
| 53 | + @Bean |
| 54 | + public DataSource dataSource() { |
| 55 | + HikariDataSource dataSource = new HikariDataSource(); |
| 56 | + dataSource.setJdbcUrl(jdbcUrl); |
| 57 | + dataSource.setDriverClassName(jdbcDriver); |
| 58 | + dataSource.setUsername(jdbcUsername); |
| 59 | + dataSource.setPassword(jdbcPassword); |
| 60 | + return dataSource; |
| 61 | + } |
| 62 | + |
| 63 | + @Bean(name = "transactionManager") |
| 64 | + public PlatformTransactionManager annotationDrivenTransactionManager(DataSource dataSource) { |
| 65 | + DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(); |
| 66 | + transactionManager.setDataSource(dataSource); |
| 67 | + return transactionManager; |
| 68 | + } |
| 69 | + |
| 70 | + @Bean(name = "dmnEngine") |
| 71 | + public DmnEngineFactoryBean dmnEngineFactoryBean(DmnEngineConfiguration dmnEngineConfiguration) { |
| 72 | + DmnEngineFactoryBean factoryBean = new DmnEngineFactoryBean(); |
| 73 | + factoryBean.setDmnEngineConfiguration(dmnEngineConfiguration); |
| 74 | + return factoryBean; |
| 75 | + } |
| 76 | + |
| 77 | + @Bean(name = "dmnEngineConfiguration") |
| 78 | + public DmnEngineConfiguration dmnEngineConfiguration(DataSource dataSource, PlatformTransactionManager transactionManager, |
| 79 | + SpringIdmEngineConfigurator springIdmEngineConfigurator) { |
| 80 | + SpringDmnEngineConfiguration dmnEngineConfiguration = new SpringDmnEngineConfiguration(); |
| 81 | + dmnEngineConfiguration.setDataSource(dataSource); |
| 82 | + dmnEngineConfiguration.setDatabaseSchemaUpdate(DmnEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); |
| 83 | + dmnEngineConfiguration.setTransactionManager(transactionManager); |
| 84 | + dmnEngineConfiguration.setIdmEngineConfigurator(springIdmEngineConfigurator); |
34 | 85 | dmnEngineConfiguration.setHistoryEnabled(true);
|
35 |
| - return dmnEngineConfiguration.buildDmnEngine(); |
| 86 | + return dmnEngineConfiguration; |
36 | 87 | }
|
37 | 88 |
|
38 |
| - @Bean |
39 |
| - public DmnEngineConfiguration dmnEngineConfiguration() { |
40 |
| - return ruleEngine().getDmnEngineConfiguration(); |
| 89 | + @Bean(name = "springIdmEngineConfigurator") |
| 90 | + public SpringIdmEngineConfigurator springIdmEngineConfigurator() { |
| 91 | + return new SpringIdmEngineConfigurator(); |
41 | 92 | }
|
42 | 93 |
|
43 | 94 | @Bean
|
44 |
| - public DmnRepositoryService dmnRepositoryService() { |
45 |
| - return ruleEngine().getDmnRepositoryService(); |
| 95 | + public DmnRepositoryService dmnRepositoryService(DmnEngine dmnEngine) { |
| 96 | + return dmnEngine.getDmnRepositoryService(); |
46 | 97 | }
|
47 | 98 |
|
48 | 99 | @Bean
|
49 |
| - public DmnDecisionService dmnRuleService() { |
50 |
| - return ruleEngine().getDmnDecisionService(); |
| 100 | + public DmnDecisionService dmnRuleService(DmnEngine dmnEngine) { |
| 101 | + return dmnEngine.getDmnDecisionService(); |
51 | 102 | }
|
52 | 103 |
|
53 | 104 | @Bean
|
54 |
| - public DmnHistoryService dmnHistoryService() { |
55 |
| - return ruleEngine().getDmnHistoryService(); |
| 105 | + public DmnHistoryService dmnHistoryService(DmnEngine dmnEngine) { |
| 106 | + return dmnEngine.getDmnHistoryService(); |
56 | 107 | }
|
57 | 108 | }
|
0 commit comments