Strabon

changeset 229:0077ec91f90b

Logging in Strabon main classes and properly handle of exceptions and closing the Strabon connection.
author Babis Nikolaou <charnik@di.uoa.gr>
date Sat Jun 02 19:21:19 2012 +0300 (2012-06-02)
parents 788831ebb99b
children 1849dd7b408f
files runtime/src/main/java/eu/earthobservatory/runtime/postgis/DescribeOp.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/StoreOp.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/UpdateOp.java
line diff
     1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/DescribeOp.java	Sat Jun 02 19:11:53 2012 +0300
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/DescribeOp.java	Sat Jun 02 19:21:19 2012 +0300
     1.3 @@ -1,13 +1,18 @@
     1.4  package eu.earthobservatory.runtime.postgis;
     1.5  
     1.6 +import org.slf4j.Logger;
     1.7 +import org.slf4j.LoggerFactory;
     1.8 +
     1.9  
    1.10  public class DescribeOp {
    1.11  
    1.12 +	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.runtime.postgis.DescribeOp.class);
    1.13 +	
    1.14  	/**
    1.15  	 * @param args
    1.16  	 * @throws Exception 
    1.17  	 */
    1.18 -	public static void main(String[] args) throws Exception {
    1.19 +	public static void main(String[] args) {
    1.20  
    1.21  		if (args.length < 7) {
    1.22  			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> <OUTPUT>");
    1.23 @@ -29,9 +34,17 @@
    1.24  		String queryString = args[5];
    1.25  		String outFile = args[6];
    1.26  		
    1.27 -		Strabon strabon = new Strabon(db, user, passwd, port, host, true);
    1.28 -		strabon.describe(queryString, strabon.getSailRepoConnection(), outFile);
    1.29 -
    1.30 -		strabon.close();
    1.31 +		Strabon strabon = null;
    1.32 +		
    1.33 +		try {
    1.34 +			strabon = new Strabon(db, user, passwd, port, host, true);
    1.35 +			strabon.describe(queryString, strabon.getSailRepoConnection(), outFile);
    1.36 +			
    1.37 +		} catch (Exception e) {
    1.38 +			logger.error("[Strabon.DescribeOp] Error during execution of DESCRIBE query.", e);
    1.39 +			
    1.40 +		} finally {
    1.41 +			strabon.close();
    1.42 +		}
    1.43  	}
    1.44  }
     2.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java	Sat Jun 02 19:11:53 2012 +0300
     2.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java	Sat Jun 02 19:21:19 2012 +0300
     2.3 @@ -12,7 +12,7 @@
     2.4  	 * @param args
     2.5  	 * @throws Exception 
     2.6  	 */
     2.7 -	public static void main(String[] args) throws Exception {
     2.8 +	public static void main(String[] args) {
     2.9  
    2.10  		if (args.length < 6) {
    2.11  			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> ");
    2.12 @@ -37,11 +37,19 @@
    2.13  			resultsFormat = args[6];
    2.14  		}
    2.15  
    2.16 -		Strabon strabon = new Strabon(db, user, passwd, port, host, true);
    2.17 -
    2.18 -		logger.info("[QueryOp] Executing query: " + queryString);
    2.19 -		strabon.query(queryString, resultsFormat, strabon.getSailRepoConnection());
    2.20 -		strabon.close();
    2.21 +		Strabon strabon = null;
    2.22 +		try {
    2.23 +			logger.info("[QueryOp] Executing query: " + queryString);
    2.24 +			
    2.25 +			strabon = new Strabon(db, user, passwd, port, host, true);
    2.26 +			strabon.query(queryString, resultsFormat, strabon.getSailRepoConnection());
    2.27 +			
    2.28 +		} catch (Exception e) {
    2.29 +			logger.error("[Strabon.QueryOp] Error during querying.", e);
    2.30 +			
    2.31 +		} finally {
    2.32 +			strabon.close();
    2.33 +		}
    2.34  	}
    2.35  	/*
    2.36  	private static void query(String queryString, SailRepositoryConnection con) throws MalformedQueryException, RepositoryException, QueryEvaluationException, IOException, ClassNotFoundException, TupleQueryResultHandlerException {
     3.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/StoreOp.java	Sat Jun 02 19:11:53 2012 +0300
     3.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/StoreOp.java	Sat Jun 02 19:21:19 2012 +0300
     3.3 @@ -41,9 +41,10 @@
     3.4  		try {
     3.5  			strabon = new Strabon(db, user, passwd, port, host, true);
     3.6  			strabon.storeInRepo(src, format);
     3.7 -			strabon.close();
     3.8 +			
     3.9  		} catch (Exception e) {
    3.10  			logger.error("[Strabon.StoreOp] Error during store.", e);
    3.11 +			
    3.12  		} finally {
    3.13  			strabon.close();
    3.14  		}
     4.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/UpdateOp.java	Sat Jun 02 19:11:53 2012 +0300
     4.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/UpdateOp.java	Sat Jun 02 19:21:19 2012 +0300
     4.3 @@ -1,13 +1,17 @@
     4.4  package eu.earthobservatory.runtime.postgis;
     4.5  
     4.6 +import org.slf4j.Logger;
     4.7 +import org.slf4j.LoggerFactory;
     4.8  
     4.9  public class UpdateOp {
    4.10  
    4.11 +	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.runtime.postgis.UpdateOp.class);
    4.12 +	
    4.13  	/**
    4.14  	 * @param args
    4.15  	 * @throws Exception 
    4.16  	 */
    4.17 -	public static void main(String[] args) throws Exception {
    4.18 +	public static void main(String[] args) {
    4.19  
    4.20  		if (args.length < 6) {
    4.21  			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <UPDATE> ");
    4.22 @@ -27,10 +31,16 @@
    4.23  		String passwd = args[4];		
    4.24  		String queryString = args[5];
    4.25  		
    4.26 -		Strabon strabon = new Strabon(db, user, passwd, port, host, true);
    4.27 -
    4.28 -		strabon.update(queryString, strabon.getSailRepoConnection());
    4.29 -
    4.30 -		strabon.close();
    4.31 +		Strabon strabon = null;
    4.32 +		try {
    4.33 +			strabon = new Strabon(db, user, passwd, port, host, true);
    4.34 +			strabon.update(queryString, strabon.getSailRepoConnection());
    4.35 +			
    4.36 +		} catch (Exception e) {
    4.37 +			logger.error("[Strabon.UpdateOp] Error during execution of UPDATE query.", e);
    4.38 +			
    4.39 +		} finally {
    4.40 +			strabon.close();
    4.41 +		}
    4.42  	}
    4.43  }