Strabon

changeset 231:97c7efb8a600

added logging in main classes of Strabon for monetdb and properly close strabon connection in case of an exception
author Babis Nikolaou <charnik@di.uoa.gr>
date Sun Jun 03 14:28:01 2012 +0300 (2012-06-03)
parents 1849dd7b408f
children ed6dabab362c
files runtime/src/main/java/eu/earthobservatory/runtime/monetdb/DescribeOp.java runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryDir.java runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryOp.java runtime/src/main/java/eu/earthobservatory/runtime/monetdb/StoreOp.java runtime/src/main/java/eu/earthobservatory/runtime/monetdb/Strabon.java runtime/src/main/java/eu/earthobservatory/runtime/monetdb/UpdateOp.java
line diff
     1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/DescribeOp.java	Sat Jun 02 19:25:04 2012 +0300
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/DescribeOp.java	Sun Jun 03 14:28:01 2012 +0300
     1.3 @@ -1,13 +1,18 @@
     1.4  package eu.earthobservatory.runtime.monetdb;
     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.monetdb.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 @@ -28,10 +33,19 @@
    1.24  		String passwd = args[4];		
    1.25  		String queryString = args[5];
    1.26  		String outFile = args[6];
    1.27 -		
    1.28 -		Strabon strabon = new Strabon(db, user, passwd, port, host, true);
    1.29 -		strabon.describe(queryString, strabon.getSailRepoConnection(), outFile);
    1.30  
    1.31 -		strabon.close();
    1.32 +		Strabon strabon = null;
    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 +			if (strabon != null) {
    1.42 +				strabon.close();
    1.43 +			}
    1.44 +		}
    1.45  	}
    1.46  }
     2.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryDir.java	Sat Jun 02 19:25:04 2012 +0300
     2.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryDir.java	Sun Jun 03 14:28:01 2012 +0300
     2.3 @@ -6,14 +6,19 @@
     2.4  import java.io.FilenameFilter;
     2.5  import java.io.IOException;
     2.6  
     2.7 +import org.slf4j.Logger;
     2.8 +import org.slf4j.LoggerFactory;
     2.9 +
    2.10  
    2.11  public class QueryDir {
    2.12  
    2.13 +	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.runtime.monetdb.QueryDir.class);
    2.14 +	
    2.15  	/**
    2.16  	 * @param args
    2.17  	 * @throws Exception 
    2.18  	 */
    2.19 -	public static void main(String[] args) throws Exception {
    2.20 +	public static void main(String[] args) {
    2.21  
    2.22  		if (args.length < 7) {
    2.23  			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <PATH> [<FORMAT>]");
    2.24 @@ -40,30 +45,38 @@
    2.25  			resultsFormat = args[7];
    2.26  		}
    2.27  
    2.28 -		Strabon strabon = new Strabon(db, user, passwd, port, host, true);
    2.29 +		Strabon strabon = null;
    2.30 +		try {
    2.31 +			strabon = new Strabon(db, user, passwd, port, host, true);
    2.32  
    2.33 -		File dir = new File(path);
    2.34 -
    2.35 -		FilenameFilter filter = new FilenameFilter() {
    2.36 -			public boolean accept(File dir, String name) {
    2.37 -				return name.endsWith(extension);
    2.38 -			}
    2.39 -		};
    2.40 -
    2.41 -		String[] children = dir.list(filter);
    2.42 -		if (children != null) {
    2.43 -			for (int i=0; i<children.length; i++) {
    2.44 -				String filename = children[i];
    2.45 -				try {
    2.46 -					String queryString = readFile(path + System.getProperty("file.separator") + filename);
    2.47 -					strabon.query(queryString, resultsFormat, strabon.getSailRepoConnection());
    2.48 -				} catch (IOException e) {
    2.49 -					System.err.println("IOException while reading " + filename);
    2.50 +			File dir = new File(path);
    2.51 +			FilenameFilter filter = new FilenameFilter() {
    2.52 +				public boolean accept(File dir, String name) {
    2.53 +					return name.endsWith(extension);
    2.54 +				}
    2.55 +			};
    2.56 +	
    2.57 +			String[] children = dir.list(filter);
    2.58 +			if (children != null) {
    2.59 +				for (int i=0; i<children.length; i++) {
    2.60 +					String filename = children[i];
    2.61 +					try {
    2.62 +						String queryString = readFile(path + System.getProperty("file.separator") + filename);
    2.63 +						strabon.query(queryString, resultsFormat, strabon.getSailRepoConnection());
    2.64 +						
    2.65 +					} catch (IOException e) {
    2.66 +						logger.error("[Strabon.QueryDir] IOException while reading " + filename, e);
    2.67 +					}
    2.68  				}
    2.69  			}
    2.70 +		} catch (Exception e) {
    2.71 +			logger.error("[Strabon.QueryDir] Error in QueryDir.", e);
    2.72 +			
    2.73 +		} finally {
    2.74 +			if (strabon != null) {
    2.75 +				strabon.close();
    2.76 +			}
    2.77  		}
    2.78 -		
    2.79 -		strabon.close();
    2.80  	}
    2.81  
    2.82  	private static String readFile(String file) throws IOException {
    2.83 @@ -77,27 +90,4 @@
    2.84  		}
    2.85  		return stringBuilder.toString();
    2.86  	}
    2.87 -
    2.88 -	/*
    2.89 -	private static void query(String queryString, SailRepositoryConnection con) throws MalformedQueryException, RepositoryException, QueryEvaluationException, IOException, ClassNotFoundException, TupleQueryResultHandlerException {
    2.90 -		TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    2.91 -
    2.92 -		System.out.println(queryString);
    2.93 -		TupleQueryResult result = tupleQuery.evaluate();
    2.94 -
    2.95 -		System.out.println("-------------------------------------------");
    2.96 -		System.out.println("-                RESULTS                  -");
    2.97 -		System.out.println("-------------------------------------------");
    2.98 -
    2.99 -		tupleQuery.evaluate(new SPARQLResultsXMLWriter(System.out));
   2.100 -
   2.101 -		List<String> bindingNames = result.getBindingNames();
   2.102 -		while (result.hasNext()) {
   2.103 -			BindingSet bindingSet = result.next();			
   2.104 -			System.out.println(bindingSet.toString());
   2.105 -		}
   2.106 -		System.out.println("-------------------------------------------");
   2.107 -		System.out.flush();
   2.108 -	}
   2.109 -	 */
   2.110  }
     3.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryOp.java	Sat Jun 02 19:25:04 2012 +0300
     3.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryOp.java	Sun Jun 03 14:28:01 2012 +0300
     3.3 @@ -1,13 +1,17 @@
     3.4  package eu.earthobservatory.runtime.monetdb;
     3.5  
     3.6 +import org.slf4j.Logger;
     3.7 +import org.slf4j.LoggerFactory;
     3.8  
     3.9  public class QueryOp {
    3.10  
    3.11 +	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.runtime.monetdb.QueryOp.class);
    3.12 +	
    3.13  	/**
    3.14  	 * @param args
    3.15  	 * @throws Exception 
    3.16  	 */
    3.17 -	public static void main(String[] args) throws Exception {
    3.18 +	public static void main(String[] args) {
    3.19  
    3.20  		if (args.length < 6) {
    3.21  			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> ");
    3.22 @@ -32,35 +36,18 @@
    3.23  			resultsFormat = args[6];
    3.24  		}
    3.25  
    3.26 -
    3.27 -
    3.28 -
    3.29 -		Strabon strabon = new Strabon(db, user, passwd, port, host, true);
    3.30 -
    3.31 -		strabon.query(queryString, resultsFormat, strabon.getSailRepoConnection());
    3.32 -
    3.33 -		strabon.close();
    3.34 +		Strabon strabon = null;
    3.35 +		try {
    3.36 +			strabon = new Strabon(db, user, passwd, port, host, true);
    3.37 +			strabon.query(queryString, resultsFormat, strabon.getSailRepoConnection());
    3.38 +			
    3.39 +		} catch (Exception e) {
    3.40 +			logger.error("[Strabon.QueryOp] Error during execution of SPARQL query.", e);
    3.41 +			
    3.42 +		} finally {
    3.43 +			if (strabon != null) {
    3.44 +				strabon.close();
    3.45 +			}
    3.46 +		}
    3.47  	}
    3.48 -	/*
    3.49 -	private static void query(String queryString, SailRepositoryConnection con) throws MalformedQueryException, RepositoryException, QueryEvaluationException, IOException, ClassNotFoundException, TupleQueryResultHandlerException {
    3.50 -		TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    3.51 -
    3.52 -		System.out.println(queryString);
    3.53 -		TupleQueryResult result = tupleQuery.evaluate();
    3.54 -
    3.55 -		System.out.println("-------------------------------------------");
    3.56 -		System.out.println("-                RESULTS                  -");
    3.57 -		System.out.println("-------------------------------------------");
    3.58 -
    3.59 -		tupleQuery.evaluate(new SPARQLResultsXMLWriter(System.out));
    3.60 -
    3.61 -		List<String> bindingNames = result.getBindingNames();
    3.62 -		while (result.hasNext()) {
    3.63 -			BindingSet bindingSet = result.next();			
    3.64 -			System.out.println(bindingSet.toString());
    3.65 -		}
    3.66 -		System.out.println("-------------------------------------------");
    3.67 -		System.out.flush();
    3.68 -	}
    3.69 -	 */
    3.70  }
     4.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/StoreOp.java	Sat Jun 02 19:25:04 2012 +0300
     4.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/StoreOp.java	Sun Jun 03 14:28:01 2012 +0300
     4.3 @@ -1,15 +1,17 @@
     4.4  package eu.earthobservatory.runtime.monetdb;
     4.5  
     4.6 -import java.io.File;
     4.7 -
     4.8 +import org.slf4j.Logger;
     4.9 +import org.slf4j.LoggerFactory;
    4.10  
    4.11  public class StoreOp {
    4.12  
    4.13 +	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.runtime.monetdb.StoreOp.class);
    4.14 +	
    4.15  	/**
    4.16  	 * @param args
    4.17  	 * @throws Exception 
    4.18  	 */
    4.19 -	public static void main(String[] args) throws Exception {
    4.20 +	public static void main(String[] args) {
    4.21  
    4.22  		if (args.length < 6) {
    4.23  			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> ");
    4.24 @@ -34,9 +36,19 @@
    4.25  			format = args[6];
    4.26  		}
    4.27  
    4.28 -		Strabon strabon = new Strabon(db, user, passwd, port, host, true);
    4.29 -		strabon.storeInRepo(src, format);
    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.storeInRepo(src, format);
    4.35 +		
    4.36 +		} catch (Exception e) {
    4.37 +			logger.error("[Strabon.StoreOp] Error during store.", e);
    4.38 +			
    4.39 +		} finally {
    4.40 +			if (strabon != null) {
    4.41 +				strabon.close();
    4.42 +			}
    4.43 +		}
    4.44  	}
    4.45  
    4.46  }
     5.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/Strabon.java	Sat Jun 02 19:25:04 2012 +0300
     5.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/Strabon.java	Sun Jun 03 14:28:01 2012 +0300
     5.3 @@ -1,14 +1,10 @@
     5.4  package eu.earthobservatory.runtime.monetdb;
     5.5  
     5.6 -import info.aduna.concurrent.locks.Properties;
     5.7 -
     5.8  import java.sql.Connection;
     5.9  import java.sql.DriverManager;
    5.10  import java.sql.ResultSet;
    5.11  import java.sql.SQLException;
    5.12 -import java.util.Map;
    5.13  
    5.14 -import org.apache.commons.collections.map.HashedMap;
    5.15  import org.openrdf.sail.monetdb.MonetDBSqlStore;
    5.16  
    5.17  public class Strabon extends eu.earthobservatory.runtime.generaldb.Strabon {
     6.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/UpdateOp.java	Sat Jun 02 19:25:04 2012 +0300
     6.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/UpdateOp.java	Sun Jun 03 14:28:01 2012 +0300
     6.3 @@ -1,13 +1,18 @@
     6.4  package eu.earthobservatory.runtime.monetdb;
     6.5  
     6.6 +import org.slf4j.Logger;
     6.7 +import org.slf4j.LoggerFactory;
     6.8 +
     6.9  
    6.10  public class UpdateOp {
    6.11  
    6.12 +	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.runtime.monetdb.UpdateOp.class);
    6.13 +	
    6.14  	/**
    6.15  	 * @param args
    6.16  	 * @throws Exception 
    6.17  	 */
    6.18 -	public static void main(String[] args) throws Exception {
    6.19 +	public static void main(String[] args) {
    6.20  
    6.21  		if (args.length < 6) {
    6.22  			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <UPDATE> ");
    6.23 @@ -27,10 +32,18 @@
    6.24  		String passwd = args[4];		
    6.25  		String queryString = args[5];
    6.26  		
    6.27 -		Strabon strabon = new Strabon(db, user, passwd, port, host, true);
    6.28 -
    6.29 -		strabon.update(queryString, strabon.getSailRepoConnection());
    6.30 -
    6.31 -		strabon.close();
    6.32 +		Strabon strabon = null;
    6.33 +		try {
    6.34 +			strabon = new Strabon(db, user, passwd, port, host, true);
    6.35 +			strabon.update(queryString, strabon.getSailRepoConnection());
    6.36 +			
    6.37 +		} catch (Exception e) {
    6.38 +			logger.error("[Strabon.UpdateOp] Error during execution of UPDATE query.", e);
    6.39 +			
    6.40 +		} finally {
    6.41 +			if (strabon != null) {
    6.42 +				strabon.close();
    6.43 +			}
    6.44 +		}
    6.45  	}
    6.46  }