public void beginAppend() throws DataException { this.resourcesBegin(); try { FeatureStore store = this.getFeatureStore(); FeatureType fType = store.getDefaultFeatureType(); // TODO Comprobar el campo de geometria EditableFeatureType dbfFtype = fType.getEditable(); removeGeometryColumn(dbfFtype); FeatureSet set = store.getFeatureSet(); writer = new SHPFeatureWriter(this.getName()); writer.begin(getShpParameters(), fType, dbfFtype, set.getSize()); } finally { this.resourcesEnd(); } }
public void performChanges( Iterator deleteds, Iterator inserteds, Iterator updateds, Iterator originalFeatureTypesUpdated) throws PerformEditingException { FeatureType fType; try { fType = this.getStoreServices().getDefaultFeatureType(); } catch (DataException e) { throw new PerformEditingException(this.getName(), e); } // TODO Comprobar el campo de geometria EditableFeatureType dbfFtype = fType.getEditable(); removeGeometryColumn(dbfFtype); try { this.resourcesBegin(); } catch (ResourceBeginException e1) { throw new PerformEditingException(this.getName(), e1); } try { FeatureSet set = this.getFeatureStore().getFeatureSet(); writer = new SHPFeatureWriter(this.getName()); SHPStoreParameters shpParams = this.getShpParameters(); SHPStoreParameters tmpParams = (SHPStoreParameters) shpParams.getCopy(); tmpParams.setDBFFileName(tmpParams.getDBFFileName() + ".tmp"); tmpParams.setSHPFileName(tmpParams.getSHPFileName() + ".tmp"); tmpParams.setSHXFileName(tmpParams.getSHXFileName() + ".tmp"); writer.begin(tmpParams, fType, dbfFtype, set.getSize()); DisposableIterator iter = set.fastIterator(); while (iter.hasNext()) { Feature feature = (Feature) iter.next(); writer.append(feature); } writer.end(); this.close(); this.resourceCloseRequest(); if (!shpParams.getDBFFile().delete()) { throw new PerformEditingException( this.getName(), new IOException(shpParams.getDBFFileName())); } if (!shpParams.getSHPFile().delete()) { throw new PerformEditingException( this.getName(), new IOException(shpParams.getSHPFileName())); } if (!shpParams.getSHXFile().delete()) { throw new PerformEditingException( this.getName(), new IOException(shpParams.getSHXFileName())); } if (!tmpParams.getDBFFile().renameTo(shpParams.getDBFFile())) { throw new PerformEditingException( this.getName(), new IOException(shpParams.getSHPFileName())); } if (!tmpParams.getSHPFile().renameTo(shpParams.getSHPFile())) { throw new PerformEditingException( this.getName(), new IOException(shpParams.getSHPFileName())); } if (!tmpParams.getSHXFile().renameTo(shpParams.getSHXFile())) { throw new PerformEditingException( this.getName(), new IOException(shpParams.getSHXFileName())); } this.resourcesNotifyChanges(); this.initFeatureType(); } catch (Exception e) { throw new PerformEditingException(this.getName(), e); } finally { this.resourcesEnd(); } }