Revision 24202
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/feature/spi/index/FeatureIndexProviderServices.java | ||
---|---|---|
32 | 32 |
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor; |
33 | 33 |
import org.gvsig.fmap.data.feature.FeatureIndex; |
34 | 34 |
import org.gvsig.fmap.data.feature.FeatureType; |
35 |
import org.gvsig.fmap.data.feature.exceptions.DataIndexException;
|
|
35 |
import org.gvsig.fmap.data.feature.exceptions.FeatureIndexException;
|
|
36 | 36 |
import org.gvsig.fmap.data.feature.spi.FeatureStoreProviderServices; |
37 | 37 |
|
38 | 38 |
|
... | ... | |
65 | 65 |
public String getNewFileName(String prefix, String sufix); |
66 | 66 |
|
67 | 67 |
/** Fills this index with the store's data */ |
68 |
public void fill() throws DataIndexException;
|
|
68 |
public void fill() throws FeatureIndexException;
|
|
69 | 69 |
} |
70 | 70 |
|
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/feature/spi/index/FeatureIndexProvider.java | ||
---|---|---|
32 | 32 |
|
33 | 33 |
import org.gvsig.fmap.data.exceptions.InitializeException; |
34 | 34 |
import org.gvsig.fmap.data.feature.FeatureReference; |
35 |
import org.gvsig.fmap.data.feature.exceptions.DataIndexException;
|
|
35 |
import org.gvsig.fmap.data.feature.exceptions.FeatureIndexException;
|
|
36 | 36 |
|
37 | 37 |
|
38 | 38 |
public interface FeatureIndexProvider { |
... | ... | |
49 | 49 |
/** Deletes a value from the index, given its reference */ |
50 | 50 |
public void delete(Object value, FeatureReference fref); |
51 | 51 |
|
52 |
/** Performs a search in the index and returns a list with all the values that match the given value */ |
|
53 |
public List match(Object value); |
|
52 |
/** Performs a search in the index and returns a list with all the values that match the given value |
|
53 |
* @throws FeatureIndexException TODO*/ |
|
54 |
public List match(Object value) throws FeatureIndexException; |
|
54 | 55 |
|
55 |
/** Performs a search in the index and returns a list with the values that intersect with the given interval */ |
|
56 |
public List match(Object min, Object max); |
|
56 |
/** Performs a search in the index and returns a list with the values that intersect with the given interval |
|
57 |
* @throws FeatureIndexException TODO*/ |
|
58 |
public List range(Object value1, Object value2) throws FeatureIndexException; |
|
57 | 59 |
|
58 | 60 |
/** Performs a search in the index and returns the list of up to n values which are nearest to the given value. */ |
59 |
public List nearest(int n, Object value) throws DataIndexException;
|
|
61 |
public List nearest(int count, Object value) throws FeatureIndexException;
|
|
60 | 62 |
|
63 |
/** Performs a search in the index and returns the list of up to n values which are nearest to the given value and within the distance specified by tolerance. */ |
|
64 |
public List nearest(int count, Object value, double tolerance) throws FeatureIndexException; |
|
65 |
|
|
66 |
|
|
67 |
/** Returns true if the provider supports the match function */ |
|
68 |
public boolean isMatchSupported(); |
|
69 |
/** Returns true if the provider supports the range function */ |
|
70 |
public boolean isRangeSupported(); |
|
71 |
/** Returns true if the provider supports the nearest function */ |
|
72 |
public boolean isNearestSupported(); |
|
73 |
/** Returns true if the provider supports the nearest with tolerance function */ |
|
74 |
public boolean isNearestToleranceSupported(); |
|
75 |
|
|
61 | 76 |
} |
62 | 77 |
|
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/feature/impl/DefaultFeatureStore.java | ||
---|---|---|
38 | 38 |
import org.gvsig.fmap.data.feature.exceptions.ConcurrentDataModificationException; |
39 | 39 |
import org.gvsig.fmap.data.feature.exceptions.CreateFeatureException; |
40 | 40 |
import org.gvsig.fmap.data.feature.exceptions.DataExportException; |
41 |
import org.gvsig.fmap.data.feature.exceptions.DataIndexException;
|
|
41 |
import org.gvsig.fmap.data.feature.exceptions.FeatureIndexException;
|
|
42 | 42 |
import org.gvsig.fmap.data.feature.exceptions.FinishEditingException; |
43 | 43 |
import org.gvsig.fmap.data.feature.exceptions.GetFeatureTypeException; |
44 | 44 |
import org.gvsig.fmap.data.feature.exceptions.IllegalFeatureException; |
... | ... | |
1115 | 1115 |
index = getManager().createFeatureIndexProvider(null, this, featureType, indexName, featureType.getAttributeDescriptor(attributeName)); |
1116 | 1116 |
try { |
1117 | 1117 |
index.fill(); |
1118 |
} catch (DataIndexException e) {
|
|
1118 |
} catch (FeatureIndexException e) {
|
|
1119 | 1119 |
throw new InitializeException(index.getName(), e); |
1120 | 1120 |
} |
1121 | 1121 |
((DefaultFeatureIndexes) getIndexes()).addIndex(index); |
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/feature/impl/DefaultFeatureIndexes.java | ||
---|---|---|
37 | 37 |
import org.gvsig.fmap.data.feature.FeatureIndex; |
38 | 38 |
import org.gvsig.fmap.data.feature.FeatureIndexes; |
39 | 39 |
import org.gvsig.fmap.data.feature.FeatureType; |
40 |
import org.gvsig.fmap.data.feature.exceptions.FeatureIndexException; |
|
40 | 41 |
import org.gvsig.fmap.data.feature.spi.FeatureSetProvider; |
41 | 42 |
import org.gvsig.fmap.data.feature.spi.index.FeatureIndexProviderServices; |
42 | 43 |
import org.gvsig.tools.evaluator.Evaluator; |
... | ... | |
105 | 106 |
featureTypes.put(index.getFeatureType(), indexes); |
106 | 107 |
} |
107 | 108 |
// FIXME Taking into account only the first attribute |
108 |
indexes.put(index.getAttributeNames()[0], index);
|
|
109 |
indexes.put(index.getAttributeNames().get(0), index);
|
|
109 | 110 |
|
110 | 111 |
// By name |
111 | 112 |
names.put(index.getName(), index); |
... | ... | |
150 | 151 |
this.index = index; |
151 | 152 |
this.data = data; |
152 | 153 |
} |
154 |
|
|
155 |
/** |
|
156 |
* Checks whether the index supports the evaluator request |
|
157 |
* @return |
|
158 |
*/ |
|
159 |
boolean isSupported() { |
|
160 |
switch(data[0].getType()) { |
|
161 |
case EvaluatorFieldValue.MATCH: |
|
162 |
return index.getFeatureIndexProvider().isMatchSupported(); |
|
163 |
case EvaluatorFieldValue.NEAREST: |
|
164 |
return index.getFeatureIndexProvider().isNearestSupported(); |
|
165 |
case EvaluatorFieldValue.RANGE: |
|
166 |
return index.getFeatureIndexProvider().isRangeSupported(); |
|
167 |
default: |
|
168 |
return false; |
|
169 |
} |
|
170 |
} |
|
171 |
|
|
172 |
/** |
|
173 |
* Applies the index using the evaluator fields |
|
174 |
* @return FeatureSetProvider with the result |
|
175 |
* @throws FeatureIndexException |
|
176 |
*/ |
|
177 |
FeatureSetProvider apply() throws FeatureIndexException { |
|
178 |
switch (data[0].getType()) { |
|
179 |
case EvaluatorFieldValue.MATCH: |
|
180 |
return index.getMatchFeatureSet(data[0].getValue()); |
|
181 |
case EvaluatorFieldValue.RANGE: |
|
182 |
return index.getRangeFeatureSet(data[0].getValue1(), |
|
183 |
data[0].getValue2()); |
|
184 |
case EvaluatorFieldValue.NEAREST: |
|
185 |
if ((data[0].getTolerance() == -1) || (!isSupported()) ) { |
|
186 |
return index.getNearestFeatureSet(data[0] |
|
187 |
.getCount(), data[0].getValue()); |
|
188 |
} else { |
|
189 |
return index.getNearestFeatureSet(data[0].getCount(), data[0].getValue(), data[0].getTolerance()); |
|
190 |
} |
|
191 |
} |
|
192 |
return null; |
|
193 |
} |
|
153 | 194 |
} |
195 |
|
|
196 |
// Select applicable indexes |
|
154 | 197 |
try { |
155 |
List applyIndex = new ArrayList(); |
|
198 |
List applyIndexes = new ArrayList();
|
|
156 | 199 |
Iterator indexes = this.iterator(); |
157 | 200 |
while (indexes.hasNext()) { |
158 | 201 |
DefaultFeatureIndex index = (DefaultFeatureIndex) indexes |
159 | 202 |
.next(); |
160 |
String[] attrs = index.getAttributeNames();
|
|
203 |
String[] attrs = (String[])index.getAttributeNames().toArray();
|
|
161 | 204 |
for (int i = 0; i < attrs.length; i++) { |
162 | 205 |
String attrname = attrs[i]; |
163 | 206 |
EvaluatorFieldValue[] values = evaluator |
164 | 207 |
.getFieldValues(attrname); |
165 | 208 |
if (values != null) { |
166 |
applyIndex.add(new ApplyIndex(index, values)); |
|
209 |
applyIndexes.add(new ApplyIndex(index, values));
|
|
167 | 210 |
break; |
168 | 211 |
} |
169 | 212 |
} |
170 | 213 |
} |
171 |
switch (applyIndex.size()) { |
|
172 |
case 0: |
|
173 |
return null; |
|
174 |
|
|
175 |
default: |
|
176 |
// FIXME: hay mas de un indice aplicable, que hacer? de momento |
|
177 |
// usa el primero. |
|
178 |
this.store |
|
179 |
.getLogger() |
|
180 |
.info( |
|
181 |
"Mas de un indice applica para la consulta. Se escoge arbitrariamente el primero."); |
|
182 |
|
|
183 |
case 1: |
|
184 |
ApplyIndex x = (ApplyIndex) applyIndex.get(0); |
|
185 |
switch (x.data[0].getType()) { |
|
186 |
case EvaluatorFieldValue.MATCH: |
|
187 |
return x.index.getMatchFeatureSet(x.data[0].getValue()); |
|
188 |
case EvaluatorFieldValue.RANGE: |
|
189 |
return x.index.getRangeFeatureSet(x.data[0].getValue1(), |
|
190 |
x.data[0].getValue2()); |
|
191 |
case EvaluatorFieldValue.NEAREST: |
|
192 |
if (x.data[0].getTolerance() == -1) { |
|
193 |
return x.index.getNearestFeatureSet(x.data[0] |
|
194 |
.getCount(), x.data[0].getValue()); |
|
195 |
} else { |
|
196 |
return x.index.getNearestFeatureSet(x.data[0] |
|
197 |
.getCount(), x.data[0].getTolerance(), |
|
198 |
x.data[0].getValue()); |
|
199 |
} |
|
200 |
} |
|
214 |
|
|
215 |
// If there's not any applicable index, return null |
|
216 |
if (applyIndexes.size() == 0) return null; |
|
217 |
|
|
218 |
// Lookup an index with support for the requested function |
|
219 |
Iterator it = applyIndexes.iterator(); |
|
220 |
ApplyIndex index = (ApplyIndex) it.next(); |
|
221 |
while ( it.hasNext() && (!index.isSupported()) ) { |
|
222 |
index = (ApplyIndex) it.next(); |
|
201 | 223 |
} |
202 |
|
|
224 |
|
|
225 |
// If there is not any any index supporting the function, use the first one |
|
226 |
if (!index.isSupported()) { |
|
227 |
this.store.getLogger().info("No index support for the evaluator values. Using default index."); |
|
228 |
index = (ApplyIndex) applyIndexes.get(0); |
|
229 |
} |
|
230 |
|
|
231 |
// Apply index |
|
232 |
return index.apply(); |
|
233 |
|
|
203 | 234 |
} catch (Exception e) { |
204 | 235 |
this.store.getLogger().error("Error buscando indice que aplicar.", |
205 | 236 |
e); |
206 | 237 |
return null; |
207 | 238 |
} |
208 |
|
|
209 |
return null; |
|
210 | 239 |
} |
211 | 240 |
} |
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/feature/impl/DefaultFeatureIndex.java | ||
---|---|---|
40 | 40 |
import org.gvsig.fmap.data.feature.FeatureReference; |
41 | 41 |
import org.gvsig.fmap.data.feature.FeatureSet; |
42 | 42 |
import org.gvsig.fmap.data.feature.FeatureType; |
43 |
import org.gvsig.fmap.data.feature.exceptions.DataIndexException;
|
|
43 |
import org.gvsig.fmap.data.feature.exceptions.FeatureIndexException;
|
|
44 | 44 |
import org.gvsig.fmap.data.feature.spi.DefaultLongList; |
45 | 45 |
import org.gvsig.fmap.data.feature.spi.FeatureSetProvider; |
46 | 46 |
import org.gvsig.fmap.data.feature.spi.FeatureStoreProviderServices; |
47 | 47 |
import org.gvsig.fmap.data.feature.spi.index.FeatureIndexProvider; |
48 | 48 |
import org.gvsig.fmap.data.feature.spi.index.FeatureIndexProviderServices; |
49 |
import org.gvsig.tools.exception.NotYetImplemented; |
|
50 | 49 |
|
51 | 50 |
/** |
52 | 51 |
* Default feature index provider services. |
... | ... | |
122 | 121 |
/** |
123 | 122 |
* Fills this index with all the data in its FeatureStore |
124 | 123 |
*/ |
125 |
public final void fill() throws DataIndexException {
|
|
124 |
public final void fill() throws FeatureIndexException {
|
|
126 | 125 |
try { |
127 | 126 |
insert(getFeatureStore().getFeatureSet()); |
128 | 127 |
} catch (DataException e) { |
129 |
throw new DataIndexException(e);
|
|
128 |
throw new FeatureIndexException(e);
|
|
130 | 129 |
} |
131 | 130 |
} |
132 | 131 |
|
... | ... | |
149 | 148 |
} |
150 | 149 |
|
151 | 150 |
public FeatureSetProvider getMatchFeatureSet(Object value) |
152 |
throws DataIndexException {
|
|
151 |
throws FeatureIndexException {
|
|
153 | 152 |
return new IndexFeatureSet(this, new DefaultLongList(indexProvider |
154 | 153 |
.match(value))); |
155 | 154 |
} |
156 | 155 |
|
157 | 156 |
public FeatureSetProvider getRangeFeatureSet(Object value1, Object value2) |
158 |
throws DataIndexException {
|
|
157 |
throws FeatureIndexException {
|
|
159 | 158 |
return new IndexFeatureSet(this, new DefaultLongList(indexProvider |
160 |
.match(value1, value2)));
|
|
159 |
.range(value1, value2)));
|
|
161 | 160 |
} |
162 | 161 |
|
163 | 162 |
public FeatureSetProvider getNearestFeatureSet(int count, Object value) |
164 |
throws DataIndexException {
|
|
163 |
throws FeatureIndexException {
|
|
165 | 164 |
return new IndexFeatureSet(this, new DefaultLongList(indexProvider |
166 | 165 |
.nearest(count, value))); |
167 | 166 |
} |
168 | 167 |
|
169 |
public FeatureSetProvider getNearestFeatureSet(int count, int tolerance, |
|
170 |
Object value) throws DataIndexException { |
|
171 |
// TODO Ver si indice soporta tolerancia / Implementar con tolerancia |
|
168 |
public FeatureSetProvider getNearestFeatureSet(int count, Object value, double tolerance) throws FeatureIndexException { |
|
172 | 169 |
return new IndexFeatureSet(this, new DefaultLongList(indexProvider |
173 |
.nearest(count, value))); |
|
170 |
.nearest(count, value, tolerance)));
|
|
174 | 171 |
} |
175 | 172 |
|
176 | 173 |
public void initialize() throws InitializeException { |
... | ... | |
186 | 183 |
indexProvider.delete(feat.get(this.attributeName), feat.getReference()); |
187 | 184 |
} |
188 | 185 |
|
189 |
public void delete(FeatureSet data) throws DataIndexException {
|
|
186 |
public void delete(FeatureSet data) throws FeatureIndexException {
|
|
190 | 187 |
try { |
191 | 188 |
Iterator it = data.iterator(); |
192 | 189 |
while (it.hasNext()) { |
... | ... | |
194 | 191 |
delete(feat); |
195 | 192 |
} |
196 | 193 |
} catch (DataException e) { |
197 |
throw new DataIndexException(e);
|
|
194 |
throw new FeatureIndexException(e);
|
|
198 | 195 |
} |
199 | 196 |
} |
200 | 197 |
|
201 |
public String[] getAttributeNames() {
|
|
198 |
public List getAttributeNames() {
|
|
202 | 199 |
// TODO Auto-generated method stub |
203 | 200 |
return null; |
204 | 201 |
} |
... | ... | |
223 | 220 |
return null; |
224 | 221 |
} |
225 | 222 |
|
223 |
public FeatureIndexProvider getFeatureIndexProvider() { |
|
224 |
return this.indexProvider; |
|
225 |
} |
|
226 | 226 |
|
227 | 227 |
} |
228 | 228 |
|
Also available in: Unified diff