svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_data / src / org / gvsig / fmap / data / vectorial / joinstore / JoinDataCollection.java @ 22333
History | View | Annotate | Download (6.44 KB)
1 |
package org.gvsig.fmap.data.vectorial.joinstore; |
---|---|
2 |
|
3 |
import java.util.Collection; |
4 |
import java.util.Iterator; |
5 |
import java.util.NoSuchElementException; |
6 |
|
7 |
import org.gvsig.fmap.data.DataCollection; |
8 |
import org.gvsig.fmap.data.ReadException; |
9 |
import org.gvsig.fmap.data.vectorial.AbstractFeatureCollection; |
10 |
import org.gvsig.fmap.data.vectorial.Feature; |
11 |
import org.gvsig.fmap.data.vectorial.FeatureCollection; |
12 |
import org.gvsig.fmap.data.vectorial.FeatureID; |
13 |
import org.gvsig.fmap.data.vectorial.FeatureManager; |
14 |
import org.gvsig.fmap.data.vectorial.FeatureStore; |
15 |
import org.gvsig.fmap.data.vectorial.FeatureType; |
16 |
import org.gvsig.fmap.data.vectorial.JoinFeature; |
17 |
import org.gvsig.fmap.data.vectorial.expressionevaluator.FeatureFilter; |
18 |
|
19 |
public class JoinDataCollection extends AbstractFeatureCollection{ |
20 |
// private DataCollection dataCollection1 = null;
|
21 |
// private DataCollection dataCollection2 = null;
|
22 |
private FeatureType featureType;
|
23 |
private String filter; |
24 |
private FeatureFilter parser;
|
25 |
// private FeatureStore store1;
|
26 |
// private FeatureStore store2;
|
27 |
private String order; |
28 |
private JoinFeatureStore joinStore;
|
29 |
|
30 |
public JoinDataCollection(JoinFeatureStore joinStore,FeatureType type, String filter,String order) throws ReadException { |
31 |
this.joinStore=joinStore;
|
32 |
// this.store1=joinStore.getPrimaryStore();
|
33 |
// this.store2=joinStore.getSecondaryStore();
|
34 |
this.order=order;
|
35 |
// driverFeatureCount1=store1.getFeatureCount();
|
36 |
this.featureType=type;
|
37 |
this.filter=filter;
|
38 |
if (this.filter!=null) |
39 |
parser = new FeatureFilter(filter,this.featureType); |
40 |
|
41 |
} |
42 |
|
43 |
public int size() { |
44 |
return 0; |
45 |
} |
46 |
|
47 |
public boolean contains(Object arg0) { |
48 |
// TODO Auto-generated method stub
|
49 |
return false; |
50 |
} |
51 |
|
52 |
public Iterator iterator() { |
53 |
this.checkModified();
|
54 |
JoinIterator complexIter = null;
|
55 |
try {
|
56 |
FeatureStore store1=joinStore.getPrimaryStore(); |
57 |
FeatureStore store2=joinStore.getSecondaryStore(); |
58 |
//TODO el featureType y el order hay que modificarlo y reorganizarlo.
|
59 |
FeatureCollection coll1=(FeatureCollection)store1.getDataCollection(featureType,filter,order); |
60 |
|
61 |
FeatureCollection coll2=(FeatureCollection)store2.getDataCollection(featureType,filter,order); |
62 |
complexIter=new JoinIterator(this.featureType,coll1,coll2); |
63 |
} catch (ReadException e) {
|
64 |
e.printStackTrace(); |
65 |
} |
66 |
|
67 |
return complexIter;
|
68 |
} |
69 |
|
70 |
public Object[] toArray() { |
71 |
// TODO Auto-generated method stub
|
72 |
return null; |
73 |
} |
74 |
|
75 |
public Object[] toArray(Object[] arg0) { |
76 |
// TODO Auto-generated method stub
|
77 |
return null; |
78 |
} |
79 |
|
80 |
public boolean add(Object arg0) { |
81 |
// TODO Auto-generated method stub
|
82 |
return false; |
83 |
} |
84 |
|
85 |
public boolean remove(Object arg0) { |
86 |
// TODO Auto-generated method stub
|
87 |
return false; |
88 |
} |
89 |
|
90 |
public boolean containsAll(Collection arg0) { |
91 |
// TODO Auto-generated method stub
|
92 |
return false; |
93 |
} |
94 |
|
95 |
public boolean addAll(Collection arg0) { |
96 |
// TODO Auto-generated method stub
|
97 |
return false; |
98 |
} |
99 |
|
100 |
public boolean removeAll(Collection arg0) { |
101 |
// TODO Auto-generated method stub
|
102 |
return false; |
103 |
} |
104 |
|
105 |
public boolean retainAll(Collection arg0) { |
106 |
// TODO Auto-generated method stub
|
107 |
return false; |
108 |
} |
109 |
|
110 |
public void clear() { |
111 |
// TODO Auto-generated method stub
|
112 |
|
113 |
} |
114 |
protected class JoinIterator implements Iterator{ |
115 |
// protected long position=0;
|
116 |
// private boolean nextChecked=false;
|
117 |
private Feature feature;
|
118 |
private FeatureType featureType;
|
119 |
private FeatureCollection coll1;
|
120 |
private FeatureCollection coll2;
|
121 |
private Iterator iterator1; |
122 |
|
123 |
public JoinIterator(FeatureType featureType,FeatureCollection coll1,FeatureCollection coll2){
|
124 |
this.featureType=featureType;
|
125 |
this.coll1=coll1;
|
126 |
this.coll2=coll2;
|
127 |
this.iterator1=coll1.iterator();
|
128 |
} |
129 |
|
130 |
|
131 |
// protected FeatureID createCurrentFeatureID(long pos){
|
132 |
// if (pos<driverFeatureCount){
|
133 |
// return new ComplexFeatureID(store1,store2,pos);
|
134 |
// } else {
|
135 |
// return null;
|
136 |
// }
|
137 |
// }
|
138 |
|
139 |
public boolean hasNext(){ |
140 |
return iterator1.hasNext();
|
141 |
} |
142 |
|
143 |
public Object next() { |
144 |
Feature feature=(Feature)iterator1.next(); |
145 |
JoinFeatureStoreParameters jfsp=joinStore.getJoinParameters(); |
146 |
String linkFieldPrimary=jfsp.getLinkFieldPrimary();
|
147 |
String linkFieldSecondary=jfsp.getLinkFieldSecondary();
|
148 |
|
149 |
Object obj=feature.get(linkFieldPrimary);
|
150 |
|
151 |
Iterator iter=null; |
152 |
JoinFeature complexFeature=null;
|
153 |
try {
|
154 |
iter = joinStore.getSecondaryStore().getDataCollection(featureType,linkFieldSecondary + " = " + obj.toString() + " and "+ filter,null).iterator(); |
155 |
|
156 |
Feature fea = null;
|
157 |
while (iter.hasNext()) {
|
158 |
fea = (Feature) iter.next(); |
159 |
break;
|
160 |
} |
161 |
complexFeature=new JoinFeature(featureType,feature,fea);
|
162 |
} catch (ReadException e) {
|
163 |
e.printStackTrace(); |
164 |
} |
165 |
return complexFeature;
|
166 |
} |
167 |
|
168 |
public void remove() { |
169 |
throw new UnsupportedOperationException(); |
170 |
} |
171 |
|
172 |
} |
173 |
|
174 |
|
175 |
public void dispose() { |
176 |
// this.observable.deleteObservers();
|
177 |
// this.observable = null;
|
178 |
// this.featureIDs.clear();
|
179 |
// this.featureIDs = null;
|
180 |
// this.featureType = null;
|
181 |
// this.store = null;
|
182 |
// this.parser = null;
|
183 |
// this.featureManager = null;
|
184 |
// ;
|
185 |
} |
186 |
public Feature getFeature(int index) { |
187 |
FeatureStore store1=joinStore.getPrimaryStore(); |
188 |
FeatureStore store2=joinStore.getSecondaryStore(); |
189 |
//TODO el featureType y el order hay que modificarlo y reorganizarlo.
|
190 |
FeatureCollection coll1=null;
|
191 |
FeatureCollection coll2=null;
|
192 |
try {
|
193 |
coll1 = (FeatureCollection)store1.getDataCollection(featureType,filter,order); |
194 |
|
195 |
|
196 |
coll2=(FeatureCollection)store2.getDataCollection(featureType,filter,order); |
197 |
} catch (ReadException e1) {
|
198 |
// TODO Auto-generated catch block
|
199 |
e1.printStackTrace(); |
200 |
} |
201 |
// TODO falta modificar el featureType para pedir solo los atributos que tenga en el primaryStore.
|
202 |
Feature feature=coll1.getFeature(index); |
203 |
|
204 |
Object obj=feature.get(((JoinFeatureStoreParameters)joinStore.getParameters()).getLinkFieldPrimary());
|
205 |
|
206 |
Iterator iter=null; |
207 |
JoinFeature complexFeature=null;
|
208 |
try {
|
209 |
iter = joinStore.getSecondaryStore().getDataCollection(joinStore.getPrimaryStore().getDefaultFeatureType(),((JoinFeatureStoreParameters)joinStore.getParameters()).getLinkFieldSecondary() + " = " + obj.toString(),null).iterator(); |
210 |
|
211 |
Feature fea = null;
|
212 |
while (iter.hasNext()) {
|
213 |
fea = (Feature) iter.next(); |
214 |
break;
|
215 |
} |
216 |
complexFeature=new JoinFeature(featureType,feature,fea);
|
217 |
} catch (ReadException e) {
|
218 |
e.printStackTrace(); |
219 |
} |
220 |
return complexFeature;
|
221 |
} |
222 |
|
223 |
} |