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