root / branches / v2_0_0_prep / libraries / libFMap_data / src / org / gvsig / fmap / data / feature / spi / AbstractDataIndexProvider.java @ 23867
History | View | Annotate | Download (4.92 KB)
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.spi; |
30 |
|
31 |
import java.util.Iterator; |
32 |
import java.util.List; |
33 |
|
34 |
import org.gvsig.fmap.data.exceptions.DataException; |
35 |
import org.gvsig.fmap.data.feature.Feature; |
36 |
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor; |
37 |
import org.gvsig.fmap.data.feature.FeatureSet; |
38 |
import org.gvsig.fmap.data.feature.FeatureStore; |
39 |
import org.gvsig.fmap.data.feature.FeatureType; |
40 |
import org.gvsig.fmap.data.feature.exceptions.DataIndexException; |
41 |
import org.gvsig.fmap.data.index.QueryParameters; |
42 |
|
43 |
/**
|
44 |
* Abstract factory for registering and retrieving available indexing engines.
|
45 |
* You can force the use of a specific implementation by passing its key, or you can use the default
|
46 |
* implementation for a given data type by specifying the {@link AttributeDescriptor} of the column
|
47 |
* to be indexed.
|
48 |
*
|
49 |
* @author jyarza
|
50 |
*
|
51 |
*/
|
52 |
public abstract class AbstractDataIndexProvider implements DataIndexProvider { |
53 |
|
54 |
private final FeatureStore featureStore; |
55 |
private final FeatureType featureType; |
56 |
private final String attributeName; |
57 |
private final String name; |
58 |
private final int dataType; |
59 |
|
60 |
public AbstractDataIndexProvider(FeatureStore featureStore, FeatureType featureType, String attributeName, String indexName) throws DataIndexException { |
61 |
if (featureStore == null) throw new IllegalArgumentException("featureStore cannot be null."); |
62 |
if (featureType == null) throw new IllegalArgumentException("featureType cannot be null."); |
63 |
if (attributeName == null) throw new IllegalArgumentException("attributeName cannot be null."); |
64 |
if (indexName == null) throw new IllegalArgumentException("indexName cannot be null."); |
65 |
|
66 |
FeatureAttributeDescriptor attr = featureType.getAttributeDescriptor(attributeName); |
67 |
if (attr == null) |
68 |
throw new IllegalArgumentException("Attribute " + attributeName +" not found in FeatureType " + featureType.toString()); |
69 |
|
70 |
this.featureStore = featureStore;
|
71 |
this.featureType = featureType;
|
72 |
this.attributeName = attributeName;
|
73 |
this.name = indexName;
|
74 |
this.dataType = attr.getDataType();
|
75 |
} |
76 |
|
77 |
public final FeatureAttributeDescriptor getFeatureAttributeDescriptor() { |
78 |
return featureType.getAttributeDescriptor(attributeName);
|
79 |
} |
80 |
|
81 |
public final FeatureStore getFeatureStore() { |
82 |
return featureStore;
|
83 |
} |
84 |
|
85 |
public final FeatureType getFeatureType() { |
86 |
return featureType;
|
87 |
} |
88 |
|
89 |
public final String getName() { |
90 |
return name;
|
91 |
} |
92 |
|
93 |
public final String getAttributeName() { |
94 |
return attributeName;
|
95 |
} |
96 |
|
97 |
public final int getDataType() { |
98 |
return dataType;
|
99 |
} |
100 |
|
101 |
/**
|
102 |
* Fills this index with all the data in its FeatureStore
|
103 |
*/
|
104 |
public final void fill() throws DataIndexException { |
105 |
try {
|
106 |
insert(getFeatureStore().getFeatureSet()); |
107 |
} catch (DataException e) {
|
108 |
throw new DataIndexException(e); |
109 |
} |
110 |
} |
111 |
|
112 |
public final void insert(FeatureSet data) { |
113 |
Iterator it = data.iterator();
|
114 |
while (it.hasNext()) {
|
115 |
Feature feat = (Feature) it.next(); |
116 |
insert(feat); |
117 |
} |
118 |
} |
119 |
|
120 |
public void insert(Feature feat) { |
121 |
try {
|
122 |
insert(feat.get(attributeName), feat.getReference()); |
123 |
} catch (NullPointerException e) { |
124 |
throw new IllegalArgumentException("Feature does not contain a column with name " + attributeName); |
125 |
} catch (ClassCastException e) { |
126 |
throw new IllegalArgumentException("Attribute data type is not valid."); |
127 |
} |
128 |
} |
129 |
|
130 |
public abstract List query(QueryParameters params) throws DataIndexException; |
131 |
public abstract void initialize(); |
132 |
|
133 |
/**
|
134 |
* FIXME ver que hacemos con estas constantes
|
135 |
* Convenience constants to identify sets of providers classified by supported data types.
|
136 |
*/
|
137 |
public interface PROVIDERS { |
138 |
|
139 |
public interface GEOMETRY { |
140 |
public static final String GT2_QUADTREE = "QuadTreeGt2Factory"; |
141 |
public static final String JSI_RTREE = "RTreeJsiFactory"; |
142 |
public static final String JTS_QUADTREE = "QuadTreeJtsFactory"; |
143 |
public static final String SPATIALINDEX_RTREE = "RTreeSptLibFactory"; |
144 |
public static final String DEFAULT = GT2_QUADTREE; |
145 |
} |
146 |
|
147 |
public interface DATE { |
148 |
// added as example
|
149 |
} |
150 |
|
151 |
public interface INTEGER { |
152 |
// added as example
|
153 |
} |
154 |
} |
155 |
|
156 |
} |
157 |
|