Revision 44841

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial.app/org.gvsig.h2spatial.app.mainplugin/src/main/resources-plugin/config.xml
73 73
        accelerator=""
74 74
        />
75 75

  
76
      <action
77
        name="tools-h2spatial-shutdownserver"
78
        label="_Shutdown_local_server"
79
        position="902000500"
80
        icon="tools-h2spatial-shutdownserver"
81
        tooltip="_Shutdown_local_server"
82
        action-command="tools-h2spatial-shutdownserver"
83
        accelerator=""
84
        />
85

  
76 86
      <menu
77 87
        name="tools-h2spatial-show-admintool"
78 88
        text="tools/H2Spatial/_Show_H2_administration_tool"
......
89 99
        name="tools-h2spatial-downloadosm"
90 100
        text="tools/H2Spatial/_Download_OSM"
91 101
        />
102
      <menu
103
        name="tools-h2spatial-shutdownserver"
104
        text="tools/H2Spatial/_Shutdown_local_server"
105
        />
92 106

  
93 107
    </extension>
94 108

  
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial.app/org.gvsig.h2spatial.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties
17 17
_File=File
18 18
_Table_name=Table name
19 19
_Delete_tables=Delete tables
20
_Shutdown_local_server=Shutdown local server
20 21

  
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial.app/org.gvsig.h2spatial.app.mainplugin/src/main/resources-plugin/i18n/text.properties
17 17
_File=Fichero
18 18
_Table_name=Nombre de tabla
19 19
_Delete_tables=Eliminar tablas
20
_Shutdown_local_server=Detener el servidor local
20 21

  
21

  
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial.app/org.gvsig.h2spatial.app.mainplugin/src/main/java/org/gvsig/h2spatial/H2SpatialExtension.java
9 9
import java.text.MessageFormat;
10 10
import java.util.ArrayList;
11 11
import java.util.List;
12
import java.util.logging.Level;
13
import java.util.logging.Logger;
12 14
import javax.swing.JOptionPane;
13 15
import javax.swing.filechooser.FileNameExtensionFilter;
14 16
import org.apache.commons.collections.CollectionUtils;
......
25 27
import org.gvsig.filedialogchooser.FileDialogChooser;
26 28
import org.gvsig.fmap.dal.DALLocator;
27 29
import org.gvsig.fmap.dal.DataManager;
30
import org.gvsig.fmap.dal.DataServerExplorer;
31
import org.gvsig.fmap.dal.DataServerExplorerParameters;
32
import org.gvsig.fmap.dal.exception.InitializeException;
33
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
28 34
import org.gvsig.fmap.dal.feature.FeatureStore;
29 35
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
30 36
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer;
......
48 54
import org.h2.tools.Server;
49 55

  
50 56

  
57
@SuppressWarnings("UseSpecificCatch")
51 58
public class H2SpatialExtension extends Extension {
52 59

  
53 60
    public static String DAL_EXPLORER_NAME = "H2Spatial";
......
88 95
        case "tools-h2spatial-downloadosm":
89 96
            downloadOSM();
90 97
            break;
98
        case "tools-h2spatial-shutdownserver":
99
            shutdownserver();
100
            break;
91 101
        }
92 102
    }
93 103
    
104
    private void shutdownserver() {
105
      try {
106
        DataManager dataManager = DALLocator.getManager();
107
        DataServerExplorerParameters params = dataManager.createServerExplorerParameters(DAL_EXPLORER_NAME);
108
        JDBCServerExplorer server = (JDBCServerExplorer) dataManager.openServerExplorer(DAL_EXPLORER_NAME, params);
109
        server.execute("!SHUTDOWN");
110
      } catch (Exception ex) {
111
      }
112
    }
113
    
94 114
    private void startserver()  {
95 115
        try {
96 116
            Server server = Server.createWebServer("-webPort","8082");
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialHelper.java
119 119
        return connectionURL;
120 120
    }
121 121

  
122
    private static class ConnectionProvider {
122
    public static class ConnectionProvider {
123 123

  
124 124
        private static boolean needRegisterDriver = true;
125 125

  
......
134 134
            this.connectionParameters = connectionParameters;
135 135
        }
136 136
        
137
        public static void stopServer() {
138
          try {
139
            server.shutdown();
140
          } catch(Throwable th) {
141
            
142
          }
143
          try {
144
            server.stop();
145
          } catch(Throwable th) {
146
            
147
          }
148
          server = null;
149
          startServer = true;
150
          LOGGER.info("H2 Server stopped" );
151
        }
152
        
137 153
        private void startServer() {
138 154
        
139 155
            if( startServer && server == null ) {
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialExplorer.java
1 1
package org.gvsig.fmap.dal.store.h2;
2 2

  
3 3
import org.apache.commons.io.FilenameUtils;
4
import org.apache.commons.lang3.StringUtils;
4 5
import org.gvsig.fmap.dal.DataStore;
5 6
import org.gvsig.fmap.dal.exception.InitializeException;
6 7
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
......
8 9
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
9 10
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
10 11
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCServerExplorerBase;
12
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ExecuteOperation;
11 13
import org.gvsig.tools.resourcesstorage.EmptyResourcesStorage;
12 14
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
15
import sun.swing.StringUIClientPropertyKey;
13 16

  
14 17
/**
15 18
 *
......
38 41
        return ress;
39 42
    }
40 43
    
41
    
44
    @Override
45
    public void execute(String sql) {
46
      if( StringUtils.equalsIgnoreCase(sql, "!SHUTDOWN") ) {
47
        H2SpatialHelper.ConnectionProvider.stopServer();
48
        return;
49
      }
50
      super.execute(sql);
51
    }    
42 52
}

Also available in: Unified diff