Revision 45901
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/java/org/gvsig/fmap/dal/store/h2/H2FilenameTest.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.store.h2; |
2 | 2 |
|
3 | 3 |
import junit.framework.TestCase; |
4 |
import org.gvsig.fmap.dal.DALLocator; |
|
5 |
import org.gvsig.fmap.dal.DataManager; |
|
6 |
import org.gvsig.fmap.dal.DataTypes; |
|
7 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
8 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
9 |
import org.gvsig.fmap.dal.feature.Feature; |
|
10 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
11 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
12 |
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters; |
|
13 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
14 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
|
15 |
import org.gvsig.fmap.geom.Geometry; |
|
16 |
import org.gvsig.fmap.geom.GeometryUtils; |
|
17 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
18 | 4 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
19 | 5 |
|
20 | 6 |
/** |
... | ... | |
45 | 31 |
|
46 | 32 |
|
47 | 33 |
public void testRemoveH2FileNameExtension() throws Exception { |
48 |
assertEquals("/tmp/test", H2SpatialHelper.removeH2FileNameExtension("/tmp/test.mv.db"));
|
|
49 |
assertEquals("/tmp/test", H2SpatialHelper.removeH2FileNameExtension("/tmp/test.trace.db"));
|
|
50 |
assertEquals("/tmp/test", H2SpatialHelper.removeH2FileNameExtension("/tmp/test.mv"));
|
|
51 |
assertEquals("/tmp/test", H2SpatialHelper.removeH2FileNameExtension("/tmp/test.trace"));
|
|
52 |
assertEquals("/tmp/test", H2SpatialHelper.removeH2FileNameExtension("/tmp/test.txt"));
|
|
34 |
assertEquals("/tmp/test", H2SpatialUtils.removeH2FileNameExtension("/tmp/test.mv.db"));
|
|
35 |
assertEquals("/tmp/test", H2SpatialUtils.removeH2FileNameExtension("/tmp/test.trace.db"));
|
|
36 |
assertEquals("/tmp/test", H2SpatialUtils.removeH2FileNameExtension("/tmp/test.mv"));
|
|
37 |
assertEquals("/tmp/test", H2SpatialUtils.removeH2FileNameExtension("/tmp/test.trace"));
|
|
38 |
assertEquals("/tmp/test", H2SpatialUtils.removeH2FileNameExtension("/tmp/test.txt"));
|
|
53 | 39 |
} |
54 | 40 |
|
55 | 41 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialHelper.java | ||
---|---|---|
25 | 25 |
import java.sql.Connection; |
26 | 26 |
import java.sql.DriverManager; |
27 | 27 |
import java.sql.SQLException; |
28 |
import java.text.MessageFormat; |
|
29 | 28 |
import org.apache.commons.dbcp.BasicDataSource; |
30 |
import org.apache.commons.io.FilenameUtils; |
|
31 | 29 |
import org.apache.commons.lang3.StringUtils; |
32 | 30 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType; |
33 | 31 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_CONFIGURATION_NAME; |
... | ... | |
68 | 66 |
|
69 | 67 |
public static final String H2SPATIAL_JDBC_DRIVER = "org.h2.Driver"; |
70 | 68 |
|
71 |
public static File getLocalFile(H2SpatialConnectionParameters params) { |
|
72 |
String host = params.getHost(); |
|
73 |
if( !StringUtils.isEmpty(host) ) { |
|
74 |
host = host.toLowerCase().trim(); |
|
75 |
if( !(host.equals("localhost") || host.equals("127.0.0.1")) ) { |
|
76 |
return null; |
|
77 |
} |
|
78 |
} |
|
79 |
File f = params.getFile(); |
|
80 |
return normalizeH2File(f); |
|
81 |
} |
|
82 |
|
|
83 |
public static File normalizeH2File(File f) { |
|
84 |
if( f==null ) { |
|
85 |
return null; |
|
86 |
} |
|
87 |
f = new File(f.getParentFile(), H2SpatialHelper.normalizeH2FileName(f.getName())); |
|
88 |
return f; |
|
89 |
} |
|
90 |
|
|
91 |
public static String normalizeH2FileName(String name) { |
|
92 |
String s = removeH2FileNameExtension(name); |
|
93 |
if( s == null ) { |
|
94 |
return null; |
|
95 |
} |
|
96 |
return s+".mv.db"; |
|
97 |
} |
|
98 |
|
|
99 |
public static String removeH2FileNameExtension(String name) { |
|
100 |
if( StringUtils.isBlank(name) ) { |
|
101 |
return null; |
|
102 |
} |
|
103 |
if( name.endsWith(".mv.db") ) { |
|
104 |
int l = name.length(); |
|
105 |
return name.substring(0, l-6); |
|
106 |
} |
|
107 |
if( name.endsWith(".trace.db") ) { |
|
108 |
int l = name.length(); |
|
109 |
return name.substring(0, l-9); |
|
110 |
} |
|
111 |
return FilenameUtils.removeExtension(name); |
|
112 |
} |
|
113 |
|
|
114 |
public static String getConnectionURL(H2SpatialConnectionParameters params) { |
|
115 |
String connectionURL; |
|
116 |
String dbfilename = params.getFile().getAbsolutePath().replace("\\","/"); |
|
117 |
if( dbfilename!=null ) { |
|
118 |
dbfilename = removeH2FileNameExtension(dbfilename); |
|
119 |
} |
|
120 |
StringBuilder commonParameters = new StringBuilder(); |
|
121 |
commonParameters.append(";MODE=PostgreSQL"); |
|
122 |
commonParameters.append(";SCHEMA=PUBLIC"); |
|
123 |
commonParameters.append(";ALLOW_LITERALS=ALL"); |
|
124 |
if( StringUtils.isEmpty(params.getHost()) ) { |
|
125 |
// Asumimos que es una conexion directa sobre el filesystem |
|
126 |
if( StringUtils.equalsIgnoreCase(FilenameUtils.getExtension(params.getFile().getName()),"zip") ) { |
|
127 |
connectionURL = MessageFormat.format( |
|
128 |
"jdbc:h2:zip:{0}!/{1}"+commonParameters.toString(), |
|
129 |
dbfilename, |
|
130 |
params.getDBName() |
|
131 |
); |
|
132 |
} else { |
|
133 |
connectionURL = MessageFormat.format( |
|
134 |
"jdbc:h2:file:{0}"+commonParameters.toString(), |
|
135 |
dbfilename |
|
136 |
); |
|
137 |
} |
|
138 |
} else if( params.getPort() == null ) { |
|
139 |
connectionURL = MessageFormat.format( |
|
140 |
"jdbc:h2:tcp://{0}/{1}"+commonParameters.toString(), |
|
141 |
params.getHost(), |
|
142 |
dbfilename |
|
143 |
); |
|
144 |
} else { |
|
145 |
connectionURL = MessageFormat.format("jdbc:h2:tcp://{0}:{1,number,#######}/{2}"+commonParameters.toString(), |
|
146 |
params.getHost(), |
|
147 |
(int) params.getPort(), |
|
148 |
dbfilename |
|
149 |
); |
|
150 |
} |
|
151 |
LOGGER.debug("connectionURL: {}", connectionURL); |
|
152 |
return connectionURL; |
|
153 |
} |
|
154 |
|
|
155 | 69 |
public static class ConnectionProviderImpl implements ConnectionProvider { |
156 | 70 |
|
157 | 71 |
private static boolean needRegisterDriver = true; |
... | ... | |
160 | 74 |
|
161 | 75 |
private H2SpatialConnectionParameters connectionParameters; |
162 | 76 |
|
163 |
private static Server h2server = null; |
|
164 |
private static boolean startServer = true; |
|
165 |
|
|
166 | 77 |
public ConnectionProviderImpl(H2SpatialConnectionParameters connectionParameters) { |
167 | 78 |
this.connectionParameters = connectionParameters; |
168 | 79 |
} |
... | ... | |
201 | 112 |
closeDataSource(); |
202 | 113 |
} |
203 | 114 |
|
204 |
public static void stopServer() { |
|
205 |
if (h2server == null) { |
|
206 |
LOGGER.info("The H2 server is already stopped."); |
|
207 |
} else { |
|
208 |
LOGGER.info("Stopping the H2 server."); |
|
209 |
LOGGER.info(" port :" + h2server.getPort()); |
|
210 |
LOGGER.info(" URL :" + h2server.getURL()); |
|
211 |
LOGGER.info(" shutdown server..."); |
|
212 |
try { |
|
213 |
h2server.shutdown(); |
|
214 |
} catch (Throwable th) { |
|
215 |
LOGGER.warn("Problems shutdown the H2 server.", th); |
|
216 |
} |
|
217 |
LOGGER.info(" Stoping server..."); |
|
218 |
try { |
|
219 |
h2server.stop(); |
|
220 |
} catch (Throwable th) { |
|
221 |
LOGGER.warn("Problems stopping the H2 server.", th); |
|
222 |
} |
|
223 |
LOGGER.info(" status:" + h2server.getStatus()); |
|
224 |
h2server = null; |
|
225 |
LOGGER.info("H2 Server stopped"); |
|
226 |
} |
|
227 |
startServer = true; |
|
228 |
} |
|
229 |
|
|
230 |
private void startServer() { |
|
231 |
|
|
232 |
if( startServer && h2server == null ) { |
|
233 |
String port = "9123"; |
|
234 |
try { |
|
235 |
Server theH2Server; |
|
236 |
Server thePgServer; |
|
237 |
if( this.connectionParameters.getServerPort()>0 ) { |
|
238 |
port = String.valueOf(this.connectionParameters.getServerPort()); |
|
239 |
} |
|
240 |
if( this.connectionParameters.getServerAllowOthers() ) { |
|
241 |
theH2Server = Server.createTcpServer("-tcpPort", port, "-ifExists", "-tcpAllowOthers"); |
|
242 |
} else { |
|
243 |
theH2Server = Server.createTcpServer("-tcpPort", port, "-ifExists"); |
|
244 |
} |
|
245 |
theH2Server.start(); |
|
246 |
h2server = theH2Server; |
|
247 |
LOGGER.info("H2 Server started" ); |
|
248 |
LOGGER.info(" Engine version : h2 "+ org.h2.engine.Constants.getFullVersion()+", h2gis "+H2GISversion.geth2gisVersion()); |
|
249 |
LOGGER.info(" Connection url : jdbc:h2:"+h2server.getURL()+"/ABSOLUTE_DATABASE_PATH;MODE=PostgreSQL;SCHEMA=PUBLIC;ALLOW_LITERALS=ALL"); |
|
250 |
// LOGGER.info(" port :"+ server.getPort()); |
|
251 |
// LOGGER.info(" URL :"+ server.getURL()); |
|
252 |
LOGGER.info(" status:"+ h2server.getStatus()); |
|
253 |
Runtime.getRuntime().addShutdownHook(new Thread() { |
|
254 |
@Override |
|
255 |
public void run() { |
|
256 |
stopServer(); |
|
257 |
} |
|
258 |
}); |
|
259 |
} catch (SQLException ex) { |
|
260 |
LOGGER.warn("H2 Server not started",ex); |
|
261 |
} |
|
262 |
// Tanto si consigue lanzar el server como si no, no lo vuelve a intentar |
|
263 |
startServer = false; |
|
264 |
} |
|
265 |
|
|
266 |
} |
|
267 |
|
|
268 | 115 |
@Override |
269 | 116 |
public String toString() { |
270 | 117 |
StringBuilder builder = new StringBuilder(); |
... | ... | |
276 | 123 |
|
277 | 124 |
@Override |
278 | 125 |
public synchronized Connection getConnection() throws SQLException { |
279 |
File f = H2SpatialHelper.getLocalFile(connectionParameters);
|
|
126 |
File f = H2SpatialUtils.getLocalFile(connectionParameters);
|
|
280 | 127 |
boolean newdb = !f.exists(); |
281 | 128 |
|
282 | 129 |
Connection conn; |
... | ... | |
292 | 139 |
throw th; |
293 | 140 |
} |
294 | 141 |
|
295 |
startServer(); |
|
142 |
H2SpatialUtils.server_start( |
|
143 |
this.connectionParameters.getServerPortAsString(), |
|
144 |
this.connectionParameters.getServerAllowOthers() |
|
145 |
); |
|
296 | 146 |
|
297 | 147 |
// if (this.dataSource == null) { |
298 | 148 |
// this.dataSource = this.createDataSource(); |
... | ... | |
343 | 193 |
if (!this.isRegistered()) { |
344 | 194 |
this.registerDriver(); |
345 | 195 |
} |
346 |
// startServer(); |
|
347 | 196 |
H2SpatialConnectionParameters params = connectionParameters; |
348 | 197 |
|
349 | 198 |
BasicDataSource ds = new BasicDataSource(); |
... | ... | |
449 | 298 |
this.srssolver = new SRSSolverBase(this); |
450 | 299 |
} |
451 | 300 |
|
452 |
|
|
453 | 301 |
public void shutdown() { |
454 | 302 |
try { |
455 | 303 |
if( this.connectionProvider!=null ) { |
456 | 304 |
((ConnectionProviderImpl) this.connectionProvider).shutdown(); |
457 | 305 |
this.connectionProvider = null; |
458 | 306 |
} |
459 |
ConnectionProviderImpl.stopServer();
|
|
307 |
H2SpatialUtils.server_stop();
|
|
460 | 308 |
} catch (Throwable ex) { |
461 | 309 |
LOGGER.warn("Problems shutdown H2", ex); |
462 | 310 |
} |
... | ... | |
531 | 379 |
|
532 | 380 |
@Override |
533 | 381 |
public String getConnectionURL() { |
534 |
return getConnectionURL(this.getConnectionParameters()); |
|
382 |
return H2SpatialUtils.getConnectionURL(this.getConnectionParameters());
|
|
535 | 383 |
} |
536 | 384 |
|
537 | 385 |
@Override |
... | ... | |
647 | 495 |
public String getConnectionProviderStatus(){ |
648 | 496 |
return this.getConnectionProvider().getStatus(); |
649 | 497 |
} |
650 |
|
|
651 |
|
|
652 | 498 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialExplorer.java | ||
---|---|---|
5 | 5 |
import org.gvsig.fmap.dal.DataStore; |
6 | 6 |
import org.gvsig.fmap.dal.exception.InitializeException; |
7 | 7 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
8 |
import static org.gvsig.fmap.dal.store.h2.H2SpatialHelper.normalizeH2File; |
|
9 | 8 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
10 | 9 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
11 | 10 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCServerExplorerBase; |
... | ... | |
56 | 55 |
public boolean exists() { |
57 | 56 |
try { |
58 | 57 |
H2SpatialExplorerParameters serverParameters = this.getParameters(); |
59 |
File f = normalizeH2File(serverParameters.getFile()); |
|
58 |
File f = H2SpatialUtils.normalizeH2File(serverParameters.getFile());
|
|
60 | 59 |
if( !f.exists() ) { |
61 | 60 |
return false; |
62 | 61 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialStoreParameters.java | ||
---|---|---|
64 | 64 |
public void setFile(File database) { |
65 | 65 |
try { |
66 | 66 |
this.helper.setFile(database); |
67 |
String url = H2SpatialHelper.getConnectionURL((H2SpatialConnectionParameters) this);
|
|
67 |
String url = H2SpatialUtils.getConnectionURL((H2SpatialConnectionParameters) this);
|
|
68 | 68 |
this.setDynValue(JDBCConnectionParameters.URL_PARAMTER_NAME, url); |
69 | 69 |
} catch (Exception ex) { |
70 | 70 |
} |
... | ... | |
85 | 85 |
return this.helper.getServerPort(); |
86 | 86 |
} |
87 | 87 |
|
88 |
@Override |
|
89 |
public String getServerPortAsString() { |
|
90 |
return this.helper.getServerPortAsString(); |
|
91 |
} |
|
88 | 92 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialUtils.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.h2; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.sql.SQLException; |
|
5 |
import java.text.MessageFormat; |
|
6 |
import org.apache.commons.io.FilenameUtils; |
|
7 |
import org.apache.commons.lang3.StringUtils; |
|
8 |
import static org.gvsig.fmap.dal.store.h2.H2SpatialHelper.LOGGER; |
|
9 |
import org.h2.tools.Server; |
|
10 |
import org.h2gis.functions.system.H2GISversion; |
|
11 |
|
|
12 |
/** |
|
13 |
* |
|
14 |
* @author gvSIG Team |
|
15 |
*/ |
|
16 |
public class H2SpatialUtils { |
|
17 |
|
|
18 |
private static Server h2server = null; |
|
19 |
private static boolean startServer = true; |
|
20 |
private static boolean lastAllowOthers = true; |
|
21 |
private static String lastPort = "9123"; |
|
22 |
|
|
23 |
public static File[] getH2Files(File f) { |
|
24 |
if( f==null ) { |
|
25 |
return null; |
|
26 |
} |
|
27 |
String name = removeH2FileNameExtension(f.getName()); |
|
28 |
File f1 = new File(f.getParentFile(), name+".mv.db"); |
|
29 |
File f2 = new File(f.getParentFile(), name+".trace.db"); |
|
30 |
return new File[] { f1, f2 }; |
|
31 |
} |
|
32 |
|
|
33 |
public static File normalizeH2File(File f) { |
|
34 |
if( f==null ) { |
|
35 |
return null; |
|
36 |
} |
|
37 |
f = new File(f.getParentFile(), normalizeH2FileName(f.getName())); |
|
38 |
return f; |
|
39 |
} |
|
40 |
|
|
41 |
public static String normalizeH2FileName(String name) { |
|
42 |
String s = removeH2FileNameExtension(name); |
|
43 |
if( s == null ) { |
|
44 |
return null; |
|
45 |
} |
|
46 |
return s+".mv.db"; |
|
47 |
} |
|
48 |
|
|
49 |
public static String removeH2FileNameExtension(String name) { |
|
50 |
if( StringUtils.isBlank(name) ) { |
|
51 |
return null; |
|
52 |
} |
|
53 |
if( name.endsWith(".mv.db") ) { |
|
54 |
int l = name.length(); |
|
55 |
return name.substring(0, l-6); |
|
56 |
} |
|
57 |
if( name.endsWith(".trace.db") ) { |
|
58 |
int l = name.length(); |
|
59 |
return name.substring(0, l-9); |
|
60 |
} |
|
61 |
return FilenameUtils.removeExtension(name); |
|
62 |
} |
|
63 |
|
|
64 |
public static File getLocalFile(H2SpatialConnectionParameters params) { |
|
65 |
String host = params.getHost(); |
|
66 |
if( !StringUtils.isEmpty(host) ) { |
|
67 |
host = host.toLowerCase().trim(); |
|
68 |
if( !(host.equals("localhost") || host.equals("127.0.0.1")) ) { |
|
69 |
return null; |
|
70 |
} |
|
71 |
} |
|
72 |
File f = params.getFile(); |
|
73 |
return normalizeH2File(f); |
|
74 |
} |
|
75 |
|
|
76 |
public static String getConnectionURL(H2SpatialConnectionParameters params) { |
|
77 |
String connectionURL; |
|
78 |
String dbfilename = params.getFile().getAbsolutePath().replace("\\","/"); |
|
79 |
if( dbfilename!=null ) { |
|
80 |
dbfilename = H2SpatialUtils.removeH2FileNameExtension(dbfilename); |
|
81 |
} |
|
82 |
StringBuilder commonParameters = new StringBuilder(); |
|
83 |
commonParameters.append(";MODE=PostgreSQL"); |
|
84 |
commonParameters.append(";SCHEMA=PUBLIC"); |
|
85 |
commonParameters.append(";ALLOW_LITERALS=ALL"); |
|
86 |
if( StringUtils.isEmpty(params.getHost()) ) { |
|
87 |
// Asumimos que es una conexion directa sobre el filesystem |
|
88 |
if( StringUtils.equalsIgnoreCase(FilenameUtils.getExtension(params.getFile().getName()),"zip") ) { |
|
89 |
connectionURL = MessageFormat.format( |
|
90 |
"jdbc:h2:zip:{0}!/{1}"+commonParameters.toString(), |
|
91 |
dbfilename, |
|
92 |
params.getDBName() |
|
93 |
); |
|
94 |
} else { |
|
95 |
connectionURL = MessageFormat.format( |
|
96 |
"jdbc:h2:file:{0}"+commonParameters.toString(), |
|
97 |
dbfilename |
|
98 |
); |
|
99 |
} |
|
100 |
} else if( params.getPort() == null ) { |
|
101 |
connectionURL = MessageFormat.format( |
|
102 |
"jdbc:h2:tcp://{0}/{1}"+commonParameters.toString(), |
|
103 |
params.getHost(), |
|
104 |
dbfilename |
|
105 |
); |
|
106 |
} else { |
|
107 |
connectionURL = MessageFormat.format("jdbc:h2:tcp://{0}:{1,number,#######}/{2}"+commonParameters.toString(), |
|
108 |
params.getHost(), |
|
109 |
(int) params.getPort(), |
|
110 |
dbfilename |
|
111 |
); |
|
112 |
} |
|
113 |
LOGGER.debug("connectionURL: {}", connectionURL); |
|
114 |
return connectionURL; |
|
115 |
} |
|
116 |
|
|
117 |
public static void server_stop() { |
|
118 |
if (h2server == null) { |
|
119 |
LOGGER.info("The H2 server is already stopped."); |
|
120 |
} else { |
|
121 |
LOGGER.info("Stopping the H2 server."); |
|
122 |
LOGGER.info(" port :" + h2server.getPort()); |
|
123 |
LOGGER.info(" URL :" + h2server.getURL()); |
|
124 |
LOGGER.info(" shutdown server..."); |
|
125 |
try { |
|
126 |
h2server.shutdown(); |
|
127 |
} catch (Throwable th) { |
|
128 |
LOGGER.warn("Problems shutdown the H2 server.", th); |
|
129 |
} |
|
130 |
LOGGER.info(" Stoping server..."); |
|
131 |
try { |
|
132 |
h2server.stop(); |
|
133 |
} catch (Throwable th) { |
|
134 |
LOGGER.warn("Problems stopping the H2 server.", th); |
|
135 |
} |
|
136 |
LOGGER.info(" status:" + h2server.getStatus()); |
|
137 |
h2server = null; |
|
138 |
LOGGER.info("H2 Server stopped"); |
|
139 |
} |
|
140 |
startServer = true; |
|
141 |
} |
|
142 |
|
|
143 |
public static void server_start() { |
|
144 |
server_start(lastPort, lastAllowOthers); |
|
145 |
} |
|
146 |
|
|
147 |
public static void server_start(String port, Boolean allowOthers) { |
|
148 |
if( startServer && h2server == null ) { |
|
149 |
if( StringUtils.isBlank(port) ) { |
|
150 |
port = lastPort; |
|
151 |
} |
|
152 |
if( allowOthers==null ) { |
|
153 |
allowOthers = lastAllowOthers; |
|
154 |
} |
|
155 |
try { |
|
156 |
Server theH2Server; |
|
157 |
if( allowOthers) { |
|
158 |
theH2Server = Server.createTcpServer("-tcpPort", port, "-ifExists", "-tcpAllowOthers"); |
|
159 |
} else { |
|
160 |
theH2Server = Server.createTcpServer("-tcpPort", port, "-ifExists"); |
|
161 |
} |
|
162 |
theH2Server.start(); |
|
163 |
h2server = theH2Server; |
|
164 |
LOGGER.info("H2 Server started" ); |
|
165 |
LOGGER.info(" Engine version : h2 "+ org.h2.engine.Constants.getFullVersion()+", h2gis "+H2GISversion.geth2gisVersion()); |
|
166 |
LOGGER.info(" Connection url : jdbc:h2:"+h2server.getURL()+"/ABSOLUTE_DATABASE_PATH;MODE=PostgreSQL;SCHEMA=PUBLIC;ALLOW_LITERALS=ALL"); |
|
167 |
LOGGER.info(" status:"+ h2server.getStatus()); |
|
168 |
Runtime.getRuntime().addShutdownHook(new Thread() { |
|
169 |
@Override |
|
170 |
public void run() { |
|
171 |
server_stop(); |
|
172 |
} |
|
173 |
}); |
|
174 |
lastPort = port; |
|
175 |
lastAllowOthers = allowOthers; |
|
176 |
} catch (SQLException ex) { |
|
177 |
LOGGER.warn("H2 Server not started",ex); |
|
178 |
} |
|
179 |
// Tanto si consigue lanzar el server como si no, no lo vuelve a intentar |
|
180 |
startServer = false; |
|
181 |
} |
|
182 |
} |
|
183 |
|
|
184 |
|
|
185 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialConnectionParameters.java | ||
---|---|---|
13 | 13 |
|
14 | 14 |
public int getServerPort(); |
15 | 15 |
|
16 |
public String getServerPortAsString(); |
|
17 |
|
|
16 | 18 |
public boolean getServerAllowOthers(); |
17 | 19 |
|
18 | 20 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialConnectionParametersHelper.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.io.File; |
4 | 4 |
import java.util.Properties; |
5 |
import org.apache.commons.io.FilenameUtils; |
|
6 | 5 |
import org.apache.commons.lang3.StringUtils; |
7 | 6 |
import org.gvsig.fmap.dal.DataParameters; |
8 | 7 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
... | ... | |
26 | 25 |
public String getUrl() { |
27 | 26 |
String url = (String) this.getDynValue(JDBCConnectionParameters.URL_PARAMTER_NAME); |
28 | 27 |
if( StringUtils.isEmpty(url) ) { |
29 |
url = H2SpatialHelper.getConnectionURL((H2SpatialConnectionParameters) this.parameters);
|
|
28 |
url = H2SpatialUtils.getConnectionURL((H2SpatialConnectionParameters) this.parameters);
|
|
30 | 29 |
this.setDynValue(JDBCConnectionParameters.URL_PARAMTER_NAME, url); |
31 | 30 |
} |
32 | 31 |
return url; |
... | ... | |
55 | 54 |
} |
56 | 55 |
} |
57 | 56 |
if( this.getDynValue(JDBCConnectionParameters.URL_PARAMTER_NAME) == null ) { |
58 |
String url = H2SpatialHelper.getConnectionURL((H2SpatialConnectionParameters) this.parameters);
|
|
57 |
String url = H2SpatialUtils.getConnectionURL((H2SpatialConnectionParameters) this.parameters);
|
|
59 | 58 |
this.setDynValue(JDBCConnectionParameters.URL_PARAMTER_NAME, url); |
60 | 59 |
} |
61 | 60 |
} |
... | ... | |
117 | 116 |
} |
118 | 117 |
|
119 | 118 |
private String getDbNameFromFile(File f) { |
120 |
String name = H2SpatialHelper.removeH2FileNameExtension(f.getName());
|
|
119 |
String name = H2SpatialUtils.removeH2FileNameExtension(f.getName());
|
|
121 | 120 |
return name; |
122 | 121 |
} |
123 | 122 |
|
123 |
public String getServerPortAsString() { |
|
124 |
int port = this.getServerPort(); |
|
125 |
if( port<=0 ) { |
|
126 |
return null; |
|
127 |
} |
|
128 |
String port_s = String.valueOf(port); |
|
129 |
return port_s; |
|
130 |
} |
|
124 | 131 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialExplorerParameters.java | ||
---|---|---|
85 | 85 |
public int getServerPort() { |
86 | 86 |
return this.helper.getServerPort(); |
87 | 87 |
} |
88 |
|
|
88 |
|
|
89 |
@Override |
|
90 |
public String getServerPortAsString() { |
|
91 |
return this.helper.getServerPortAsString(); |
|
92 |
} |
|
93 |
|
|
89 | 94 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialNewStoreParameters.java | ||
---|---|---|
82 | 82 |
public int getServerPort() { |
83 | 83 |
return this.helper.getServerPort(); |
84 | 84 |
} |
85 |
|
|
86 |
@Override |
|
87 |
public String getServerPortAsString() { |
|
88 |
return this.helper.getServerPortAsString(); |
|
89 |
} |
|
85 | 90 |
} |
Also available in: Unified diff