Strabon

changeset 1467:8d66204196ba sqlite

sqlite changes. Replaced jdbc sqlite driver.
author Liza Sakellari <esakellari@di.uoa.gr>
date Fri Jan 23 16:46:51 2015 +0200 (2015-01-23)
parents 194886c8647e
children efaa42ce64b0
files runtime/pom.xml runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.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/sqlite/SpatialiteSample.java runtime/src/main/java/eu/earthobservatory/runtime/sqlite/StoreOp.java runtime/src/main/java/eu/earthobservatory/runtime/sqlite/Strabon.java sqlite/pom.xml sqlite/src/main/java/org/openrdf/sail/sqlite/SpatiaLiteSqlStore.java sqlite/src/main/java/org/openrdf/sail/sqlite/SqliteConnectionFactory.java
line diff
     1.1 --- a/runtime/pom.xml	Thu Jan 15 18:54:03 2015 +0200
     1.2 +++ b/runtime/pom.xml	Fri Jan 23 16:46:51 2015 +0200
     1.3 @@ -318,7 +318,7 @@
     1.4  <dependency>
     1.5  	<groupId>org.xerial</groupId>
     1.6  	<artifactId>sqlite-jdbc</artifactId>
     1.7 -	<version>3.7.2</version>
     1.8 +	<version>3.8.7</version>
     1.9  </dependency>
    1.10  
    1.11  		<dependency>
     2.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Thu Jan 15 18:54:03 2015 +0200
     2.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Fri Jan 23 16:46:51 2015 +0200
     2.3 @@ -229,9 +229,7 @@
     2.4  	public Object query(String queryString, Format resultsFormat, SailRepositoryConnection con, OutputStream out)
     2.5  	throws MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException {
     2.6  		boolean status = true;
     2.7 -		
     2.8 -		System.out.println(queryString);
     2.9 -		
    2.10 +						
    2.11  		logger.info("[Strabon.query] Executing query: {}", queryString);
    2.12  		
    2.13  		// check for null stream
    2.14 @@ -271,7 +269,7 @@
    2.15  				long t3 = System.nanoTime();
    2.16  	
    2.17  				return new long[]{t2-t1, t3-t2, t3-t1, results};
    2.18 -//				break;
    2.19 +				//break;
    2.20  				
    2.21  		default:
    2.22  			// get the writer for the specified format
    2.23 @@ -362,9 +360,7 @@
    2.24  				
    2.25  			} else {
    2.26  				
    2.27 -				File file = new File(src);
    2.28 -				System.out.println(file.getAbsolutePath());
    2.29 -				System.out.println(src);
    2.30 +				File file = new File(src);			
    2.31  				if (file.exists()) {
    2.32  					storeURL(new URL("file://" + src), baseURI, uriContext, realFormat);
    2.33  
     3.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java	Thu Jan 15 18:54:03 2015 +0200
     3.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java	Fri Jan 23 16:46:51 2015 +0200
     3.3 @@ -54,7 +54,7 @@
     3.4  		Strabon strabon = null;
     3.5  		try {
     3.6  			strabon = new Strabon(db, user, passwd, port, host, forceDelete);
     3.7 -			System.out.println(queryString);
     3.8 +	
     3.9  			strabon.query(queryString, Format.fromString(resultsFormat), strabon.getSailRepoConnection(), System.out);
    3.10  			
    3.11  		} catch (UnsupportedExtensionFunctionException e) {
     4.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/StoreOp.java	Thu Jan 15 18:54:03 2015 +0200
     4.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/StoreOp.java	Fri Jan 23 16:46:51 2015 +0200
     4.3 @@ -37,6 +37,7 @@
     4.4  		String graph = null;
     4.5  		Boolean inference = false;
     4.6  		
     4.7 +		
     4.8  		for (int i = 6; i < args.length; i += 2) {
     4.9  			if (args[i].equals("-f")) {
    4.10  				if (i + 1 >= args.length) {
    4.11 @@ -76,10 +77,10 @@
    4.12  		Strabon strabon = null;
    4.13  		try {
    4.14  			strabon = new Strabon(db, user, passwd, port, host, false);
    4.15 -			if (graph == null) {//System.out.println("graph = null");System.out.println(src);
    4.16 +			if (graph == null) {
    4.17  				strabon.storeInRepo(src, format, inference);
    4.18  				
    4.19 -			} else {System.out.println("graph!=null");
    4.20 +			} else {
    4.21  				strabon.storeInRepo(src, null, graph, format, inference);
    4.22  			}
    4.23  			
     5.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/sqlite/SpatialiteSample.java	Thu Jan 15 18:54:03 2015 +0200
     5.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/sqlite/SpatialiteSample.java	Fri Jan 23 16:46:51 2015 +0200
     5.3 @@ -30,8 +30,8 @@
     5.4        stmt.setQueryTimeout(30); // set timeout to 30 sec.
     5.5  
     5.6        // loading SpatiaLite
     5.7 -      stmt.execute("SELECT load_extension('/usr/local/lib/libspatialite.so')");
     5.8 -      stmt.execute("SELECT load_extension('/usr/lib/sqlite3/pcre.so')");
     5.9 +      stmt.execute("SELECT load_extension('/usr/lib/x86_64-linux-gnu/libspatialite.so')");
    5.10 +      stmt.execute("SELECT load_extension(' /usr/lib/x86_64-linux-gnu/libpcre.so')");
    5.11        // enabling Spatial Metadata
    5.12        // using v.2.4.0 this automatically initializes SPATIAL_REF_SYS and GEOMETRY_COLUMNS
    5.13        String sql = "SELECT InitSpatialMetadata()";
     6.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/sqlite/StoreOp.java	Thu Jan 15 18:54:03 2015 +0200
     6.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/sqlite/StoreOp.java	Fri Jan 23 16:46:51 2015 +0200
     6.3 @@ -73,7 +73,12 @@
     6.4  	}
     6.5  
     6.6  	private static void help() {
     6.7 -		System.err.println("Usage: eu.earthobservatory.runtime.postgis.StoreOp <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <FILE> [-f <FORMAT>] [-g <NAMED_GRAPH>]");	
     6.8 +		System.err.println("Usage: eu.earthobservatory.runtime.sqlite.StoreOp "
     6.9 +				+ "<DATABASE_FILE> "
    6.10 +				+ "<SPATIALITE_LIB_PATH> "
    6.11 +				+ "<PCRE_PATH> "
    6.12 +				+ "<FILE> "
    6.13 +				+ " [-f <FORMAT>]");	
    6.14  		System.err.println("             <DATABASE>   		 is the spatially enabled postgis database that Strabon will use as a backend, ");
    6.15  		System.err.println("             [-f <FORMAT>] 		 is the format of the file (default: NTRIPLES)");
    6.16  		System.err.println("             [-g <NAMED_GRAPH>]  is the URI of the named graph to store the input file (default: default graph)");
     7.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/sqlite/Strabon.java	Thu Jan 15 18:54:03 2015 +0200
     7.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/sqlite/Strabon.java	Fri Jan 23 16:46:51 2015 +0200
     7.3 @@ -36,7 +36,8 @@
     7.4  public class Strabon extends eu.earthobservatory.runtime.generaldb.Strabon {
     7.5  	
     7.6  	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.runtime.postgis.Strabon.class);
     7.7 -	
     7.8 +	private String spatiaLiteLib;
     7.9 +	private String pcreLib;
    7.10  	public Strabon(String databaseName, String spatialite, String regex, boolean checkForLockTable) 
    7.11  	throws Exception {
    7.12  		super(databaseName, spatialite, regex, 0, "", checkForLockTable);
    7.13 @@ -50,6 +51,8 @@
    7.14  
    7.15  	private void createSpatialAndDeleteTemp(String databaseName, String libspatial, String regex) throws SQLException, ClassNotFoundException {
    7.16  		String url = "";
    7.17 +		this.spatiaLiteLib=libspatial;
    7.18 +		this.pcreLib=regex;
    7.19  		try {
    7.20  			logger.info("[Strabon] Cleaning...");
    7.21  			Class.forName("org.sqlite.JDBC");
    7.22 @@ -61,6 +64,7 @@
    7.23  		Statement st=c.createStatement();
    7.24  		//st.execute("SELECT load_extension('/usr/local/lib/libspatialite.so')");
    7.25  		//st.execute("SELECT load_extension('/usr/lib/sqlite3/pcre.so')");
    7.26 +		System.out.println(libspatial);
    7.27  		st.execute("SELECT load_extension('"+libspatial+"')");
    7.28  		try{
    7.29  		st.execute("SELECT load_extension('"+regex+"')");
    7.30 @@ -210,6 +214,8 @@
    7.31  		SpatiaLiteSqlStore spatialLite_store = (SpatiaLiteSqlStore) db_store;
    7.32  		
    7.33  		spatialLite_store.setDatabaseName(databaseName);
    7.34 +		spatialLite_store.setSpatiaLiteLib(spatiaLiteLib);
    7.35 +		spatialLite_store.setPcreLib(pcreLib);
    7.36  		spatialLite_store.setMaxNumberOfTripleTables(2048);
    7.37  		init();
    7.38  		logger.info("[Strabon] Initialization completed.");
     8.1 --- a/sqlite/pom.xml	Thu Jan 15 18:54:03 2015 +0200
     8.2 +++ b/sqlite/pom.xml	Fri Jan 23 16:46:51 2015 +0200
     8.3 @@ -74,7 +74,7 @@
     8.4  		<dependency>
     8.5  			<groupId>org.xerial</groupId>
     8.6  			<artifactId>sqlite-jdbc</artifactId>
     8.7 -			<version>3.7.2</version>
     8.8 +			<version>3.8.7</version>
     8.9  		</dependency>
    8.10  		
    8.11   		<dependency>
     9.1 --- a/sqlite/src/main/java/org/openrdf/sail/sqlite/SpatiaLiteSqlStore.java	Thu Jan 15 18:54:03 2015 +0200
     9.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/SpatiaLiteSqlStore.java	Fri Jan 23 16:46:51 2015 +0200
     9.3 @@ -16,6 +16,8 @@
     9.4  public class SpatiaLiteSqlStore extends org.openrdf.sail.generaldb.GeneralDBStore{
     9.5  
     9.6  	protected String databaseName;
     9.7 +	protected String spatiaLiteLib;
     9.8 +	protected String pcreLib;
     9.9  
    9.10  	@Override
    9.11  	protected GeneralDBConnectionFactory newFactory(DatabaseMetaData metaData)
    9.12 @@ -47,6 +49,8 @@
    9.13          }
    9.14      		
    9.15  		SqliteConnectionFactory factory = new SqliteConnectionFactory();
    9.16 +		factory.setPcre(pcreLib);
    9.17 +		factory.setSpatiaLite(spatiaLiteLib);
    9.18  		factory.setSail(this);
    9.19  		factory.setDataSource(ds);
    9.20  		setBasicDataSource(ds);
    9.21 @@ -60,5 +64,12 @@
    9.22  	public void setDatabaseName(String databaseName2) {
    9.23  		this.databaseName = databaseName2;		
    9.24  	}
    9.25 +	public void setSpatiaLiteLib(String spatiaLiteLib) {
    9.26 +		this.spatiaLiteLib = spatiaLiteLib;
    9.27 +	}
    9.28 +
    9.29 +	public void setPcreLib(String pcreLib) {
    9.30 +		this.pcreLib = pcreLib;
    9.31 +	}
    9.32  
    9.33  }
    10.1 --- a/sqlite/src/main/java/org/openrdf/sail/sqlite/SqliteConnectionFactory.java	Thu Jan 15 18:54:03 2015 +0200
    10.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/SqliteConnectionFactory.java	Fri Jan 23 16:46:51 2015 +0200
    10.3 @@ -45,6 +45,8 @@
    10.4  import org.openrdf.sail.generaldb.schema.IntegerIdSequence;
    10.5  import org.openrdf.sail.generaldb.schema.LongIdSequence;
    10.6  import org.openrdf.sail.generaldb.schema.ValueTableFactory;
    10.7 +import org.slf4j.Logger;
    10.8 +import org.slf4j.LoggerFactory;
    10.9  
   10.10  /**
   10.11   * Responsible to initialise and wire all components together that will be
   10.12 @@ -53,7 +55,9 @@
   10.13   * @author James Leigh
   10.14   */
   10.15  public class SqliteConnectionFactory extends GeneralDBConnectionFactory {
   10.16 -	
   10.17 +	private String spatiaLite;
   10.18 +	private String pcre;
   10.19 +	private static Logger logger = LoggerFactory.getLogger(org.openrdf.sail.sqlite.SqliteConnectionFactory.class);
   10.20  	protected Connection singleSQLiteCon;
   10.21  //	protected SqliteTripleTableManager sqliteTripleTableManager;
   10.22  
   10.23 @@ -163,9 +167,12 @@
   10.24  		      stmt.setQueryTimeout(30); // set timeout to 30 sec.
   10.25  
   10.26  		      // loading SpatiaLite
   10.27 -		      stmt.execute("SELECT load_extension('/usr/local/lib/libspatialite.so')");
   10.28 -		      stmt.execute("SELECT load_extension('/usr/lib/sqlite3/pcre.so')");
   10.29 -		      
   10.30 +		      stmt.execute("SELECT load_extension('" +this.spatiaLite+"')");
   10.31 +		      try{
   10.32 +		      stmt.execute("SELECT load_extension('" +this.pcre+"')");
   10.33 +		      }catch(Exception e){
   10.34 +					logger.warn("Error loading regex library. Regular expressions will not be supported.");
   10.35 +					}
   10.36  
   10.37  			return conn;
   10.38  //			return new net.sf.log4jdbc.ConnectionSpy(conn);
   10.39 @@ -313,4 +320,11 @@
   10.40  			}
   10.41  		}
   10.42  	}
   10.43 +	public void setSpatiaLite(String spatiaLite) {
   10.44 +		this.spatiaLite = spatiaLite;
   10.45 +	}
   10.46 +
   10.47 +	public void setPcre(String pcre) {
   10.48 +		this.pcre = pcre;
   10.49 +	}
   10.50  }