Revision 44871 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
DefaultFeatureStore.java | ||
---|---|---|
94 | 94 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
95 | 95 |
import org.gvsig.fmap.dal.feature.FeatureStoreTimeSupport; |
96 | 96 |
import org.gvsig.fmap.dal.feature.FeatureStoreTransform; |
97 |
import org.gvsig.fmap.dal.feature.FeatureType.FeatureTypeChanged; |
|
97 | 98 |
import org.gvsig.fmap.dal.feature.exception.AlreadyEditingException; |
98 | 99 |
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException; |
99 | 100 |
import org.gvsig.fmap.dal.feature.exception.CreateFeatureException; |
... | ... | |
368 | 369 |
LOGGER.warn("Opening a store in editing/append mode ("+this.getFullName()+").",ex); |
369 | 370 |
} |
370 | 371 |
} |
371 |
this.notifyChange(DataStoreNotification.BEFORE_OPEN); |
|
372 |
if( this.notifyChange(DataStoreNotification.BEFORE_OPEN).isCanceled() ) { |
|
373 |
return; |
|
374 |
} |
|
372 | 375 |
this.provider.open(); |
373 | 376 |
this.notifyChange(DataStoreNotification.AFTER_OPEN); |
374 | 377 |
} |
... | ... | |
378 | 381 |
if (this.mode != MODE_QUERY) { |
379 | 382 |
throw new IllegalStateException(); |
380 | 383 |
} |
381 |
this.notifyChange(FeatureStoreNotification.BEFORE_REFRESH); |
|
384 |
if( this.notifyChange(FeatureStoreNotification.BEFORE_REFRESH).isCanceled() ) { |
|
385 |
return; |
|
386 |
} |
|
382 | 387 |
if( state.isBroken() ) { |
383 | 388 |
this.load(state); |
384 | 389 |
} else { |
... | ... | |
397 | 402 |
LOGGER.warn("Clossing a store in editing/append mode ("+this.getFullName()+").",ex); |
398 | 403 |
} |
399 | 404 |
} |
400 |
this.notifyChange(DataStoreNotification.BEFORE_CLOSE); |
|
405 |
if( this.notifyChange(DataStoreNotification.BEFORE_CLOSE).isCanceled() ) { |
|
406 |
return; |
|
407 |
} |
|
401 | 408 |
this.featureCount = null; |
402 | 409 |
this.provider.close(); |
403 | 410 |
this.notifyChange(DataStoreNotification.AFTER_CLOSE); |
... | ... | |
413 | 420 |
LOGGER.warn("Dispossing a store in editing/append mode ("+this.getFullName()+").",ex); |
414 | 421 |
} |
415 | 422 |
} |
416 |
this.notifyChange(DataStoreNotification.BEFORE_DISPOSE); |
|
423 |
if( this.notifyChange(DataStoreNotification.BEFORE_DISPOSE).isCanceled() ) { |
|
424 |
return; |
|
425 |
} |
|
417 | 426 |
this.disposeIndexes(); |
418 | 427 |
if( this.provider!=null ) { |
419 | 428 |
this.provider.dispose(); |
... | ... | |
898 | 907 |
// |
899 | 908 |
|
900 | 909 |
@Override |
901 |
public void notifyChange(FeatureStoreNotification storeNotification) { |
|
902 |
try { |
|
903 |
delegateObservable.notifyObservers(storeNotification); |
|
904 |
} catch (Throwable ex) { |
|
905 |
LOGGER.warn("Problems notifying changes in the store '"+this.getName()+" ("+storeNotification.getType()+").",ex); |
|
910 |
public FeatureStoreNotification notifyChange(FeatureStoreNotification storeNotification) { |
|
911 |
if (delegateObservable != null) { |
|
912 |
try { |
|
913 |
delegateObservable.notifyObservers(storeNotification); |
|
914 |
} catch (Throwable ex) { |
|
915 |
LOGGER.warn("Problems notifying changes in the store '"+this.getName()+" ("+storeNotification.getType()+").",ex); |
|
916 |
} |
|
906 | 917 |
} |
918 |
return storeNotification; |
|
907 | 919 |
} |
908 | 920 |
|
909 | 921 |
@Override |
910 |
public void notifyChange(String notification) { |
|
911 |
if (delegateObservable != null) { |
|
912 |
notifyChange(new DefaultFeatureStoreNotification(this, notification)); |
|
913 |
} |
|
914 |
|
|
922 |
public FeatureStoreNotification notifyChange(String notification) { |
|
923 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification)); |
|
915 | 924 |
} |
925 |
|
|
926 |
public FeatureStoreNotification notifyChange(String notification, |
|
927 |
Iterator<FeatureReference> deleteds, |
|
928 |
Iterator<Feature> inserteds, |
|
929 |
Iterator<Feature> updateds, |
|
930 |
Iterator<FeatureTypeChanged> featureTypesChanged, |
|
931 |
boolean isSelectionCompromised) { |
|
932 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification, |
|
933 |
deleteds, inserteds, updateds, featureTypesChanged, isSelectionCompromised)); |
|
934 |
} |
|
916 | 935 |
|
917 | 936 |
@Override |
918 |
public void notifyChange(String notification, FeatureProvider data) {
|
|
937 |
public FeatureStoreNotification notifyChange(String notification, FeatureProvider data) {
|
|
919 | 938 |
Feature f = null; |
920 |
try { |
|
921 |
f = createFeature(data); |
|
922 |
} catch (Throwable ex) { |
|
923 |
LOGGER.warn("Problems creating a feature to notifying changes in the store '"+this.getName()+" ("+notification+").",ex); |
|
939 |
if( data !=null ) { |
|
940 |
try { |
|
941 |
f = createFeature(data); |
|
942 |
} catch (Throwable ex) { |
|
943 |
LOGGER.warn("Problems creating a feature to notifying changes in the store '"+this.getName()+" ("+notification+").",ex); |
|
944 |
} |
|
924 | 945 |
} |
925 |
notifyChange(notification, f); |
|
946 |
return notifyChange(notification, f);
|
|
926 | 947 |
} |
927 | 948 |
|
928 |
public void notifyChange(String notification, Feature feature) {
|
|
929 |
notifyChange(new DefaultFeatureStoreNotification(this, notification, |
|
949 |
public FeatureStoreNotification notifyChange(String notification, Feature feature) {
|
|
950 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification,
|
|
930 | 951 |
feature)); |
931 | 952 |
} |
932 | 953 |
|
933 |
public void notifyChange(String notification, Command command) {
|
|
934 |
notifyChange(new DefaultFeatureStoreNotification(this, notification, |
|
954 |
public FeatureStoreNotification notifyChange(String notification, Command command) {
|
|
955 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification,
|
|
935 | 956 |
command)); |
936 | 957 |
} |
937 | 958 |
|
938 |
public void notifyChange(String notification, EditableFeatureType type) {
|
|
939 |
notifyChange(new DefaultFeatureStoreNotification(this, notification, |
|
959 |
public FeatureStoreNotification notifyChange(String notification, EditableFeatureType type) {
|
|
960 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification,
|
|
940 | 961 |
type)); |
941 | 962 |
} |
942 | 963 |
|
943 | 964 |
@Override |
944 |
public void notifyChange(String notification, Resource resource) {
|
|
945 |
notifyChange(new DefaultFeatureStoreNotification(this, |
|
965 |
public FeatureStoreNotification notifyChange(String notification, Resource resource) {
|
|
966 |
return notifyChange(new DefaultFeatureStoreNotification(this,
|
|
946 | 967 |
DataStoreNotification.RESOURCE_CHANGED)); |
947 | 968 |
} |
948 | 969 |
|
... | ... | |
1127 | 1148 |
if (!this.transforms.isEmpty()) { |
1128 | 1149 |
throw new IllegalStateException(this.getName()); |
1129 | 1150 |
} |
1130 |
notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING); |
|
1151 |
if( notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING).isCanceled() ) { |
|
1152 |
return; |
|
1153 |
} |
|
1131 | 1154 |
invalidateIndexes(); |
1132 | 1155 |
featureManager = new FeatureManager(); |
1133 | 1156 |
featureTypeManager = new FeatureTypeManager(this); |
... | ... | |
1145 | 1168 |
if (!this.transforms.isEmpty()) { |
1146 | 1169 |
throw new IllegalStateException(this.getName()); |
1147 | 1170 |
} |
1148 |
notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING); |
|
1171 |
if( notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING).isCanceled() ) { |
|
1172 |
return; |
|
1173 |
} |
|
1149 | 1174 |
invalidateIndexes(); |
1150 | 1175 |
this.provider.beginAppend(); |
1151 | 1176 |
this.mode = MODE_APPEND; |
... | ... | |
1236 | 1261 |
throw new NullFeatureTypeException(getName()); |
1237 | 1262 |
} |
1238 | 1263 |
if (mode == MODE_QUERY && type.hasOnlyMetadataChanges(this.defaultFeatureType)) { |
1239 |
notifyChange(FeatureStoreNotification.BEFORE_UPDATE_TYPE, type); |
|
1264 |
if( notifyChange(FeatureStoreNotification.BEFORE_UPDATE_TYPE, type).isCanceled() ) { |
|
1265 |
return; |
|
1266 |
} |
|
1240 | 1267 |
FeatureType theType = type.getNotEditableCopy(); |
1241 | 1268 |
if( defaultFeatureType.getId().equals(theType.getId()) ) { |
1242 | 1269 |
defaultFeatureType = theType; |
... | ... | |
1261 | 1288 |
throw new NeedEditingModeException(this.getName()); |
1262 | 1289 |
} |
1263 | 1290 |
// FIXME: Comprobar que es un featureType aceptable. |
1264 |
notifyChange(FeatureStoreNotification.BEFORE_UPDATE_TYPE, type); |
|
1291 |
if( notifyChange(FeatureStoreNotification.BEFORE_UPDATE_TYPE, type).isCanceled() ) { |
|
1292 |
return; |
|
1293 |
} |
|
1265 | 1294 |
newVersionOfUpdate(); |
1266 | 1295 |
|
1267 | 1296 |
FeatureType oldt = type.getSource().getCopy(); |
... | ... | |
1288 | 1317 |
if (feature instanceof EditableFeature) { |
1289 | 1318 |
throw new StoreDeleteEditableFeatureException(getName()); |
1290 | 1319 |
} |
1291 |
notifyChange(FeatureStoreNotification.BEFORE_DELETE, feature); |
|
1320 |
if( notifyChange(FeatureStoreNotification.BEFORE_DELETE, feature).isCanceled() ) { |
|
1321 |
return; |
|
1322 |
} |
|
1292 | 1323 |
|
1293 | 1324 |
//Update the featureManager and the spatialManager |
1294 | 1325 |
featureManager.delete(feature.getReference()); |
... | ... | |
1318 | 1349 |
if (feature.getSource() != null) { |
1319 | 1350 |
throw new NoNewFeatureInsertException(this.getName()); |
1320 | 1351 |
} |
1352 |
if( notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature).isCanceled() ) { |
|
1353 |
return; |
|
1354 |
} |
|
1321 | 1355 |
this.featureCount = null; |
1322 |
notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature); |
|
1323 | 1356 |
feature.validate(Feature.UPDATE); |
1324 | 1357 |
provider.append(((DefaultEditableFeature) feature).getData()); |
1325 | 1358 |
hasStrongChanges = true; |
... | ... | |
1331 | 1364 |
if (feature.getSource() != null) { |
1332 | 1365 |
throw new NoNewFeatureInsertException(this.getName()); |
1333 | 1366 |
} |
1367 |
feature.validate(Feature.UPDATE); |
|
1334 | 1368 |
commands.insert(feature); |
1335 | 1369 |
} |
1336 | 1370 |
} catch (Exception e) { |
... | ... | |
1344 | 1378 |
|
1345 | 1379 |
waitForIndexes(); |
1346 | 1380 |
|
1347 |
notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature); |
|
1381 |
if( notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature).isCanceled() ) { |
|
1382 |
return; |
|
1383 |
} |
|
1348 | 1384 |
newVersionOfUpdate(); |
1349 | 1385 |
if ((lastChangedFeature == null) |
1350 | 1386 |
|| (lastChangedFeature.getSource() != feature.getSource())) { |
... | ... | |
1380 | 1416 |
try { |
1381 | 1417 |
checkInEditingMode(); |
1382 | 1418 |
checkIsOwnFeature(feature); |
1383 |
notifyChange(FeatureStoreNotification.BEFORE_UPDATE, feature); |
|
1419 |
if( notifyChange(FeatureStoreNotification.BEFORE_UPDATE, feature).isCanceled() ) { |
|
1420 |
return; |
|
1421 |
} |
|
1384 | 1422 |
newVersionOfUpdate(); |
1385 | 1423 |
if ((lastChangedFeature == null) |
1386 | 1424 |
|| (lastChangedFeature.getSource() != feature.getSource())) { |
... | ... | |
1409 | 1447 |
} catch (NeedEditingModeException ex) { |
1410 | 1448 |
throw new RedoException(redo, ex); |
1411 | 1449 |
} |
1412 |
notifyChange(FeatureStoreNotification.BEFORE_REDO, redo); |
|
1450 |
if( notifyChange(FeatureStoreNotification.BEFORE_REDO, redo).isCanceled() ) { |
|
1451 |
return; |
|
1452 |
} |
|
1413 | 1453 |
newVersionOfUpdate(); |
1414 | 1454 |
commands.redo(); |
1415 | 1455 |
hasStrongChanges = true; |
... | ... | |
1424 | 1464 |
} catch (NeedEditingModeException ex) { |
1425 | 1465 |
throw new UndoException(undo, ex); |
1426 | 1466 |
} |
1427 |
notifyChange(FeatureStoreNotification.BEFORE_UNDO, undo); |
|
1467 |
if( notifyChange(FeatureStoreNotification.BEFORE_UNDO, undo).isCanceled() ) { |
|
1468 |
return; |
|
1469 |
} |
|
1428 | 1470 |
newVersionOfUpdate(); |
1429 | 1471 |
commands.undo(); |
1430 | 1472 |
hasStrongChanges = true; |
... | ... | |
1466 | 1508 |
throw new NeedEditingModeException(this.getName()); |
1467 | 1509 |
|
1468 | 1510 |
case MODE_APPEND: |
1469 |
notifyChange(FeatureStoreNotification.BEFORE_CANCELEDITING); |
|
1511 |
if( notifyChange(FeatureStoreNotification.BEFORE_CANCELEDITING).isCanceled() ) { |
|
1512 |
return; |
|
1513 |
} |
|
1470 | 1514 |
provider.abortAppend(); |
1471 | 1515 |
exitEditingMode(); |
1472 | 1516 |
((FeatureSelection) this.getSelection()).deselectAll(); |
... | ... | |
1478 | 1522 |
if (this.selection instanceof FeatureReferenceSelection) { |
1479 | 1523 |
clearSelection = this.hasInserts; |
1480 | 1524 |
} |
1481 |
notifyChange(FeatureStoreNotification.BEFORE_CANCELEDITING); |
|
1525 |
if( notifyChange(FeatureStoreNotification.BEFORE_CANCELEDITING).isCanceled() ) { |
|
1526 |
return; |
|
1527 |
} |
|
1482 | 1528 |
exitEditingMode(); |
1483 | 1529 |
if (clearSelection) { |
1484 | 1530 |
((FeatureSelection) this.getSelection()).deselectAll(); |
... | ... | |
1511 | 1557 |
if( selection!=null ) { |
1512 | 1558 |
selection = null; |
1513 | 1559 |
} |
1514 |
notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING); |
|
1560 |
if( notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING).isCanceled() ) { |
|
1561 |
return; |
|
1562 |
} |
|
1515 | 1563 |
saveDALFile(); |
1516 | 1564 |
provider.endAppend(); |
1517 | 1565 |
exitEditingMode(); |
... | ... | |
1525 | 1573 |
if (hasStrongChanges && !this.allowWrite()) { |
1526 | 1574 |
throw new WriteNotAllowedException(getName()); |
1527 | 1575 |
} |
1576 |
if( notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING, |
|
1577 |
featureManager.getDeleted(), |
|
1578 |
featureManager.getInsertedFeatures(), |
|
1579 |
featureManager.getUpdatedFeatures(), |
|
1580 |
featureTypeManager.getFeatureTypesChanged().iterator(), |
|
1581 |
featureManager.isSelectionCompromised()).isCanceled() ) { |
|
1582 |
return; |
|
1583 |
} |
|
1528 | 1584 |
saveDALFile(); |
1529 | 1585 |
if(featureManager.isSelectionCompromised() && selection!=null ) { |
1530 | 1586 |
selection = null; |
1531 | 1587 |
} |
1532 |
notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING); |
|
1533 | 1588 |
if (hasStrongChanges) { |
1534 | 1589 |
validateFeatures(Feature.FINISH_EDITING); |
1535 | 1590 |
|
... | ... | |
1596 | 1651 |
} |
1597 | 1652 |
|
1598 | 1653 |
} |
1599 |
private List<FeatureStoreProvider.FeatureTypeChanged> removeCalculatedAttributes(List<FeatureStoreProvider.FeatureTypeChanged> ftypes) {
|
|
1654 |
private List<FeatureTypeChanged> removeCalculatedAttributes(List<FeatureTypeChanged> ftypes) {
|
|
1600 | 1655 |
// FIXME: Falta por implementar |
1601 | 1656 |
// for (FeatureStoreProvider.FeatureTypeChanged ftype : ftypes) { |
1602 | 1657 |
// EditableFeatureType target = (EditableFeatureType) ftype.getTarget(); |
Also available in: Unified diff