svn-gvsig-desktop / 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 @ 45742
History | View | Annotate | Download (23.7 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2020 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.fmap.dal.store.h2; |
23 |
|
24 |
import java.io.File; |
25 |
import java.sql.Connection; |
26 |
import java.sql.DriverManager; |
27 |
import java.sql.SQLException; |
28 |
import java.text.MessageFormat; |
29 |
import javax.activation.DataSource; |
30 |
import org.apache.commons.dbcp.BasicDataSource; |
31 |
import org.apache.commons.io.FilenameUtils; |
32 |
import org.apache.commons.lang3.StringUtils; |
33 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType; |
34 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_CONFIGURATION_NAME; |
35 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_CONFIGURATION_VALUE; |
36 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_RESOURCES_NAME; |
37 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_RESOURCES_RESOURCE; |
38 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_CONFIGURATION_NAME; |
39 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_RESOURCES_NAME; |
40 |
import org.gvsig.fmap.dal.exception.InitializeException; |
41 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
42 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
43 |
import static org.gvsig.fmap.dal.store.h2.H2SpatialHelper.LOGGER; |
44 |
import org.gvsig.fmap.dal.store.h2.operations.H2SpatialOperationsFactory; |
45 |
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters; |
46 |
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters; |
47 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
48 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
49 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCDriverClassNotFoundException; |
50 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
51 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
52 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
53 |
import org.gvsig.fmap.dal.store.jdbc2.spi.ConnectionProvider; |
54 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase; |
55 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
56 |
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolverBase; |
57 |
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolverDumb; |
58 |
import org.h2.tools.Server; |
59 |
import org.h2gis.functions.factory.H2GISFunctions; |
60 |
import org.h2gis.functions.system.H2GISversion; |
61 |
import org.slf4j.Logger; |
62 |
import org.slf4j.LoggerFactory; |
63 |
|
64 |
|
65 |
@SuppressWarnings("UseSpecificCatch") |
66 |
public class H2SpatialHelper extends JDBCHelperBase { |
67 |
|
68 |
static final Logger LOGGER = LoggerFactory.getLogger(H2SpatialHelper.class); |
69 |
|
70 |
public static final String H2SPATIAL_JDBC_DRIVER = "org.h2.Driver"; |
71 |
|
72 |
public static File getLocalFile(H2SpatialConnectionParameters params) { |
73 |
String host = params.getHost();
|
74 |
if( !StringUtils.isEmpty(host) ) {
|
75 |
host = host.toLowerCase().trim(); |
76 |
if( !(host.equals("localhost") || host.equals("127.0.0.1")) ) { |
77 |
return null; |
78 |
} |
79 |
} |
80 |
File f = params.getFile();
|
81 |
if( f == null ) { |
82 |
return null; |
83 |
} |
84 |
String pathname = f.getAbsolutePath().replace("\\","/"); |
85 |
if( !pathname.endsWith(".mv.db") ) { |
86 |
pathname += ".mv.db";
|
87 |
} |
88 |
|
89 |
return new File(pathname); |
90 |
} |
91 |
|
92 |
public static String getConnectionURL(H2SpatialConnectionParameters params) { |
93 |
String connectionURL;
|
94 |
String dbfilename = params.getFile().getAbsolutePath().replace("\\","/"); |
95 |
if( dbfilename!=null && dbfilename.endsWith(".mv.db") ) { |
96 |
dbfilename = dbfilename.substring(0, dbfilename.length()-6); |
97 |
} |
98 |
StringBuilder commonParameters = new StringBuilder(); |
99 |
commonParameters.append(";MODE=PostgreSQL");
|
100 |
commonParameters.append(";SCHEMA=PUBLIC");
|
101 |
commonParameters.append(";ALLOW_LITERALS=ALL");
|
102 |
if( StringUtils.isEmpty(params.getHost()) ) {
|
103 |
// Asumimos que es una conexion directa sobre el filesystem
|
104 |
if( StringUtils.equalsIgnoreCase(FilenameUtils.getExtension(params.getFile().getName()),"zip") ) { |
105 |
connectionURL = MessageFormat.format(
|
106 |
"jdbc:h2:zip:{0}!/{1}"+commonParameters.toString(),
|
107 |
dbfilename, |
108 |
params.getDBName() |
109 |
); |
110 |
} else {
|
111 |
connectionURL = MessageFormat.format(
|
112 |
"jdbc:h2:file:{0}"+commonParameters.toString(),
|
113 |
dbfilename |
114 |
); |
115 |
} |
116 |
} else if( params.getPort() == null ) { |
117 |
connectionURL = MessageFormat.format(
|
118 |
"jdbc:h2:tcp://{0}/{1}"+commonParameters.toString(),
|
119 |
params.getHost(), |
120 |
dbfilename |
121 |
); |
122 |
} else {
|
123 |
connectionURL = MessageFormat.format("jdbc:h2:tcp://{0}:{1,number,#######}/{2}"+commonParameters.toString(), |
124 |
params.getHost(), |
125 |
(int) params.getPort(),
|
126 |
dbfilename |
127 |
); |
128 |
} |
129 |
LOGGER.debug("connectionURL: {}", connectionURL);
|
130 |
return connectionURL;
|
131 |
} |
132 |
|
133 |
public static class ConnectionProviderImpl implements ConnectionProvider { |
134 |
|
135 |
private static boolean needRegisterDriver = true; |
136 |
|
137 |
private BasicDataSource dataSource = null; |
138 |
|
139 |
private H2SpatialConnectionParameters connectionParameters;
|
140 |
|
141 |
private static Server server = null; |
142 |
private static boolean startServer = true; |
143 |
|
144 |
public ConnectionProviderImpl(H2SpatialConnectionParameters connectionParameters) {
|
145 |
this.connectionParameters = connectionParameters;
|
146 |
} |
147 |
|
148 |
@Override
|
149 |
public String getStatus() { |
150 |
if(dataSource == null) { |
151 |
return "Not using pool."; |
152 |
} |
153 |
StringBuilder builder = new StringBuilder(); |
154 |
builder.append("Pool: ");
|
155 |
builder.append(JDBCUtils.getHexId(dataSource)); |
156 |
builder.append(" Actives: ");
|
157 |
builder.append(dataSource.getNumActive()); |
158 |
builder.append("/");
|
159 |
builder.append(dataSource.getMaxActive()); |
160 |
builder.append(" idle: ");
|
161 |
builder.append(dataSource.getNumIdle()); |
162 |
builder.append("/");
|
163 |
builder.append(dataSource.getMinIdle()); |
164 |
builder.append(":");
|
165 |
builder.append(dataSource.getMaxIdle()); |
166 |
return builder.toString();
|
167 |
} |
168 |
|
169 |
@SuppressWarnings("ConvertToTryWithResources") |
170 |
public void shutdown() { |
171 |
LOGGER.info("Shutdown H2 connection.");
|
172 |
try {
|
173 |
Connection conn = this.getConnection(); |
174 |
conn.createStatement().execute("SHUTDOWN");
|
175 |
conn.close(); |
176 |
} catch (Throwable th) { |
177 |
LOGGER.warn("Problems shutdown the database.", th);
|
178 |
} |
179 |
closeDataSource(); |
180 |
} |
181 |
|
182 |
public static void stopServer() { |
183 |
if (server == null) { |
184 |
LOGGER.info("The H2 server is already stopped.");
|
185 |
} else {
|
186 |
LOGGER.info("Stopping the H2 server.");
|
187 |
LOGGER.info(" port :" + server.getPort());
|
188 |
LOGGER.info(" URL :" + server.getURL());
|
189 |
LOGGER.info(" shutdown server...");
|
190 |
try {
|
191 |
server.shutdown(); |
192 |
} catch (Throwable th) { |
193 |
LOGGER.warn("Problems shutdown the H2 server.", th);
|
194 |
} |
195 |
LOGGER.info(" Stoping server...");
|
196 |
try {
|
197 |
server.stop(); |
198 |
} catch (Throwable th) { |
199 |
LOGGER.warn("Problems stopping the H2 server.", th);
|
200 |
} |
201 |
LOGGER.info(" status:" + server.getStatus());
|
202 |
server = null;
|
203 |
LOGGER.info("H2 Server stopped");
|
204 |
} |
205 |
startServer = true;
|
206 |
} |
207 |
|
208 |
private void startServer() { |
209 |
|
210 |
if( startServer && server == null ) { |
211 |
String port = "9123"; |
212 |
try {
|
213 |
Server theServer; |
214 |
if( this.connectionParameters.getServerPort()>0 ) { |
215 |
port = String.valueOf(this.connectionParameters.getServerPort()); |
216 |
} |
217 |
if( this.connectionParameters.getServerAllowOthers() ) { |
218 |
theServer = Server.createTcpServer("-tcpPort", port, "-ifExists", "-tcpAllowOthers"); |
219 |
} else {
|
220 |
theServer = Server.createTcpServer("-tcpPort", port, "-ifExists"); |
221 |
} |
222 |
theServer.start(); |
223 |
server = theServer; |
224 |
LOGGER.info("H2 Server started" );
|
225 |
LOGGER.info(" Engine version : h2 "+ org.h2.engine.Constants.getFullVersion()+", h2gis "+H2GISversion.geth2gisVersion()); |
226 |
LOGGER.info(" Connection url : jdbc:h2:"+server.getURL()+"/ABSOLUTE_DATABASE_PATH;MODE=PostgreSQL;SCHEMA=PUBLIC;ALLOW_LITERALS=ALL"); |
227 |
// LOGGER.info(" port :"+ server.getPort());
|
228 |
// LOGGER.info(" URL :"+ server.getURL());
|
229 |
LOGGER.info(" status:"+ server.getStatus());
|
230 |
Runtime.getRuntime().addShutdownHook(new Thread() { |
231 |
@Override
|
232 |
public void run() { |
233 |
stopServer(); |
234 |
} |
235 |
}); |
236 |
} catch (SQLException ex) { |
237 |
LOGGER.warn("H2 Server not started",ex);
|
238 |
} |
239 |
// Tanto si consigue lanzar el server como si no, no lo vuelve a intentar
|
240 |
startServer = false;
|
241 |
} |
242 |
|
243 |
} |
244 |
|
245 |
@Override
|
246 |
public String toString() { |
247 |
StringBuilder builder = new StringBuilder(); |
248 |
builder.append(" url=").append(connectionParameters.getUrl());
|
249 |
builder.append(" driver name=").append(connectionParameters.getJDBCDriverClassName());
|
250 |
builder.append(" user=").append(connectionParameters.getUser());
|
251 |
return builder.toString();
|
252 |
} |
253 |
|
254 |
@Override
|
255 |
public synchronized Connection getConnection() throws SQLException { |
256 |
File f = H2SpatialHelper.getLocalFile(connectionParameters);
|
257 |
boolean newdb = !f.exists();
|
258 |
|
259 |
Connection conn;
|
260 |
|
261 |
try {
|
262 |
conn = DriverManager.getConnection(
|
263 |
connectionParameters.getUrl(), |
264 |
connectionParameters.getUser(), |
265 |
connectionParameters.getPassword() |
266 |
); |
267 |
|
268 |
} catch(Throwable th) { |
269 |
throw th;
|
270 |
} |
271 |
|
272 |
|
273 |
// if (this.dataSource == null) {
|
274 |
// this.dataSource = this.createDataSource();
|
275 |
// }
|
276 |
//
|
277 |
// try {
|
278 |
// conn = this.dataSource.getConnection();
|
279 |
// } catch(Throwable th) {
|
280 |
// LOGGER.warn("Can't create connection to '"+this.dataSource.getUrl()+"'. "+this.getStatus());
|
281 |
// LOGGER.warn("Can't create connection to '"+this.dataSource.getUrl()+"'.",th);
|
282 |
// throw th;
|
283 |
// }
|
284 |
|
285 |
|
286 |
try {
|
287 |
conn.createStatement().execute("SELECT TOP 1 SRID FROM SPATIAL_REF_SYS");
|
288 |
} catch(SQLException ex) { |
289 |
H2GISFunctions.load(conn); |
290 |
} |
291 |
try {
|
292 |
conn.createStatement().execute("CREATE SCHEMA IF NOT EXISTS PUBLIC;SET SCHEMA PUBLIC");
|
293 |
} catch(SQLException ex) { |
294 |
LOGGER.trace("Can't create schema public.",ex);
|
295 |
// Ignore this error.
|
296 |
} |
297 |
|
298 |
if( newdb ) {
|
299 |
String[] sqls = new String[] { |
300 |
"CREATE CACHED TABLE PUBLIC.\""+TABLE_RESOURCES_NAME+"\"(\""+FIELD_RESOURCES_NAME+"\" VARCHAR(150) NOT NULL, \""+FIELD_RESOURCES_RESOURCE+"\" BLOB DEFAULT NULL)", |
301 |
"ALTER TABLE PUBLIC.\""+TABLE_RESOURCES_NAME+"\" ADD CONSTRAINT PUBLIC.CONSTRAINT_E PRIMARY KEY(\""+FIELD_RESOURCES_NAME+"\")", |
302 |
"CREATE CACHED TABLE PUBLIC.\""+TABLE_CONFIGURATION_NAME+"\"(\""+FIELD_CONFIGURATION_NAME+"\" VARCHAR(200) NOT NULL, \""+FIELD_CONFIGURATION_VALUE+"\" VARCHAR(200) DEFAULT NULL)", |
303 |
"ALTER TABLE PUBLIC.\""+TABLE_CONFIGURATION_NAME+"\" ADD CONSTRAINT PUBLIC.CONSTRAINT_2 PRIMARY KEY(\""+FIELD_CONFIGURATION_NAME+"\")" |
304 |
}; |
305 |
for (String sql : sqls) { |
306 |
try {
|
307 |
conn.createStatement().execute(sql); |
308 |
} catch(SQLException ex) { |
309 |
LOGGER.debug("Can't configure gvsig tables.",ex);
|
310 |
LOGGER.warn("Can't configure gvsig tables. "+sql);
|
311 |
// Ignore this error.
|
312 |
} |
313 |
} |
314 |
} |
315 |
return conn;
|
316 |
} |
317 |
|
318 |
private BasicDataSource createDataSource() throws SQLException { |
319 |
if (!this.isRegistered()) { |
320 |
this.registerDriver();
|
321 |
} |
322 |
startServer(); |
323 |
H2SpatialConnectionParameters params = connectionParameters; |
324 |
|
325 |
BasicDataSource ds = new BasicDataSource();
|
326 |
ds.setDriverClassName(params.getJDBCDriverClassName()); |
327 |
if( !StringUtils.isEmpty(params.getUser()) ) {
|
328 |
ds.setUsername(params.getUser()); |
329 |
} |
330 |
if( !StringUtils.isEmpty(params.getPassword()) ) {
|
331 |
ds.setPassword(params.getPassword()); |
332 |
} |
333 |
ds.setUrl(params.getUrl()); |
334 |
|
335 |
ds.setMaxWait(60L * 1000); |
336 |
|
337 |
//
|
338 |
// Ajustamos el pool para que las conexiones se cierren a los
|
339 |
// 10 segundos, asi tratamos de que al salir de gvSIG no queden
|
340 |
// conexiones abiertas con la BBDD y pueda quedar corrupta esta.
|
341 |
// Hay que tener en cuenta que es una BBDD embebida, y mientras
|
342 |
// hayan conexiones abiertas pueden quedar cosas por bajar a disco.
|
343 |
//
|
344 |
int sidle = this.connectionParameters.getMaxSecondsIdle(); |
345 |
if( sidle < 0 ) { |
346 |
ds.setTimeBetweenEvictionRunsMillis(-1);
|
347 |
ds.setMinEvictableIdleTimeMillis(30*1000); |
348 |
} else {
|
349 |
// Revisamos las conexiones inactivas cada 10 segundos
|
350 |
ds.setTimeBetweenEvictionRunsMillis(sidle*1000);
|
351 |
// Eliminadmos las conexiones que lleven inactivas mas de 10 segundos.
|
352 |
ds.setMinEvictableIdleTimeMillis(sidle*1000);
|
353 |
} |
354 |
|
355 |
// Ajustamos el numero minimo de conexiones a 0 para permitir
|
356 |
// que se lleguen a cerrar todas las conexiones del pool.
|
357 |
ds.setMinIdle(0);
|
358 |
// dejaremos el MaxIdle a 20, no parece importante. .
|
359 |
ds.setMaxIdle(20);
|
360 |
|
361 |
return ds;
|
362 |
} |
363 |
|
364 |
private boolean isRegistered() { |
365 |
return needRegisterDriver;
|
366 |
} |
367 |
|
368 |
@Override
|
369 |
public void registerDriver() throws SQLException { |
370 |
String className = this.connectionParameters.getJDBCDriverClassName(); |
371 |
if (className == null) { |
372 |
return;
|
373 |
} |
374 |
try {
|
375 |
Class theClass = Class.forName(className); |
376 |
if (theClass == null) { |
377 |
throw new JDBCDriverClassNotFoundException(H2SpatialLibrary.NAME, className); |
378 |
} |
379 |
} catch (Exception e) { |
380 |
throw new SQLException("Can't register JDBC driver '" + className + "'.", e); |
381 |
} |
382 |
needRegisterDriver = false;
|
383 |
} |
384 |
|
385 |
@Override
|
386 |
public void dispose() { |
387 |
closeDataSource(); |
388 |
this.connectionParameters = null; |
389 |
} |
390 |
|
391 |
private void closeDataSource() { |
392 |
try {
|
393 |
if( dataSource!=null ) { |
394 |
LOGGER.info("Clossing connection pool.");
|
395 |
LOGGER.info(this.getStatus());
|
396 |
dataSource.close(); |
397 |
dataSource = null;
|
398 |
LOGGER.info("Connection pool closed.");
|
399 |
LOGGER.info(this.getStatus());
|
400 |
} |
401 |
} catch (Throwable th) { |
402 |
LOGGER.warn("Problems closing connections pool.", th);
|
403 |
} |
404 |
|
405 |
} |
406 |
|
407 |
} |
408 |
|
409 |
private ConnectionProvider connectionProvider = null; |
410 |
|
411 |
/**
|
412 |
* Constructor for use only for testing purposes.
|
413 |
*
|
414 |
* @param connectionParameters
|
415 |
* @param connectionProvider
|
416 |
*/
|
417 |
public H2SpatialHelper(JDBCConnectionParameters connectionParameters, ConnectionProvider connectionProvider) {
|
418 |
super(connectionParameters);
|
419 |
this.srssolver = new SRSSolverDumb(this); |
420 |
this.connectionProvider = connectionProvider;
|
421 |
} |
422 |
|
423 |
public H2SpatialHelper(JDBCConnectionParameters connectionParameters) {
|
424 |
super(connectionParameters);
|
425 |
this.srssolver = new SRSSolverBase(this); |
426 |
} |
427 |
|
428 |
|
429 |
public void shutdown() { |
430 |
try {
|
431 |
if( this.connectionProvider!=null ) { |
432 |
((ConnectionProviderImpl) this.connectionProvider).shutdown();
|
433 |
this.connectionProvider = null; |
434 |
} |
435 |
ConnectionProviderImpl.stopServer(); |
436 |
} catch (Throwable ex) { |
437 |
LOGGER.warn("Problems shutdown H2", ex);
|
438 |
} |
439 |
} |
440 |
|
441 |
private void logConnectionStatus(String msg, Connection conn) { |
442 |
ConnectionProvider cp = this.getConnectionProvider();
|
443 |
StringBuilder builder = new StringBuilder(); |
444 |
builder.append(msg); |
445 |
if( conn == null ) { |
446 |
builder.append(": connection null");
|
447 |
} else {
|
448 |
Boolean closed = null; |
449 |
try {
|
450 |
closed = conn.isClosed(); |
451 |
} catch(Throwable th) { |
452 |
} |
453 |
builder.append(": connection ");
|
454 |
builder.append(JDBCUtils.getConnId(conn)); |
455 |
if( closed ) {
|
456 |
builder.append(" (c)");
|
457 |
} |
458 |
builder.append(" ");
|
459 |
} |
460 |
builder.append(cp.getStatus()); |
461 |
LOGGER.info(builder.toString()); |
462 |
} |
463 |
|
464 |
private ConnectionProvider getConnectionProvider() {
|
465 |
if (this.connectionProvider == null) { |
466 |
H2SpatialConnectionParameters connectionParameters = this.getConnectionParameters();
|
467 |
if( connectionParameters==null ) { |
468 |
return null; // Testing mode? |
469 |
} |
470 |
this.connectionProvider = new ConnectionProviderImpl(connectionParameters); |
471 |
} |
472 |
return this.connectionProvider; |
473 |
} |
474 |
|
475 |
@Override
|
476 |
public synchronized Connection getConnection() throws AccessResourceException { |
477 |
try {
|
478 |
if (this.connectionProvider == null) { |
479 |
H2SpatialConnectionParameters connectionParameters = this.getConnectionParameters();
|
480 |
if( connectionParameters==null ) { |
481 |
return null; // Testing mode? |
482 |
} |
483 |
this.connectionProvider = new ConnectionProviderImpl(connectionParameters); |
484 |
} |
485 |
Connection connection = this.connectionProvider.getConnection(); |
486 |
if( LOGGER.isDebugEnabled() ) {
|
487 |
LOGGER.debug("["+JDBCUtils.getConnId(connection)+"] getConnection "+connectionProvider.getStatus()+" "+ connectionProvider.toString()); |
488 |
} |
489 |
return connection;
|
490 |
} catch (SQLException ex) { |
491 |
throw new AccessResourceException(H2SpatialLibrary.NAME, ex); |
492 |
} |
493 |
} |
494 |
|
495 |
@Override
|
496 |
public void closeConnection(Connection connection) { |
497 |
if( connection!=null ) { // In test ??? |
498 |
LOGGER.debug("["+JDBCUtils.getConnId(connection)+"] closeConnection "+ this.connectionProvider.getStatus()); |
499 |
} |
500 |
super.closeConnection(connection);
|
501 |
} |
502 |
|
503 |
@Override
|
504 |
public H2SpatialConnectionParameters getConnectionParameters() {
|
505 |
return (H2SpatialConnectionParameters) super.getConnectionParameters(); |
506 |
} |
507 |
|
508 |
@Override
|
509 |
public String getConnectionURL() { |
510 |
return getConnectionURL(this.getConnectionParameters()); |
511 |
} |
512 |
|
513 |
@Override
|
514 |
protected String getResourceType() { |
515 |
return H2SpatialLibrary.NAME;
|
516 |
} |
517 |
|
518 |
@Override
|
519 |
public String getProviderName() { |
520 |
return H2SpatialLibrary.NAME;
|
521 |
} |
522 |
|
523 |
@Override
|
524 |
public JDBCSQLBuilderBase createSQLBuilder() {
|
525 |
return new H2SpatialSQLBuilder(this); |
526 |
} |
527 |
|
528 |
@Override
|
529 |
public OperationsFactory getOperations() {
|
530 |
if (this.operationsFactory == null) { |
531 |
this.operationsFactory = new H2SpatialOperationsFactory(this); |
532 |
} |
533 |
return operationsFactory;
|
534 |
} |
535 |
|
536 |
@Override
|
537 |
public GeometrySupportType getGeometrySupportType() {
|
538 |
return GeometrySupportType.WKB;
|
539 |
} |
540 |
|
541 |
@Override
|
542 |
public boolean hasSpatialFunctions() { |
543 |
return true; |
544 |
} |
545 |
|
546 |
@Override
|
547 |
public boolean canWriteGeometry(int geometryType, int geometrySubtype) { |
548 |
return true; |
549 |
} |
550 |
|
551 |
@Override
|
552 |
public String getQuoteForIdentifiers() { |
553 |
return "\""; |
554 |
} |
555 |
|
556 |
@Override
|
557 |
public boolean allowAutomaticValues() { |
558 |
return true; |
559 |
} |
560 |
|
561 |
@Override
|
562 |
public boolean supportOffsetInSelect() { |
563 |
return true; |
564 |
} |
565 |
|
566 |
@Override
|
567 |
public String getQuoteForStrings() { |
568 |
return "'"; |
569 |
} |
570 |
|
571 |
@Override
|
572 |
public String getSourceId(JDBCStoreParameters parameters) { |
573 |
H2SpatialStoreParameters h2params = (H2SpatialStoreParameters) parameters; |
574 |
StringBuilder builder = new StringBuilder(); |
575 |
builder.append(h2params.getTable()); |
576 |
builder.append("(");
|
577 |
if( StringUtils.isNotBlank(h2params.getHost()) ) {
|
578 |
builder.append(h2params.getHost()); |
579 |
} |
580 |
if( h2params.getPort()>0 ) { |
581 |
builder.append(",");
|
582 |
builder.append(h2params.getPort()); |
583 |
} |
584 |
File f = h2params.getFile();
|
585 |
if( f != null ) { |
586 |
builder.append(",");
|
587 |
builder.append(h2params.getFile().getAbsolutePath()); |
588 |
} |
589 |
builder.append(")");
|
590 |
return builder.toString();
|
591 |
} |
592 |
|
593 |
@Override
|
594 |
public JDBCNewStoreParameters createNewStoreParameters() {
|
595 |
return new H2SpatialNewStoreParameters(); |
596 |
} |
597 |
|
598 |
@Override
|
599 |
public JDBCStoreParameters createOpenStoreParameters() {
|
600 |
return new H2SpatialStoreParameters(); |
601 |
} |
602 |
|
603 |
@Override
|
604 |
public JDBCServerExplorerParameters createServerExplorerParameters() {
|
605 |
return new H2SpatialExplorerParameters(); |
606 |
} |
607 |
|
608 |
@Override
|
609 |
public JDBCServerExplorer createServerExplorer(
|
610 |
JDBCServerExplorerParameters parameters, |
611 |
DataServerExplorerProviderServices providerServices |
612 |
) throws InitializeException {
|
613 |
|
614 |
JDBCServerExplorer explorer = new H2SpatialExplorer(
|
615 |
parameters, |
616 |
providerServices, |
617 |
this
|
618 |
); |
619 |
this.initialize(explorer, parameters, null); |
620 |
return explorer;
|
621 |
} |
622 |
|
623 |
public String getConnectionProviderStatus(){ |
624 |
return this.getConnectionProvider().getStatus(); |
625 |
} |
626 |
|
627 |
|
628 |
} |