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 @ 44541
History | View | Annotate | Download (5.42 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.ArrayList; |
27 |
import java.util.Iterator; |
28 |
import java.util.List; |
29 |
|
30 |
import org.gvsig.fmap.dal.DataStoreParameters; |
31 |
import org.gvsig.fmap.dal.exception.DataException; |
32 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
33 |
import org.gvsig.fmap.dal.feature.FeatureType; |
34 |
import org.gvsig.fmap.dal.feature.exception.PerformEditingException; |
35 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider; |
36 |
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider; |
37 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
38 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
39 |
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
40 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
41 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
42 |
import org.gvsig.tools.dynobject.DynObject; |
43 |
import org.gvsig.tools.exception.BaseException; |
44 |
|
45 |
/**
|
46 |
* Abstract implementation for {@link FeatureStoreProvider} for provider that
|
47 |
* are loaded statically in memory
|
48 |
*
|
49 |
*/
|
50 |
public abstract class AbstractMemoryStoreProvider extends |
51 |
AbstractFeatureStoreProvider { |
52 |
|
53 |
protected List data; |
54 |
|
55 |
protected AbstractMemoryStoreProvider(DataStoreParameters params,
|
56 |
DataStoreProviderServices storeServices, DynObject metadata) { |
57 |
super(params, storeServices, metadata);
|
58 |
} |
59 |
|
60 |
protected AbstractMemoryStoreProvider(DataStoreParameters params,
|
61 |
DataStoreProviderServices storeServices) { |
62 |
super(params, storeServices);
|
63 |
} |
64 |
|
65 |
public void performChanges(Iterator deleteds, Iterator inserteds, Iterator updateds, Iterator originalFeatureTypesUpdated) throws PerformEditingException { |
66 |
throw new UnsupportedOperationException(); |
67 |
} |
68 |
|
69 |
/**
|
70 |
* Load a {@link FeatureProvider} into memory store.<br>
|
71 |
* Use this when loading data.
|
72 |
*
|
73 |
* @param data
|
74 |
*/
|
75 |
public void addFeatureProvider(FeatureProvider data) { |
76 |
if( this.data == null ) { |
77 |
this.data = new ArrayList(); |
78 |
} |
79 |
data.setOID(this.createNewOID());
|
80 |
this.data.add(data);
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Return the current size of the memory store.
|
85 |
*
|
86 |
* @return
|
87 |
* @throws DataException
|
88 |
*/
|
89 |
public long getDataSize() throws DataException { |
90 |
this.open();
|
91 |
return this.data.size(); |
92 |
} |
93 |
|
94 |
protected FeatureProvider internalGetFeatureProviderByReference(
|
95 |
FeatureReferenceProviderServices reference) throws DataException {
|
96 |
int oid = ((Long) reference.getOID()).intValue(); |
97 |
return (FeatureProvider) this.data.get(oid); |
98 |
} |
99 |
|
100 |
protected FeatureProvider internalGetFeatureProviderByReference(
|
101 |
FeatureReferenceProviderServices reference, FeatureType featureType) |
102 |
throws DataException {
|
103 |
return new MemoryFeatureProviderAttributeMapper( |
104 |
(DefaultFeatureProvider) internalGetFeatureProviderByReference(reference), |
105 |
featureType); |
106 |
} |
107 |
|
108 |
/*
|
109 |
* (non-Javadoc)
|
110 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#createSet(org.gvsig.fmap.dal.feature.FeatureQuery, org.gvsig.fmap.dal.feature.FeatureType)
|
111 |
*/
|
112 |
public FeatureSetProvider createSet(FeatureQuery query, FeatureType featureType)
|
113 |
throws DataException {
|
114 |
this.open();
|
115 |
return new MemoryFeatureSet(this, query, featureType, this.data); |
116 |
} |
117 |
|
118 |
/*
|
119 |
* (non-Javadoc)
|
120 |
* @see org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider#createFeatureProvider(org.gvsig.fmap.dal.feature.FeatureType)
|
121 |
*/
|
122 |
public FeatureProvider createFeatureProvider(FeatureType featureType)throws DataException { |
123 |
this.open();
|
124 |
return new MemoryFeatureProvider(featureType, this.createNewOID()); |
125 |
} |
126 |
|
127 |
/*
|
128 |
* (non-Javadoc)
|
129 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#getFeatureCount()
|
130 |
*/
|
131 |
public long getFeatureCount() throws DataException { |
132 |
return data.size();
|
133 |
} |
134 |
|
135 |
protected AbstractMemoryStoreProvider getMemoryProvider() {
|
136 |
return this; |
137 |
} |
138 |
|
139 |
protected void doDispose() throws BaseException { |
140 |
super.doDispose();
|
141 |
data = null;
|
142 |
} |
143 |
|
144 |
public class MemoryFeatureProvider extends DefaultFeatureProvider { |
145 |
|
146 |
public MemoryFeatureProvider(FeatureType type) {
|
147 |
super(type);
|
148 |
} |
149 |
|
150 |
public MemoryFeatureProvider(FeatureType featureType, Object createNewOID) { |
151 |
super(featureType, createNewOID);
|
152 |
} |
153 |
|
154 |
@Override
|
155 |
public FeatureType getType() {
|
156 |
try {
|
157 |
if (getStoreServices().getFeatureTypes().size()==1) { |
158 |
return getStoreServices().getDefaultFeatureType();
|
159 |
} else {
|
160 |
return super.getType(); |
161 |
} |
162 |
} catch (DataException ex) {
|
163 |
return super.getType(); |
164 |
} |
165 |
} |
166 |
} |
167 |
} |