Revision 37595

View differences:

branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/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
    //
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/undo/command/AbstractFeatureCommand.java
42 42

  
43 43
package org.gvsig.fmap.dal.feature.impl.undo.command;
44 44

  
45
import org.gvsig.fmap.dal.exception.DataException;
45 46
import org.gvsig.fmap.dal.feature.Feature;
46
import org.gvsig.fmap.dal.feature.impl.FeatureManager;
47
import org.gvsig.fmap.dal.feature.impl.SpatialManager;
47
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore;
48
import org.gvsig.tools.undo.RedoException;
48 49
import org.gvsig.tools.undo.command.impl.AbstractCommand;
49 50

  
50 51

  
......
55 56
 */
56 57
public abstract class AbstractFeatureCommand extends AbstractCommand {
57 58
    protected Feature feature;
58
    protected FeatureManager expansionManager;
59
    protected SpatialManager spatialManager;
60

  
61
    protected AbstractFeatureCommand(FeatureManager expansionManager,
62
            SpatialManager spatialManager, Feature feature,
63
        String description) {
59
    protected DefaultFeatureStore featureStore;
60
    
61
    protected AbstractFeatureCommand(DefaultFeatureStore featureStore,         
62
        Feature feature, String description) {
64 63
        super(description);
64
        this.featureStore = featureStore;
65 65
        this.feature = feature;
66
        this.expansionManager = expansionManager;
67
        this.spatialManager = spatialManager;
68 66
    }
69 67

  
70 68
    /**
......
75 73
    public Feature getFeature() {
76 74
        return feature;
77 75
    }
76

  
77

  
78
    public int getType() {
79
        return DELETE;
80
    }
81
    
82
    
83
    public void redo() throws RedoException {
84
        try {
85
            execute();
86
        } catch (DataException e) {
87
            throw new RedoException(this, e);
88
        }
89
    }
90

  
91
    public abstract void execute() throws DataException;      
78 92
}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/undo/command/FeatureInsertCommand.java
42 42

  
43 43
package org.gvsig.fmap.dal.feature.impl.undo.command;
44 44

  
45
import org.gvsig.fmap.dal.exception.DataException;
46
import org.gvsig.fmap.dal.feature.EditableFeature;
45 47
import org.gvsig.fmap.dal.feature.Feature;
46
import org.gvsig.fmap.dal.feature.impl.FeatureManager;
47
import org.gvsig.fmap.dal.feature.impl.SpatialManager;
48
import org.gvsig.tools.undo.RedoException;
48
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore;
49 49
import org.gvsig.tools.undo.UndoException;
50 50

  
51 51

  
......
56 56
 */
57 57
public class FeatureInsertCommand extends AbstractFeatureCommand {
58 58

  
59
    public FeatureInsertCommand(FeatureManager expansionManager,
60
        SpatialManager spatialManager,Feature feature,
61
        String description) {
62
        super(expansionManager, spatialManager, feature, description);
59
    public FeatureInsertCommand(DefaultFeatureStore featureStore,        
60
        Feature feature, String description) {
61
        super(featureStore, feature, description);
63 62
    }
64 63

  
65 64
    public void undo() throws UndoException {
66
        expansionManager.delete(feature.getReference());
67
        spatialManager.deleteFeature(feature);
65
       try {
66
           featureStore.doDelete(((EditableFeature)feature).getNotEditableCopy());
67
       } catch (DataException e) {
68
           throw new UndoException(this, e);
69
       }
68 70
    }
69 71

  
70
    public void redo() throws RedoException {
71
        execute();
72
    }
73

  
74 72
    public int getType() {
75 73
        return INSERT;
76 74
    }
77 75

  
78
    /* (non-Javadoc)
79
     * @see org.gvsig.fmap.dal.commands.Command#execute()
80
     */
81
    public void execute() {
82
        expansionManager.add(feature);
83
        spatialManager.insertFeature(feature);
76
    public void execute() throws DataException {
77
        featureStore.doInsert((EditableFeature)feature);
84 78
    }
85 79
}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/undo/command/FeatureDeleteCommand.java
42 42

  
43 43
package org.gvsig.fmap.dal.feature.impl.undo.command;
44 44

  
45
import org.gvsig.fmap.dal.exception.DataException;
45 46
import org.gvsig.fmap.dal.feature.Feature;
46
import org.gvsig.fmap.dal.feature.impl.FeatureManager;
47
import org.gvsig.fmap.dal.feature.impl.SpatialManager;
48
import org.gvsig.tools.undo.RedoException;
47
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore;
49 48
import org.gvsig.tools.undo.UndoException;
50 49

  
51 50

  
......
56 55
 */
57 56
public class FeatureDeleteCommand extends AbstractFeatureCommand {
58 57

  
59
    public FeatureDeleteCommand(FeatureManager expansionManager,
60
        SpatialManager spatialManager, Feature feature,
61
        String description) {
62
        super(expansionManager, spatialManager, feature, description);
58
    public FeatureDeleteCommand(DefaultFeatureStore featureStore,        
59
        Feature feature, String description) {
60
        super(featureStore, feature, description);
63 61
    }
64 62

  
65 63
    public void undo() throws UndoException {
66
        expansionManager.restore(feature.getReference());
67
        spatialManager.insertFeature(feature);
64
        try {
65
            featureStore.doInsert(feature.getEditable());
66
        } catch (DataException e) {
67
            throw new UndoException(this, e);
68
        }
68 69
    }
69 70

  
70
    public void redo() throws RedoException {
71
        execute();
72
    }
73

  
74 71
    public int getType() {
75 72
        return DELETE;
76 73
    }
77 74

  
78
    /* (non-Javadoc)
79
     * @see org.gvsig.fmap.dal.commands.Command#execute()
80
     */
81
    public void execute() {
82
        expansionManager.delete(feature.getReference());
83
        spatialManager.deleteFeature(feature);
75
    public void execute() throws DataException {
76
       featureStore.doDelete(feature);
84 77
    }
85 78
}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/undo/command/FeatureUpdateCommand.java
82 82
 */
83 83
package org.gvsig.fmap.dal.feature.impl.undo.command;
84 84

  
85
import org.gvsig.fmap.dal.exception.DataException;
86
import org.gvsig.fmap.dal.feature.EditableFeature;
85 87
import org.gvsig.fmap.dal.feature.Feature;
86
import org.gvsig.fmap.dal.feature.impl.FeatureManager;
87
import org.gvsig.fmap.dal.feature.impl.SpatialManager;
88
import org.gvsig.tools.undo.RedoException;
88
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore;
89 89
import org.gvsig.tools.undo.UndoException;
90 90

  
91 91

  
......
96 96
 */
97 97
public class FeatureUpdateCommand extends AbstractFeatureCommand {
98 98
    private Feature oldFeature;
99
    private int position=-1;
100 99

  
101
    public FeatureUpdateCommand(FeatureManager expansionManager,
102
        SpatialManager spatialManager, Feature feature, Feature oldFeature, String description) {
103
        super(expansionManager, spatialManager, feature, description);
100
    public FeatureUpdateCommand(DefaultFeatureStore featureStore,        
101
        Feature feature, Feature oldFeature, String description) {
102
        super(featureStore, feature, description);
104 103
        this.oldFeature = oldFeature;
105 104
    }
106 105

  
107
    /* (non-Javadoc)
108
    * @see org.gvsig.fmap.dal.commands.Command#undo()
109
    */
110 106
    public void undo() throws UndoException {
111
//        if (expansionManager.contains(oldFeature.getReference())) {
112
//            expansionManager.deleteLastFeature(feature.getReference());
113
//        } else {
114
//            expansionManager.delete(feature.getReference());
115
//        }
116

  
117
        expansionManager.restore(oldFeature.getReference(),position);
118
        spatialManager.updateFeature(oldFeature, feature);
107
        try {
108
            featureStore.doUpdate(oldFeature.getEditable(), 
109
                ((EditableFeature)feature).getNotEditableCopy());
110
        } catch (DataException e) {
111
            throw new UndoException(this, e);
112
        }
119 113
    }
120 114

  
121
    /* (non-Javadoc)
122
     * @see org.gvsig.fmap.dal.commands.Command#redo()
123
     */
124
    public void redo() throws RedoException {
125
        execute();
126
    }
127

  
128 115
    public int getType() {
129 116
        return UPDATE;
130 117
    }
131

  
132
    /* (non-Javadoc)
133
     * @see org.gvsig.fmap.dal.commands.Command#execute()
134
     */
135
    public void execute() {
136
        //		 Si la geometr?a no ha sido modificada
137
//        if (!expansionManager.contains(oldFeature.getReference())) {
138
//        if (expansionManager.delete(oldFeature.getReference())!=null){
139
//            expansionManager.add(feature);
140
//        } else {
141
    	position = expansionManager.update(feature, oldFeature);
142
//        }
143

  
144
        spatialManager.updateFeature(feature, oldFeature); //setFullExtentDirty(true);
118
    
119
    public void execute() throws DataException {
120
        featureStore.doUpdate((EditableFeature)feature, oldFeature);
145 121
    }
146 122

  
147 123
	public Feature getOldFeature() {
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/undo/FeatureCommandsStack.java
8 8

  
9 9
public interface FeatureCommandsStack extends UndoRedoCommandStack {
10 10

  
11
    public void insert(Feature feature);
11
    public void insert(Feature feature) throws DataException;
12 12

  
13
    public void update(Feature feature, Feature oldFeature);
13
    public void update(Feature feature, Feature oldFeature) throws DataException;
14 14

  
15
    public void delete(Feature feature);
15
    public void delete(Feature feature) throws DataException;
16 16

  
17
//    public void insert(FeatureType featureType);
18

  
19 17
    public void update(FeatureType featureType, FeatureType oldFeatureType);
20 18

  
21
//    public void delete(FeatureType featureType);
22

  
23 19
    public void select(DefaultFeatureReferenceSelection selection,
24 20
            FeatureReference reference);
25 21

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/undo/DefaultFeatureCommandsStack.java
1 1
package org.gvsig.fmap.dal.feature.impl.undo;
2 2

  
3 3
import org.gvsig.fmap.dal.exception.DataException;
4
import org.gvsig.fmap.dal.feature.*;
5
import org.gvsig.fmap.dal.feature.impl.*;
6
import org.gvsig.fmap.dal.feature.impl.undo.command.*;
4
import org.gvsig.fmap.dal.feature.Feature;
5
import org.gvsig.fmap.dal.feature.FeatureReference;
6
import org.gvsig.fmap.dal.feature.FeatureSelection;
7
import org.gvsig.fmap.dal.feature.FeatureType;
8
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureReferenceSelection;
9
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore;
10
import org.gvsig.fmap.dal.feature.impl.FeatureManager;
11
import org.gvsig.fmap.dal.feature.impl.FeatureTypeManager;
12
import org.gvsig.fmap.dal.feature.impl.SpatialManager;
13
import org.gvsig.fmap.dal.feature.impl.undo.command.FTypeUpdateCommand;
14
import org.gvsig.fmap.dal.feature.impl.undo.command.FeatureDeleteCommand;
15
import org.gvsig.fmap.dal.feature.impl.undo.command.FeatureInsertCommand;
16
import org.gvsig.fmap.dal.feature.impl.undo.command.FeatureUpdateCommand;
17
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandReverse;
18
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandSelect;
19
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandSelectAll;
20
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandSet;
7 21
import org.gvsig.tools.undo.command.impl.DefaultUndoRedoCommandStack;
8 22

  
9 23
/**
......
25 39
    private FeatureManager expansionManager;
26 40
    private SpatialManager spatialManager;
27 41
    private FeatureTypeManager featureTypeManager;
42
    private DefaultFeatureStore featureStore;
28 43

  
29
    public DefaultFeatureCommandsStack(FeatureManager expansionManager,
30
            SpatialManager spatialManager, FeatureTypeManager featureTypeManager) {
44
    public DefaultFeatureCommandsStack(DefaultFeatureStore featureStore,
45
        FeatureManager expansionManager, SpatialManager spatialManager, 
46
        FeatureTypeManager featureTypeManager) {
47
        this.featureStore = featureStore;
31 48
        this.expansionManager = expansionManager;
32 49
        this.spatialManager = spatialManager;
33 50
        this.featureTypeManager = featureTypeManager;
......
81 98
        add(command);
82 99
    }
83 100

  
84
    public void delete(Feature feature) {
85
        FeatureDeleteCommand command = new FeatureDeleteCommand(
86
                expansionManager, spatialManager, feature, "_featureDelete");
101
    public void delete(Feature feature) throws DataException {
102
        FeatureDeleteCommand command = new FeatureDeleteCommand(featureStore,
103
                feature, "_featureDelete");
87 104
        add(command);
88 105
        command.execute();
89 106
    }
90 107

  
91
//    public void delete(FeatureType featureType) {
92
//        FTypeDeleteCommand command = new FTypeDeleteCommand(
93
//                featureTypeManager, featureType, "_typeDelete");
94
//        add(command);
95
//        command.execute();
96
//    }
97

  
98
    public void insert(Feature feature) {
99
        FeatureInsertCommand command = new FeatureInsertCommand(
100
                expansionManager, spatialManager, feature, "_featureInsert");
108
    public void insert(Feature feature) throws DataException {
109
        FeatureInsertCommand command = new FeatureInsertCommand(featureStore,
110
                feature, "_featureInsert");
101 111
        add(command);
102 112
        command.execute();
103 113
    }
104 114

  
105
//    public void insert(FeatureType featureType) {
106
//        FTypeInsertCommand command = new FTypeInsertCommand(
107
//                featureTypeManager, featureType, "_typeInsert");
108
//        add(command);
109
//        command.execute();
110
//    }
111

  
112
    public void update(Feature feature, Feature oldFeature) {
113
        FeatureUpdateCommand command = new FeatureUpdateCommand(
114
                expansionManager, spatialManager, feature, oldFeature,
115
    public void update(Feature feature, Feature oldFeature) throws DataException {
116
        FeatureUpdateCommand command = new FeatureUpdateCommand(featureStore,
117
               feature, oldFeature,
115 118
                "_featureUpdate");
116 119
        add(command);
117 120
        command.execute();

Also available in: Unified diff