1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.generator.config;
17
18 import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
19 import static org.mybatis.generator.internal.util.messages.Messages.getString;
20
21 import java.util.List;
22
23 import org.mybatis.generator.api.dom.xml.Attribute;
24 import org.mybatis.generator.api.dom.xml.XmlElement;
25
26
27
28
29
30 public class JDBCConnectionConfiguration extends PropertyHolder {
31
32 private String driverClass;
33
34 private String connectionURL;
35
36 private String userId;
37
38 private String password;
39
40 public JDBCConnectionConfiguration() {
41 super();
42 }
43
44 public String getConnectionURL() {
45 return connectionURL;
46 }
47
48 public void setConnectionURL(String connectionURL) {
49 this.connectionURL = connectionURL;
50 }
51
52 public String getPassword() {
53 return password;
54 }
55
56 public void setPassword(String password) {
57 this.password = password;
58 }
59
60 public String getUserId() {
61 return userId;
62 }
63
64 public void setUserId(String userId) {
65 this.userId = userId;
66 }
67
68 public String getDriverClass() {
69 return driverClass;
70 }
71
72 public void setDriverClass(String driverClass) {
73 this.driverClass = driverClass;
74 }
75
76 public XmlElement toXmlElement() {
77 XmlElement xmlElement = new XmlElement("jdbcConnection");
78 xmlElement.addAttribute(new Attribute("driverClass", driverClass));
79 xmlElement.addAttribute(new Attribute("connectionURL", connectionURL));
80
81 if (stringHasValue(userId)) {
82 xmlElement.addAttribute(new Attribute("userId", userId));
83 }
84
85 if (stringHasValue(password)) {
86 xmlElement.addAttribute(new Attribute("password", password));
87 }
88
89 addPropertyXmlElements(xmlElement);
90
91 return xmlElement;
92 }
93
94 public void validate(List<String> errors) {
95 if (!stringHasValue(driverClass)) {
96 errors.add(getString("ValidationError.4"));
97 }
98
99 if (!stringHasValue(connectionURL)) {
100 errors.add(getString("ValidationError.5"));
101 }
102 }
103 }