1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.mapping;
17
18 import javax.sql.DataSource;
19
20 import org.apache.ibatis.transaction.TransactionFactory;
21
22
23
24
25 public final class Environment {
26 private final String id;
27 private final TransactionFactory transactionFactory;
28 private final DataSource dataSource;
29
30 public Environment(String id, TransactionFactory transactionFactory, DataSource dataSource) {
31 if (id == null) {
32 throw new IllegalArgumentException("Parameter 'id' must not be null");
33 }
34 if (transactionFactory == null) {
35 throw new IllegalArgumentException("Parameter 'transactionFactory' must not be null");
36 }
37 this.id = id;
38 if (dataSource == null) {
39 throw new IllegalArgumentException("Parameter 'dataSource' must not be null");
40 }
41 this.transactionFactory = transactionFactory;
42 this.dataSource = dataSource;
43 }
44
45 public static class Builder {
46 private final String id;
47 private TransactionFactory transactionFactory;
48 private DataSource dataSource;
49
50 public Builder(String id) {
51 this.id = id;
52 }
53
54 public Builder transactionFactory(TransactionFactory transactionFactory) {
55 this.transactionFactory = transactionFactory;
56 return this;
57 }
58
59 public Builder dataSource(DataSource dataSource) {
60 this.dataSource = dataSource;
61 return this;
62 }
63
64 public String id() {
65 return this.id;
66 }
67
68 public Environment build() {
69 return new Environment(this.id, this.transactionFactory, this.dataSource);
70 }
71
72 }
73
74 public String getId() {
75 return this.id;
76 }
77
78 public TransactionFactory getTransactionFactory() {
79 return this.transactionFactory;
80 }
81
82 public DataSource getDataSource() {
83 return this.dataSource;
84 }
85
86 }