Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.api / src / main / java / org / gvsig / fmap / dal / DataStore.java @ 47197

History | View | Annotate | Download (11.6 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
package org.gvsig.fmap.dal;
25

    
26
import java.util.Collection;
27

    
28
import org.gvsig.fmap.dal.exception.DataException;
29
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
30
import org.gvsig.metadata.Metadata;
31
import org.gvsig.timesupport.Interval;
32
import org.gvsig.timesupport.Time;
33
import org.gvsig.tools.dispose.Disposable;
34
import org.gvsig.tools.dynobject.DynObject;
35
import org.gvsig.tools.dynobject.DynObject_v2;
36
import org.gvsig.tools.exception.BaseException;
37
import org.gvsig.tools.observer.ComplexWeakReferencingObservable;
38
import org.gvsig.tools.observer.Observer;
39
import org.gvsig.tools.persistence.Persistent;
40
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
41
import org.gvsig.tools.service.spi.Services;
42
import org.gvsig.tools.util.UnmodifiableBasicMap;
43
import org.gvsig.tools.visitor.Visitable;
44
import org.gvsig.tools.visitor.Visitor;
45

    
46
/**
47
 * <p>
48
 * This is the basic interface for all data stores. Depending on the context, it
49
 * can represent a geographic layer, an alphanumeric database table or any data
50
 * file. DataStore offers generic services like:
51
 * <ul>
52
 * <li>Open and close data stores</li>
53
 * <li>Access to data sets, with the possibility of loading data in background.</li>
54
 * <li>Use of selection and locks, as well as data sets</li>
55
 * <li>Editing</li>
56
 * <li>Register event observers through the Observable interface</li>
57
 * <li>Access to embedded data stores (like GML)</li>
58
 * <li>Information about the Spatial Reference Systems used by the data store</li>
59
 * </ul>
60
 * </p>
61
 * <br>
62
 *
63
 */
64
public interface DataStore extends ComplexWeakReferencingObservable,
65
                Persistent, Metadata, Disposable, Visitable, DataFactoryUnit, Services, DynObject_v2 {
66

    
67
    public static String getFullNameQuietly(DataStore store) {
68
        try {
69
            return store.getFullName();
70
        } catch(Throwable th) {
71
            return null;
72
        }
73
    }
74

    
75
    public static String getNameQuietly(DataStore store) {
76
        try {
77
            return store.getName();
78
        } catch(Throwable th) {
79
            return null;
80
        }
81
    }
82
        public static final String SHAPE_PROVIDER_NAME = "Shape";
83
        public static final String DBASE_PROVIDER_NAME = "DBF";
84
        public static final String CSV_PROVIDER_NAME = "CSV";
85
        public static final String H2SPATIAL_PROVIDER_NAME = "H2Spatial";
86
        public static final String MDB_PROVIDER_NAME = "MDB";
87
    
88
        public static final String METADATA_DEFINITION_NAME = "DataProvider";
89

    
90
        public static final String FEATURE_METADATA_DEFINITION_NAME = "FeatureProvider";
91

    
92
        public static final String SPATIAL_METADATA_DEFINITION_NAME = "SpatialProvider";
93

    
94
        /**
95
         * Metadata property name for the provider name provided by the data provider.
96
         *
97
         * This metadata is provided by all data providers.
98
         */
99
        public static final String METADATA_PROVIDER = "ProviderName";
100

    
101
        /**
102
         * Metadata property name for Container name provided by the data provider.
103
         * By explample, in a dbf file, this is the name of dbf.
104
         *
105
         * This metadata is provided by all data providers.
106
         */
107
        public static final String METADATA_CONTAINERNAME = "ContainerName";
108

    
109
        /**
110
         * Metadata property name for the feature type provided by the data provider.
111
         *
112
         * This metadata is provided by all tabular data providers.
113
         */
114
        public static final String METADATA_FEATURETYPE = "FeatureType";
115

    
116
        /**
117
         * Metadata property name for CRS provided by the data provider.
118
         *
119
         * This metadata is only provided by data provider with spatial
120
         * information.
121
         */
122
        public static final String METADATA_CRS = "CRS";
123

    
124
        /**
125
         * Metadata property name for Envelope provided by the data provider
126
         *
127
         * This metadata is only provided by data provider with spatial
128
         * information.
129
         */
130
        public static final String METADATA_ENVELOPE = "Envelope";
131

    
132
        /**
133
         * Returns the name associated to the store.
134
         * This name is provided for informational purposes only.
135
         * Explamples:
136
         *
137
         * In a dbf the filename without the path
138
         *
139
         * In a DDBB table the name of the table
140
         *
141
         * In a WFS layer the name of the layer.
142
         *
143
         * @return String containing this store's name.
144
         */
145
        public String getName();
146

    
147
        /**
148
         * Returns a more descriptive name for the store that getName.
149
         * This name is provided for informational purposes only.
150
         * Explamples:
151
         *
152
         * In a file based store may return the full name of the filename, path and filename.
153
         *
154
         * In a data base based store may return "server:dbname:tablename"
155
         *
156
         * In a WFS layer based store may return "server:layername"
157
         *
158
         * @return String Containing the full name of the store
159
         */
160
        public String getFullName();
161

    
162
        /**
163
         * Return the of parameters of this store
164
         *
165
         * @return parameters of this store
166
         */
167
        public DataStoreParameters getParameters();
168

    
169
        /**
170
         * Return the provider name that use this store.
171
         *
172
         * @return provider name of this store
173
         */
174
        public String getProviderName();
175

    
176
        /**
177
         * Refreshes this store state.
178
         *
179
         * @throws DataException
180
         */
181
        public void refresh() throws DataException;
182

    
183
        /**
184
         * Returns all available data.
185
         *
186
         * @return a set of data
187
         * @throws DataException
188
         *             if there is any error while loading the data
189
         */
190
        DataSet getDataSet() throws DataException;
191

    
192
        /**
193
         * Returns a subset of data taking into account the properties and
194
         * restrictions of the DataQuery.
195
         *
196
         * @param dataQuery
197
         *            defines the properties of the requested data
198
         * @return a set of data
199
         * @throws DataException
200
         *             if there is any error while loading the data
201
         */
202
        DataSet getDataSet(DataQuery dataQuery) throws DataException;
203

    
204
    /**
205
     * Provides each value of this Store to the provided {@link Visitor}.
206
     * The values received through the {@link Visitor#visit(Object)} method
207
     * may be transient, reused or externally modifiable, so they can't
208
     * be used to be stored in any external form out of the visit method.
209
     *
210
     * If you need to store any of the values out of the
211
     * {@link Visitor#visit(Object)} method execution, create a copy or clone
212
     * the received value in order to be stored.
213
     *
214
     * @param visitor
215
     *            the visitor to apply to each value.
216
     * @exception BaseException
217
     *                if there is an error while performing the visit
218
     */
219
    public void accept(Visitor visitor) throws BaseException;
220

    
221
        /**
222
     * Provides each value of this Store to the provided {@link Visitor}.
223
     * The values received through the {@link Visitor#visit(Object)} method
224
     * may be transient, reused or externally modifiable, so they can't
225
     * be used to be stored in any external form out of the visit method.
226
     *
227
     * If you need to store any of the values out of the
228
     * {@link Visitor#visit(Object)} method execution, create a copy or clone
229
     * the received value in order to be stored.
230
     *
231
     * @param visitor
232
     *            the visitor to apply to each value.
233
     * @param dataQuery
234
     *            defines the properties of the data to visit
235
     * @exception BaseException
236
     *                if there is an error while performing the visit
237
     */
238
        public void accept(Visitor visitor, DataQuery dataQuery)
239
                        throws BaseException;
240

    
241
        /**
242
         * Loads all available data and notifies the observer for each loaded block of data.
243
         *
244
         * @param observer
245
         *            to be notified for each block of data loaded
246
         * @throws DataException
247
         *             if there is any error while loading the data
248
         */
249
        void getDataSet(Observer observer) throws DataException;
250

    
251
        /**
252
         * Loads a subset of data taking into account the properties and
253
         * restrictions of the DataQuery. Data loading is performed by calling the
254
         * Observer, once each data block is loaded.
255
         *
256
         * @param dataQuery
257
         *            defines the properties of the requested data
258
         * @param observer
259
         *            to be notified for each block of data loaded
260
         * @throws DataException
261
         *             if there is any error while loading the data
262
         */
263
        void getDataSet(DataQuery dataQuery, Observer observer) throws DataException;
264

    
265
        /**
266
         * Returns the selected set of data
267
         *
268
         * @return DataSet
269
         * @throws org.gvsig.fmap.dal.exception.DataException
270
         */
271

    
272
        public DataSet getSelection() throws DataException;
273

    
274
        /**
275
         * Sets the current data selection with the given data set.
276
         *
277
         * @param selection
278
         * @throws DataException
279
         */
280
        public void setSelection(DataSet selection) throws DataException;
281

    
282
        /**
283
         * Creates a new selection.
284
         *
285
         * @return DataSet that contains the selection
286
         *
287
         * @throws DataException
288
         */
289
        public DataSet createSelection() throws DataException;
290

    
291
        /**
292
         * Returns an UnmodifiableBasicMap with this store children.
293
         * If do not have children, return an empty map.
294
         * Never returns null.
295
         *
296
         * @return an UnmodifiableBasicMap with this DataStore children
297
         */
298
        public UnmodifiableBasicMap<String,DataStore> getChildren();
299
        
300

    
301
        /**
302
         * Returns the DataServerExplorer to which this DataStore belongs, if there
303
         * is any.
304
         * This server explorer can be disposed.
305
         *
306
         * @return DataServerExplorer to which this DataStore belongs, or
307
         *         <code>null</code> if this was not accessed through any
308
         *         DataServerExplorer.
309
         *
310
         * @throws DataException
311
         * @throws ValidateDataParametersException
312
         */
313
        public DataServerExplorer getExplorer() throws DataException,
314
                        ValidateDataParametersException;
315

    
316

    
317
        /**
318
         * Returns a new instance of a {@link DataQuery}.
319
         *
320
         * @return new {@link DataQuery} instance.
321
         */
322
        public DataQuery createQuery();
323

    
324
        /**
325
         * Gets the {@link Interval} of the store, that means the temporal
326
         * interval where the store has valid data.
327
         * @return
328
         *         a time interval or null if there is not time support
329
         */
330
        public Interval getInterval();
331

    
332
        /**
333
         * Gets all the possible values of time for which the store has data.
334
         * @return
335
         *         a collection of {@link Time} objects.
336
         */
337
        public Collection getTimes();
338

    
339
        /**
340
         * Gets all the possible values of time for which the store has data
341
         * and intersects with an interval.
342
         * @param interval
343
         *         the interval of time
344
         * @return
345
         *         a collection of {@link Time} objects.
346
         */
347
        public Collection getTimes(Interval interval);
348

    
349
        /**
350
         * @param providerName
351
         * @param parameters
352
         * @throws DataException
353
         */
354
        public void useCache(String providerName, DynObject parameters) throws DataException;
355

    
356
        public DataStoreProviderFactory getProviderFactory();
357

    
358
    /**
359
     * @return
360
     */
361
    public DataCache getCache();
362

    
363
    public ResourcesStorage getResourcesStorage();
364
    
365
    public StoresRepository getStoresRepository();
366

    
367
}
368