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 @ 40596
History | View | Annotate | Download (6.98 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 |
* @author jmvivo
|
35 |
*
|
36 |
*/
|
37 |
public class JDBCStoreParameters extends DBStoreParameters |
38 |
implements JDBCConnectionParameters {
|
39 |
|
40 |
public static final String PARAMETERS_DEFINITION_NAME = "JDBCStoreParameters"; |
41 |
|
42 |
public JDBCStoreParameters() {
|
43 |
super(PARAMETERS_DEFINITION_NAME,JDBCStoreProvider.NAME);
|
44 |
} |
45 |
|
46 |
protected JDBCStoreParameters(String parametersDefinitionName) { |
47 |
super(parametersDefinitionName,JDBCStoreProvider.NAME);
|
48 |
} |
49 |
|
50 |
protected JDBCStoreParameters(String parametersDefinitionName, String providerName) { |
51 |
super(parametersDefinitionName,providerName);
|
52 |
} |
53 |
|
54 |
public boolean isValid() { |
55 |
return this.getHost() != null; |
56 |
} |
57 |
|
58 |
public String getHost() { |
59 |
return (String) this.getDynValue(HOST_PARAMTER_NAME); |
60 |
} |
61 |
|
62 |
public Integer getPort() { |
63 |
return (Integer) this.getDynValue(PORT_PARAMTER_NAME); |
64 |
} |
65 |
|
66 |
public String getDBName() { |
67 |
return (String) this.getDynValue(DBNAME_PARAMTER_NAME); |
68 |
} |
69 |
|
70 |
public String getUser() { |
71 |
return (String) this.getDynValue(USER_PARAMTER_NAME); |
72 |
} |
73 |
|
74 |
public String getPassword() { |
75 |
return (String) this.getDynValue(PASSWORD_PARAMTER_NAME); |
76 |
} |
77 |
|
78 |
public void setHost(String host) { |
79 |
this.setDynValue(HOST_PARAMTER_NAME, host);
|
80 |
} |
81 |
|
82 |
public void setPort(int port) { |
83 |
this.setDynValue(PORT_PARAMTER_NAME, new Integer(port)); |
84 |
} |
85 |
|
86 |
public void setPort(Integer port) { |
87 |
this.setDynValue(PORT_PARAMTER_NAME, port);
|
88 |
} |
89 |
|
90 |
public void setDBName(String dbName) { |
91 |
this.setDynValue(DBNAME_PARAMTER_NAME, dbName);
|
92 |
} |
93 |
|
94 |
public void setUser(String user) { |
95 |
this.setDynValue(USER_PARAMTER_NAME, user);
|
96 |
} |
97 |
|
98 |
public void setPassword(String password) { |
99 |
this.setDynValue(PASSWORD_PARAMTER_NAME, password);
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* Set <code>JDBC Driver class name</code> parameter
|
104 |
*
|
105 |
* @param className
|
106 |
*/
|
107 |
public void setJDBCDriverClassName(String className) { |
108 |
this.setDynValue(JDBC_DRIVER_CLASS_PARAMTER_NAME, className);
|
109 |
} |
110 |
|
111 |
public String getJDBCDriverClassName() { |
112 |
return (String) this.getDynValue(JDBC_DRIVER_CLASS_PARAMTER_NAME); |
113 |
} |
114 |
|
115 |
public String getCatalog() { |
116 |
return (String) this.getDynValue(CATALOG_PARAMTER_NAME); |
117 |
} |
118 |
|
119 |
|
120 |
/**
|
121 |
* Set <code>catalog</code> parameter
|
122 |
*
|
123 |
* @param className
|
124 |
*/
|
125 |
public void setCatalog(String catalog) { |
126 |
this.setDynValue(CATALOG_PARAMTER_NAME, catalog);
|
127 |
} |
128 |
|
129 |
public String getSchema() { |
130 |
return (String) this.getDynValue(SCHEMA_PARAMTER_NAME); |
131 |
} |
132 |
|
133 |
/**
|
134 |
* Set <code>schema</code> parameter
|
135 |
*
|
136 |
* @param className
|
137 |
*/
|
138 |
public void setSchema(String schema) { |
139 |
this.setDynValue(SCHEMA_PARAMTER_NAME, schema);
|
140 |
} |
141 |
|
142 |
public String getTable() { |
143 |
return (String) this.getDynValue(TABLE_PARAMTER_NAME); |
144 |
} |
145 |
|
146 |
public void setTable(String table) { |
147 |
this.setDynValue(TABLE_PARAMTER_NAME, table);
|
148 |
} |
149 |
|
150 |
public String getFieldsString() { |
151 |
return (String) this.getDynValue(FIELDS_PARAMTER_NAME); |
152 |
} |
153 |
|
154 |
public String[] getFields() { |
155 |
String fields = (String) this.getDynValue(FIELDS_PARAMTER_NAME); |
156 |
if (fields == null) { |
157 |
return null; |
158 |
} |
159 |
// FIXME check for fields with spaces and special chars
|
160 |
return fields.split(","); |
161 |
} |
162 |
|
163 |
public void setFields(String fields) { |
164 |
this.setDynValue(FIELDS_PARAMTER_NAME, fields);
|
165 |
} |
166 |
|
167 |
public void setFields(String[] fields) { |
168 |
StringBuilder str = new StringBuilder(); |
169 |
for (int i = 0; i < fields.length - 1; i++) { |
170 |
str.append(fields[i]); |
171 |
str.append(",");
|
172 |
} |
173 |
str.append(fields[fields.length - 1]);
|
174 |
|
175 |
this.setDynValue(FIELDS_PARAMTER_NAME, str.toString());
|
176 |
} |
177 |
|
178 |
public String getSQL() { |
179 |
return (String) this.getDynValue(SQL_PARAMTER_NAME); |
180 |
} |
181 |
|
182 |
public void setSQL(String sql) { |
183 |
this.setDynValue(SQL_PARAMTER_NAME, sql);
|
184 |
} |
185 |
|
186 |
public String getBaseFilter() { |
187 |
return (String) this.getDynValue(BASEFILTER_PARAMTER_NAME); |
188 |
} |
189 |
|
190 |
public void setBaseFilter(String initialFilter) { |
191 |
this.setDynValue(BASEFILTER_PARAMTER_NAME, initialFilter);
|
192 |
} |
193 |
|
194 |
public String getBaseOrder() { |
195 |
return (String) this.getDynValue(BASEORDER_PARAMTER_NAME); |
196 |
} |
197 |
|
198 |
public void setBaseOrder(String order) { |
199 |
this.setDynValue(BASEORDER_PARAMTER_NAME, order);
|
200 |
} |
201 |
|
202 |
public String getPkFieldsString() { |
203 |
return (String) this.getDynValue(PKFIELDS_PARAMTER_NAME); |
204 |
} |
205 |
|
206 |
public String[] getPkFields() { |
207 |
String fields = (String) this.getDynValue(PKFIELDS_PARAMTER_NAME); |
208 |
if (fields == null) { |
209 |
return null; |
210 |
} |
211 |
// FIXME check for fields with spaces and special chars
|
212 |
return fields.split(","); |
213 |
} |
214 |
|
215 |
public void setPkFields(String fields) { |
216 |
this.setDynValue(PKFIELDS_PARAMTER_NAME, fields);
|
217 |
} |
218 |
|
219 |
public void setPkFields(String[] fields) { |
220 |
StringBuilder str = new StringBuilder(); |
221 |
for (int i = 0; i < fields.length - 1; i++) { |
222 |
str.append(fields[i]); |
223 |
str.append(",");
|
224 |
} |
225 |
str.append(fields[fields.length - 1]);
|
226 |
|
227 |
this.setDynValue(PKFIELDS_PARAMTER_NAME, str.toString());
|
228 |
} |
229 |
|
230 |
/**
|
231 |
* Return table <code>name</code> or <code>schema.tableName</code> if
|
232 |
* <code>schema</code> parameter is set.
|
233 |
*
|
234 |
* @return
|
235 |
*/
|
236 |
public String tableID() { |
237 |
if (this.getSchema() == null || this.getSchema() == "") { |
238 |
return escapeName(this.getTable()); |
239 |
} |
240 |
return escapeName(this.getSchema()) + "." + escapeName(this.getTable()); |
241 |
} |
242 |
|
243 |
protected String escapeName(String name) { |
244 |
return "\"".concat(name).concat("\""); |
245 |
} |
246 |
|
247 |
/**
|
248 |
* Compound a string that can identify the source
|
249 |
*
|
250 |
* @return
|
251 |
*/
|
252 |
public String getSourceId() { |
253 |
if (getTable() != null) { |
254 |
return MessageFormat.format( |
255 |
"provider={0}:url=\"{1}\":table=\"{2}\":user={3}:driverclass={4}",
|
256 |
this.getDataStoreName(),
|
257 |
this.getUrl(),
|
258 |
this.getTable(),
|
259 |
this.getUser(),
|
260 |
this.getJDBCDriverClassName()
|
261 |
); |
262 |
} |
263 |
return MessageFormat.format( |
264 |
"provider={0}:url=\"{1}\":sql=\"{2}\":user={3}:driverclass={4}",
|
265 |
this.getDataStoreName(),
|
266 |
this.getUrl(),
|
267 |
this.getSQL(),
|
268 |
this.getUser(),
|
269 |
this.getJDBCDriverClassName()
|
270 |
); |
271 |
} |
272 |
|
273 |
public String getUrl() { |
274 |
return (String) this.getDynValue(URL_PARAMTER_NAME); |
275 |
} |
276 |
|
277 |
/**
|
278 |
* Set <code>JDBC connection url</code> parameter
|
279 |
*
|
280 |
* @param url
|
281 |
*/
|
282 |
public void setUrl(String url) { |
283 |
this.setDynValue(URL_PARAMTER_NAME, url);
|
284 |
} |
285 |
|
286 |
} |