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

History | View | Annotate | Download (11.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
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 GEOPACKAGE_PROVIDER_NAME = "SQLite";
87
        public static final String MDB_PROVIDER_NAME = "MDB";
88
    
89
        public static final String METADATA_DEFINITION_NAME = "DataProvider";
90

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
273
        public DataSet getSelection() throws DataException;
274

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

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

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

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

    
317

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

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

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

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

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

    
357
        public DataStoreProviderFactory getProviderFactory();
358

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

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

    
368
}
369