Revision 47049 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/featureset/AbstractFeatureSet.java
AbstractFeatureSet.java | ||
---|---|---|
28 | 28 |
import javax.json.JsonArray; |
29 | 29 |
import javax.json.JsonArrayBuilder; |
30 | 30 |
import javax.json.JsonObject; |
31 |
import org.apache.commons.lang3.mutable.MutableInt; |
|
32 |
import org.gvsig.expressionevaluator.Expression; |
|
33 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
34 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
31 | 35 |
import org.gvsig.fmap.dal.DataStore; |
32 | 36 |
import org.gvsig.fmap.dal.exception.DataException; |
37 |
import org.gvsig.fmap.dal.feature.DisposableFeatureSetIterable; |
|
33 | 38 |
import org.gvsig.fmap.dal.feature.Feature; |
39 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
34 | 40 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
35 | 41 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
42 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
36 | 43 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
37 | 44 |
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.DynObjectSetFeatureSetFacade; |
38 |
import org.gvsig.json.JsonObjectBuilder; |
|
39 | 45 |
import org.gvsig.tools.dispose.DisposableIterator; |
40 | 46 |
import org.gvsig.tools.dispose.DisposeUtils; |
41 | 47 |
import org.gvsig.tools.dynobject.DynObjectSet; |
... | ... | |
47 | 53 |
import org.slf4j.LoggerFactory; |
48 | 54 |
|
49 | 55 |
|
56 |
@SuppressWarnings("UseSpecificCatch") |
|
50 | 57 |
public abstract class AbstractFeatureSet |
51 | 58 |
extends AbstractIndexedVisitable |
52 | 59 |
implements FeatureSet { |
53 | 60 |
|
61 |
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractFeatureSet.class); |
|
62 |
|
|
54 | 63 |
private static class DisposableFeatureSetIterableImpl implements DisposableFeatureSetIterable { |
55 | 64 |
|
56 | 65 |
private final FeatureSet fset; |
... | ... | |
103 | 112 |
|
104 | 113 |
protected static final Logger LOG = LoggerFactory.getLogger(AbstractFeatureSet.class); |
105 | 114 |
|
115 |
@Override |
|
106 | 116 |
public abstract FeatureStore getFeatureStore(); |
107 | 117 |
|
108 | 118 |
@Override |
... | ... | |
111 | 121 |
doAccept(visitor, firstValueIndex, elements); |
112 | 122 |
} catch (VisitCanceledException ex) { |
113 | 123 |
// The visit has been cancelled by the visitor, so we finish here. |
114 |
LOG.debug( |
|
115 |
"The visit, beggining on position {}, has been cancelled " |
|
116 |
+ "by the visitor: {}", new Long(firstValueIndex), |
|
124 |
LOG.debug("The visit, beggining on position {}, has been cancelled " |
|
125 |
+ "by the visitor: {}", firstValueIndex, |
|
117 | 126 |
visitor); |
118 | 127 |
} |
119 | 128 |
} |
... | ... | |
237 | 246 |
// tendria que construirse en memoria el JSON entero. |
238 | 247 |
try { |
239 | 248 |
JsonArrayBuilder builder = Json.createArrayBuilder(); |
240 |
this.accept(new Visitor() { |
|
241 |
@Override |
|
242 |
public void visit(Object obj) throws VisitCanceledException, BaseException { |
|
243 |
DefaultFeature f = (DefaultFeature) obj; |
|
244 |
JsonObject fjson = f.toJson(); |
|
245 |
builder.add(fjson); |
|
246 |
} |
|
249 |
this.accept((Object obj) -> { |
|
250 |
DefaultFeature f = (DefaultFeature) obj; |
|
251 |
JsonObject fjson = f.toJson(); |
|
252 |
builder.add(fjson); |
|
247 | 253 |
}); |
248 | 254 |
return builder; |
249 | 255 |
} catch (Exception ex) { |
... | ... | |
252 | 258 |
} |
253 | 259 |
|
254 | 260 |
@Deprecated |
261 |
@Override |
|
255 | 262 |
public JsonArray toJSON() { |
256 | 263 |
return this.toJson(); |
257 | 264 |
} |
265 |
|
|
266 |
@Override |
|
267 |
public Expression makeFilter(int maxfeatures) { |
|
268 |
try { |
|
269 |
FeatureType ftype = this.getDefaultFeatureType(); |
|
270 |
if( !ftype.hasPrimaryKey() ) { |
|
271 |
return null; |
|
272 |
} |
|
273 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
|
274 |
final MutableInt counter = new MutableInt(0); |
|
275 |
this.accept((Object obj) -> { |
|
276 |
if( counter.getAndIncrement()>maxfeatures ) { |
|
277 |
throw new VisitCanceledException(); |
|
278 |
} |
|
279 |
Feature feature = (Feature) obj; |
|
280 |
for (FeatureAttributeDescriptor attrdesc : ftype.getPrimaryKey()) { |
|
281 |
builder.and( |
|
282 |
builder.eq( |
|
283 |
builder.column(attrdesc.getName()), |
|
284 |
builder.constant(feature.get(attrdesc.getName())) |
|
285 |
) |
|
286 |
); |
|
287 |
} |
|
288 |
}); |
|
289 |
Expression filter = ExpressionUtils.createExpression(builder.toString()); |
|
290 |
return filter; |
|
291 |
} catch (Exception ex) { |
|
292 |
LOGGER.warn("Can't build filter expression.", ex); |
|
293 |
return null; |
|
294 |
} |
|
295 |
} |
|
296 |
|
|
258 | 297 |
} |
Also available in: Unified diff