Strabon

changeset 316:ab82fc8816c0

added deregisterDriver method in Strabon to deregister the JDBC driver. In older versions of Tomcat the JDBC driver is not deregistered automatically, which leads to memory leaks
author Babis Nikolaou <charnik@di.uoa.gr>
date Thu Jun 21 14:56:00 2012 +0300 (2012-06-21)
parents d8aa169eb72b
children ca965a7829ba
files runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java runtime/src/main/java/eu/earthobservatory/runtime/monetdb/Strabon.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/Strabon.java
line diff
     1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Thu Jun 21 14:32:26 2012 +0300
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Thu Jun 21 14:56:00 2012 +0300
     1.3 @@ -113,7 +113,9 @@
     1.4  	}
     1.5  
     1.6  
     1.7 -	protected abstract void initiate(String databaseName, String user, String password, int port, String serverName) ;
     1.8 +	protected abstract void deregisterDriver();
     1.9 +	
    1.10 +	protected abstract void initiate(String databaseName, String user, String password, int port, String serverName);
    1.11  
    1.12  	protected void init() {
    1.13  
    1.14 @@ -158,6 +160,9 @@
    1.15  			con1.commit();
    1.16  			con1.close();
    1.17  			repo1.shutDown();
    1.18 +			
    1.19 +			// deregister jdbc driver
    1.20 +			deregisterDriver();
    1.21  
    1.22  		} catch (RepositoryException e) {
    1.23  			logger.error("[Strabon.close]", e);
     2.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/Strabon.java	Thu Jun 21 14:32:26 2012 +0300
     2.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/Strabon.java	Thu Jun 21 14:56:00 2012 +0300
     2.3 @@ -62,4 +62,17 @@
     2.4  			throw e;
     2.5  		}
     2.6  	}
     2.7 +	
     2.8 +	@Override
     2.9 +	protected void deregisterDriver() {
    2.10 +		try {
    2.11 +			logger.info("[Strabon.deregisterDriver] Deregistering JDBC driver...");
    2.12 +	        java.sql.Driver driver = DriverManager.getDriver("jdbc:monetdb://" + serverName + ":" + port + "/");
    2.13 +	        DriverManager.deregisterDriver(driver);
    2.14 +	        logger.info("[Strabon.deregisterDriver] JDBC driver deregistered successfully.");
    2.15 +	        
    2.16 +	    } catch (SQLException e) {
    2.17 +	        logger.warn("[Strabon.deregisterDriver] Could not deregister JDBC driver: {}", e.getMessage());
    2.18 +	    }
    2.19 +	}
    2.20  }
     3.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/Strabon.java	Thu Jun 21 14:32:26 2012 +0300
     3.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/Strabon.java	Thu Jun 21 14:56:00 2012 +0300
     3.3 @@ -54,4 +54,17 @@
     3.4  			throw e;
     3.5  		}
     3.6  	}
     3.7 +
     3.8 +	@Override
     3.9 +	protected void deregisterDriver() {
    3.10 +		try {
    3.11 +			logger.info("[Strabon.deregisterDriver] Deregistering JDBC driver...");
    3.12 +	        java.sql.Driver driver = DriverManager.getDriver("jdbc:postgresql://" + serverName + ":" + port + "/");
    3.13 +	        DriverManager.deregisterDriver(driver);
    3.14 +	        logger.info("[Strabon.deregisterDriver] JDBC driver deregistered successfully.");
    3.15 +	        
    3.16 +	    } catch (SQLException e) {
    3.17 +	        logger.warn("[Strabon.deregisterDriver] Could not deregister JDBC driver: {}", e.getMessage());
    3.18 +	    }
    3.19 +	}
    3.20  }