Revision 23949

View differences:

branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/feature/impl/DefaultFeatureStore.java
17 17
import org.gvsig.fmap.data.exceptions.DataException;
18 18
import org.gvsig.fmap.data.exceptions.InitializeException;
19 19
import org.gvsig.fmap.data.exceptions.OpenException;
20
import org.gvsig.fmap.data.exceptions.ProviderNotRegisteredException;
20 21
import org.gvsig.fmap.data.exceptions.ReadException;
21 22
import org.gvsig.fmap.data.feature.Command;
22 23
import org.gvsig.fmap.data.feature.CommandsRecord;
23
import org.gvsig.fmap.data.feature.DataIndex;
24
import org.gvsig.fmap.data.feature.DataIndexes;
24
import org.gvsig.fmap.data.feature.FeatureIndex;
25
import org.gvsig.fmap.data.feature.FeatureIndexes;
25 26
import org.gvsig.fmap.data.feature.EditableFeature;
26 27
import org.gvsig.fmap.data.feature.EditableFeatureType;
27 28
import org.gvsig.fmap.data.feature.Feature;
28 29
import org.gvsig.fmap.data.feature.FeatureExplorer;
29
import org.gvsig.fmap.data.feature.FeatureIndexes;
30 30
import org.gvsig.fmap.data.feature.FeatureQuery;
31 31
import org.gvsig.fmap.data.feature.FeatureReference;
32 32
import org.gvsig.fmap.data.feature.FeatureSelection;
......
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 42
import org.gvsig.fmap.data.feature.exceptions.FeatureNotAllowedForThisStoreException;
42 43
import org.gvsig.fmap.data.feature.exceptions.FeatureTypeNotAllowedForThisStoreException;
43 44
import org.gvsig.fmap.data.feature.exceptions.FinishEditingException;
......
66 67
import org.gvsig.fmap.data.feature.spi.FeatureLocks;
67 68
import org.gvsig.fmap.data.feature.spi.FeatureStoreProvider;
68 69
import org.gvsig.fmap.data.feature.spi.FeatureStoreProviderServices;
70
import org.gvsig.fmap.data.feature.spi.index.FeatureIndexProviderServices;
69 71
import org.gvsig.fmap.data.impl.DefaultDataManager;
70 72
import org.gvsig.fmap.geom.primitive.Envelope;
71 73
import org.gvsig.metadata.Metadata;
......
109 111

  
110 112
	private FeatureStoreProvider provider = null;
111 113

  
112
	private FeatureIndexes indexes;
114
	private DefaultDataIndexes indexes;
113 115

  
114 116
	private Logger logger = null;
115 117

  
......
1078 1080
		return this.logger;
1079 1081
	}
1080 1082

  
1081
	public DataIndex createDataIndex(FeatureType featureType,
1082
			String attributeName, String indexName) throws DataException {
1083
		// TODO Auto-generated method stub
1084
		return null;
1083
	public FeatureIndex createIndex(FeatureType featureType,
1084
			String attributeName, String indexName) throws ProviderNotRegisteredException, InitializeException {
1085
		FeatureIndexProviderServices index = null;
1086
		index = getManager().createDataIndexProvider(this, featureType, featureType.getAttributeDescriptor(attributeName));
1087
		try {
1088
			index.fill();
1089
		} catch (DataIndexException e) {
1090
			throw new InitializeException(index.getName(), e);
1091
		}
1092
		((DefaultDataIndexes) getIndexes()).addIndex(index);						
1093
		return index;
1085 1094
	}
1086 1095

  
1087
	public DataIndexes getDataIndexes() {
1088
		// TODO Auto-generated method stub
1089
		return null;
1090
	}
1091

  
1092
	public boolean hasDataIndex(FeatureType featureType, String attributeName) {
1093
		// TODO Auto-generated method stub
1094
		return false;
1095
	}
1096 1096
}
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/feature/impl/DefaultFeatureIndex.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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 2
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
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 {{Company}}   {{Task}}
26
*/
27
 
28

  
29
package org.gvsig.fmap.data.feature.impl;
30

  
31
import java.util.Iterator;
32
import java.util.List;
33

  
34
import org.gvsig.fmap.data.DataTypes;
35
import org.gvsig.fmap.data.exceptions.DataException;
36
import org.gvsig.fmap.data.feature.Feature;
37
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor;
38
import org.gvsig.fmap.data.feature.FeatureReference;
39
import org.gvsig.fmap.data.feature.FeatureSet;
40
import org.gvsig.fmap.data.feature.FeatureType;
41
import org.gvsig.fmap.data.feature.exceptions.DataIndexException;
42
import org.gvsig.fmap.data.feature.spi.DefaultLongList;
43
import org.gvsig.fmap.data.feature.spi.FeatureSetProvider;
44
import org.gvsig.fmap.data.feature.spi.FeatureStoreProviderServices;
45
import org.gvsig.fmap.data.feature.spi.index.FeatureIndexProvider;
46
import org.gvsig.fmap.data.feature.spi.index.FeatureIndexProviderServices;
47

  
48
/**
49
 * Abstract index provider. 
50
 * 
51
 * @author jyarza
52
 *
53
 */
54
public class DefaultFeatureIndex implements FeatureIndexProviderServices {
55

  
56
	private final FeatureStoreProviderServices featureStore;
57
	private final FeatureType featureType;
58
	private final String attributeName;
59
	private final String name;
60
	private final int dataType;
61
	private final FeatureIndexProvider indexProvider;
62

  
63
	public DefaultFeatureIndex(FeatureStoreProviderServices featureStore, FeatureType featureType, FeatureIndexProvider indexProvider, String attributeName, String indexName) {
64
		if (featureStore == null) throw new IllegalArgumentException("featureStore cannot be null.");
65
		if (featureType == null) throw new IllegalArgumentException("featureType cannot be null.");
66
		if (attributeName == null) throw new IllegalArgumentException("attributeName cannot be null.");
67
		if (indexName == null) throw new IllegalArgumentException("indexName cannot be null.");
68
		
69
		if (featureStore.getProvider().getFeatureReferenceIdType() != DataTypes.INT) {
70
			throw new IllegalArgumentException();
71
		}
72
		
73
		FeatureAttributeDescriptor attr = featureType.getAttributeDescriptor(attributeName);
74
		if (attr == null) 
75
			throw new IllegalArgumentException("Attribute " + attributeName +" not found in FeatureType " + featureType.toString());
76
			
77
		this.featureStore = featureStore;
78
		this.featureType = featureType;
79
		this.attributeName = attributeName;
80
		this.name = indexName;
81
		this.dataType = attr.getDataType();
82
		this.indexProvider = indexProvider;
83
	}
84

  
85
	public final FeatureAttributeDescriptor getFeatureAttributeDescriptor() {
86
		return featureType.getAttributeDescriptor(attributeName);
87
	}
88

  
89
	public final FeatureStoreProviderServices getFeatureStore() {
90
		return featureStore;
91
	}
92

  
93
	public final FeatureType getFeatureType() {
94
		return featureType;
95
	}
96

  
97
	public final String getName() {
98
		return name;
99
	}
100
	
101
	public final String getAttributeName() {
102
		return attributeName;
103
	}
104
	
105
	public final int getDataType() {
106
		return dataType;
107
	}
108

  
109
	/**
110
	 * Fills this index with all the data in its FeatureStore
111
	 */
112
	public final void fill() throws DataIndexException {
113
		try {
114
			insert(getFeatureStore().getFeatureSet());
115
		} catch (DataException e) {
116
			throw new DataIndexException(e);
117
		}
118
	}
119

  
120
	public final void insert(FeatureSet data) throws DataException {
121
		Iterator it = data.iterator();
122
		while (it.hasNext()) {
123
			Feature feat = (Feature) it.next();
124
			insert(feat);
125
		}
126
	}
127

  
128
	public void insert(Feature feat) {
129
		try {
130
			indexProvider.insert(feat.get(attributeName), feat.getReference());
131
		} catch (NullPointerException e) {
132
			throw new IllegalArgumentException("Feature does not contain a column with name " + attributeName);
133
		} catch (ClassCastException e) {
134
			throw new IllegalArgumentException("Attribute data type is not valid.");
135
		}
136
	}
137

  
138
	/** Performs a search in the index. The type of search depends on the passed data 
139
	 * 
140
	 *  TODO explain 
141
	 * */
142
	public FeatureSetProvider getFeatureSet(String attrName, Object[] data) throws DataIndexException {
143
		return new IndexFeatureSet(this, new DefaultLongList(this.match(data)));
144
	}
145
	
146
	/** Performs a search in the index and returns a list with the elements that match the parameters */
147
	private List match(Object[] values) throws DataIndexException {
148
		
149
		if (values == null) throw new IllegalArgumentException("values can't be null.");
150
		if (values.length == 0) throw new IllegalArgumentException("values must contain at least 1 value.");
151
		
152
		List result = null;
153
		if (values.length == 1) {
154
			result = indexProvider.match(values[0]);
155
		}
156
		if (values.length == 2) {
157
			if (values[0] instanceof Integer && !(values[1] instanceof Integer)) {
158
				result = indexProvider.nearest(((Integer)values[0]).intValue(), values[1]);
159
			} else {
160
				result = indexProvider.match(values[0], values[1]);	
161
			}			
162
		}
163
		return result;
164
	}
165
	
166
	
167
	public void initialize() {
168
		indexProvider.initialize();
169
	}
170
	
171

  
172

  
173
	public void delete(Object o, FeatureReference fref) {
174
		indexProvider.delete(o, fref);
175
		
176
	}
177

  
178
	public void delete(Feature feat) {
179
		// TODO Auto-generated method stub
180
		
181
	}
182

  
183
	public void delete(FeatureSet data) throws DataIndexException {
184
		// TODO Auto-generated method stub
185
		
186
	}
187

  
188
	public String[] getAttributeNames() {
189
		// TODO Auto-generated method stub
190
		return null;
191
	}
192

  
193
	
194
	/**
195
	 * FIXME ver que hacemos con estas constantes
196
	 * Convenience constants to identify sets of providers classified by supported data types. 
197
	 */
198
	public interface PROVIDERS {
199
		
200
		public interface GEOMETRY {
201
			public static final String GT2_QUADTREE = "QuadTreeGt2Factory";
202
			public static final String JSI_RTREE = "RTreeJsiFactory";
203
			public static final String JTS_QUADTREE = "QuadTreeJtsFactory";
204
			public static final String SPATIALINDEX_RTREE = "RTreeSptLibFactory";
205
			public static final String DEFAULT = GT2_QUADTREE;
206
		}
207
		
208
		public interface DATE {
209
			// added as example
210
		}
211
		
212
		public interface INTEGER {
213
			// added as example
214
		}		
215
	}	
216
	
217
}
218

  
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/feature/impl/DefaultDataIndexes.java
32 32
import java.util.Map;
33 33

  
34 34
import org.gvsig.fmap.data.exceptions.DataException;
35
import org.gvsig.fmap.data.feature.DataIndex;
36
import org.gvsig.fmap.data.feature.DataIndexes;
35
import org.gvsig.fmap.data.feature.FeatureIndex;
36
import org.gvsig.fmap.data.feature.FeatureIndexes;
37 37
import org.gvsig.fmap.data.feature.FeatureStore;
38 38
import org.gvsig.fmap.data.feature.FeatureType;
39 39

  
......
42 42
 * FeatureType and attrName or by index name.
43 43
 * @author jyarza
44 44
 */
45
public class DefaultDataIndexes implements DataIndexes {
45
public class DefaultDataIndexes implements FeatureIndexes {
46 46

  
47 47
	// Access by FeatureType and attribute name
48 48
	private Map featureTypes = new HashMap();
......
68 68
	/* (non-Javadoc)
69 69
	 * @see org.gvsig.fmap.data.index.DataIndexes#getDataIndex(org.gvsig.fmap.data.feature.FeatureType, java.lang.String)
70 70
	 */
71
	public DataIndex getDataIndex(FeatureType fType, String attrName) {
71
	public FeatureIndex getDataIndex(FeatureType fType, String attrName) {
72 72
		Map indexes = (Map) featureTypes.get(fType);
73 73
		if (indexes != null) {
74
			return (DataIndex) (indexes.get(attrName));
74
			return (FeatureIndex) (indexes.get(attrName));
75 75
		}
76 76
		return null;
77 77
	}
......
79 79
	/* (non-Javadoc)
80 80
	 * @see org.gvsig.fmap.data.index.DataIndexes#getDataIndex(java.lang.String)
81 81
	 */
82
	public DataIndex getDataIndex(String name) {
83
		return (DataIndex) names.get(name);
82
	public FeatureIndex getDataIndex(String name) {
83
		return (FeatureIndex) names.get(name);
84 84
	}
85 85

  
86 86
	/* (non-Javadoc)
87 87
	 * @see org.gvsig.fmap.data.index.DataIndexes#addIndex(org.gvsig.fmap.data.feature.FeatureType, java.lang.String, org.gvsig.fmap.data.feature.DataIndex)
88 88
	 */
89
	public void addIndex(FeatureType fType, String attrName, DataIndex index) {
89
	public void addIndex(FeatureIndex index) {
90 90
		Map indexes = (Map) featureTypes.get(fType);
91 91
		if (indexes == null) {
92 92
			// This would mean that a new feature type has been added to the FeatureStore since this Indexes was created

Also available in: Unified diff