Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.spi / src / main / java / org / gvsig / fmap / dal / feature / spi / memory / AbstractMemoryStoreProvider.java @ 40767

History | View | Annotate | Download (4.58 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.feature.spi.memory;
25

    
26
import java.util.Iterator;
27
import java.util.List;
28

    
29
import org.gvsig.fmap.dal.DataStoreParameters;
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.dal.feature.FeatureQuery;
32
import org.gvsig.fmap.dal.feature.FeatureType;
33
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
34
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider;
35
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider;
36
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
37
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
38
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider;
39
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
40
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
41
import org.gvsig.tools.dynobject.DynObject;
42
import org.gvsig.tools.exception.BaseException;
43

    
44
/**
45
 * Abstract implementation for {@link FeatureStoreProvider} for provider that
46
 * are loaded statically in memory
47
 * 
48
 */
49
public abstract class AbstractMemoryStoreProvider extends
50
                AbstractFeatureStoreProvider {
51

    
52
        protected List data;
53

    
54
        protected AbstractMemoryStoreProvider(DataStoreParameters params,
55
                        DataStoreProviderServices storeServices, DynObject metadata) {
56
                super(params, storeServices, metadata);
57
        }
58

    
59
        protected AbstractMemoryStoreProvider(DataStoreParameters params,
60
                        DataStoreProviderServices storeServices) {
61
                super(params, storeServices);
62
        }
63

    
64
        public void performChanges(Iterator deleteds, Iterator inserteds, Iterator updateds, Iterator originalFeatureTypesUpdated) throws PerformEditingException {
65
                throw new UnsupportedOperationException();
66
        }
67

    
68
        /**
69
         * Load a {@link FeatureProvider} into memory store.<br>
70
         * Use this when loading data.
71
         * 
72
         * @param data
73
         */
74
        public void addFeatureProvider(FeatureProvider data) {
75
                data.setOID(this.createNewOID());
76
                this.data.add(data);
77
        }
78

    
79
        /**
80
         * Return the current size of the memory store.
81
         * 
82
         * @return
83
         * @throws DataException
84
         */
85
        public long getDataSize() throws DataException {
86
                this.open();
87
                return this.data.size();
88
        }
89

    
90
        protected FeatureProvider internalGetFeatureProviderByReference(
91
                        FeatureReferenceProviderServices reference) throws DataException {
92
                int oid = ((Long) reference.getOID()).intValue();
93
                return (FeatureProvider) this.data.get(oid);
94
        }
95

    
96
        protected FeatureProvider internalGetFeatureProviderByReference(
97
                        FeatureReferenceProviderServices reference, FeatureType featureType)
98
                        throws DataException {
99
        return new MemoryFeatureProviderAttributeMapper(
100
            (DefaultFeatureProvider) internalGetFeatureProviderByReference(reference),
101
            featureType);
102
        }
103

    
104
        /*
105
         * (non-Javadoc)
106
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#createSet(org.gvsig.fmap.dal.feature.FeatureQuery, org.gvsig.fmap.dal.feature.FeatureType)
107
         */
108
        public FeatureSetProvider createSet(FeatureQuery query, FeatureType featureType)
109
                        throws DataException {
110
                this.open();
111
                return new MemoryFeatureSet(this, query, featureType, this.data);
112
        }
113

    
114
        /*
115
         * (non-Javadoc)
116
         * @see org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider#createFeatureProvider(org.gvsig.fmap.dal.feature.FeatureType)
117
         */
118
        public FeatureProvider createFeatureProvider(FeatureType featureType)throws DataException  {
119
                this.open();
120
                return new DefaultFeatureProvider(featureType);
121
        }
122

    
123
        /*
124
         * (non-Javadoc)
125
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#getFeatureCount()
126
         */
127
        public long getFeatureCount() throws DataException {
128
                return data.size();
129
        }
130

    
131
        protected AbstractMemoryStoreProvider getMemoryProvider() {
132
                return this;
133
        }
134

    
135
        protected void doDispose() throws BaseException {
136
                super.doDispose();
137
                data = null;
138
        }
139
}