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