Revision 37595 branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStore.java

View differences:

DefaultFeatureStore.java
35 35
import java.util.Iterator;
36 36
import java.util.List;
37 37
import java.util.Map;
38
import java.util.Map.Entry;
38 39
import java.util.Set;
39
import java.util.Map.Entry;
40 40

  
41 41
import org.cresques.cts.IProjection;
42 42
import org.slf4j.Logger;
......
853 853
                    new SpatialManager(this, provider.getEnvelope());
854 854

  
855 855
                commands =
856
                    new DefaultFeatureCommandsStack(featureManager,
856
                    new DefaultFeatureCommandsStack(this, featureManager,
857 857
                        spatialManager, featureTypeManager);
858 858
                this.mode = MODE_FULLEDIT;
859 859
                hasStrongChanges = false;
......
966 966
        }
967 967
    }
968 968

  
969
    synchronized public void delete(Feature feature) throws DataException {
969
    public void delete(Feature feature) throws DataException {       
970
        this.commands.delete(feature);
971
    }
972
    
973
    synchronized public void doDelete(Feature feature) throws DataException {
970 974
        try {
971 975
            checkInEditingMode();
972 976
            checkIsOwnFeature(feature);
973 977
            if (feature instanceof EditableFeature) {
974 978
                throw new StoreDeleteEditableFeatureException(getName());
975 979
            }
976
            notifyChange(FeatureStoreNotification.BEFORE_DELETE, feature);
977
            this.commands.delete(feature);
980
            notifyChange(FeatureStoreNotification.BEFORE_DELETE, feature);            
981
            
982
            //Update the featureManager and the spatialManager
983
            featureManager.delete(feature.getReference());
984
            spatialManager.deleteFeature(feature);
985
            
978 986
            newVersionOfUpdate();
979 987
            hasStrongChanges = true;
980 988
            notifyChange(FeatureStoreNotification.AFTER_DELETE, feature);
......
985 993

  
986 994
    private static EditableFeature lastChangedFeature = null;
987 995

  
988
    synchronized public void insert(EditableFeature feature)
996
    public synchronized void insert(EditableFeature feature) 
989 997
        throws DataException {
990 998
        LOG.debug("In editing mode {}, insert feature: {}", new Integer(mode),
991 999
            feature);
......
1008 1016
                notifyChange(FeatureStoreNotification.AFTER_INSERT, feature);
1009 1017
                break;
1010 1018

  
1011
            case MODE_FULLEDIT:
1012
                checkIsOwnFeature(feature);
1019
            case MODE_FULLEDIT: 
1013 1020
                if (feature.getSource() != null) {
1014 1021
                    throw new NoNewFeatureInsertException(this.getName());
1015 1022
                }
1016

  
1017
                waitForIndexes();
1018

  
1019
                notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature);
1020
                newVersionOfUpdate();
1021
                if ((lastChangedFeature == null)
1022
                    || (lastChangedFeature.getSource() != feature.getSource())) {
1023
                    lastChangedFeature = feature;
1024
                    feature.validate(Feature.UPDATE);
1025
                    lastChangedFeature = null;
1026
                }
1027
                commands.insert(feature.getNotEditableCopy());
1028
                hasStrongChanges = true;
1029
                hasInserts = true;
1030
                notifyChange(FeatureStoreNotification.AFTER_INSERT, feature);
1031
                break;
1023
                commands.insert(feature);               
1032 1024
            }
1033 1025
        } catch (Exception e) {
1034 1026
            throw new StoreInsertFeatureException(e, this.getName());
1035 1027
        }
1036 1028
    }
1029
    
1030
    synchronized public void doInsert(EditableFeature feature)
1031
        throws DataException {
1032
        checkIsOwnFeature(feature);
1033
   
1034
        waitForIndexes();
1037 1035

  
1038
    synchronized public void update(EditableFeature feature)
1036
        notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature);
1037
        newVersionOfUpdate();
1038
        if ((lastChangedFeature == null)
1039
            || (lastChangedFeature.getSource() != feature.getSource())) {
1040
            lastChangedFeature = feature;
1041
            feature.validate(Feature.UPDATE);
1042
            lastChangedFeature = null;
1043
        }
1044
        //Update the featureManager and the spatialManager
1045
        Feature newFeature = feature.getNotEditableCopy();
1046
        featureManager.add(newFeature);
1047
        spatialManager.insertFeature(newFeature);
1048
        
1049
        hasStrongChanges = true;
1050
        hasInserts = true;
1051
        notifyChange(FeatureStoreNotification.AFTER_INSERT, feature);       
1052
    }
1053
    
1054
    public void update(EditableFeature feature)
1055
    throws DataException {        
1056
        if ((feature).getSource() == null) {
1057
            insert(feature);
1058
            return;
1059
        }
1060
        commands.update(feature, feature.getSource());
1061
    }
1062

  
1063
    synchronized public void doUpdate(EditableFeature feature, Feature oldFeature)
1039 1064
        throws DataException {
1040
        try {
1041
            if ((feature).getSource() == null) {
1042
                insert(feature);
1043
                return;
1044
            }
1065
        try {          
1045 1066
            checkInEditingMode();
1046 1067
            checkIsOwnFeature(feature);
1047 1068
            notifyChange(FeatureStoreNotification.BEFORE_UPDATE, feature);
......
1052 1073
                feature.validate(Feature.UPDATE);
1053 1074
                lastChangedFeature = null;
1054 1075
            }
1055

  
1056
            Feature oldf = feature.getSource();
1076
            
1077
            //Update the featureManager and the spatialManager
1057 1078
            Feature newf = feature.getNotEditableCopy();
1058
            commands.update(newf, oldf);
1059

  
1079
            featureManager.update(newf, oldFeature);
1080
            spatialManager.updateFeature(newf, oldFeature);
1081
   
1060 1082
            hasStrongChanges = true;
1061 1083
            notifyChange(FeatureStoreNotification.AFTER_UPDATE, feature);
1062 1084
        } catch (Exception e) {
......
1766 1788
    }
1767 1789

  
1768 1790
    public void redo(int num) throws RedoException {
1769
        commands.redo(num);
1791
        for (int i = 0; i < num; i++) {
1792
            redo();
1793
        }
1770 1794
    }
1771 1795

  
1772 1796
    public void undo(int num) throws UndoException {
1773
        commands.undo(num);
1797
        for (int i = 0; i < num; i++) {
1798
            undo();
1799
        }
1774 1800
    }
1775 1801

  
1776 1802
    //

Also available in: Unified diff