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.lib / src / main / java / org / gvsig / fmap / dal / store / db / DBStoreParameters.java @ 40596
History | View | Annotate | Download (14.9 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.db; |
26 |
|
27 |
import org.cresques.cts.IProjection; |
28 |
import org.gvsig.fmap.dal.DataStoreParameters; |
29 |
import org.gvsig.fmap.dal.feature.Feature; |
30 |
import org.gvsig.fmap.dal.serverexplorer.db.DBConnectionParameter; |
31 |
import org.gvsig.fmap.dal.spi.AbstractDataParameters; |
32 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
33 |
import org.gvsig.fmap.geom.primitive.Envelope; |
34 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
35 |
|
36 |
/**
|
37 |
* Abstract Data base Store Parameters
|
38 |
*
|
39 |
* @author jmvivo
|
40 |
*
|
41 |
*/
|
42 |
public abstract class DBStoreParameters extends AbstractDataParameters |
43 |
implements
|
44 |
DataStoreParameters, DBConnectionParameter { |
45 |
|
46 |
public static final String PARAMETERS_DEFINITION_NAME = "DBStoreParameters"; |
47 |
|
48 |
/**
|
49 |
* Parameter name for specify the feature type in the creacion of
|
50 |
* news stores.
|
51 |
*
|
52 |
* Is defined only in "new" paramaters.
|
53 |
*
|
54 |
*/
|
55 |
public static final String FEATURETYPE_PARAMTER_NAME = "FeatureType"; |
56 |
|
57 |
|
58 |
/**
|
59 |
* Parameter name for <code>sql</code><br>
|
60 |
*
|
61 |
* @see #getSQL()
|
62 |
* @see #setSQL(String)
|
63 |
*/
|
64 |
public static final String SQL_PARAMTER_NAME = "SQL"; |
65 |
|
66 |
/**
|
67 |
* Parameter name for <code>fields</code><br>
|
68 |
*
|
69 |
* @see #getFields()
|
70 |
* @see #getFieldsString()
|
71 |
* @see #setFields(String)
|
72 |
* @see #setFields(String[])
|
73 |
*/
|
74 |
public static final String FIELDS_PARAMTER_NAME = "Fields"; |
75 |
|
76 |
/**
|
77 |
* Parameter name for <code>initial filter</code><br>
|
78 |
*
|
79 |
* @see #getBaseFilter()
|
80 |
* @see #setBaseFilter(String)
|
81 |
*/
|
82 |
public static final String BASEFILTER_PARAMTER_NAME = "BaseFilter"; |
83 |
|
84 |
/**
|
85 |
* Parameter name for <code>initial order</code><br>
|
86 |
*
|
87 |
* @see #getBaseOrder()
|
88 |
* @see #setBaseOrder(String)
|
89 |
*/
|
90 |
public static final String BASEORDER_PARAMTER_NAME = "BaseOrder"; |
91 |
|
92 |
/**
|
93 |
* Parameter name for <code>pk fields</code><br>
|
94 |
*
|
95 |
* @see #getPkFields()
|
96 |
* @see #getPkFieldsString()
|
97 |
* @see #setPkFields(String)
|
98 |
* @see #setPkFields(String[])
|
99 |
*/
|
100 |
public static final String PKFIELDS_PARAMTER_NAME = "PKFields"; |
101 |
|
102 |
/**
|
103 |
* Parameter name for <code>default geometry</code><br>
|
104 |
*
|
105 |
* @see #getDefaultGeometryField()
|
106 |
* @see #setDefaultGeometryField(String)
|
107 |
*/
|
108 |
public static final String DEFAULTGEOMETRY_PARAMTER_NAME = "DefaultGeometryField"; |
109 |
|
110 |
/**
|
111 |
* Parameter name for the name of <code>table</code><br>
|
112 |
*
|
113 |
* @see #getTable()
|
114 |
* @see #setTable(String)
|
115 |
*/
|
116 |
public static final String TABLE_PARAMTER_NAME = "Table"; |
117 |
|
118 |
/**
|
119 |
* Parameter name for <code>working area</code><br>O
|
120 |
*
|
121 |
* @see #getWorkingArea()
|
122 |
* @see #setWorkingArea(Envelope)
|
123 |
*/
|
124 |
public static final String WORKINGAREA_PARAMTER_NAME = "Workingarea"; |
125 |
|
126 |
|
127 |
/**
|
128 |
* Parameter name for <code>CRS</code><br>
|
129 |
*
|
130 |
* @see #setSRSID(String)
|
131 |
* @see #getSRS()
|
132 |
* @see #setSRS(IProjection)
|
133 |
*/
|
134 |
public static final String CRS_PARAMTER_NAME = "CRS"; |
135 |
|
136 |
/**
|
137 |
* This instance contains the value of the current parameters.
|
138 |
*/
|
139 |
private DelegatedDynObject parameters;
|
140 |
|
141 |
public DBStoreParameters(String parametersDefinitionName, String providerName) { |
142 |
this.parameters = (DelegatedDynObject) DBHelper.newParameters(parametersDefinitionName);
|
143 |
this.setDynValue( DataStoreProviderServices.PROVIDER_PARAMTER_NAME, providerName);
|
144 |
} |
145 |
|
146 |
protected DelegatedDynObject getDelegatedDynObject() {
|
147 |
return parameters;
|
148 |
} |
149 |
|
150 |
public String getDataStoreName() { |
151 |
return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME); |
152 |
} |
153 |
|
154 |
public String getDescription() { |
155 |
return this.getDynClass().getDescription(); |
156 |
} |
157 |
|
158 |
public boolean isValid() { |
159 |
return this.getHost() != null; |
160 |
} |
161 |
|
162 |
public String getHost() { |
163 |
return (String) this.getDynValue(HOST_PARAMTER_NAME); |
164 |
} |
165 |
|
166 |
public Integer getPort() { |
167 |
return (Integer) this.getDynValue(PORT_PARAMTER_NAME); |
168 |
} |
169 |
|
170 |
public String getDBName() { |
171 |
return (String) this.getDynValue(DBNAME_PARAMTER_NAME); |
172 |
} |
173 |
|
174 |
public String getUser() { |
175 |
return (String) this.getDynValue(USER_PARAMTER_NAME); |
176 |
} |
177 |
|
178 |
public String getPassword() { |
179 |
return (String) this.getDynValue(PASSWORD_PARAMTER_NAME); |
180 |
} |
181 |
|
182 |
public void setHost(String host) { |
183 |
this.setDynValue(HOST_PARAMTER_NAME, host);
|
184 |
} |
185 |
|
186 |
public void setPort(int port) { |
187 |
this.setDynValue(PORT_PARAMTER_NAME, new Integer(port)); |
188 |
} |
189 |
|
190 |
/**
|
191 |
* Set <code>port/code> parameter value
|
192 |
*
|
193 |
* @param port
|
194 |
*/
|
195 |
public void setPort(Integer port) { |
196 |
this.setDynValue(PORT_PARAMTER_NAME, port);
|
197 |
} |
198 |
|
199 |
/**
|
200 |
* Set <code>data base name/code> parameter value
|
201 |
*
|
202 |
* @param data
|
203 |
* base name
|
204 |
*/
|
205 |
public void setDBName(String dbName) { |
206 |
this.setDynValue(DBNAME_PARAMTER_NAME, dbName);
|
207 |
} |
208 |
|
209 |
/**
|
210 |
* Set <code>user/code> parameter value
|
211 |
*
|
212 |
* @param user
|
213 |
*/
|
214 |
public void setUser(String user) { |
215 |
this.setDynValue(USER_PARAMTER_NAME, user);
|
216 |
} |
217 |
|
218 |
/**
|
219 |
* Set <code>password/code> parameter value
|
220 |
*
|
221 |
* @param password
|
222 |
*/
|
223 |
public void setPassword(String password) { |
224 |
this.setDynValue(PASSWORD_PARAMTER_NAME, password);
|
225 |
} |
226 |
|
227 |
/**
|
228 |
* Get <code>table</code> parameter value<br>
|
229 |
* <br>
|
230 |
*
|
231 |
* This parameters describes what table or view we want to connect.<br>
|
232 |
*
|
233 |
* Not used if <code>sql</code> parameter set.
|
234 |
*
|
235 |
*
|
236 |
* @param password
|
237 |
*
|
238 |
* @see #setTable(String)
|
239 |
* @see #getSQL()
|
240 |
* @see #setSQL(String)
|
241 |
*/
|
242 |
public String getTable() { |
243 |
return (String) this.getDynValue(TABLE_PARAMTER_NAME); |
244 |
} |
245 |
|
246 |
/**
|
247 |
* Set <code>table</code> parameter value<br>
|
248 |
* <br>
|
249 |
*
|
250 |
* This parameters describes what table or view we want to connect.<br>
|
251 |
*
|
252 |
* Not used if <code>sql</code> parameter set.
|
253 |
*
|
254 |
*
|
255 |
* @param password
|
256 |
*
|
257 |
* @see #getTable(String)
|
258 |
* @see #getSQL()
|
259 |
* @see #setSQL(String)
|
260 |
*/
|
261 |
public void setTable(String table) { |
262 |
this.setDynValue(TABLE_PARAMTER_NAME, table);
|
263 |
} |
264 |
|
265 |
/**
|
266 |
* Get a comma separated list of the field names that we want to use.<br>
|
267 |
* <br>
|
268 |
*
|
269 |
* A <code>null</code> or empty string means that we want all fields
|
270 |
* available.
|
271 |
*
|
272 |
* @return
|
273 |
* @see #getFields()
|
274 |
* @see #setFields(String)
|
275 |
* @see #setFields(String[])
|
276 |
*/
|
277 |
public String getFieldsString() { |
278 |
return (String) this.getDynValue(FIELDS_PARAMTER_NAME); |
279 |
} |
280 |
|
281 |
/**
|
282 |
* Get an array of the field names that we want to use.<br>
|
283 |
* <br>
|
284 |
*
|
285 |
* A <code>null</code> means that we want all fields available.
|
286 |
*
|
287 |
* @return
|
288 |
* @see #getFieldsString()
|
289 |
* @see #setFields(String)
|
290 |
* @see #setFields(String[])
|
291 |
*/
|
292 |
public String[] getFields() { |
293 |
String fields = (String) this.getDynValue(FIELDS_PARAMTER_NAME); |
294 |
if (fields == null) { |
295 |
return null; |
296 |
} |
297 |
// FIXME check for fields with spaces and special chars
|
298 |
return fields.split(","); |
299 |
} |
300 |
|
301 |
/**
|
302 |
* Set a comma separated list of the field names that we want to use.<br>
|
303 |
* <br>
|
304 |
*
|
305 |
* A <code>null</code> means that we want all fields available.
|
306 |
*
|
307 |
* @return
|
308 |
* @see #getFields()
|
309 |
* @see #getFieldsString()
|
310 |
* @see #setFields(String[])
|
311 |
*/
|
312 |
public void setFields(String fields) { |
313 |
this.setDynValue(FIELDS_PARAMTER_NAME, fields);
|
314 |
} |
315 |
|
316 |
/**
|
317 |
* Set an array of the field names that we want to use.<br>
|
318 |
* <br>
|
319 |
*
|
320 |
* A <code>null</code> means that we want all fields available.
|
321 |
*
|
322 |
* @return
|
323 |
* @see #getFieldsString()
|
324 |
* @see #getFields()
|
325 |
* @see #setFields(String)
|
326 |
*/
|
327 |
public void setFields(String[] fields) { |
328 |
StringBuilder str = new StringBuilder(); |
329 |
for (int i = 0; i < fields.length - 1; i++) { |
330 |
str.append(fields[i]); |
331 |
str.append(",");
|
332 |
} |
333 |
str.append(fields.length - 1);
|
334 |
|
335 |
this.setDynValue(FIELDS_PARAMTER_NAME, fields);
|
336 |
} |
337 |
|
338 |
/**
|
339 |
* Get the SQL to use as source of the store instead a table or a view.<br>
|
340 |
* <br>
|
341 |
*
|
342 |
* If this property is set the store changes his work flow:
|
343 |
* <ul>
|
344 |
* <li>store is in <i>read only</i> mode.</li>
|
345 |
* <li><code>table</code> property is ignored.</li>
|
346 |
* <li><code>pkFields</code> is not identified automatically</li>
|
347 |
* <li>filter and order will be resolved locally <i>(pour performance)</i></li>
|
348 |
* </ul>
|
349 |
*
|
350 |
* @return sql to use
|
351 |
*
|
352 |
* @see #getTable()
|
353 |
* @see #setTable()
|
354 |
* @see #getPkFields()
|
355 |
* @see #setPkFields(String)
|
356 |
*/
|
357 |
public String getSQL() { |
358 |
return (String) this.getDynValue(SQL_PARAMTER_NAME); |
359 |
} |
360 |
|
361 |
/**
|
362 |
* Set the SQL to use as source of the store instead a table or a view.<br>
|
363 |
* <br>
|
364 |
* <strong>Note:</strong>see {@link #getSQL()} for description
|
365 |
*
|
366 |
* @see #getSQL()
|
367 |
* @see #getTable()
|
368 |
* @see #setTable()
|
369 |
* @see #getPkFields()
|
370 |
* @see #setPkFields(String)
|
371 |
*/
|
372 |
public void setSQL(String sql) { |
373 |
this.setDynValue(SQL_PARAMTER_NAME, sql);
|
374 |
} |
375 |
|
376 |
/**
|
377 |
* Get initial filter to use.<br>
|
378 |
* <br>
|
379 |
*
|
380 |
* This filter is passed to BD provider on each request as a base filter.
|
381 |
*
|
382 |
* @return filter
|
383 |
*
|
384 |
* @see #setBaseFilter(String)
|
385 |
*/
|
386 |
public String getBaseFilter() { |
387 |
return (String) this.getDynValue(BASEFILTER_PARAMTER_NAME); |
388 |
} |
389 |
|
390 |
/**
|
391 |
* Set initial filter to use.<br>
|
392 |
* <br>
|
393 |
*
|
394 |
* This filter is passed to BD provider on each request as a base filter.
|
395 |
*
|
396 |
* @return filter
|
397 |
*
|
398 |
* @see #getInitialFilter(String)
|
399 |
*/
|
400 |
public void setBaseFilter(String filter) { |
401 |
this.setDynValue(BASEFILTER_PARAMTER_NAME, filter);
|
402 |
} |
403 |
|
404 |
/**
|
405 |
* Get initial order to use.<br>
|
406 |
* <br>
|
407 |
*
|
408 |
* This order is used if no custom order is request in query.
|
409 |
*
|
410 |
* @return order
|
411 |
*
|
412 |
* @see #setBaseOrder(String)
|
413 |
*/
|
414 |
public String getBaseOrder() { |
415 |
return (String) this.getDynValue(BASEORDER_PARAMTER_NAME); |
416 |
} |
417 |
|
418 |
/**
|
419 |
* Set initial order to use.<br>
|
420 |
* <br>
|
421 |
*
|
422 |
* This order is used if no custom order is request in query.
|
423 |
*
|
424 |
* @return filter
|
425 |
*
|
426 |
* @see #getBaseOrder()
|
427 |
*/
|
428 |
public void setBaseOrder(String order) { |
429 |
this.setDynValue(BASEORDER_PARAMTER_NAME, order);
|
430 |
} |
431 |
|
432 |
/**
|
433 |
* Get a comma separated list of the field names that compound the primary
|
434 |
* key.<br>
|
435 |
* <br>
|
436 |
*
|
437 |
* A <code>null</code> or empty string means that library must detect this
|
438 |
* information.<br>
|
439 |
* <br>
|
440 |
* <strong>Note:</strong>If this parameters is undefined, the library can't
|
441 |
* do this detection, some services will don't be available for this store
|
442 |
* (<i>like selection, editing or {@link Feature#getReference()}</i>)
|
443 |
*
|
444 |
* @return
|
445 |
* @see #getPkFields()
|
446 |
* @see #setPkFields(String)
|
447 |
* @see #setPkFields(String[])
|
448 |
*/
|
449 |
public String getPkFieldsString() { |
450 |
return (String) this.getDynValue(PKFIELDS_PARAMTER_NAME); |
451 |
} |
452 |
|
453 |
/**
|
454 |
* Get an array of the field names that compound the primary key.<br>
|
455 |
* <br>
|
456 |
*
|
457 |
* A <code>null</code> or empty string means that library must detect this
|
458 |
* information.<br>
|
459 |
* <br>
|
460 |
* <strong>Note:</strong> see {@link #getPkFieldsString()}
|
461 |
*
|
462 |
* @return
|
463 |
* @see #getPkFieldsString()
|
464 |
* @see #setPkFields(String)
|
465 |
* @see #setPkFields(String[])
|
466 |
*/
|
467 |
public String[] getPkFields() { |
468 |
String fields = (String) this.getDynValue(PKFIELDS_PARAMTER_NAME); |
469 |
if (fields == null) { |
470 |
return null; |
471 |
} |
472 |
// FIXME check for fields with spaces and special chars
|
473 |
return fields.split(","); |
474 |
} |
475 |
|
476 |
/**
|
477 |
* Set a comma separated list of the field names that compound the primary
|
478 |
* key.<br>
|
479 |
* <br>
|
480 |
*
|
481 |
* A <code>null</code> or empty string means that library must detect this
|
482 |
* information.<br>
|
483 |
* <br>
|
484 |
* <strong>Note:</strong> see {@link #getPkFieldsString()}
|
485 |
*
|
486 |
* @return
|
487 |
* @see #getPkFields()
|
488 |
* @see #getPkFieldsString()
|
489 |
* @see #setPkFields(String[])
|
490 |
*/
|
491 |
public void setPkFields(String fields) { |
492 |
this.setDynValue(PKFIELDS_PARAMTER_NAME, fields);
|
493 |
} |
494 |
|
495 |
/**
|
496 |
* Set an array of the field names that compound the primary key.<br>
|
497 |
* <br>
|
498 |
*
|
499 |
* A <code>null</code> or empty string means that library must detect this
|
500 |
* information.<br>
|
501 |
* <br>
|
502 |
* <strong>Note:</strong> see {@link #getPkFieldsString()}
|
503 |
*
|
504 |
* @return
|
505 |
* @see #getPkFieldsString()
|
506 |
* @see #getPkFieldsString()
|
507 |
* @see #setPkFields(String)
|
508 |
*/
|
509 |
public void setPkFields(String[] fields) { |
510 |
StringBuilder str = new StringBuilder(); |
511 |
for (int i = 0; i < fields.length - 1; i++) { |
512 |
str.append(fields[i]); |
513 |
str.append(",");
|
514 |
} |
515 |
str.append(fields.length - 1);
|
516 |
|
517 |
this.setDynValue(PKFIELDS_PARAMTER_NAME, fields);
|
518 |
} |
519 |
|
520 |
/**
|
521 |
* Return the geometry field to use like default geometry (<i>see
|
522 |
* {@link Feature#getDefaultGeometry()}</i>)<br>
|
523 |
* <br>
|
524 |
*
|
525 |
* This option is supported only in geometry providers.<br>
|
526 |
* If this parameters is not set and store has only one field geometry then
|
527 |
* library uses that field as default
|
528 |
*
|
529 |
* @return
|
530 |
*
|
531 |
* @see #setDefaultGeometryField(String)
|
532 |
*/
|
533 |
public String getDefaultGeometryField() { |
534 |
return (String) this.getDynValue(DEFAULTGEOMETRY_PARAMTER_NAME); |
535 |
} |
536 |
|
537 |
/**
|
538 |
* Set the geometry field to use like default geometry.<br>
|
539 |
* See {@link #getDefaultGeometryField()} for description.
|
540 |
*
|
541 |
* @param geomName
|
542 |
*
|
543 |
* @see #getDefaultGeometryField()
|
544 |
*/
|
545 |
public void setDefaultGeometryField(String geomName) { |
546 |
this.setDynValue(DEFAULTGEOMETRY_PARAMTER_NAME, geomName);
|
547 |
} |
548 |
|
549 |
/**
|
550 |
* Get the filter by area of {@link #getDefaultGeometryField()} used in this
|
551 |
* store.<br>
|
552 |
* <br>
|
553 |
*
|
554 |
* Supported only for stores with geometric fields
|
555 |
*
|
556 |
* @return
|
557 |
*/
|
558 |
public Envelope getWorkingArea() {
|
559 |
return (Envelope) this.getDynValue(WORKINGAREA_PARAMTER_NAME); |
560 |
} |
561 |
|
562 |
/**
|
563 |
* Set the filter by area of {@link #getDefaultGeometryField()} used in this
|
564 |
* store.<br>
|
565 |
* <br>
|
566 |
*
|
567 |
* Supported only for stores with geometric fields
|
568 |
*
|
569 |
*/
|
570 |
public void setWorkingArea(Envelope workingArea) { |
571 |
this.setDynValue(WORKINGAREA_PARAMTER_NAME, workingArea);
|
572 |
} |
573 |
|
574 |
/**
|
575 |
* Set manually the SRS for the <code>default geometry</code> field of this
|
576 |
* layer.<br>
|
577 |
* <br>
|
578 |
*
|
579 |
* if is set to <code>null</code> or empty string means that the library
|
580 |
* must detect it automatically.<br>
|
581 |
* <br>
|
582 |
*
|
583 |
* Supported only for stores with geometric fields.
|
584 |
*
|
585 |
* @return
|
586 |
*
|
587 |
* @see #setSRSID(String)
|
588 |
* @see #getSRSID()
|
589 |
* @see #getSRS()
|
590 |
*/
|
591 |
public void setCRS(IProjection srs) { |
592 |
setDynValue(CRS_PARAMTER_NAME, srs); |
593 |
} |
594 |
|
595 |
public void setCRS(String srs) { |
596 |
setDynValue(CRS_PARAMTER_NAME, srs); |
597 |
} |
598 |
|
599 |
/**
|
600 |
* Get the SRS id string set manually for the <code>default geometry</code>
|
601 |
* field of this layer.<br>
|
602 |
* <br>
|
603 |
*
|
604 |
* if is set to <code>null</code> means that the library must detect it
|
605 |
* automatically.<br>
|
606 |
* <br>
|
607 |
*
|
608 |
* Supported only for stores with geometric fields.
|
609 |
*
|
610 |
* @return
|
611 |
*
|
612 |
* @see #setSRSID(String)
|
613 |
* @see #getSRS()
|
614 |
* @see #setSRS(IProjection)
|
615 |
*/
|
616 |
public IProjection getCRS() {
|
617 |
return (IProjection) getDynValue(CRS_PARAMTER_NAME);
|
618 |
} |
619 |
|
620 |
} |