Statistics
| Revision:

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 @ 40435

History | View | Annotate | Download (14.9 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.db;
29

    
30
import org.cresques.cts.IProjection;
31
import org.gvsig.fmap.dal.DataStoreParameters;
32
import org.gvsig.fmap.dal.feature.Feature;
33
import org.gvsig.fmap.dal.serverexplorer.db.DBConnectionParameter;
34
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
35
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
36
import org.gvsig.fmap.geom.primitive.Envelope;
37
import org.gvsig.tools.dynobject.DelegatedDynObject;
38

    
39
/**
40
 * Abstract Data base Store Parameters
41
 *
42
 * @author jmvivo
43
 *
44
 */
45
public abstract class DBStoreParameters extends AbstractDataParameters
46
                implements
47
                DataStoreParameters, DBConnectionParameter {
48

    
49
        public static final String PARAMETERS_DEFINITION_NAME = "DBStoreParameters";
50

    
51
        /**
52
         * Parameter name for specify the feature type in the creacion of
53
         * news stores.
54
         * 
55
         * Is defined only in "new" paramaters.
56
         *
57
         */
58
        public static final String FEATURETYPE_PARAMTER_NAME = "FeatureType";
59
    
60

    
61
        /**
62
         * Parameter name for <code>sql</code><br>
63
         *
64
         * @see #getSQL()
65
         * @see #setSQL(String)
66
         */
67
        public static final String SQL_PARAMTER_NAME = "SQL";
68

    
69
        /**
70
         * Parameter name for <code>fields</code><br>
71
         *
72
         * @see #getFields()
73
         * @see #getFieldsString()
74
         * @see #setFields(String)
75
         * @see #setFields(String[])
76
         */
77
        public static final String FIELDS_PARAMTER_NAME = "Fields";
78

    
79
        /**
80
         * Parameter name for <code>initial filter</code><br>
81
         *
82
         * @see #getBaseFilter()
83
         * @see #setBaseFilter(String)
84
         */
85
        public static final String BASEFILTER_PARAMTER_NAME = "BaseFilter";
86

    
87
        /**
88
         * Parameter name for <code>initial order</code><br>
89
         *
90
         * @see #getBaseOrder()
91
         * @see #setBaseOrder(String)
92
         */
93
        public static final String BASEORDER_PARAMTER_NAME = "BaseOrder";
94

    
95
        /**
96
         * Parameter name for <code>pk fields</code><br>
97
         *
98
         * @see #getPkFields()
99
         * @see #getPkFieldsString()
100
         * @see #setPkFields(String)
101
         * @see #setPkFields(String[])
102
         */
103
        public static final String PKFIELDS_PARAMTER_NAME = "PKFields";
104

    
105
        /**
106
         * Parameter name for <code>default geometry</code><br>
107
         *
108
         * @see #getDefaultGeometryField()
109
         * @see #setDefaultGeometryField(String)
110
         */
111
        public static final String DEFAULTGEOMETRY_PARAMTER_NAME = "DefaultGeometryField";
112

    
113
        /**
114
         * Parameter name for the name of <code>table</code><br>
115
         *
116
         * @see #getTable()
117
         * @see #setTable(String)
118
         */
119
        public static final String TABLE_PARAMTER_NAME = "Table";
120

    
121
        /**
122
         * Parameter name for <code>working area</code><br>O
123
         *
124
         * @see #getWorkingArea()
125
         * @see #setWorkingArea(Envelope)
126
         */
127
        public static final String WORKINGAREA_PARAMTER_NAME = "Workingarea";
128

    
129

    
130
        /**
131
         * Parameter name for <code>CRS</code><br>
132
         * 
133
         * @see #setSRSID(String)
134
         * @see #getSRS()
135
         * @see #setSRS(IProjection)
136
         */
137
        public static final String CRS_PARAMTER_NAME = "CRS";
138

    
139
        /**
140
         * This instance contains the value of the current parameters.
141
         */
142
        private DelegatedDynObject parameters;
143

    
144
        public DBStoreParameters(String parametersDefinitionName, String providerName) {
145
                this.parameters  = (DelegatedDynObject) DBHelper.newParameters(parametersDefinitionName);
146
                this.setDynValue( DataStoreProviderServices.PROVIDER_PARAMTER_NAME, providerName);
147
        }
148
        
149
        protected DelegatedDynObject getDelegatedDynObject() {
150
                return parameters;
151
        }
152

    
153
        public String getDataStoreName() {
154
                return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME);
155
        }
156

    
157
        public String getDescription() {
158
                return this.getDynClass().getDescription();
159
        }
160

    
161
        public boolean isValid() {
162
                return this.getHost() != null;
163
        }
164

    
165
        public String getHost() {
166
                return (String) this.getDynValue(HOST_PARAMTER_NAME);
167
        }
168

    
169
        public Integer getPort() {
170
                return (Integer) this.getDynValue(PORT_PARAMTER_NAME);
171
        }
172

    
173
        public String getDBName() {
174
                return (String) this.getDynValue(DBNAME_PARAMTER_NAME);
175
        }
176

    
177
        public String getUser() {
178
                return (String) this.getDynValue(USER_PARAMTER_NAME);
179
        }
180

    
181
        public String getPassword() {
182
                return (String) this.getDynValue(PASSWORD_PARAMTER_NAME);
183
        }
184

    
185
        public void setHost(String host) {
186
                this.setDynValue(HOST_PARAMTER_NAME, host);
187
        }
188

    
189
        public void setPort(int port) {
190
                this.setDynValue(PORT_PARAMTER_NAME, new Integer(port));
191
        }
192

    
193
        /**
194
         * Set <code>port/code> parameter value
195
         *
196
         * @param port
197
         */
198
        public void setPort(Integer port) {
199
                this.setDynValue(PORT_PARAMTER_NAME, port);
200
        }
201

    
202
        /**
203
         * Set <code>data base name/code> parameter value
204
         *
205
         * @param data
206
         *            base name
207
         */
208
        public void setDBName(String dbName) {
209
                this.setDynValue(DBNAME_PARAMTER_NAME, dbName);
210
        }
211

    
212
        /**
213
         * Set <code>user/code> parameter value
214
         *
215
         * @param user
216
         */
217
        public void setUser(String user) {
218
                this.setDynValue(USER_PARAMTER_NAME, user);
219
        }
220

    
221
        /**
222
         * Set <code>password/code> parameter value
223
         *
224
         * @param password
225
         */
226
        public void setPassword(String password) {
227
                this.setDynValue(PASSWORD_PARAMTER_NAME, password);
228
        }
229

    
230
        /**
231
         * Get <code>table</code> parameter value<br>
232
         * <br>
233
         *
234
         * This parameters describes what table or view we want to connect.<br>
235
         *
236
         * Not used if <code>sql</code> parameter set.
237
         *
238
         *
239
         * @param password
240
         *
241
         * @see #setTable(String)
242
         * @see #getSQL()
243
         * @see #setSQL(String)
244
         */
245
        public String getTable() {
246
                return (String) this.getDynValue(TABLE_PARAMTER_NAME);
247
        }
248

    
249
        /**
250
         * Set <code>table</code> parameter value<br>
251
         * <br>
252
         *
253
         * This parameters describes what table or view we want to connect.<br>
254
         *
255
         * Not used if <code>sql</code> parameter set.
256
         *
257
         *
258
         * @param password
259
         *
260
         * @see #getTable(String)
261
         * @see #getSQL()
262
         * @see #setSQL(String)
263
         */
264
        public void setTable(String table) {
265
                this.setDynValue(TABLE_PARAMTER_NAME, table);
266
        }
267

    
268
        /**
269
         * Get a comma separated list of the field names that we want to use.<br>
270
         * <br>
271
         *
272
         * A <code>null</code> or empty string means that we want all fields
273
         * available.
274
         *
275
         * @return
276
         * @see #getFields()
277
         * @see #setFields(String)
278
         * @see #setFields(String[])
279
         */
280
        public String getFieldsString() {
281
                return (String) this.getDynValue(FIELDS_PARAMTER_NAME);
282
        }
283

    
284
        /**
285
         * Get an array of the field names that we want to use.<br>
286
         * <br>
287
         *
288
         * A <code>null</code> means that we want all fields available.
289
         *
290
         * @return
291
         * @see #getFieldsString()
292
         * @see #setFields(String)
293
         * @see #setFields(String[])
294
         */
295
        public String[] getFields() {
296
                String fields = (String) this.getDynValue(FIELDS_PARAMTER_NAME);
297
                if (fields == null) {
298
                        return null;
299
                }
300
                // FIXME check for fields with spaces and special chars
301
                return fields.split(",");
302
        }
303

    
304
        /**
305
         * Set a comma separated list of the field names that we want to use.<br>
306
         * <br>
307
         *
308
         * A <code>null</code> means that we want all fields available.
309
         *
310
         * @return
311
         * @see #getFields()
312
         * @see #getFieldsString()
313
         * @see #setFields(String[])
314
         */
315
        public void setFields(String fields) {
316
                this.setDynValue(FIELDS_PARAMTER_NAME, fields);
317
        }
318

    
319
        /**
320
         * Set an array of the field names that we want to use.<br>
321
         * <br>
322
         *
323
         * A <code>null</code> means that we want all fields available.
324
         *
325
         * @return
326
         * @see #getFieldsString()
327
         * @see #getFields()
328
         * @see #setFields(String)
329
         */
330
        public void setFields(String[] fields) {
331
                StringBuilder str = new StringBuilder();
332
                for (int i = 0; i < fields.length - 1; i++) {
333
                        str.append(fields[i]);
334
                        str.append(",");
335
                }
336
                str.append(fields.length - 1);
337

    
338
                this.setDynValue(FIELDS_PARAMTER_NAME, fields);
339
        }
340

    
341
        /**
342
         * Get the SQL to use as source of the store instead a table or a view.<br>
343
         * <br>
344
         *
345
         * If this property is set the store changes his work flow:
346
         * <ul>
347
         * <li>store is in <i>read only</i> mode.</li>
348
         * <li><code>table</code> property is ignored.</li>
349
         * <li><code>pkFields</code> is not identified automatically</li>
350
         * <li>filter and order will be resolved locally <i>(pour performance)</i></li>
351
         * </ul>
352
         *
353
         * @return sql to use
354
         *
355
         * @see #getTable()
356
         * @see #setTable()
357
         * @see #getPkFields()
358
         * @see #setPkFields(String)
359
         */
360
        public String getSQL() {
361
                return (String) this.getDynValue(SQL_PARAMTER_NAME);
362
        }
363

    
364
        /**
365
         * Set the SQL to use as source of the store instead a table or a view.<br>
366
         * <br>
367
         * <strong>Note:</strong>see {@link #getSQL()} for description
368
         *
369
         * @see #getSQL()
370
         * @see #getTable()
371
         * @see #setTable()
372
         * @see #getPkFields()
373
         * @see #setPkFields(String)
374
         */
375
        public void setSQL(String sql) {
376
                this.setDynValue(SQL_PARAMTER_NAME, sql);
377
        }
378

    
379
        /**
380
         * Get initial filter to use.<br>
381
         * <br>
382
         *
383
         * This filter is passed to BD provider on each request as a base filter.
384
         *
385
         * @return filter
386
         *
387
         * @see #setBaseFilter(String)
388
         */
389
        public String getBaseFilter() {
390
                return (String) this.getDynValue(BASEFILTER_PARAMTER_NAME);
391
        }
392

    
393
        /**
394
         * Set initial filter to use.<br>
395
         * <br>
396
         *
397
         * This filter is passed to BD provider on each request as a base filter.
398
         *
399
         * @return filter
400
         *
401
         * @see #getInitialFilter(String)
402
         */
403
        public void setBaseFilter(String filter) {
404
                this.setDynValue(BASEFILTER_PARAMTER_NAME, filter);
405
        }
406

    
407
        /**
408
         * Get initial order to use.<br>
409
         * <br>
410
         *
411
         * This order is used if no custom order is request in query.
412
         *
413
         * @return order
414
         *
415
         * @see #setBaseOrder(String)
416
         */
417
        public String getBaseOrder() {
418
                return (String) this.getDynValue(BASEORDER_PARAMTER_NAME);
419
        }
420

    
421
        /**
422
         * Set initial order to use.<br>
423
         * <br>
424
         *
425
         * This order is used if no custom order is request in query.
426
         *
427
         * @return filter
428
         *
429
         * @see #getBaseOrder()
430
         */
431
        public void setBaseOrder(String order) {
432
                this.setDynValue(BASEORDER_PARAMTER_NAME, order);
433
        }
434

    
435
        /**
436
         * Get a comma separated list of the field names that compound the primary
437
         * 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>If this parameters is undefined, the library can't
444
         * do this detection, some services will don't be available for this store
445
         * (<i>like selection, editing or {@link Feature#getReference()}</i>)
446
         *
447
         * @return
448
         * @see #getPkFields()
449
         * @see #setPkFields(String)
450
         * @see #setPkFields(String[])
451
         */
452
        public String getPkFieldsString() {
453
                return (String) this.getDynValue(PKFIELDS_PARAMTER_NAME);
454
        }
455

    
456
        /**
457
         * Get an array of the field names that compound the primary key.<br>
458
         * <br>
459
         *
460
         * A <code>null</code> or empty string means that library must detect this
461
         * information.<br>
462
         * <br>
463
         * <strong>Note:</strong> see {@link #getPkFieldsString()}
464
         *
465
         * @return
466
         * @see #getPkFieldsString()
467
         * @see #setPkFields(String)
468
         * @see #setPkFields(String[])
469
         */
470
        public String[] getPkFields() {
471
                String fields = (String) this.getDynValue(PKFIELDS_PARAMTER_NAME);
472
                if (fields == null) {
473
                        return null;
474
                }
475
                // FIXME check for fields with spaces and special chars
476
                return fields.split(",");
477
        }
478

    
479
        /**
480
         * Set a comma separated list of the field names that compound the primary
481
         * key.<br>
482
         * <br>
483
         *
484
         * A <code>null</code> or empty string means that library must detect this
485
         * information.<br>
486
         * <br>
487
         * <strong>Note:</strong> see {@link #getPkFieldsString()}
488
         *
489
         * @return
490
         * @see #getPkFields()
491
         * @see #getPkFieldsString()
492
         * @see #setPkFields(String[])
493
         */
494
        public void setPkFields(String fields) {
495
                this.setDynValue(PKFIELDS_PARAMTER_NAME, fields);
496
        }
497

    
498
        /**
499
         * Set an array of the field names that compound the primary key.<br>
500
         * <br>
501
         *
502
         * A <code>null</code> or empty string means that library must detect this
503
         * information.<br>
504
         * <br>
505
         * <strong>Note:</strong> see {@link #getPkFieldsString()}
506
         *
507
         * @return
508
         * @see #getPkFieldsString()
509
         * @see #getPkFieldsString()
510
         * @see #setPkFields(String)
511
         */
512
        public void setPkFields(String[] fields) {
513
                StringBuilder str = new StringBuilder();
514
                for (int i = 0; i < fields.length - 1; i++) {
515
                        str.append(fields[i]);
516
                        str.append(",");
517
                }
518
                str.append(fields.length - 1);
519

    
520
                this.setDynValue(PKFIELDS_PARAMTER_NAME, fields);
521
        }
522

    
523
        /**
524
         * Return the geometry field to use like default geometry (<i>see
525
         * {@link Feature#getDefaultGeometry()}</i>)<br>
526
         * <br>
527
         *
528
         * This option is supported only in geometry providers.<br>
529
         * If this parameters is not set and store has only one field geometry then
530
         * library uses that field as default
531
         *
532
         * @return
533
         *
534
         * @see #setDefaultGeometryField(String)
535
         */
536
        public String getDefaultGeometryField() {
537
                return (String) this.getDynValue(DEFAULTGEOMETRY_PARAMTER_NAME);
538
        }
539

    
540
        /**
541
         * Set the geometry field to use like default geometry.<br>
542
         * See {@link #getDefaultGeometryField()} for description.
543
         *
544
         * @param geomName
545
         *
546
         * @see #getDefaultGeometryField()
547
         */
548
        public void setDefaultGeometryField(String geomName) {
549
                this.setDynValue(DEFAULTGEOMETRY_PARAMTER_NAME, geomName);
550
        }
551

    
552
        /**
553
         * Get 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
         * @return
560
         */
561
        public Envelope getWorkingArea() {
562
                return (Envelope) this.getDynValue(WORKINGAREA_PARAMTER_NAME);
563
        }
564

    
565
        /**
566
         * Set the filter by area of {@link #getDefaultGeometryField()} used in this
567
         * store.<br>
568
         * <br>
569
         *
570
         * Supported only for stores with geometric fields
571
         *
572
         */
573
        public void setWorkingArea(Envelope workingArea) {
574
                this.setDynValue(WORKINGAREA_PARAMTER_NAME, workingArea);
575
        }
576

    
577
        /**
578
         * Set manually the SRS for the <code>default geometry</code> field of this
579
         * layer.<br>
580
         * <br>
581
         * 
582
         * if is set to <code>null</code> or empty string means that the library
583
         * must detect it automatically.<br>
584
         * <br>
585
         * 
586
         * Supported only for stores with geometric fields.
587
         * 
588
         * @return
589
         * 
590
         * @see #setSRSID(String)
591
         * @see #getSRSID()
592
         * @see #getSRS()
593
         */
594
        public void setCRS(IProjection srs) {
595
                setDynValue(CRS_PARAMTER_NAME, srs);
596
        }
597

    
598
        public void setCRS(String srs) {
599
                setDynValue(CRS_PARAMTER_NAME, srs);
600
        }
601

    
602
        /**
603
         * Get the SRS id string set manually for the <code>default geometry</code>
604
         * field of this layer.<br>
605
         * <br>
606
         *
607
         * if is set to <code>null</code> means that the library must detect it
608
         * automatically.<br>
609
         * <br>
610
         *
611
         * Supported only for stores with geometric fields.
612
         *
613
         * @return
614
         *
615
         * @see #setSRSID(String)
616
         * @see #getSRS()
617
         * @see #setSRS(IProjection)
618
         */
619
        public IProjection getCRS() {
620
                return (IProjection) getDynValue(CRS_PARAMTER_NAME);
621
        }
622

    
623
}