Revision 45738 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 | ||
---|---|---|
35 | 35 |
import java.util.Map.Entry; |
36 | 36 |
import java.util.Objects; |
37 | 37 |
import java.util.Set; |
38 |
import java.util.UUID; |
|
38 | 39 |
import javax.json.JsonObject; |
39 | 40 |
import org.apache.commons.io.FilenameUtils; |
40 | 41 |
import org.apache.commons.io.IOUtils; |
... | ... | |
236 | 237 |
|
237 | 238 |
private PropertiesSupportHelper propertiesSupportHelper; |
238 | 239 |
private DataTransaction transaction; |
240 |
|
|
241 |
private String editingSessionCode; |
|
239 | 242 |
|
240 | 243 |
private class StateInformation extends HashMap<Object, Object> { |
241 | 244 |
|
... | ... | |
966 | 969 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification)); |
967 | 970 |
} |
968 | 971 |
|
972 |
public FeatureStoreNotification notifyChange(String notification, String editingSessionCode) { |
|
973 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification, editingSessionCode)); |
|
974 |
} |
|
975 |
|
|
976 |
public FeatureStoreNotification notifyChange(String notification, String editingSessionCode, int editMode) { |
|
977 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification, editingSessionCode, editMode)); |
|
978 |
} |
|
979 |
|
|
969 | 980 |
public FeatureStoreNotification notifyChange(String notification, |
981 |
String editingSessionCode, |
|
970 | 982 |
Iterator<FeatureReference> deleteds, |
971 | 983 |
Iterator<Feature> inserteds, |
972 | 984 |
Iterator<Feature> updateds, |
973 | 985 |
Iterator<FeatureTypeChanged> featureTypesChanged, |
974 | 986 |
boolean isSelectionCompromised) { |
975 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification, |
|
987 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification, editingSessionCode,
|
|
976 | 988 |
deleteds, inserteds, updateds, featureTypesChanged, isSelectionCompromised)); |
977 | 989 |
} |
978 | 990 |
|
... | ... | |
1147 | 1159 |
|
1148 | 1160 |
private void exitEditingMode() { |
1149 | 1161 |
if (commands != null) { |
1150 |
commands.clear(); |
|
1162 |
try { |
|
1163 |
commands.clear(); |
|
1164 |
} catch(Exception ex) { |
|
1165 |
LOGGER.trace("Can't clear commands",ex); |
|
1166 |
} |
|
1151 | 1167 |
commands = null; |
1152 | 1168 |
} |
1153 | 1169 |
|
1154 | 1170 |
if (featureTypeManager != null) { |
1155 |
featureTypeManager.dispose();
|
|
1171 |
DisposeUtils.disposeQuietly(featureTypeManager);
|
|
1156 | 1172 |
featureTypeManager = null; |
1157 | 1173 |
|
1158 | 1174 |
} |
... | ... | |
1166 | 1182 |
mode = MODE_QUERY; |
1167 | 1183 |
hasStrongChanges = true; // Lo deja a true por si las moscas |
1168 | 1184 |
hasInserts = true; |
1185 |
|
|
1186 |
this.editingSessionCode = null; |
|
1169 | 1187 |
} |
1170 | 1188 |
|
1171 | 1189 |
@Override |
... | ... | |
1176 | 1194 |
@Override |
1177 | 1195 |
synchronized public void edit(int mode) throws DataException { |
1178 | 1196 |
LOGGER.debug("Starting editing in mode: {}", mode); |
1197 |
String newSessionCode = this.createUniqueID(); |
|
1179 | 1198 |
try { |
1180 | 1199 |
if (this.mode != MODE_QUERY) { |
1181 | 1200 |
throw new AlreadyEditingException(this.getName()); |
... | ... | |
1191 | 1210 |
if (!this.transforms.isEmpty()) { |
1192 | 1211 |
throw new IllegalStateException(this.getName()); |
1193 | 1212 |
} |
1194 |
if( notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING).isCanceled() ) { |
|
1213 |
if( notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING, |
|
1214 |
newSessionCode, mode).isCanceled() ) { |
|
1195 | 1215 |
return; |
1196 | 1216 |
} |
1217 |
this.editingSessionCode = newSessionCode; |
|
1197 | 1218 |
invalidateIndexes(); |
1198 | 1219 |
featureManager = new FeatureManager(this); |
1199 | 1220 |
featureTypeManager = new FeatureTypeManager(this); |
... | ... | |
1205 | 1226 |
this.mode = MODE_FULLEDIT; |
1206 | 1227 |
hasStrongChanges = false; |
1207 | 1228 |
hasInserts = false; |
1208 |
notifyChange(FeatureStoreNotification.AFTER_STARTEDITING); |
|
1229 |
notifyChange(FeatureStoreNotification.AFTER_STARTEDITING, newSessionCode, this.mode);
|
|
1209 | 1230 |
break; |
1231 |
|
|
1210 | 1232 |
case MODE_APPEND: |
1211 | 1233 |
if (!this.transforms.isEmpty()) { |
1212 | 1234 |
throw new IllegalStateException(this.getName()); |
1213 | 1235 |
} |
1214 |
if( notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING).isCanceled() ) { |
|
1236 |
if( notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING, |
|
1237 |
newSessionCode, mode).isCanceled() ) { |
|
1215 | 1238 |
return; |
1216 | 1239 |
} |
1240 |
this.editingSessionCode = newSessionCode; |
|
1217 | 1241 |
invalidateIndexes(); |
1218 | 1242 |
this.provider.beginAppend(); |
1219 | 1243 |
this.mode = MODE_APPEND; |
1220 | 1244 |
hasInserts = false; |
1221 |
notifyChange(FeatureStoreNotification.AFTER_STARTEDITING); |
|
1245 |
notifyChange(FeatureStoreNotification.AFTER_STARTEDITING, |
|
1246 |
newSessionCode, this.mode); |
|
1222 | 1247 |
break; |
1223 | 1248 |
case MODE_PASS_THROUGH: |
1224 | 1249 |
if(!this.provider.supportsPassThroughMode()){ |
... | ... | |
1227 | 1252 |
if (!this.transforms.isEmpty()) { |
1228 | 1253 |
throw new IllegalStateException(this.getName()); |
1229 | 1254 |
} |
1230 |
if( notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING).isCanceled() ) { |
|
1255 |
if( notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING, |
|
1256 |
newSessionCode, mode).isCanceled() ) { |
|
1231 | 1257 |
return; |
1232 | 1258 |
} |
1259 |
this.editingSessionCode = newSessionCode; |
|
1233 | 1260 |
invalidateIndexes(); |
1234 | 1261 |
this.mode = MODE_PASS_THROUGH; |
1235 | 1262 |
hasInserts = false; |
1236 |
notifyChange(FeatureStoreNotification.AFTER_STARTEDITING); |
|
1263 |
notifyChange(FeatureStoreNotification.AFTER_STARTEDITING, |
|
1264 |
newSessionCode, this.mode); |
|
1237 | 1265 |
break; |
1238 | 1266 |
|
1239 | 1267 |
|
1240 | 1268 |
} |
1241 | 1269 |
} catch (Exception e) { |
1270 |
try { |
|
1271 |
if (this.mode != MODE_QUERY) { |
|
1272 |
exitEditingMode(); |
|
1273 |
} |
|
1274 |
notifyChange(FeatureStoreNotification.FAILED_STARTEDITING, |
|
1275 |
newSessionCode, mode); |
|
1276 |
} catch(Throwable th) { |
|
1277 |
LOGGER.warn("Can't cleanup after error in start editing.",th); |
|
1278 |
} |
|
1242 | 1279 |
throw new StoreEditException(e, this.getName()); |
1243 | 1280 |
} |
1244 | 1281 |
} |
... | ... | |
1305 | 1342 |
|
1306 | 1343 |
@Override |
1307 | 1344 |
public boolean isEditing() { |
1308 |
return mode == MODE_FULLEDIT; |
|
1345 |
return mode == MODE_FULLEDIT;
|
|
1309 | 1346 |
} |
1310 | 1347 |
|
1311 | 1348 |
@Override |
... | ... | |
1833 | 1870 |
if( selection!=null ) { |
1834 | 1871 |
selection = null; |
1835 | 1872 |
} |
1836 |
if( notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING).isCanceled() ) { |
|
1873 |
if( notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING,this.editingSessionCode).isCanceled() ) {
|
|
1837 | 1874 |
return; |
1838 | 1875 |
} |
1839 | 1876 |
saveDALFile(); |
... | ... | |
1842 | 1879 |
this.updateComputedFields(computedFields); |
1843 | 1880 |
loadDALFile(); |
1844 | 1881 |
updateIndexes(); |
1845 |
notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING); |
|
1882 |
notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING,this.editingSessionCode);
|
|
1846 | 1883 |
break; |
1847 | 1884 |
|
1848 | 1885 |
case MODE_FULLEDIT: |
... | ... | |
1851 | 1888 |
throw new WriteNotAllowedException(getName()); |
1852 | 1889 |
} |
1853 | 1890 |
if( notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING, |
1891 |
this.editingSessionCode, |
|
1854 | 1892 |
featureManager.getDeleted(), |
1855 | 1893 |
featureManager.getInsertedFeatures(), |
1856 | 1894 |
featureManager.getUpdatedFeatures(), |
... | ... | |
1879 | 1917 |
exitEditingMode(); |
1880 | 1918 |
loadDALFile(); |
1881 | 1919 |
updateIndexes(); |
1882 |
notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING); |
|
1920 |
notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING,this.editingSessionCode);
|
|
1883 | 1921 |
} else { |
1884 | 1922 |
exitEditingMode(); |
1885 | 1923 |
} |
... | ... | |
1888 | 1926 |
if( selection!=null ) { |
1889 | 1927 |
selection = null; |
1890 | 1928 |
} |
1891 |
if( notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING).isCanceled() ) { |
|
1929 |
if( notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING,this.editingSessionCode).isCanceled() ) {
|
|
1892 | 1930 |
return; |
1893 | 1931 |
} |
1894 | 1932 |
exitEditingMode(); |
1895 | 1933 |
updateIndexes(); |
1896 |
notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING); |
|
1934 |
notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING,this.editingSessionCode);
|
|
1897 | 1935 |
break; |
1898 | 1936 |
} |
1899 | 1937 |
} catch (PerformEditingException pee) { |
1900 |
notifyChange(FeatureStoreNotification.FAILED_FINISHEDITING); |
|
1938 |
notifyChange(FeatureStoreNotification.FAILED_FINISHEDITING,this.editingSessionCode);
|
|
1901 | 1939 |
throw new WriteException(provider.getSourceId().toString(), pee); |
1902 | 1940 |
} catch (Exception e) { |
1903 |
notifyChange(FeatureStoreNotification.FAILED_FINISHEDITING); |
|
1941 |
notifyChange(FeatureStoreNotification.FAILED_FINISHEDITING,this.editingSessionCode);
|
|
1904 | 1942 |
throw new FinishEditingException(e); |
1905 | 1943 |
} |
1906 | 1944 |
} |
1945 |
|
|
1946 |
@Override |
|
1947 |
public String getEditingSession() { |
|
1948 |
return this.editingSessionCode; |
|
1949 |
} |
|
1950 |
|
|
1907 | 1951 |
private Map<String,List<FeatureAttributeDescriptor>> getComputedFields() throws DataException { |
1908 | 1952 |
Map<String,List<FeatureAttributeDescriptor>> r = new HashMap<>(); |
1909 | 1953 |
|
... | ... | |
1998 | 2042 |
dalFile.updateStore(this); |
1999 | 2043 |
} |
2000 | 2044 |
} catch (Throwable ex) { |
2001 |
if( resource==null) { |
|
2045 |
if( resource==null || resourcesStorage==null) {
|
|
2002 | 2046 |
if( resourcesStorage==null ) { |
2003 | 2047 |
LOGGER.warn("Can't load DAL resource (resname=null, resurl=null, storage=null)", ex); |
2004 | 2048 |
} else { |
... | ... | |
3544 | 3588 |
return this.featureManager.getPendingChangesCount(); |
3545 | 3589 |
} |
3546 | 3590 |
|
3591 |
private ResourcesStorage resourcesStorage; |
|
3592 |
|
|
3547 | 3593 |
@Override |
3548 | 3594 |
public ResourcesStorage getResourcesStorage() { |
3549 |
ResourcesStorage resourcesStorage; |
|
3595 |
if( this.resourcesStorage!=null ) { |
|
3596 |
return this.resourcesStorage; |
|
3597 |
} |
|
3598 |
ResourcesStorage theResourcesStorage; |
|
3550 | 3599 |
try { |
3551 |
resourcesStorage = this.provider.getResourcesStorage(); |
|
3552 |
if( resourcesStorage!=null ) { |
|
3553 |
return resourcesStorage; |
|
3600 |
theResourcesStorage = this.provider.getResourcesStorage(); |
|
3601 |
if( theResourcesStorage!=null ) { |
|
3602 |
this.resourcesStorage = theResourcesStorage; |
|
3603 |
return theResourcesStorage; |
|
3554 | 3604 |
} |
3555 | 3605 |
} catch(Throwable th) { |
3556 | 3606 |
|
... | ... | |
3560 | 3610 |
if( explorer==null ) { |
3561 | 3611 |
return null; |
3562 | 3612 |
} |
3563 |
resourcesStorage = explorer.getResourcesStorage(this);
|
|
3613 |
theResourcesStorage = explorer.getResourcesStorage(this);
|
|
3564 | 3614 |
explorer.dispose(); |
3565 |
return resourcesStorage; |
|
3615 |
this.resourcesStorage = theResourcesStorage; |
|
3616 |
return theResourcesStorage; |
|
3566 | 3617 |
} catch (Exception ex) { |
3567 | 3618 |
LOGGER.trace("Can't create resources storage",ex); |
3568 | 3619 |
return null; |
... | ... | |
3709 | 3760 |
} |
3710 | 3761 |
} |
3711 | 3762 |
|
3763 |
public String createUniqueID() { |
|
3764 |
UUID x = UUID.randomUUID(); |
|
3765 |
String s = x.toString(); |
|
3766 |
return s; |
|
3767 |
} |
|
3768 |
|
|
3712 | 3769 |
} |
Also available in: Unified diff