|
4 | 4 |
|
5 | 5 | import javax.sql.DataSource;
|
6 | 6 |
|
7 |
| -public class Environment { |
8 |
| - private String id; |
9 |
| - private TransactionFactory transactionFactory; |
10 |
| - private DataSource dataSource; |
| 7 | +public final class Environment { |
| 8 | + private final String id; |
| 9 | + private final TransactionFactory transactionFactory; |
| 10 | + private final DataSource dataSource; |
11 | 11 |
|
12 | 12 | public Environment(String id, TransactionFactory transactionFactory, DataSource dataSource) {
|
| 13 | + if (id == null) { |
| 14 | + throw new IllegalArgumentException("Parameter 'id' must not be null"); |
| 15 | + } |
| 16 | + if (transactionFactory == null) { |
| 17 | + throw new IllegalArgumentException("Parameter 'transactionFactory' must not be null"); |
| 18 | + } |
13 | 19 | this.id = id;
|
| 20 | + if (dataSource == null) { |
| 21 | + throw new IllegalArgumentException("Parameter 'dataSource' must not be null"); |
| 22 | + } |
14 | 23 | this.transactionFactory = transactionFactory;
|
15 | 24 | this.dataSource = dataSource;
|
16 | 25 | }
|
17 | 26 |
|
18 |
| - private Environment() { |
19 |
| - } |
20 |
| - |
21 | 27 | public static class Builder {
|
22 |
| - private Environment environment = new Environment(); |
| 28 | + private String id; |
| 29 | + private TransactionFactory transactionFactory; |
| 30 | + private DataSource dataSource; |
23 | 31 |
|
24 |
| - public Builder(String id, TransactionFactory transactionManager, DataSource dataSource) { |
25 |
| - environment.id = id; |
26 |
| - environment.transactionFactory = transactionManager; |
27 |
| - environment.dataSource = dataSource; |
| 32 | + public Builder(String id) { |
| 33 | + this.id = id; |
28 | 34 | }
|
29 | 35 |
|
30 | 36 | public Builder transactionFactory(TransactionFactory transactionFactory) {
|
31 |
| - environment.transactionFactory = transactionFactory; |
| 37 | + this.transactionFactory = transactionFactory; |
32 | 38 | return this;
|
33 | 39 | }
|
34 | 40 |
|
35 | 41 | public Builder dataSource(DataSource dataSource) {
|
36 |
| - environment.dataSource = dataSource; |
| 42 | + this.dataSource = dataSource; |
37 | 43 | return this;
|
38 | 44 | }
|
39 | 45 |
|
40 | 46 | public String id() {
|
41 |
| - return environment.id; |
| 47 | + return this.id; |
42 | 48 | }
|
43 | 49 |
|
44 | 50 | public Environment build() {
|
45 |
| - return environment; |
| 51 | + return new Environment(this.id, this.transactionFactory, this.dataSource); |
46 | 52 | }
|
47 | 53 |
|
48 | 54 | }
|
49 | 55 |
|
50 | 56 | public String getId() {
|
51 |
| - return id; |
| 57 | + return this.id; |
52 | 58 | }
|
53 | 59 |
|
54 | 60 | public TransactionFactory getTransactionFactory() {
|
55 |
| - return transactionFactory; |
| 61 | + return this.transactionFactory; |
56 | 62 | }
|
57 | 63 |
|
58 | 64 | public DataSource getDataSource() {
|
59 |
| - return dataSource; |
| 65 | + return this.dataSource; |
60 | 66 | }
|
61 | 67 |
|
62 | 68 | }
|
0 commit comments