Revision 47606 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

View differences:

DefaultFeatureStore.java
141 141
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
142 142
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
143 143
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices;
144
import org.gvsig.fmap.dal.feature.spi.LocalTransaction;
144 145
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProvider;
145 146
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices;
146 147
import org.gvsig.fmap.dal.impl.DefaultDataManager;
......
181 182
import org.gvsig.tools.persistence.Persistent;
182 183
import org.gvsig.tools.persistence.PersistentState;
183 184
import org.gvsig.tools.persistence.exception.PersistenceException;
185
import org.gvsig.tools.resourcesstorage.CompoundResourcesStorage;
184 186
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
185 187
import org.gvsig.tools.undo.RedoException;
186 188
import org.gvsig.tools.undo.UndoException;
......
2000 2002
        }
2001 2003
    }
2002 2004

  
2005
    
2003 2006
    @Override
2004 2007
    synchronized public void finishEditing() throws DataException {
2005 2008
        LOGGER.debug("finish editing of mode: {}", mode);
2009
        LocalTransaction trans = new LocalTransaction(this.dataManager, this.getTransaction());
2006 2010
        try {
2007 2011
            Map<String, List<FeatureAttributeDescriptor>> computedFields = this.getComputedFields();
2008 2012
            switch (mode) {
......
2016 2020
                    if (notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING).isCanceled()) {
2017 2021
                        return;
2018 2022
                    }
2023
                    trans.begin();
2024
                    trans.add(this);
2019 2025
                    saveDALFile();
2020 2026
                    provider.endAppend();
2021 2027
                    exitEditingMode();
2022 2028
                    this.updateComputedFields(computedFields);
2023 2029
                    loadDALFile();
2024 2030
                    updateIndexes();
2031
                    trans.commit();
2032
                    trans.close();
2025 2033
                    notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING);
2026 2034
                    break;
2027 2035

  
......
2044 2052
                                featureManager.isSelectionCompromised()).isCanceled()) {
2045 2053
                            return;
2046 2054
                        }
2055
                        trans.begin();
2056
                        trans.add(this);
2047 2057
                        saveDALFile();
2048 2058
                        if (featureManager.isSelectionCompromised() && selection != null) {
2049 2059
                            selection = null;
......
2061 2071
                        exitEditingMode();
2062 2072
                        loadDALFile();
2063 2073
                        updateIndexes();
2074
                        trans.commit();
2075
                        trans.close();
2064 2076
                    } else {
2065 2077
                        exitEditingMode();
2066 2078
                    }
......
2080 2092
            }
2081 2093
        } catch (ValidateFeaturesException | WriteNotAllowedException ex) {
2082 2094
            // Don't notify failed.
2095
            trans.abortQuietly();
2083 2096
            throw ex;
2084 2097
        } catch (PerformEditingException pee) {
2098
            trans.abortQuietly();
2085 2099
            notifyChange(FeatureStoreNotification.FAILED_FINISHEDITING);
2086 2100
            throw new WriteException(provider.getSourceId().toString(), pee);
2087 2101
        } catch (Exception e) {
2102
            trans.abortQuietly();
2088 2103
            notifyChange(FeatureStoreNotification.FAILED_FINISHEDITING);
2089 2104
            throw new FinishEditingException(e);
2105
        } finally {
2106
            trans.closeQuietly();
2090 2107
        }
2091 2108
    }
2092

  
2109
    
2093 2110
    @Override
2094 2111
    public String getEditingSession() {
2095 2112
        return this.editingSessionCode;
......
2388 2405

  
2389 2406
    @Override
2390 2407
    public void copyTo(final FeatureStore target) {
2408
        LocalTransaction trans = new LocalTransaction(this.getDataManager(), this.getTransaction(), ((DefaultFeatureStore)target).getTransaction());
2391 2409
        boolean finishEditingAtEnd = false;
2392 2410
        try {
2411
            trans.begin();
2412
            trans.add(this); //Es posible que hubiera que pasarle un local a true
2413
            trans.add(target); //Es posible que hubiera que pasarle un local a true
2393 2414
            if (!target.isEditing() && !target.isAppending()) {
2394 2415
                finishEditingAtEnd = true;
2395 2416
                target.edit(MODE_APPEND);
......
2402 2423
            if (finishEditingAtEnd) {
2403 2424
                target.finishEditing();
2404 2425
            }
2426
            trans.commit();
2405 2427

  
2406 2428
        } catch (Exception ex) {
2407 2429
            try {
......
2410 2432
                }
2411 2433
            } catch (Exception ex1) {
2412 2434
            }
2435
            trans.abortQuietly();
2413 2436
            throw new RuntimeException("Can't copy store.", ex);
2437
        } finally {
2438
            trans.closeQuietly();
2414 2439
        }
2415 2440

  
2416 2441
    }
......
3789 3814
    @Override
3790 3815
    public ResourcesStorage getResourcesStorage() {
3791 3816
        if (this.resourcesStorage != null) {
3817
            if(this.resourcesStorage instanceof SupportTransactions){
3818
                ((SupportTransactions)this.resourcesStorage).setTransaction(transaction);
3819
            } else if(this.resourcesStorage instanceof CompoundResourcesStorage) {
3820
                for (ResourcesStorage storage : (CompoundResourcesStorage)this.resourcesStorage) {
3821
                    if(storage instanceof SupportTransactions){
3822
                        ((SupportTransactions)storage).setTransaction(transaction);
3823
                    }
3824
                }
3825
            }
3792 3826
            DisposeUtils.bind(this.resourcesStorage);
3793 3827
            return this.resourcesStorage;
3794 3828
        }
......
3968 4002
            this.transaction.deleteObserver(transactionObserver);
3969 4003
        }
3970 4004
        this.transaction = transaction;
3971
        if (transaction == null || transaction instanceof DataTransactionServices) {
3972
            this.provider.setTransaction((DataTransactionServices) transaction);
4005
        if (this.provider != null){
4006
            if (transaction == null || transaction instanceof DataTransactionServices) {
4007
                this.provider.setTransaction((DataTransactionServices) transaction);
4008
            }
3973 4009
        }
3974 4010
        if( transaction!=null ) {
3975 4011
            transaction.addObserver(transactionObserver);

Also available in: Unified diff