Revision 47665
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/DefaultFeatureStore.java | ||
---|---|---|
361 | 361 |
this.metadataChildren.add(provider); |
362 | 362 |
if (!this.ignoreDALResource) { |
363 | 363 |
loadDALFile(); |
364 |
|
|
365 |
// Habria que crear un metodo en el proveedor para que de prioidad |
|
366 |
// a los parametros frente a lo que se a leido en el fichero dal |
|
367 |
// DataStoreProvider arreglalo segun los parametros del usuario |
|
368 |
// fixFeatureTypeFromParameters |
|
364 |
// Este metodo en el proveedor da prioridad |
|
365 |
// a los parametros frente a lo que se ha leido en el fichero dal |
|
369 | 366 |
this.provider.fixFeatureTypeFromParameters(); |
370 | 367 |
try { |
371 | 368 |
if (defaultFeatureType != null) { |
... | ... | |
599 | 596 |
if (hasDynValue(DataStore.METADATA_ENVELOPE)) { |
600 | 597 |
return (Envelope) getDynValue(DataStore.METADATA_ENVELOPE); |
601 | 598 |
} |
602 |
Envelope envelope = this.provider.getEnvelope(); |
|
603 |
if (envelope != null) { |
|
604 |
return envelope; |
|
605 |
} |
|
606 | 599 |
FeatureAttributeDescriptor attrdesc = this.getDefaultFeatureType().getDefaultGeometryAttribute(); |
607 |
if (attrdesc == null || (!attrdesc.isComputed() && this.getTransforms().isEmpty())) {
|
|
600 |
if (attrdesc == null) { |
|
608 | 601 |
return null; |
609 | 602 |
} |
603 |
if (!attrdesc.isComputed()) { |
|
604 |
Envelope envelope = this.provider.getEnvelope(attrdesc.getName()); |
|
605 |
if (envelope != null) { |
|
606 |
return envelope; |
|
607 |
} |
|
608 |
if (this.getTransforms().isEmpty()) { |
|
609 |
return null; |
|
610 |
} |
|
611 |
} |
|
610 | 612 |
final int index = attrdesc.getIndex(); |
611 | 613 |
final MutableObject<Envelope> envelopeValue = new MutableObject<>(); |
612 | 614 |
try { |
... | ... | |
1558 | 1560 |
throw new StoreUpdateFeatureTypeException(e, this.getName()); |
1559 | 1561 |
} |
1560 | 1562 |
} |
1561 |
|
|
1563 |
|
|
1562 | 1564 |
@Override |
1563 | 1565 |
public void delete(Feature feature) throws DataException { |
1564 | 1566 |
switch (this.mode) { |
... | ... | |
2011 | 2013 |
LOGGER.debug("finish editing of mode: {}", mode); |
2012 | 2014 |
LocalTransaction trans = new LocalTransaction(this.dataManager, this.getTransaction()); |
2013 | 2015 |
try { |
2014 |
Map<String, List<FeatureAttributeDescriptor>> computedFields = this.getComputedFields(); |
|
2015 | 2016 |
switch (mode) { |
2016 | 2017 |
case MODE_QUERY: |
2017 | 2018 |
throw new NeedEditingModeException(this.getName()); |
... | ... | |
2028 | 2029 |
saveDALFile(); |
2029 | 2030 |
provider.endAppend(); |
2030 | 2031 |
exitEditingMode(); |
2031 |
this.updateComputedFields(computedFields); |
|
2032 | 2032 |
loadDALFile(); |
2033 | 2033 |
updateIndexes(); |
2034 | 2034 |
trans.commit(); |
... | ... | |
2067 | 2067 |
provider.performChanges(featureManager.getDeleted(), |
2068 | 2068 |
featureManager.getInserted(), |
2069 | 2069 |
featureManager.getUpdated(), |
2070 |
removeCalculatedAttributes(featureTypeManager.getFeatureTypesChanged()).iterator()); |
|
2071 |
|
|
2070 |
featureTypeManager.getFeatureTypesChanged().iterator()); |
|
2072 | 2071 |
} |
2073 |
this.updateComputedFields(computedFields); |
|
2074 | 2072 |
exitEditingMode(); |
2075 | 2073 |
loadDALFile(); |
2076 | 2074 |
updateIndexes(); |
... | ... | |
2115 | 2113 |
return this.editingSessionCode; |
2116 | 2114 |
} |
2117 | 2115 |
|
2118 |
private Map<String, List<FeatureAttributeDescriptor>> getComputedFields() throws DataException { |
|
2119 |
Map<String, List<FeatureAttributeDescriptor>> r = new HashMap<>(); |
|
2120 |
|
|
2121 |
List<FeatureType> theTypes = new ArrayList<>(); |
|
2122 |
theTypes.addAll(this.getFeatureTypes()); |
|
2123 |
theTypes.add(this.getDefaultFeatureType()); |
|
2124 |
for (int n = 0; n < theTypes.size(); n++) { |
|
2125 |
FeatureType type = theTypes.get(n); |
|
2126 |
for (FeatureAttributeDescriptor attrdesc : type) { |
|
2127 |
FeatureAttributeEmulator emulator = attrdesc.getFeatureAttributeEmulator(); |
|
2128 |
if (emulator != null) { |
|
2129 |
List<FeatureAttributeDescriptor> l = r.get(type.getId()); |
|
2130 |
if (l == null) { |
|
2131 |
l = new ArrayList<>(); |
|
2132 |
r.put(type.getId(), l); |
|
2133 |
} |
|
2134 |
l.add(attrdesc); |
|
2135 |
} |
|
2136 |
} |
|
2137 |
} |
|
2138 |
return r; |
|
2139 |
} |
|
2140 |
|
|
2141 |
private void updateComputedFields(Map<String, List<FeatureAttributeDescriptor>> computedFields) throws DataException { |
|
2142 |
|
|
2143 |
List<FeatureType> theTypes = new ArrayList<>(); |
|
2144 |
theTypes.addAll(this.getFeatureTypes()); |
|
2145 |
theTypes.add(this.getDefaultFeatureType()); |
|
2146 |
for (int n = 0; n < theTypes.size(); n++) { |
|
2147 |
DefaultFeatureType type = (DefaultFeatureType) theTypes.get(n); |
|
2148 |
List<FeatureAttributeDescriptor> x = computedFields.get(type.getId()); |
|
2149 |
if (x != null && !x.isEmpty()) { |
|
2150 |
for (FeatureAttributeDescriptor attrdesc : x) { |
|
2151 |
if (type.get(attrdesc.getName()) == null) { |
|
2152 |
type.add(attrdesc); |
|
2153 |
} |
|
2154 |
} |
|
2155 |
} |
|
2156 |
} |
|
2157 |
|
|
2158 |
} |
|
2159 |
|
|
2160 |
private List<FeatureTypeChanged> removeCalculatedAttributes(List<FeatureTypeChanged> ftypes) { |
|
2161 |
// FIXME: Falta por implementar |
|
2162 |
// for (FeatureStoreProvider.FeatureTypeChanged ftype : ftypes) { |
|
2163 |
// EditableFeatureType target = (EditableFeatureType) ftype.getTarget(); |
|
2164 |
// for (FeatureAttributeDescriptor attributeDescriptor : ftype.getSource().getAttributeDescriptors()) { |
|
2165 |
// if (attributeDescriptor.isComputed()) { |
|
2166 |
// target.remove(attributeDescriptor.getName()); |
|
2167 |
// } |
|
2168 |
// } |
|
2169 |
// } |
|
2170 |
return ftypes; |
|
2171 |
} |
|
2172 |
|
|
2173 | 2116 |
private void clearResourcesCache() { |
2174 | 2117 |
ResourcesStorage theResourcesStorage = null; |
2175 | 2118 |
try { |
... | ... | |
2283 | 2226 |
provider.performChanges(featureManager.getDeleted(), |
2284 | 2227 |
featureManager.getInserted(), |
2285 | 2228 |
featureManager.getUpdated(), |
2286 |
removeCalculatedAttributes(featureTypeManager.getFeatureTypesChanged()).iterator()); |
|
2229 |
// removeCalculatedAttributes(featureTypeManager.getFeatureTypesChanged()).iterator()); |
|
2230 |
featureTypeManager.getFeatureTypesChanged().iterator()); |
|
2287 | 2231 |
} |
2288 | 2232 |
invalidateIndexes(); |
2289 | 2233 |
featureManager = new FeatureManager(this); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/AbstractFeatureSetProvider.java | ||
---|---|---|
34 | 34 |
import org.gvsig.expressionevaluator.Interpreter; |
35 | 35 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
36 | 36 |
import org.gvsig.expressionevaluator.SymbolTable; |
37 |
|
|
38 | 37 |
import org.gvsig.fmap.dal.exception.DataException; |
39 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
40 | 38 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
41 | 39 |
import org.gvsig.fmap.dal.feature.FeatureType; |
42 | 40 |
import org.gvsig.fmap.geom.Geometry; |
... | ... | |
214 | 212 |
} |
215 | 213 |
} |
216 | 214 |
|
215 |
protected SpatialIndex getSpatialIndex(String name) { |
|
216 |
return null; |
|
217 |
} |
|
217 | 218 |
|
218 | 219 |
@SuppressWarnings("Convert2Lambda") |
219 |
protected Iterator createSpatialIterator(FeatureType featureType, FeatureQuery query, SpatialIndex spatialIndex) {
|
|
220 |
if( featureType==null || spatialIndex == null || query == null || query.getFilter()==null) {
|
|
220 |
protected Iterator createSpatialIterator(FeatureType featureType, FeatureQuery query) { |
|
221 |
if( featureType==null || query == null || query.getFilter()==null) { |
|
221 | 222 |
return null; |
222 | 223 |
} |
223 |
FeatureAttributeDescriptor geomdesc = featureType.getDefaultGeometryAttribute(); |
|
224 |
if( geomdesc == null ) { |
|
225 |
return null; |
|
226 |
} |
|
227 | 224 |
ExpressionEvaluatorManager expmanager = ExpressionEvaluatorLocator.getExpressionEvaluatorManager(); |
228 | 225 |
Code filterCode = null; |
229 | 226 |
try { |
... | ... | |
240 | 237 |
filterSymbolTable = filterExp.getSymbolTable(); |
241 | 238 |
} |
242 | 239 |
MutableObject<Code> spatialQuery = new MutableObject<>(); |
240 |
MutableObject<SpatialIndex> spatialIndex = new MutableObject<>(); |
|
243 | 241 |
try { |
244 | 242 |
filterCode.accept(new Visitor() { |
245 | 243 |
@Override |
246 | 244 |
public void visit(Object obj) throws VisitCanceledException, BaseException { |
247 |
if (Code.isFunction((Code) obj, "ST_INTERSECTS") |
|
245 |
SpatialIndex spaIndex = null; |
|
246 |
if (Code.isFunction((Code) obj, "NOT") && spatialIndex.getValue() == null) { |
|
247 |
Code isCode = ((Code.Callable)obj).parameters().get(0); |
|
248 |
if (Code.isFunction(isCode, "IS")) { |
|
249 |
Code p1 = ((Code.Callable)isCode).parameters().get(0); |
|
250 |
Code p2 = ((Code.Callable)isCode).parameters().get(1); |
|
251 |
if (p1.code() == Code.IDENTIFIER && p2.code()==Code.CONSTANT && ((Code.Constant)p2).value()==null) { |
|
252 |
spaIndex = getSpatialIndex(((Code.Identifier) p1).name()); |
|
253 |
if(spaIndex != null) { |
|
254 |
spatialIndex.setValue(spaIndex); |
|
255 |
} |
|
256 |
} |
|
257 |
} |
|
258 |
} else if (Code.isFunction((Code) obj, "ST_INTERSECTS") |
|
248 | 259 |
|| Code.isFunction((Code) obj, "ST_CONTAINS") |
249 | 260 |
|| Code.isFunction((Code) obj, "&&")) { |
250 | 261 |
Code.Callable intersects = (Code.Callable) obj; |
251 | 262 |
Code p1 = intersects.parameters().get(0); |
252 | 263 |
Code p2 = intersects.parameters().get(1); |
253 | 264 |
Code sq = null; |
254 |
if (Code.isIdentifier(p1, geomdesc.getName())) { |
|
255 |
sq = p2; |
|
256 |
} else if (Code.isIdentifier(p2, geomdesc.getName())) { |
|
257 |
sq = p1; |
|
265 |
if (p1.code() == Code.IDENTIFIER) { |
|
266 |
spaIndex = getSpatialIndex(((Code.Identifier) p1).name()); |
|
267 |
if(spaIndex != null) { |
|
268 |
sq = p2; |
|
269 |
} |
|
270 |
} else if (p2.code() == Code.IDENTIFIER) { |
|
271 |
spaIndex = getSpatialIndex(((Code.Identifier) p2).name()); |
|
272 |
if(spaIndex != null) { |
|
273 |
sq = p1; |
|
274 |
} |
|
258 | 275 |
} |
259 | 276 |
if (sq != null) { |
277 |
spatialIndex.setValue(spaIndex); |
|
260 | 278 |
spatialQuery.setValue(sq); |
261 | 279 |
throw new VisitCanceledException(); |
262 | 280 |
} |
... | ... | |
266 | 284 |
} catch(VisitCanceledException ex) { |
267 | 285 |
|
268 | 286 |
} |
269 |
if( spatialQuery.getValue()!=null ) { |
|
287 |
if( spatialIndex.getValue() != null && spatialQuery.getValue()!=null ) {
|
|
270 | 288 |
Interpreter interpreter = expmanager.createInterpreter(); |
271 | 289 |
MutableSymbolTable symbolTable; |
272 | 290 |
if( filterSymbolTable instanceof MutableSymbolTable ) { |
... | ... | |
286 | 304 |
envelope = (Envelope) value; |
287 | 305 |
} |
288 | 306 |
if( envelope!=null ) { |
289 |
return spatialIndex.query(envelope, Long.MAX_VALUE); |
|
307 |
return spatialIndex.getValue().query(envelope, Long.MAX_VALUE);
|
|
290 | 308 |
} |
309 |
} else if( spatialIndex.getValue() != null) { |
|
310 |
return spatialIndex.getValue().queryAll(); |
|
291 | 311 |
} |
312 |
|
|
292 | 313 |
} catch (Exception ex) { |
293 | 314 |
LOGGER.warn("Can't use spatial index for query '"+Objects.toString(filterCode)+"'.",ex); |
294 | 315 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/AbstractFeatureStoreProvider.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
import java.io.BufferedOutputStream; |
28 | 28 |
import java.io.File; |
29 |
import java.io.FileOutputStream; |
|
30 | 29 |
import java.io.OutputStream; |
31 | 30 |
import java.nio.charset.StandardCharsets; |
32 | 31 |
import java.util.Collection; |
... | ... | |
63 | 62 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
64 | 63 |
import org.gvsig.fmap.dal.spi.AbstractDataStoreProvider; |
65 | 64 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
66 |
import org.gvsig.fmap.dal.spi.DataTransactionServices; |
|
67 | 65 |
import org.gvsig.fmap.geom.primitive.Envelope; |
68 | 66 |
import org.gvsig.timesupport.Interval; |
69 | 67 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
... | ... | |
342 | 340 |
* |
343 | 341 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#getEnvelope() |
344 | 342 |
*/ |
343 |
@Override |
|
345 | 344 |
public Envelope getEnvelope() throws DataException { |
346 | 345 |
return null; |
347 | 346 |
} |
348 | 347 |
|
348 |
/** |
|
349 |
* Override on providers that allow more than one geometry |
|
350 |
* |
|
351 |
* @param geomname |
|
352 |
* @return |
|
353 |
* @throws DataException |
|
354 |
*/ |
|
355 |
@Override |
|
356 |
public Envelope getEnvelope(String geomname) throws DataException { |
|
357 |
return getEnvelope(); |
|
358 |
} |
|
359 |
|
|
360 |
|
|
361 |
|
|
349 | 362 |
/** |
350 | 363 |
* unsupported geometry write by default (return <code>false</code>), |
351 | 364 |
* override this otherwise |
... | ... | |
654 | 667 |
public FeatureSetProvider createSet(FeatureQuery query, FeatureType providerFeatureType, FeatureType storeFeatureType) throws DataException { |
655 | 668 |
return this.createSet(query, storeFeatureType); |
656 | 669 |
} |
657 |
|
|
658 |
|
|
670 |
|
|
659 | 671 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/FeatureStoreProvider.java | ||
---|---|---|
27 | 27 |
import java.util.Iterator; |
28 | 28 |
import org.gvsig.expressionevaluator.Expression; |
29 | 29 |
import org.gvsig.fmap.dal.DataStoreParameters; |
30 |
import org.gvsig.fmap.dal.DataTransaction; |
|
31 | 30 |
import org.gvsig.fmap.dal.DataTypes; |
32 | 31 |
import org.gvsig.fmap.dal.exception.DataException; |
33 | 32 |
import org.gvsig.fmap.dal.feature.FeatureLocks; |
... | ... | |
37 | 36 |
import org.gvsig.fmap.dal.feature.FeatureType; |
38 | 37 |
import org.gvsig.fmap.dal.feature.FeatureType.FeatureTypeChanged; |
39 | 38 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
40 |
import org.gvsig.fmap.dal.spi.DataTransactionServices; |
|
41 | 39 |
import org.gvsig.fmap.geom.primitive.Envelope; |
42 | 40 |
|
43 | 41 |
/** |
... | ... | |
185 | 183 |
* @throws org.gvsig.fmap.dal.exception.DataException |
186 | 184 |
*/ |
187 | 185 |
public Envelope getEnvelope() throws DataException; |
186 |
|
|
187 |
public Envelope getEnvelope(String geomname) throws DataException; |
|
188 | 188 |
|
189 | 189 |
/** |
190 | 190 |
* Informs if store supports locks |
... | ... | |
278 | 278 |
public void passThroughDelete(Expression filter) throws DataException; |
279 | 279 |
|
280 | 280 |
public void passThroughUpdate(Object[] parameters, Expression filter); |
281 |
|
|
281 |
|
|
282 | 282 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/store/simplereader/SimpleReaderUtils.java | ||
---|---|---|
11 | 11 |
import java.io.InputStream; |
12 | 12 |
import java.io.InputStreamReader; |
13 | 13 |
import java.nio.charset.Charset; |
14 |
import java.util.Objects; |
|
15 |
import org.apache.commons.io.FileUtils; |
|
14 | 16 |
import org.apache.commons.io.input.BOMInputStream; |
15 | 17 |
import org.apache.commons.lang3.StringUtils; |
16 | 18 |
import org.slf4j.Logger; |
... | ... | |
43 | 45 |
return isr; |
44 | 46 |
} |
45 | 47 |
|
48 |
public static boolean isFileNewer(File file, File fileReference){ |
|
49 |
if(file == null || fileReference == null){ |
|
50 |
return false; |
|
51 |
} |
|
52 |
long lastModified = fileReference.lastModified(); |
|
53 |
// Por si el archivo nos lo ha enviado el Doctor Who desde el futuro |
|
54 |
long now = System.currentTimeMillis(); |
|
55 |
if(now < lastModified){ |
|
56 |
LOGGER.warn("The file date is future " + Objects.toString(fileReference)); |
|
57 |
lastModified = now; |
|
58 |
} |
|
59 |
return FileUtils.isFileNewer(file, lastModified); |
|
60 |
} |
|
46 | 61 |
|
62 |
public static boolean isFileNewer(File file, long reference){ |
|
63 |
if(file == null){ |
|
64 |
return false; |
|
65 |
} |
|
66 |
// Por si el archivo nos lo ha enviado el Doctor Who desde el futuro |
|
67 |
long now = System.currentTimeMillis(); |
|
68 |
if(now < reference){ |
|
69 |
LOGGER.warn("The reference file date is future " + Objects.toString(file)); |
|
70 |
reference = now; |
|
71 |
} |
|
72 |
return FileUtils.isFileNewer(file, reference); |
|
73 |
} |
|
47 | 74 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/store/simplereader/SimpleReaderSetProvider.java | ||
---|---|---|
33 | 33 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureProviderIterator; |
34 | 34 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureSetProvider; |
35 | 35 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
36 |
import org.gvsig.fmap.geom.SpatialIndex; |
|
36 | 37 |
import org.gvsig.tools.exception.BaseException; |
37 | 38 |
|
38 | 39 |
/** |
... | ... | |
99 | 100 |
if( this.query!=null ) { |
100 | 101 |
this.spatialIndexIt = createSpatialIterator( |
101 | 102 |
store.getFeatureStore().getDefaultFeatureTypeQuietly(), |
102 |
query, |
|
103 |
store.getSpatialIndex() |
|
103 |
query |
|
104 | 104 |
); |
105 | 105 |
} |
106 | 106 |
} |
... | ... | |
190 | 190 |
return (SimpleReaderStoreProvider) super.getStore(); |
191 | 191 |
} |
192 | 192 |
|
193 |
@Override |
|
194 |
protected SpatialIndex getSpatialIndex(String name) { |
|
195 |
return getStore().getSpatialIndex(name); |
|
196 |
} |
|
197 |
|
|
193 | 198 |
protected String getStoreFullName() { |
194 | 199 |
try { |
195 | 200 |
return this.getStore().getFullName(); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/store/simplereader/SimpleReaderStoreProvider.java | ||
---|---|---|
110 | 110 |
|
111 | 111 |
protected static final Logger LOGGER = LoggerFactory.getLogger(SimpleReaderStoreProvider.class); |
112 | 112 |
|
113 |
// public static final String NAME = DataStore.CSV_PROVIDER_NAME; |
|
114 |
// public static final String DESCRIPTION = "CSV file"; |
|
115 |
// |
|
116 |
// public static final String METADATA_DEFINITION_NAME = NAME; |
|
117 |
|
|
118 | 113 |
protected final ResourceProvider resource; |
119 | 114 |
|
120 | 115 |
protected long counterNewsOIDs = 0; |
... | ... | |
138 | 133 |
metadata |
139 | 134 |
); |
140 | 135 |
TaskStatusManager manager = ToolsLocator.getTaskStatusManager(); |
141 |
this.taskStatus = manager.createDefaultSimpleTaskStatus("CSV");
|
|
136 |
this.taskStatus = manager.createDefaultSimpleTaskStatus(this.getProviderName());
|
|
142 | 137 |
this.taskStatus.setAutoremove(true); |
143 | 138 |
|
144 | 139 |
this.envelopes = new HashMap<>(); |
... | ... | |
189 | 184 |
try { |
190 | 185 |
loadFeatures(); |
191 | 186 |
} catch (RuntimeException e) { |
192 |
LOGGER.debug("Can't load features from CSV '" + getFullFileName() + "'.", e);
|
|
187 |
LOGGER.debug("Can't load features from '" + getFullFileName() + "'.", e); |
|
193 | 188 |
throw e; |
194 | 189 |
} catch (Exception e) { |
195 |
LOGGER.debug("Can't load features from CSV '" + getFullFileName() + "'.", e);
|
|
190 |
LOGGER.debug("Can't load features from '" + getFullFileName() + "'.", e); |
|
196 | 191 |
throw new RuntimeException(e); |
197 | 192 |
} |
198 | 193 |
} |
... | ... | |
272 | 267 |
} |
273 | 268 |
} |
274 | 269 |
|
275 |
@Override |
|
276 |
@SuppressWarnings("Convert2Lambda") |
|
277 |
public Envelope getEnvelope() throws DataException { |
|
270 |
public Envelope getEnvelope(String geomName) throws DataException { |
|
278 | 271 |
this.open(); |
279 |
FeatureAttributeDescriptor geomdesc = this.featureType.getDefaultGeometryAttribute(); |
|
280 |
String geomName = geomdesc.getName(); |
|
272 |
if(geomName == null){ |
|
273 |
FeatureAttributeDescriptor geomdesc = this.featureType.getDefaultGeometryAttribute(); |
|
274 |
geomName = geomdesc.getName(); |
|
275 |
} |
|
281 | 276 |
Envelope env = this.envelopes.get(geomName); |
282 | 277 |
if (env != null) { |
283 | 278 |
return env; |
284 | 279 |
} |
285 |
env = bboxFileLoad("_"+geomName); |
|
286 |
if (env != null) { |
|
287 |
this.envelopes.put(geomName, env); |
|
288 |
return env; |
|
280 |
|
|
281 |
File data_file = SimpleReaderStoreParameters.getFile(this.getSimpleReaderParameters()); |
|
282 |
File bboxfile = this.getAuxFile("_"+geomName, "bbox"); |
|
283 |
if (bboxfile.exists() && SimpleReaderUtils.isFileNewer(bboxfile, data_file)) { |
|
284 |
env = bboxFileLoad(bboxfile); |
|
285 |
if (env != null) { |
|
286 |
this.envelopes.put(geomName, env); |
|
287 |
return env; |
|
288 |
} |
|
289 | 289 |
} |
290 | 290 |
if (!this.need_calculate_envelope) { |
291 | 291 |
return null; |
... | ... | |
331 | 331 |
|
332 | 332 |
this.need_calculate_envelope = false; |
333 | 333 |
return env; |
334 |
|
|
334 | 335 |
} |
336 |
|
|
337 |
@Override |
|
338 |
public Envelope getEnvelope() throws DataException { |
|
339 |
return getEnvelope(null); |
|
340 |
} |
|
335 | 341 |
|
336 | 342 |
@Override |
337 | 343 |
public Object getDynValue(String name) throws DynFieldNotFoundException { |
... | ... | |
425 | 431 |
return point; |
426 | 432 |
} catch (Exception ex) { |
427 | 433 |
if (++errorcount < 5) { |
428 |
logger.warn("[" + errorcount + "] Can't create point in CSV provider. XNAME='"
|
|
434 |
logger.warn("[" + errorcount + "] Can't create point. XNAME='" |
|
429 | 435 |
+ xname + "', YNAME='" + yname + "', ZNAME='" + zname + "', data=" + data.toString()); |
430 | 436 |
} |
431 | 437 |
return null; |
... | ... | |
529 | 535 |
InputStreamReader in = null; |
530 | 536 |
SimpleReader reader = null; |
531 | 537 |
try { |
532 |
taskStatus.setTitle("CSV "+this.getName());
|
|
538 |
taskStatus.setTitle(this.getProviderName()+" "+this.getName());
|
|
533 | 539 |
taskStatus.add(); |
534 |
// boolean ignore_errors = CSVStoreParameters.getIgnoreErrors(getCSVParameters()); |
|
535 | 540 |
|
536 | 541 |
// Initialize the feature types |
537 | 542 |
EditableFeatureType edftype = getStoreServices().createFeatureType(this.getName()); |
... | ... | |
598 | 603 |
} |
599 | 604 |
for (int i = 0; i < ftype.size(); i++) { |
600 | 605 |
if (this.rowToFeatureTranslator.getColumnSize(i) > 0) { |
601 |
// if (sizes[i] > 0) { |
|
602 | 606 |
EditableFeatureAttributeDescriptor efad = ((EditableFeatureAttributeDescriptor) edftype.getAttributeDescriptor(i)); |
603 |
// efad.setSize(sizes[i]); |
|
604 | 607 |
efad.setSize(this.rowToFeatureTranslator.getColumnSize(i)); |
605 | 608 |
} |
606 | 609 |
} |
... | ... | |
654 | 657 |
} |
655 | 658 |
|
656 | 659 |
protected boolean mustFixFeatureType() { |
660 |
FeatureStore theStore = this.getStoreServices().getFeatureStore(); |
|
661 |
FeatureType ft = theStore.getDefaultFeatureTypeQuietly(); |
|
662 |
String geomName = ft.getDefaultGeometryAttributeName(); |
|
663 |
if(StringUtils.isNotBlank(geomName)){ |
|
664 |
if(this.featureType.getAttributeDescriptor(geomName)==null){ |
|
665 |
return true; |
|
666 |
} |
|
667 |
} |
|
657 | 668 |
return false; |
658 | 669 |
} |
659 | 670 |
|
... | ... | |
804 | 815 |
String geomName = geomdesc.getName(); |
805 | 816 |
Envelope env = bboxFileLoad("_"+geomName); |
806 | 817 |
File indexfile = this.getAuxFile("_"+geomName, extname); |
807 |
boolean createIndex = !indexfile.exists(); |
|
808 | 818 |
|
819 |
File data_file = SimpleReaderStoreParameters.getFile(this.getSimpleReaderParameters()); |
|
820 |
boolean createIndex = !indexfile.exists() || SimpleReaderUtils.isFileNewer(data_file, indexfile); |
|
821 |
|
|
809 | 822 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
810 | 823 |
SpatialIndexFactory indexfactory = geomManager.getSpatialIndexFactory(indexTypeName); |
811 | 824 |
DynObject params = indexfactory.createParameters(); |
... | ... | |
884 | 897 |
return index_file; |
885 | 898 |
} |
886 | 899 |
|
900 |
public SpatialIndex getSpatialIndex(String geomName) { |
|
901 |
if(spatialIndexes == null){ |
|
902 |
return null; |
|
903 |
} |
|
904 |
return spatialIndexes.get(geomName); |
|
905 |
} |
|
906 |
|
|
887 | 907 |
public SpatialIndex getSpatialIndex() { |
888 | 908 |
if(spatialIndexes == null){ |
889 | 909 |
return null; |
... | ... | |
949 | 969 |
return null; |
950 | 970 |
} |
951 | 971 |
|
952 |
protected abstract SimpleReader getSimpleReader(SimpleReaderStoreParameters parameters, Reader in) throws IOException ;//{ |
|
953 |
// return CSVUtils.getSimpleReader(getSimpleReaderParameters(), in); |
|
954 |
// } |
|
972 |
protected abstract SimpleReader getSimpleReader(SimpleReaderStoreParameters parameters, Reader in) throws IOException ; |
|
955 | 973 |
|
956 | 974 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/csv/CSVStoreProvider.java | ||
---|---|---|
46 | 46 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
47 | 47 |
import org.gvsig.fmap.dal.store.csv.simplereaders.CSVReaderSuperCSV; |
48 | 48 |
import org.gvsig.fmap.dal.store.csv.simplereaders.FixedLenReader; |
49 |
import org.gvsig.fmap.dal.store.simplereader.simplereaders.SimpleReader; |
|
50 | 49 |
import org.gvsig.fmap.dal.store.simplereader.SimpleReaderFeatureTypeLoader; |
51 | 50 |
import org.gvsig.fmap.dal.store.simplereader.SimpleReaderStoreParameters; |
52 | 51 |
import org.gvsig.fmap.dal.store.simplereader.SimpleReaderStoreProvider; |
52 |
import org.gvsig.fmap.dal.store.simplereader.simplereaders.SimpleReader; |
|
53 | 53 |
import org.gvsig.tools.ToolsLocator; |
54 | 54 |
import org.gvsig.tools.dispose.DisposableIterator; |
55 | 55 |
import org.gvsig.tools.i18n.I18nManager; |
... | ... | |
291 | 291 |
@Override |
292 | 292 |
protected boolean mustFixFeatureType() { |
293 | 293 |
try { |
294 |
if(super.mustFixFeatureType()){ |
|
295 |
return true; |
|
296 |
} |
|
294 | 297 |
String param_types_def = CSVStoreParameters.getRawFieldTypes(this.getParameters()); |
295 | 298 |
String[] pointDimensionNames = CSVStoreParameters.getPointDimensionNames(this.getParameters()); |
296 | 299 |
String geometry_column = CSVStoreParameters.getGeometryColumn(this.getParameters()); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.gml/src/main/java/org/gvsig/fmap/dal/store/gml/virtualrows/XmlCommons.java | ||
---|---|---|
140 | 140 |
} catch(Throwable t) { |
141 | 141 |
throw new RuntimeException("Can't count lines.",t); |
142 | 142 |
} |
143 |
}
|
|
143 |
} |
|
144 | 144 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.gml/src/main/java/org/gvsig/fmap/dal/store/gml/virtualrows/XMLFileAsList.java | ||
---|---|---|
27 | 27 |
import org.apache.commons.io.IOUtils; |
28 | 28 |
import org.apache.commons.io.input.CloseShieldReader; |
29 | 29 |
import org.apache.commons.lang3.StringUtils; |
30 |
import static org.gvsig.fmap.dal.store.simplereader.SimpleReaderUtils.isFileNewer; |
|
30 | 31 |
import org.gvsig.fmap.dal.store.simplereader.virtualrows.LimitedReader; |
31 | 32 |
import org.gvsig.fmap.dal.store.simplereader.virtualrows.RandomAccessFileReader; |
32 | 33 |
import org.gvsig.fmap.dal.store.simplereader.virtualrows.RecordsFile; |
... | ... | |
80 | 81 |
private List<String> fieldPaths; |
81 | 82 |
private final List<String> geomPaths; |
82 | 83 |
private int combineMode; |
84 |
private long lastModified; |
|
83 | 85 |
|
84 | 86 |
|
85 |
// ruta recordnum ruta recordnum |
|
86 |
// public XMLFileAsList(File text, Charset charset, List<Pair<String,Integer>> recordPath, List<Pair<String,Integer>> fieldPaths) throws IOException { |
|
87 | 87 |
public XMLFileAsList(File text, Charset charset, String recordPath, List<String> geomPath, List<String> fieldPaths) throws IOException { |
88 | 88 |
this.reader = new RandomAccessFileReader(text, charset); |
89 | 89 |
this.index = null; |
90 | 90 |
this.recordPath = recordPath; |
91 | 91 |
this.geomPaths = geomPath; |
92 | 92 |
this.fieldPaths = fieldPaths; |
93 |
this.lastModified = text.lastModified(); |
|
93 | 94 |
} |
94 | 95 |
|
95 |
// public XMLFileAsList(File text, File index, Charset charset, String recordPath, List<String> geomPath, List<String> fieldPaths, SimpleTaskStatus status) throws IOException { |
|
96 |
// this.reader = new RandomAccessFileReader(text, charset); |
|
97 |
// this.recordPath = recordPath; |
|
98 |
// this.geomPaths = geomPath; |
|
99 |
// this.fieldPaths = fieldPaths; |
|
100 |
// if (index.exists()) { |
|
101 |
// // TODO: Force to create index if text newer than index |
|
102 |
// this.index = new RecordsFileImpl(index); |
|
103 |
// } else { |
|
104 |
// this.createIndex(index, status); |
|
105 |
// } |
|
106 |
// } |
|
107 |
|
|
108 | 96 |
public XMLFileAsList(RandomAccessFileReader reader, RecordsFile index, String recordPath, List<String> geomPath, List<String> fieldPaths) throws IOException { |
109 | 97 |
this.reader = reader; |
110 | 98 |
this.index = index; |
111 | 99 |
this.recordPath = recordPath; |
112 | 100 |
this.geomPaths = geomPath; |
113 | 101 |
this.fieldPaths = fieldPaths; |
102 |
this.lastModified = -1; |
|
114 | 103 |
} |
115 | 104 |
|
116 | 105 |
@Override |
... | ... | |
294 | 283 |
this.combineMode = combineMode; |
295 | 284 |
} |
296 | 285 |
|
286 |
public boolean loadIndex(File fileIndex, SimpleTaskStatus status) throws IOException{ |
|
287 |
if (!fileIndex.exists()) { |
|
288 |
return false; |
|
289 |
} |
|
290 |
if(this.lastModified > 0 && isFileNewer(fileIndex, this.lastModified)){ |
|
291 |
this.index = new RecordsFileImpl(fileIndex); |
|
292 |
return true; |
|
293 |
} |
|
294 |
return false; |
|
295 |
} |
|
296 |
|
|
297 | 297 |
final public void createIndex(File indexFile, SimpleTaskStatus status) throws IOException { |
298 | 298 |
try { |
299 | 299 |
// 1. Creamos el indice vacio |
... | ... | |
331 | 331 |
if (status != null) { |
332 | 332 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
333 | 333 |
status.push(); |
334 |
status.message(i18n.getTranslation("_Creating_the_index_of_the_lines"));
|
|
334 |
status.message(i18n.getTranslation("_Creating_record_index"));
|
|
335 | 335 |
status.setIndeterminate(); |
336 | 336 |
} |
337 | 337 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.gml/src/main/java/org/gvsig/fmap/dal/store/gml/simplereaders/GMLReader.java | ||
---|---|---|
19 | 19 |
import org.gvsig.fmap.dal.store.gml.virtualrows.GfsFile; |
20 | 20 |
import org.gvsig.fmap.dal.store.gml.virtualrows.XMLFileAsList; |
21 | 21 |
import org.gvsig.fmap.dal.store.simplereader.SimpleReaderStoreParameters; |
22 |
import static org.gvsig.fmap.dal.store.simplereader.SimpleReaderUtils.isFileNewer; |
|
22 | 23 |
import org.gvsig.fmap.dal.store.simplereader.simplereaders.AbstractSimpleReader; |
23 | 24 |
import org.gvsig.tools.ToolsLocator; |
24 | 25 |
import org.gvsig.tools.dataTypes.DataType; |
... | ... | |
49 | 50 |
File gmlIdx = new File(FilenameUtils.removeExtension(gmlFile.getAbsolutePath())+".gmlidx"); |
50 | 51 |
File gfsFile = new File(FilenameUtils.removeExtension(gmlFile.getAbsolutePath())+".gfs"); |
51 | 52 |
gfs = new GfsFile(); |
52 |
if(gfsFile.exists()){ |
|
53 |
//TODO: Comparar fechas del gfs y gml |
|
53 |
if(gfsFile.exists() && isFileNewer(gfsFile, gmlFile)){ |
|
54 | 54 |
gfs.load(gfsFile); |
55 | 55 |
} else { |
56 | 56 |
gfs.fetch(gmlFile); |
... | ... | |
217 | 217 |
); |
218 | 218 |
|
219 | 219 |
File gmlIdx = new File(FilenameUtils.removeExtension(gmlFile.getAbsolutePath()) + ".gmlidx"); |
220 |
x.createIndex(gmlIdx, status); |
|
220 |
if(!x.loadIndex(gmlIdx, status)){ |
|
221 |
x.createIndex(gmlIdx, status); |
|
222 |
} |
|
221 | 223 |
|
222 | 224 |
x.setCombineMode(this.parameters.getGeometryCombineMode()); |
223 | 225 |
|
Also available in: Unified diff