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

History | View | Annotate | Download (15.8 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
/* gvSIG. Geographic Information System of the Valencian Government
25
*
26
* Copyright (C) 2007-2008 Infrastructures and Transports Department
27
* of the Valencian Government (CIT)
28
*
29
* This program is free software; you can redistribute it and/or
30
* modify it under the terms of the GNU General Public License
31
* as published by the Free Software Foundation; either version 2
32
* of the License, or (at your option) any later version.
33
*
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
* GNU General Public License for more details.
38
*
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
42
* MA  02110-1301, USA.
43
*
44
*/
45

    
46
/*
47
* AUTHORS (In addition to CIT):
48
* 2009 IVER T.I   {{Task}}
49
*/
50

    
51
package org.gvsig.fmap.dal.store.db;
52

    
53
import org.cresques.cts.IProjection;
54
import org.gvsig.fmap.dal.DataStoreParameters;
55
import org.gvsig.fmap.dal.feature.Feature;
56
import org.gvsig.fmap.dal.serverexplorer.db.DBConnectionParameter;
57
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
58
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
59
import org.gvsig.fmap.geom.primitive.Envelope;
60
import org.gvsig.tools.dynobject.DelegatedDynObject;
61

    
62
/**
63
 * Abstract Data base Store Parameters
64
 *
65
 * @author jmvivo
66
 *
67
 */
68
public abstract class DBStoreParameters extends AbstractDataParameters
69
                implements
70
                DataStoreParameters, DBConnectionParameter {
71

    
72
        public static final String PARAMETERS_DEFINITION_NAME = "DBStoreParameters";
73

    
74
        /**
75
         * Parameter name for specify the feature type in the creacion of
76
         * news stores.
77
         * 
78
         * Is defined only in "new" paramaters.
79
         *
80
         */
81
        public static final String FEATURETYPE_PARAMTER_NAME = "FeatureType";
82
    
83

    
84
        /**
85
         * Parameter name for <code>sql</code><br>
86
         *
87
         * @see #getSQL()
88
         * @see #setSQL(String)
89
         */
90
        public static final String SQL_PARAMTER_NAME = "SQL";
91

    
92
        /**
93
         * Parameter name for <code>fields</code><br>
94
         *
95
         * @see #getFields()
96
         * @see #getFieldsString()
97
         * @see #setFields(String)
98
         * @see #setFields(String[])
99
         */
100
        public static final String FIELDS_PARAMTER_NAME = "Fields";
101

    
102
        /**
103
         * Parameter name for <code>initial filter</code><br>
104
         *
105
         * @see #getBaseFilter()
106
         * @see #setBaseFilter(String)
107
         */
108
        public static final String BASEFILTER_PARAMTER_NAME = "BaseFilter";
109

    
110
        /**
111
         * Parameter name for <code>initial order</code><br>
112
         *
113
         * @see #getBaseOrder()
114
         * @see #setBaseOrder(String)
115
         */
116
        public static final String BASEORDER_PARAMTER_NAME = "BaseOrder";
117

    
118
        /**
119
         * Parameter name for <code>pk fields</code><br>
120
         *
121
         * @see #getPkFields()
122
         * @see #getPkFieldsString()
123
         * @see #setPkFields(String)
124
         * @see #setPkFields(String[])
125
         */
126
        public static final String PKFIELDS_PARAMTER_NAME = "PKFields";
127

    
128
        /**
129
         * Parameter name for <code>default geometry</code><br>
130
         *
131
         * @see #getDefaultGeometryField()
132
         * @see #setDefaultGeometryField(String)
133
         */
134
        public static final String DEFAULTGEOMETRY_PARAMTER_NAME = "DefaultGeometryField";
135

    
136
        /**
137
         * Parameter name for the name of <code>table</code><br>
138
         *
139
         * @see #getTable()
140
         * @see #setTable(String)
141
         */
142
        public static final String TABLE_PARAMTER_NAME = "Table";
143

    
144
        /**
145
         * Parameter name for <code>working area</code><br>O
146
         *
147
         * @see #getWorkingArea()
148
         * @see #setWorkingArea(Envelope)
149
         */
150
        public static final String WORKINGAREA_PARAMTER_NAME = "Workingarea";
151

    
152

    
153
        /**
154
         * Parameter name for <code>CRS</code><br>
155
         * 
156
         * @see #setSRSID(String)
157
         * @see #getSRS()
158
         * @see #setSRS(IProjection)
159
         */
160
        public static final String CRS_PARAMTER_NAME = "CRS";
161

    
162
        /**
163
         * This instance contains the value of the current parameters.
164
         */
165
        private DelegatedDynObject parameters;
166

    
167
        public DBStoreParameters(String parametersDefinitionName, String providerName) {
168
                this.parameters  = (DelegatedDynObject) DBHelper.newParameters(parametersDefinitionName);
169
                this.setDynValue( DataStoreProviderServices.PROVIDER_PARAMTER_NAME, providerName);
170
        }
171
        
172
        protected DelegatedDynObject getDelegatedDynObject() {
173
                return parameters;
174
        }
175

    
176
        public String getDataStoreName() {
177
                return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME);
178
        }
179

    
180
        public String getDescription() {
181
                return this.getDynClass().getDescription();
182
        }
183

    
184
        public boolean isValid() {
185
                return this.getHost() != null;
186
        }
187

    
188
        public String getHost() {
189
                return (String) this.getDynValue(HOST_PARAMTER_NAME);
190
        }
191

    
192
        public Integer getPort() {
193
                return (Integer) this.getDynValue(PORT_PARAMTER_NAME);
194
        }
195

    
196
        public String getDBName() {
197
                return (String) this.getDynValue(DBNAME_PARAMTER_NAME);
198
        }
199

    
200
        public String getUser() {
201
                return (String) this.getDynValue(USER_PARAMTER_NAME);
202
        }
203

    
204
        public String getPassword() {
205
                return (String) this.getDynValue(PASSWORD_PARAMTER_NAME);
206
        }
207

    
208
        public void setHost(String host) {
209
                this.setDynValue(HOST_PARAMTER_NAME, host);
210
        }
211

    
212
        public void setPort(int port) {
213
                this.setDynValue(PORT_PARAMTER_NAME, new Integer(port));
214
        }
215

    
216
        /**
217
         * Set <code>port/code> parameter value
218
         *
219
         * @param port
220
         */
221
        public void setPort(Integer port) {
222
                this.setDynValue(PORT_PARAMTER_NAME, port);
223
        }
224

    
225
        /**
226
         * Set <code>data base name/code> parameter value
227
         *
228
         * @param data
229
         *            base name
230
         */
231
        public void setDBName(String dbName) {
232
                this.setDynValue(DBNAME_PARAMTER_NAME, dbName);
233
        }
234

    
235
        /**
236
         * Set <code>user/code> parameter value
237
         *
238
         * @param user
239
         */
240
        public void setUser(String user) {
241
                this.setDynValue(USER_PARAMTER_NAME, user);
242
        }
243

    
244
        /**
245
         * Set <code>password/code> parameter value
246
         *
247
         * @param password
248
         */
249
        public void setPassword(String password) {
250
                this.setDynValue(PASSWORD_PARAMTER_NAME, password);
251
        }
252

    
253
        /**
254
         * Get <code>table</code> parameter value<br>
255
         * <br>
256
         *
257
         * This parameters describes what table or view we want to connect.<br>
258
         *
259
         * Not used if <code>sql</code> parameter set.
260
         *
261
         *
262
         * @param password
263
         *
264
         * @see #setTable(String)
265
         * @see #getSQL()
266
         * @see #setSQL(String)
267
         */
268
        public String getTable() {
269
                return (String) this.getDynValue(TABLE_PARAMTER_NAME);
270
        }
271

    
272
        /**
273
         * Set <code>table</code> parameter value<br>
274
         * <br>
275
         *
276
         * This parameters describes what table or view we want to connect.<br>
277
         *
278
         * Not used if <code>sql</code> parameter set.
279
         *
280
         *
281
         * @param password
282
         *
283
         * @see #getTable(String)
284
         * @see #getSQL()
285
         * @see #setSQL(String)
286
         */
287
        public void setTable(String table) {
288
                this.setDynValue(TABLE_PARAMTER_NAME, table);
289
        }
290

    
291
        /**
292
         * Get a comma separated list of the field names that we want to use.<br>
293
         * <br>
294
         *
295
         * A <code>null</code> or empty string means that we want all fields
296
         * available.
297
         *
298
         * @return
299
         * @see #getFields()
300
         * @see #setFields(String)
301
         * @see #setFields(String[])
302
         */
303
        public String getFieldsString() {
304
                return (String) this.getDynValue(FIELDS_PARAMTER_NAME);
305
        }
306

    
307
        /**
308
         * Get an array of the field names that we want to use.<br>
309
         * <br>
310
         *
311
         * A <code>null</code> means that we want all fields available.
312
         *
313
         * @return
314
         * @see #getFieldsString()
315
         * @see #setFields(String)
316
         * @see #setFields(String[])
317
         */
318
        public String[] getFields() {
319
                String fields = (String) this.getDynValue(FIELDS_PARAMTER_NAME);
320
                if (fields == null) {
321
                        return null;
322
                }
323
                // FIXME check for fields with spaces and special chars
324
                return fields.split(",");
325
        }
326

    
327
        /**
328
         * Set a comma separated list of the field names that we want to use.<br>
329
         * <br>
330
         *
331
         * A <code>null</code> means that we want all fields available.
332
         *
333
         * @return
334
         * @see #getFields()
335
         * @see #getFieldsString()
336
         * @see #setFields(String[])
337
         */
338
        public void setFields(String fields) {
339
                this.setDynValue(FIELDS_PARAMTER_NAME, fields);
340
        }
341

    
342
        /**
343
         * Set an array of the field names that we want to use.<br>
344
         * <br>
345
         *
346
         * A <code>null</code> means that we want all fields available.
347
         *
348
         * @return
349
         * @see #getFieldsString()
350
         * @see #getFields()
351
         * @see #setFields(String)
352
         */
353
        public void setFields(String[] fields) {
354
                StringBuilder str = new StringBuilder();
355
                for (int i = 0; i < fields.length - 1; i++) {
356
                        str.append(fields[i]);
357
                        str.append(",");
358
                }
359
                str.append(fields.length - 1);
360

    
361
                this.setDynValue(FIELDS_PARAMTER_NAME, fields);
362
        }
363

    
364
        /**
365
         * Get the SQL to use as source of the store instead a table or a view.<br>
366
         * <br>
367
         *
368
         * If this property is set the store changes his work flow:
369
         * <ul>
370
         * <li>store is in <i>read only</i> mode.</li>
371
         * <li><code>table</code> property is ignored.</li>
372
         * <li><code>pkFields</code> is not identified automatically</li>
373
         * <li>filter and order will be resolved locally <i>(pour performance)</i></li>
374
         * </ul>
375
         *
376
         * @return sql to use
377
         *
378
         * @see #getTable()
379
         * @see #setTable()
380
         * @see #getPkFields()
381
         * @see #setPkFields(String)
382
         */
383
        public String getSQL() {
384
                return (String) this.getDynValue(SQL_PARAMTER_NAME);
385
        }
386

    
387
        /**
388
         * Set the SQL to use as source of the store instead a table or a view.<br>
389
         * <br>
390
         * <strong>Note:</strong>see {@link #getSQL()} for description
391
         *
392
         * @see #getSQL()
393
         * @see #getTable()
394
         * @see #setTable()
395
         * @see #getPkFields()
396
         * @see #setPkFields(String)
397
         */
398
        public void setSQL(String sql) {
399
                this.setDynValue(SQL_PARAMTER_NAME, sql);
400
        }
401

    
402
        /**
403
         * Get initial filter to use.<br>
404
         * <br>
405
         *
406
         * This filter is passed to BD provider on each request as a base filter.
407
         *
408
         * @return filter
409
         *
410
         * @see #setBaseFilter(String)
411
         */
412
        public String getBaseFilter() {
413
                return (String) this.getDynValue(BASEFILTER_PARAMTER_NAME);
414
        }
415

    
416
        /**
417
         * Set initial filter to use.<br>
418
         * <br>
419
         *
420
         * This filter is passed to BD provider on each request as a base filter.
421
         *
422
         * @return filter
423
         *
424
         * @see #getInitialFilter(String)
425
         */
426
        public void setBaseFilter(String filter) {
427
                this.setDynValue(BASEFILTER_PARAMTER_NAME, filter);
428
        }
429

    
430
        /**
431
         * Get initial order to use.<br>
432
         * <br>
433
         *
434
         * This order is used if no custom order is request in query.
435
         *
436
         * @return order
437
         *
438
         * @see #setBaseOrder(String)
439
         */
440
        public String getBaseOrder() {
441
                return (String) this.getDynValue(BASEORDER_PARAMTER_NAME);
442
        }
443

    
444
        /**
445
         * Set initial order to use.<br>
446
         * <br>
447
         *
448
         * This order is used if no custom order is request in query.
449
         *
450
         * @return filter
451
         *
452
         * @see #getBaseOrder()
453
         */
454
        public void setBaseOrder(String order) {
455
                this.setDynValue(BASEORDER_PARAMTER_NAME, order);
456
        }
457

    
458
        /**
459
         * Get a comma separated list of the field names that compound the primary
460
         * key.<br>
461
         * <br>
462
         *
463
         * A <code>null</code> or empty string means that library must detect this
464
         * information.<br>
465
         * <br>
466
         * <strong>Note:</strong>If this parameters is undefined, the library can't
467
         * do this detection, some services will don't be available for this store
468
         * (<i>like selection, editing or {@link Feature#getReference()}</i>)
469
         *
470
         * @return
471
         * @see #getPkFields()
472
         * @see #setPkFields(String)
473
         * @see #setPkFields(String[])
474
         */
475
        public String getPkFieldsString() {
476
                return (String) this.getDynValue(PKFIELDS_PARAMTER_NAME);
477
        }
478

    
479
        /**
480
         * Get an array of the field names that compound the primary key.<br>
481
         * <br>
482
         *
483
         * A <code>null</code> or empty string means that library must detect this
484
         * information.<br>
485
         * <br>
486
         * <strong>Note:</strong> see {@link #getPkFieldsString()}
487
         *
488
         * @return
489
         * @see #getPkFieldsString()
490
         * @see #setPkFields(String)
491
         * @see #setPkFields(String[])
492
         */
493
        public String[] getPkFields() {
494
                String fields = (String) this.getDynValue(PKFIELDS_PARAMTER_NAME);
495
                if (fields == null) {
496
                        return null;
497
                }
498
                // FIXME check for fields with spaces and special chars
499
                return fields.split(",");
500
        }
501

    
502
        /**
503
         * Set a comma separated list of the field names that compound the primary
504
         * key.<br>
505
         * <br>
506
         *
507
         * A <code>null</code> or empty string means that library must detect this
508
         * information.<br>
509
         * <br>
510
         * <strong>Note:</strong> see {@link #getPkFieldsString()}
511
         *
512
         * @return
513
         * @see #getPkFields()
514
         * @see #getPkFieldsString()
515
         * @see #setPkFields(String[])
516
         */
517
        public void setPkFields(String fields) {
518
                this.setDynValue(PKFIELDS_PARAMTER_NAME, fields);
519
        }
520

    
521
        /**
522
         * Set an array of the field names that compound the primary key.<br>
523
         * <br>
524
         *
525
         * A <code>null</code> or empty string means that library must detect this
526
         * information.<br>
527
         * <br>
528
         * <strong>Note:</strong> see {@link #getPkFieldsString()}
529
         *
530
         * @return
531
         * @see #getPkFieldsString()
532
         * @see #getPkFieldsString()
533
         * @see #setPkFields(String)
534
         */
535
        public void setPkFields(String[] fields) {
536
                StringBuilder str = new StringBuilder();
537
                for (int i = 0; i < fields.length - 1; i++) {
538
                        str.append(fields[i]);
539
                        str.append(",");
540
                }
541
                str.append(fields.length - 1);
542

    
543
                this.setDynValue(PKFIELDS_PARAMTER_NAME, fields);
544
        }
545

    
546
        /**
547
         * Return the geometry field to use like default geometry (<i>see
548
         * {@link Feature#getDefaultGeometry()}</i>)<br>
549
         * <br>
550
         *
551
         * This option is supported only in geometry providers.<br>
552
         * If this parameters is not set and store has only one field geometry then
553
         * library uses that field as default
554
         *
555
         * @return
556
         *
557
         * @see #setDefaultGeometryField(String)
558
         */
559
        public String getDefaultGeometryField() {
560
                return (String) this.getDynValue(DEFAULTGEOMETRY_PARAMTER_NAME);
561
        }
562

    
563
        /**
564
         * Set the geometry field to use like default geometry.<br>
565
         * See {@link #getDefaultGeometryField()} for description.
566
         *
567
         * @param geomName
568
         *
569
         * @see #getDefaultGeometryField()
570
         */
571
        public void setDefaultGeometryField(String geomName) {
572
                this.setDynValue(DEFAULTGEOMETRY_PARAMTER_NAME, geomName);
573
        }
574

    
575
        /**
576
         * Get the filter by area of {@link #getDefaultGeometryField()} used in this
577
         * store.<br>
578
         * <br>
579
         *
580
         * Supported only for stores with geometric fields
581
         *
582
         * @return
583
         */
584
        public Envelope getWorkingArea() {
585
                return (Envelope) this.getDynValue(WORKINGAREA_PARAMTER_NAME);
586
        }
587

    
588
        /**
589
         * Set the filter by area of {@link #getDefaultGeometryField()} used in this
590
         * store.<br>
591
         * <br>
592
         *
593
         * Supported only for stores with geometric fields
594
         *
595
         */
596
        public void setWorkingArea(Envelope workingArea) {
597
                this.setDynValue(WORKINGAREA_PARAMTER_NAME, workingArea);
598
        }
599

    
600
        /**
601
         * Set manually the SRS for the <code>default geometry</code> field of this
602
         * layer.<br>
603
         * <br>
604
         * 
605
         * if is set to <code>null</code> or empty string means that the library
606
         * must detect it automatically.<br>
607
         * <br>
608
         * 
609
         * Supported only for stores with geometric fields.
610
         * 
611
         * @return
612
         * 
613
         * @see #setSRSID(String)
614
         * @see #getSRSID()
615
         * @see #getSRS()
616
         */
617
        public void setCRS(IProjection srs) {
618
                setDynValue(CRS_PARAMTER_NAME, srs);
619
        }
620

    
621
        public void setCRS(String srs) {
622
                setDynValue(CRS_PARAMTER_NAME, srs);
623
        }
624

    
625
        /**
626
         * Get the SRS id string set manually for the <code>default geometry</code>
627
         * field of this layer.<br>
628
         * <br>
629
         *
630
         * if is set to <code>null</code> means that the library must detect it
631
         * automatically.<br>
632
         * <br>
633
         *
634
         * Supported only for stores with geometric fields.
635
         *
636
         * @return
637
         *
638
         * @see #setSRSID(String)
639
         * @see #getSRS()
640
         * @see #setSRS(IProjection)
641
         */
642
        public IProjection getCRS() {
643
                return (IProjection) getDynValue(CRS_PARAMTER_NAME);
644
        }
645

    
646
}