Revision 45650 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/impl/DefaultTransaction.java

View differences:

DefaultTransaction.java
23 23
package org.gvsig.fmap.dal.impl;
24 24

  
25 25
import java.util.ArrayList;
26
import java.util.HashMap;
26 27
import java.util.HashSet;
27 28
import java.util.List;
29
import java.util.Map;
28 30
import java.util.Set;
29 31
import java.util.UUID;
30 32
import org.gvsig.fmap.dal.DataServerExplorer;
31 33
import org.gvsig.fmap.dal.DataStore;
32
import org.gvsig.fmap.dal.DataTransaction;
34
import org.gvsig.fmap.dal.SupportTransactions;
33 35
import org.gvsig.fmap.dal.exception.DataException;
34 36
import org.gvsig.fmap.dal.feature.FeatureStore;
35 37
import static org.gvsig.fmap.dal.feature.FeatureStore.MODE_QUERY;
38
import org.gvsig.fmap.dal.spi.DataTransactionServices;
36 39
import org.gvsig.tools.dispose.Disposable;
37 40
import org.gvsig.tools.dispose.DisposeUtils;
38 41

  
......
41 44
 * @author gvSIG Team
42 45
 */
43 46
@SuppressWarnings("UseSpecificCatch")
44
public class DefaultTransaction implements DataTransaction {
47
public class DefaultTransaction implements DataTransactionServices {
45 48

  
46 49
    private final String code;
50
    private final Set<DataServerExplorer> explorers;
51
    private final Map<String,ConnectionService> connections;
47 52
    private Set<DataStore> stores;
48
    private Set<DataServerExplorer> explorers;
49 53
    private boolean inProgress;
50 54
    private List<Disposable> disposables;
51 55

  
......
55 59
        this.explorers = new HashSet<>();
56 60
        this.disposables = new ArrayList<>();
57 61
        this.inProgress = false;
62
        this.connections = new HashMap<>();
58 63
    }
59 64

  
60 65
    @Override
......
64 69

  
65 70
    @Override
66 71
    public void begin() throws DataException {
72
        if( this.inProgress ) {
73
            throw new IllegalStateException("Transaction already started.");
74
        }
67 75
        this.inProgress = true;
68 76
    }
69 77

  
......
118 126
        if(this.stores.contains(store)){
119 127
            return;
120 128
        }
121
//        if( !store.setTransaction(this) ) {
122
//            throw new IllegalStateException("Can't add store to transaction.");
123
//        }
129
        if( store instanceof SupportTransactions ) {
130
            ((SupportTransactions) store).setTransaction(this);
131
        }
124 132
        if(!local){
125 133
            DisposeUtils.bind(store);
126 134
        }
......
137 145
        if(this.explorers.contains(explorer)){
138 146
            return;
139 147
        }
140
//        if( !explorer.setTransaction(this) ) {
141
//            throw new IllegalStateException("Can't add explorer to transaction.");
142
//        }
148
        if( explorer instanceof SupportTransactions ) {
149
            ((SupportTransactions) explorer).setTransaction(this);
150
        }
143 151
        if(!local){
144 152
            DisposeUtils.bind(explorer);
145 153
        }
......
156 164
        if( this.inProgress ) {
157 165
            throw new IllegalStateException("Can't remove store from a in progress transaction.");
158 166
        }
159
//        store.setTransaction(null);
167
        if( store instanceof SupportTransactions ) {
168
            ((SupportTransactions) store).setTransaction(null);
169
        }
160 170
        this.stores.remove(store);
161 171
        DisposeUtils.dispose(store);
162 172
    }
......
172 182
            this.rollbackQuietly();
173 183
        }
174 184
        for (DataStore store : stores) {
175
//            store.setTransaction(null);
185
            if( store instanceof SupportTransactions ) {
186
                ((SupportTransactions) store).setTransaction(null);
187
            }
176 188
            DisposeUtils.disposeQuietly(store);
177 189
            
178 190
        }
179 191
        for (DataServerExplorer explorer : explorers) {
180
//            store.setTransaction(null);
192
            if( explorer instanceof SupportTransactions ) {
193
                ((SupportTransactions) explorer).setTransaction(null);
194
            }
181 195
            DisposeUtils.disposeQuietly(explorer);
182 196
            
183 197
        }
184 198
        for (Disposable resource : disposables) {
185
//            store.setTransaction(null);
199
            if( resource instanceof SupportTransactions ) {
200
                ((SupportTransactions) resource).setTransaction(null);
201
            }
186 202
            DisposeUtils.disposeQuietly(resource);
187 203
            
188 204
        }
......
194 210
    public void close() throws Exception {
195 211
        this.dispose();
196 212
    }
197
    
213

  
214
    @Override
215
    public void addConnection(ConnectionService connection) {
216
        if( this.connections.containsKey(connection.getId()) ) {
217
            return;
218
        }
219
        this.connections.put(connection.getId(), connection);
220
    }
221

  
222
    @Override
223
    public ConnectionService getConnection(String id) {
224
        return this.connections.get(id);
225
    }
226

  
227
    @Override
228
    public void removeConnection(String id) {
229
        this.connections.remove(id);
230
    }
231

  
232
    @Override
233
    public boolean existsConnection(String id) {
234
        return this.connections.containsKey(id);
235
    }
198 236
}

Also available in: Unified diff