Fixing a problem where it was not possible to connect to a datasource while the datas...
authorn.hoffmann <n.hoffmann@localhost>
Tue, 4 Oct 2011 08:59:27 +0000 (08:59 +0000)
committern.hoffmann <n.hoffmann@localhost>
Tue, 4 Oct 2011 08:59:27 +0000 (08:59 +0000)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/handler/ChangeConnectionHandler.java

index a2bc1af6cb4bb6645ed957670c7315214547bed2..d35f743dc397cafae508ad1869f2d37b36465416 100644 (file)
@@ -10,6 +10,8 @@
 
 package eu.etaxonomy.taxeditor.view.datasource.handler;
 
+import java.sql.SQLException;
+
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.jface.viewers.ISelection;
@@ -45,19 +47,21 @@ public class ChangeConnectionHandler extends AbstractHandler {
                                return null;
                        }
                        
-                       if(!container.isRunning()){
+                       try {
+                               container.getDataSource().testConnection();
+                               boolean confirmed = StoreUtil.confirmDialog("Confirm Datasource Connection", "Do you really want to connect to this datasource?\n\n"
+                                               + container.getDataSource().getName());
+                               
+                               if(confirmed){
+                                       CdmDataSourceRepository.changeDataSource(container.getDataSource());
+                               }
+                       } catch (Exception e) {
                                StoreUtil.warningDialog("Chosen datasource is not available", this, "This could mean that either the database server is " +
                                                "not running or the machine is not reachable.\n\n" +
                                                "Please also make sure that you are connected to the network when trying to connect to a remote datasource.");
+                               StoreUtil.warn(getClass(), e);
                                return null;
-                       }
-                       
-                       boolean confirmed = StoreUtil.confirmDialog("Confirm Datasource Connection", "Do you really want to connect to this datasource?\n\n"
-                                       + container.getDataSource().getName());
-                       
-                       if(confirmed){
-                               CdmDataSourceRepository.changeDataSource(container.getDataSource());
-                       }
+                       } 
                }
                
                return null;