1 package org.apache.torque.generator.source.jdbc;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.torque.generator.configuration.ConfigurationException;
23 import org.apache.torque.generator.configuration.ConfigurationHandlers;
24 import org.apache.torque.generator.control.ControllerState;
25 import org.apache.torque.generator.source.Source;
26 import org.apache.torque.generator.source.SourceProvider;
27
28
29
30
31
32
33 public class JdbcMetadataSourceProvider extends SourceProvider
34 {
35
36 private String urlOption;
37
38
39 private String driverOption;
40
41
42 private String usernameOption;
43
44
45 private String passwordOption;
46
47
48 private String schemaOption;
49
50
51 private String url;
52
53
54 private String driver;
55
56
57 private String username;
58
59
60 private String password;
61
62
63 private String schema;
64
65
66 private boolean nextCalled = false;
67
68 public JdbcMetadataSourceProvider(
69 String urlOption,
70 String driverOption,
71 String usernameOption,
72 String passwordOption,
73 String schemaOption)
74 throws ConfigurationException
75 {
76 if (urlOption == null)
77 {
78 throw new ConfigurationException(
79 "JdbcMetadataSourceProvider: urlOption must not be null");
80 }
81 if (driverOption == null)
82 {
83 throw new ConfigurationException(
84 "JdbcMetadataSourceProvider:"
85 + " driverOption must not be null");
86 }
87 this.urlOption = urlOption;
88 this.driverOption = driverOption;
89 this.usernameOption = usernameOption;
90 this.passwordOption = passwordOption;
91 this.schemaOption = schemaOption;
92 }
93
94
95
96
97
98
99
100 public void initInternal(
101 ConfigurationHandlers configurationHandlers,
102 ControllerState controllerState)
103 throws ConfigurationException
104 {
105 driver = controllerState.getStringOption(driverOption);
106 url = controllerState.getStringOption(urlOption);
107 if (usernameOption != null)
108 {
109 username = controllerState.getStringOption(usernameOption);
110 }
111 if (passwordOption != null)
112 {
113 password = controllerState.getStringOption(passwordOption);
114 }
115 if (schemaOption != null)
116 {
117 schema = controllerState.getStringOption(schemaOption);
118 }
119 }
120
121 public boolean hasNext()
122 {
123 return !nextCalled;
124 }
125
126 public Source next()
127 {
128 if (nextCalled)
129 {
130 throw new IndexOutOfBoundsException();
131 }
132 nextCalled = true;
133 return new JdbcMetadataSource(driver, url, username, password, schema);
134 }
135
136
137 protected void resetInternal(
138 ConfigurationHandlers configurationHandlers,
139 ControllerState controllerState)
140 throws ConfigurationException
141 {
142 driver = null;
143 url = null;
144 username = null;
145 password = null;
146 schema = null;
147 nextCalled = false;
148 }
149
150 public void remove()
151 {
152 throw new UnsupportedOperationException();
153 }
154
155
156 public String getUrlOption()
157 {
158 return urlOption;
159 }
160
161 public String getDriverOption()
162 {
163 return driverOption;
164 }
165
166 public String getUsernameOption()
167 {
168 return usernameOption;
169 }
170
171 public String getPasswordOption()
172 {
173 return passwordOption;
174 }
175
176 public String getSchemaOption()
177 {
178 return schemaOption;
179 }
180
181 public String getUrl()
182 {
183 return url;
184 }
185
186 public String getDriver()
187 {
188 return driver;
189 }
190
191 public String getUsername()
192 {
193 return username;
194 }
195
196 public String getPassword()
197 {
198 return password;
199 }
200
201 public String getSchema()
202 {
203 return schema;
204 }
205
206
207
208
209 public SourceProvider copy() throws ConfigurationException
210 {
211 JdbcMetadataSourceProvider result = new JdbcMetadataSourceProvider(
212 urlOption,
213 driverOption,
214 usernameOption,
215 passwordOption,
216 schemaOption);
217 return result;
218 }
219
220
221
222
223 public void copyNotSetSettingsFrom(SourceProvider sourceProvider)
224 {
225
226 }
227
228 }