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