svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.db / org.gvsig.fmap.dal.db.jdbc / src / main / java / org / gvsig / fmap / dal / store / jdbc / JDBCStoreParameters.java @ 43020
History | View | Annotate | Download (7.21 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.fmap.dal.store.jdbc; |
26 |
|
27 |
import java.text.MessageFormat; |
28 |
|
29 |
import org.gvsig.fmap.dal.store.db.DBStoreParameters; |
30 |
|
31 |
/**
|
32 |
* Parameters class for JDBC generic provider
|
33 |
*
|
34 |
*/
|
35 |
public class JDBCStoreParameters extends DBStoreParameters |
36 |
implements JDBCConnectionParameters {
|
37 |
|
38 |
// public static final String PARAMETERS_DEFINITION_NAME = "JDBCStoreParameters";
|
39 |
|
40 |
public JDBCStoreParameters() {
|
41 |
super(
|
42 |
JDBCLibrary.NAME + "StoreParameters",
|
43 |
JDBCLibrary.NAME |
44 |
); |
45 |
} |
46 |
|
47 |
protected JDBCStoreParameters(String parametersDefinitionName) { |
48 |
super(
|
49 |
parametersDefinitionName, |
50 |
JDBCLibrary.NAME |
51 |
); |
52 |
} |
53 |
|
54 |
public JDBCStoreParameters(String parametersDefinitionName, String providerName) { |
55 |
super(parametersDefinitionName,providerName);
|
56 |
} |
57 |
|
58 |
public boolean isValid() { |
59 |
return this.getHost() != null; |
60 |
} |
61 |
|
62 |
public String getHost() { |
63 |
return (String) this.getDynValue(HOST_PARAMTER_NAME); |
64 |
} |
65 |
|
66 |
public Integer getPort() { |
67 |
return (Integer) this.getDynValue(PORT_PARAMTER_NAME); |
68 |
} |
69 |
|
70 |
public String getDBName() { |
71 |
return (String) this.getDynValue(DBNAME_PARAMTER_NAME); |
72 |
} |
73 |
|
74 |
public String getUser() { |
75 |
return (String) this.getDynValue(USER_PARAMTER_NAME); |
76 |
} |
77 |
|
78 |
public String getPassword() { |
79 |
return (String) this.getDynValue(PASSWORD_PARAMTER_NAME); |
80 |
} |
81 |
|
82 |
public void setHost(String host) { |
83 |
this.setDynValue(HOST_PARAMTER_NAME, host);
|
84 |
} |
85 |
|
86 |
public void setPort(int port) { |
87 |
this.setDynValue(PORT_PARAMTER_NAME, new Integer(port)); |
88 |
} |
89 |
|
90 |
public void setPort(Integer port) { |
91 |
this.setDynValue(PORT_PARAMTER_NAME, port);
|
92 |
} |
93 |
|
94 |
public void setDBName(String dbName) { |
95 |
this.setDynValue(DBNAME_PARAMTER_NAME, dbName);
|
96 |
} |
97 |
|
98 |
public void setUser(String user) { |
99 |
this.setDynValue(USER_PARAMTER_NAME, user);
|
100 |
} |
101 |
|
102 |
public void setPassword(String password) { |
103 |
this.setDynValue(PASSWORD_PARAMTER_NAME, password);
|
104 |
} |
105 |
|
106 |
/**
|
107 |
* Set <code>JDBC Driver class name</code> parameter
|
108 |
*
|
109 |
* @param className
|
110 |
*/
|
111 |
public void setJDBCDriverClassName(String className) { |
112 |
this.setDynValue(JDBC_DRIVER_CLASS_PARAMTER_NAME, className);
|
113 |
} |
114 |
|
115 |
public String getJDBCDriverClassName() { |
116 |
return (String) this.getDynValue(JDBC_DRIVER_CLASS_PARAMTER_NAME); |
117 |
} |
118 |
|
119 |
public String getCatalog() { |
120 |
return (String) this.getDynValue(CATALOG_PARAMTER_NAME); |
121 |
} |
122 |
|
123 |
|
124 |
/**
|
125 |
* Set <code>catalog</code> parameter
|
126 |
*
|
127 |
* @param className
|
128 |
*/
|
129 |
public void setCatalog(String catalog) { |
130 |
this.setDynValue(CATALOG_PARAMTER_NAME, catalog);
|
131 |
} |
132 |
|
133 |
public String getSchema() { |
134 |
return (String) this.getDynValue(SCHEMA_PARAMTER_NAME); |
135 |
} |
136 |
|
137 |
/**
|
138 |
* Set <code>schema</code> parameter
|
139 |
*
|
140 |
* @param className
|
141 |
*/
|
142 |
public void setSchema(String schema) { |
143 |
this.setDynValue(SCHEMA_PARAMTER_NAME, schema);
|
144 |
} |
145 |
|
146 |
public String getTable() { |
147 |
return (String) this.getDynValue(TABLE_PARAMTER_NAME); |
148 |
} |
149 |
|
150 |
public void setTable(String table) { |
151 |
this.setDynValue(TABLE_PARAMTER_NAME, table);
|
152 |
} |
153 |
|
154 |
public String getFieldsString() { |
155 |
return (String) this.getDynValue(FIELDS_PARAMTER_NAME); |
156 |
} |
157 |
|
158 |
public String[] getFields() { |
159 |
String fields = (String) this.getDynValue(FIELDS_PARAMTER_NAME); |
160 |
if (fields == null) { |
161 |
return null; |
162 |
} |
163 |
// FIXME check for fields with spaces and special chars
|
164 |
return fields.split(","); |
165 |
} |
166 |
|
167 |
public void setFields(String fields) { |
168 |
this.setDynValue(FIELDS_PARAMTER_NAME, fields);
|
169 |
} |
170 |
|
171 |
public void setFields(String[] fields) { |
172 |
StringBuilder str = new StringBuilder(); |
173 |
for (int i = 0; i < fields.length - 1; i++) { |
174 |
str.append(fields[i]); |
175 |
str.append(",");
|
176 |
} |
177 |
str.append(fields[fields.length - 1]);
|
178 |
|
179 |
this.setDynValue(FIELDS_PARAMTER_NAME, str.toString());
|
180 |
} |
181 |
|
182 |
public String getSQL() { |
183 |
return (String) this.getDynValue(SQL_PARAMTER_NAME); |
184 |
} |
185 |
|
186 |
public void setSQL(String sql) { |
187 |
this.setDynValue(SQL_PARAMTER_NAME, sql);
|
188 |
} |
189 |
|
190 |
public String getBaseFilter() { |
191 |
return (String) this.getDynValue(BASEFILTER_PARAMTER_NAME); |
192 |
} |
193 |
|
194 |
public void setBaseFilter(String initialFilter) { |
195 |
this.setDynValue(BASEFILTER_PARAMTER_NAME, initialFilter);
|
196 |
} |
197 |
|
198 |
public String getBaseOrder() { |
199 |
return (String) this.getDynValue(BASEORDER_PARAMTER_NAME); |
200 |
} |
201 |
|
202 |
public void setBaseOrder(String order) { |
203 |
this.setDynValue(BASEORDER_PARAMTER_NAME, order);
|
204 |
} |
205 |
|
206 |
public String getPkFieldsString() { |
207 |
return (String) this.getDynValue(PKFIELDS_PARAMTER_NAME); |
208 |
} |
209 |
|
210 |
public String[] getPkFields() { |
211 |
String fields = (String) this.getDynValue(PKFIELDS_PARAMTER_NAME); |
212 |
if (fields == null) { |
213 |
return null; |
214 |
} |
215 |
// FIXME check for fields with spaces and special chars
|
216 |
return fields.split(","); |
217 |
} |
218 |
|
219 |
public void setPkFields(String fields) { |
220 |
this.setDynValue(PKFIELDS_PARAMTER_NAME, fields);
|
221 |
} |
222 |
|
223 |
public void setPkFields(String[] fields) { |
224 |
StringBuilder str = new StringBuilder(); |
225 |
for (int i = 0; i < fields.length - 1; i++) { |
226 |
str.append(fields[i]); |
227 |
str.append(",");
|
228 |
} |
229 |
str.append(fields[fields.length - 1]);
|
230 |
|
231 |
this.setDynValue(PKFIELDS_PARAMTER_NAME, str.toString());
|
232 |
} |
233 |
|
234 |
/**
|
235 |
* Return table <code>name</code> or <code>schema.tableName</code> if
|
236 |
* <code>schema</code> parameter is set.
|
237 |
*
|
238 |
* @return
|
239 |
*/
|
240 |
public String tableID() { |
241 |
if (this.getSchema() == null || this.getSchema() == "") { |
242 |
return escapeName(this.getTable()); |
243 |
} |
244 |
return escapeName(this.getSchema()) + "." + escapeName(this.getTable()); |
245 |
} |
246 |
|
247 |
protected String escapeName(String name) { |
248 |
return "\"".concat(name).concat("\""); |
249 |
} |
250 |
|
251 |
/**
|
252 |
* Compound a string that can identify the source
|
253 |
*
|
254 |
* @return
|
255 |
*/
|
256 |
public String getSourceId() { |
257 |
if (getTable() != null) { |
258 |
return MessageFormat.format( |
259 |
"provider={0}:url=\"{1}\":table=\"{2}\":user={3}:driverclass={4}",
|
260 |
this.getDataStoreName(),
|
261 |
this.getUrl(),
|
262 |
this.getTable(),
|
263 |
this.getUser(),
|
264 |
this.getJDBCDriverClassName()
|
265 |
); |
266 |
} |
267 |
return MessageFormat.format( |
268 |
"provider={0}:url=\"{1}\":sql=\"{2}\":user={3}:driverclass={4}",
|
269 |
this.getDataStoreName(),
|
270 |
this.getUrl(),
|
271 |
this.getSQL(),
|
272 |
this.getUser(),
|
273 |
this.getJDBCDriverClassName()
|
274 |
); |
275 |
} |
276 |
|
277 |
public String getUrl() { |
278 |
return (String) this.getDynValue(URL_PARAMTER_NAME); |
279 |
} |
280 |
|
281 |
/**
|
282 |
* Set <code>JDBC connection url</code> parameter
|
283 |
*
|
284 |
* @param url
|
285 |
*/
|
286 |
public void setUrl(String url) { |
287 |
this.setDynValue(URL_PARAMTER_NAME, url);
|
288 |
} |
289 |
|
290 |
@Override
|
291 |
public JDBCStoreParameters getCopy() {
|
292 |
return (JDBCStoreParameters) super.getCopy(); |
293 |
} |
294 |
|
295 |
|
296 |
} |