Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

import org.locationtech.udig.catalog.CatalogPlugin;
import org.locationtech.udig.catalog.ICatalog;
import org.locationtech.udig.catalog.IService;
import org.locationtech.udig.catalog.IServiceFactory;
import org.locationtech.udig.core.internal.FeatureUtils;
import org.locationtech.udig.project.AdaptableFeature;
import org.locationtech.udig.project.EditManagerEvent;
Expand All @@ -24,25 +28,27 @@
import org.locationtech.udig.project.internal.ProjectPackage;
import org.locationtech.udig.project.internal.ProjectPlugin;
import org.locationtech.udig.project.internal.render.RenderManager;
import org.locationtech.udig.ui.PlatformGIS;
import org.locationtech.udig.ui.ProgressManager;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.geotools.data.FeatureEvent;
import org.geotools.data.FeatureSource;
import org.geotools.data.FeatureStore;
Expand Down Expand Up @@ -108,7 +114,7 @@ public class EditManagerImpl extends EObjectImpl implements EditManager {
/**
* Transaction used for the map.
*/
final UDIGTransaction transaction = new UDIGTransaction();
UDIGTransaction transaction = new UDIGTransaction();

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
Expand Down Expand Up @@ -397,6 +403,15 @@ public void commitTransaction() throws IOException {
reader = results.features();
setEditFeature(reader.next(), editLayerInternal);
} catch (Exception e2) {
// provide feedback in case of error
PlatformGIS.syncInDisplayThread(new Runnable() {
@Override
public void run() {
MessageDialog.openError(new Shell(), "commit problem",
"An unrecoverable error occured while commiting the transaction. Connection will be reset and changes since last commit will be lost.");
resetEditLayerConnection();
}
});
setEditFeature(null, null);
} finally {
if (reader != null) {
Expand Down Expand Up @@ -452,7 +467,15 @@ public void rollbackTransaction() throws IOException {
transaction.rollbackInternal();

} catch (IOException e) {
throw e;
// provide feedback in case of error
PlatformGIS.syncInDisplayThread(new Runnable() {
@Override
public void run() {
MessageDialog.openError(new Shell(), "rollback problem",
"An unrecoverable error occured while executing rollbsack. Connection will be reset");
resetEditLayerConnection();
}
});
} finally {
commitRollbackComplete();

Expand Down Expand Up @@ -859,4 +882,25 @@ public void setEditLayerLocked(boolean newEditLayerLocked) {
editLayerLocked));
}

/**
* QUICK FIX to address problem with SQL Connection being closed for unknown reason. Method used
* if we catch an exception during {@link #commitTransaction()} and
* {@link #rollbackTransaction()}
*/
private void resetEditLayerConnection() {
try {
// transaction is doomed so close it, reset service and reopen it.
transaction.closeInternal();
IServiceFactory serviceFactory = CatalogPlugin.getDefault().getServiceFactory();
ICatalog catalog = CatalogPlugin.getDefault().getLocalCatalog();
IService serviceOriginal = getMapInternal().getEditManagerInternal().getEditLayer()
.findGeoResource(FeatureStore.class).service(new NullProgressMonitor());
catalog.replace(serviceOriginal.getID(),
serviceFactory.createService(serviceOriginal.getConnectionParams()).get(0));
transaction = new UDIGTransaction();

} catch (Exception e) {
e.printStackTrace();
}
}
} // LayerManagerImpl