28 |
28 |
import java.util.Map;
|
29 |
29 |
import java.util.UUID;
|
30 |
30 |
import org.apache.commons.lang3.StringUtils;
|
|
31 |
import org.apache.commons.lang3.tuple.MutablePair;
|
|
32 |
import org.apache.commons.lang3.tuple.Pair;
|
31 |
33 |
import org.gvsig.fmap.dal.DataServerExplorer;
|
32 |
34 |
import org.gvsig.fmap.dal.DataStore;
|
33 |
35 |
import org.gvsig.fmap.dal.SupportTransactions;
|
... | ... | |
56 |
58 |
private final String code;
|
57 |
59 |
private final Map<String,DataServerExplorer> explorers;
|
58 |
60 |
private final Map<String,ConnectionService> connections;
|
59 |
|
private Map<String,DataStore> stores;
|
|
61 |
private Map<String,Pair<DataStore,Boolean>> stores;
|
60 |
62 |
private boolean inProgress;
|
61 |
63 |
private List<Disposable> disposables;
|
62 |
64 |
private ObservableHelper observableHelper;
|
... | ... | |
90 |
92 |
if( !this.isInProgress() ) {
|
91 |
93 |
throw new IllegalStateException("Can't commit transaction without begin.");
|
92 |
94 |
}
|
93 |
|
for (DataStore store : stores.values()) {
|
|
95 |
for (Pair<DataStore, Boolean> item : stores.values()) {
|
|
96 |
DataStore store = item.getLeft();
|
94 |
97 |
if( store instanceof FeatureStore ) {
|
95 |
98 |
FeatureStore fstore = (FeatureStore) store;
|
96 |
99 |
if( fstore!=null && fstore.getMode() != MODE_QUERY) {
|
... | ... | |
112 |
115 |
throw new IllegalStateException("Can't rollback transaction without begin.");
|
113 |
116 |
}
|
114 |
117 |
|
115 |
|
for (DataStore store : stores.values()) {
|
|
118 |
for (Pair<DataStore, Boolean> item : stores.values()) {
|
|
119 |
DataStore store = item.getLeft();
|
116 |
120 |
if( store instanceof FeatureStore ) {
|
117 |
121 |
FeatureStore fstore = (FeatureStore) store;
|
118 |
122 |
if( fstore.getMode() != MODE_QUERY) {
|
... | ... | |
157 |
161 |
if( StringUtils.isBlank(id) ) {
|
158 |
162 |
theId = store.hashCode() + "@"+ store.getFullName();
|
159 |
163 |
} else {
|
160 |
|
DataStore theStore = this.stores.get(theId);
|
|
164 |
DataStore theStore = this.stores.get(theId).getLeft();
|
161 |
165 |
if(theStore!=null ){
|
162 |
166 |
if( theStore==store ) {
|
163 |
167 |
return;
|
... | ... | |
171 |
175 |
if(!local){
|
172 |
176 |
DisposeUtils.bind(store);
|
173 |
177 |
}
|
174 |
|
this.stores.put(theId,store);
|
|
178 |
this.stores.put(theId,new MutablePair<>(store,local));
|
175 |
179 |
}
|
176 |
180 |
|
177 |
181 |
@Override
|
... | ... | |
230 |
234 |
|
231 |
235 |
@Override
|
232 |
236 |
public void remove(DataStore store) {
|
233 |
|
if( this.inProgress ) {
|
|
237 |
if( this.inProgress && !DisposeUtils.isNullOrDisposed(store)){
|
234 |
238 |
throw new IllegalStateException("Can't remove store from a in progress transaction.");
|
235 |
239 |
}
|
236 |
240 |
String id = null;
|
237 |
|
for (Map.Entry<String, DataStore> entry : this.stores.entrySet()) {
|
238 |
|
if( store == entry.getValue() ) {
|
|
241 |
for (Map.Entry<String, Pair<DataStore,Boolean>> entry : this.stores.entrySet()) {
|
|
242 |
if( store == entry.getValue().getLeft() ) {
|
239 |
243 |
id = entry.getKey();
|
240 |
244 |
break;
|
241 |
245 |
}
|
... | ... | |
282 |
286 |
if( this.inProgress ) {
|
283 |
287 |
this.rollbackQuietly();
|
284 |
288 |
}
|
285 |
|
for (DataStore store : stores.values()) {
|
|
289 |
for (Pair<DataStore, Boolean> item : stores.values()) {
|
|
290 |
DataStore store = item.getLeft();
|
286 |
291 |
if( store instanceof SupportTransactions ) {
|
287 |
292 |
((SupportTransactions) store).setTransaction(null);
|
288 |
293 |
}
|
... | ... | |
364 |
369 |
|
365 |
370 |
@Override
|
366 |
371 |
public boolean contains(DataStore store) {
|
367 |
|
for (DataStore value : this.stores.values()) {
|
|
372 |
for (Pair<DataStore, Boolean> item : stores.values()) {
|
|
373 |
DataStore value = item.getLeft();
|
368 |
374 |
if(store == value){
|
369 |
375 |
return true;
|
370 |
376 |
}
|