Strabon

changeset 1548:e63d5e9b9f96

added an option to queryOp store results in file
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Fri May 11 16:57:40 2018 +0300 (2018-05-11)
parents 4c2fcc026c4c
children c9453adcdade
files runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryOp.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java
line diff
     1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryOp.java	Tue Mar 06 14:01:44 2018 +0200
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryOp.java	Fri May 11 16:57:40 2018 +0300
     1.3 @@ -11,6 +11,11 @@
     1.4  
     1.5  import eu.earthobservatory.utils.Format;
     1.6  
     1.7 +import java.io.File;
     1.8 +import java.io.FileNotFoundException;
     1.9 +import java.io.FileOutputStream;
    1.10 +import java.io.OutputStream;
    1.11 +
    1.12  import org.openrdf.query.MalformedQueryException;
    1.13  import org.openrdf.sail.generaldb.exceptions.UnsupportedExtensionFunctionException;
    1.14  import org.slf4j.Logger;
    1.15 @@ -36,6 +41,7 @@
    1.16  			System.err.println("             <QUERY>      is the stSPARQL query to evaluate.");
    1.17  			System.err.println("             <DELET_LOCK> is true when deletion of \"locked\" table should be enforced (e.g., when Strabon has been ungracefully shutdown).");
    1.18  			System.err.println("             [<FORMAT>]   is the format of your results (XML)");
    1.19 +			System.err.println("             [<OUTPUT FILE>]   is the path of the file to store the results (default: Sustem output) (should be preceeded by the format argument)");
    1.20  			System.exit(0);
    1.21  		}
    1.22  
    1.23 @@ -47,14 +53,23 @@
    1.24  		String queryString = args[5];
    1.25  		boolean forceDelete = Boolean.valueOf(args[6]);
    1.26  		String resultsFormat = "";
    1.27 +		OutputStream os = System.out;
    1.28  		if ( args.length == 8 ) {
    1.29  			resultsFormat = args[7];
    1.30 +		}else if (args.length == 9){
    1.31 +			resultsFormat = args[7];
    1.32 +			try {
    1.33 +				os = new FileOutputStream(new File(args[8]));
    1.34 +			} catch (FileNotFoundException e) {
    1.35 +				// TODO Auto-generated catch block
    1.36 +				e.printStackTrace();
    1.37 +			}
    1.38  		}
    1.39 -
    1.40  		Strabon strabon = null;
    1.41 +		
    1.42  		try {
    1.43  			strabon = new Strabon(db, user, passwd, port, host, forceDelete);
    1.44 -			strabon.query(queryString, Format.fromString(resultsFormat), strabon.getSailRepoConnection(), System.out);
    1.45 +			strabon.query(queryString, Format.fromString(resultsFormat), strabon.getSailRepoConnection(), os);
    1.46  			
    1.47  		} catch (UnsupportedExtensionFunctionException e) {
    1.48  			logger.error("[Strabon.QueryOp] {}", e.getMessage());
     2.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java	Tue Mar 06 14:01:44 2018 +0200
     2.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java	Fri May 11 16:57:40 2018 +0300
     2.3 @@ -9,6 +9,11 @@
     2.4   */
     2.5  package eu.earthobservatory.runtime.postgis;
     2.6  
     2.7 +import java.io.File;
     2.8 +import java.io.FileNotFoundException;
     2.9 +import java.io.FileOutputStream;
    2.10 +import java.io.OutputStream;
    2.11 +
    2.12  import org.openrdf.query.MalformedQueryException;
    2.13  import org.openrdf.sail.generaldb.exceptions.UnsupportedExtensionFunctionException;
    2.14  import org.openrdf.sail.rdbms.exceptions.UnsupportedRdbmsOperatorException;
    2.15 @@ -37,6 +42,7 @@
    2.16  			System.err.println("             <QUERY>      is the stSPARQL query to evaluate.");
    2.17  			System.err.println("             <DELET_LOCK> is true when deletion of \"locked\" table should be enforced (e.g., when Strabon has been ungracefully shutdown).");
    2.18  			System.err.println("             [<FORMAT>]   is the format of your results (default: XML)");
    2.19 +			System.err.println("             [<OUTPUT FILE>]   is the path of the file to store the results (default: Sustem output) (should be preceeded by the format argument)");
    2.20  			System.exit(0);
    2.21  		}
    2.22  
    2.23 @@ -48,14 +54,23 @@
    2.24  		String queryString = args[5];
    2.25  		boolean forceDelete = Boolean.valueOf(args[6]);
    2.26  		String resultsFormat = "";
    2.27 +		OutputStream os = System.out;
    2.28  		if ( args.length == 8 ) {
    2.29  			resultsFormat = args[7];
    2.30 +		}else if (args.length == 9){
    2.31 +			resultsFormat = args[7];
    2.32 +			try {
    2.33 +				os = new FileOutputStream(new File(args[8]));
    2.34 +			} catch (FileNotFoundException e) {
    2.35 +				// TODO Auto-generated catch block
    2.36 +				e.printStackTrace();
    2.37 +			}
    2.38  		}
    2.39  
    2.40  		Strabon strabon = null;
    2.41  		try {
    2.42  			strabon = new Strabon(db, user, passwd, port, host, forceDelete);
    2.43 -			strabon.query(queryString, Format.fromString(resultsFormat), strabon.getSailRepoConnection(), System.out);
    2.44 +			strabon.query(queryString, Format.fromString(resultsFormat), strabon.getSailRepoConnection(), os);
    2.45  			
    2.46  		} catch (UnsupportedExtensionFunctionException e) {
    2.47  			logger.error("[Strabon.QueryOp] {}", e.getMessage());