Strabon

changeset 250:a05e91b214cd

Fixed bug #2: StrabonEndpoint can now be configured with MonetDB as a database backend as well
author Babis Nikolaou <charnik@di.uoa.gr>
date Tue Jun 05 00:18:25 2012 +0300 (2012-06-05)
parents 0a24caace3a5
children bf7bfbae8c29
files endpoint/WebContent/WEB-INF/beans.xml endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.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/endpoint/WebContent/WEB-INF/beans.xml	Mon Jun 04 22:19:39 2012 +0300
     1.2 +++ b/endpoint/WebContent/WEB-INF/beans.xml	Tue Jun 05 00:18:25 2012 +0300
     1.3 @@ -47,6 +47,11 @@
     1.4              <value>true</value>
     1.5          </constructor-arg>
     1.6  
     1.7 +        <constructor-arg type="java.lang.String" >
     1.8 +            <!-- Database Backend (either "postgis" or "monetdb") -->
     1.9 +            <value>postgis</value>
    1.10 +        </constructor-arg>
    1.11 +        
    1.12           <constructor-arg>
    1.13               <list>
    1.14  	             <list>
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Mon Jun 04 22:19:39 2012 +0300
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Tue Jun 05 00:18:25 2012 +0300
     2.3 @@ -3,7 +3,6 @@
     2.4  import java.io.IOException;
     2.5  import java.io.StringReader;
     2.6  import java.net.URL;
     2.7 -import java.sql.SQLException;
     2.8  import java.util.ArrayList;
     2.9  import java.util.Iterator;
    2.10  import java.util.List;
    2.11 @@ -15,14 +14,19 @@
    2.12  import org.openrdf.repository.RepositoryException;
    2.13  import org.openrdf.repository.sail.SailRepositoryConnection;
    2.14  import org.openrdf.rio.RDFFormat;
    2.15 +
    2.16  import org.slf4j.Logger;
    2.17  import org.slf4j.LoggerFactory;
    2.18  
    2.19 -import eu.earthobservatory.runtime.postgis.Strabon;
    2.20 +import eu.earthobservatory.runtime.generaldb.Strabon;
    2.21  
    2.22  public class StrabonBeanWrapper implements org.springframework.beans.factory.DisposableBean {
    2.23 +	
    2.24  	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.org.StrabonEndpoint.StrabonBeanWrapper.class);
    2.25  	
    2.26 +	private static final String DBBACKEND_POSTGIS = "postgis";
    2.27 +	private static final String DBBACKEND_MONETDB = "monetdb";
    2.28 +	
    2.29  	private static final String FILE_PROTOCOL = "file";
    2.30  	
    2.31  	public class Entry {
    2.32 @@ -76,27 +80,22 @@
    2.33  	private String databaseName;
    2.34  	private String user;
    2.35  	private String password;
    2.36 -
    2.37 +	private String dbBackend;
    2.38 +	
    2.39  	private Strabon strabon = null;
    2.40 +	
    2.41  	private boolean checkForLockTable;
    2.42  	private List<Entry> entries;
    2.43  
    2.44 -	public StrabonBeanWrapper() {
    2.45 -		this.strabon = null;
    2.46 -	}
    2.47 -
    2.48 -	public StrabonBeanWrapper(Strabon strabon) {
    2.49 -		this.strabon = strabon;
    2.50 -	}
    2.51 -
    2.52  	public StrabonBeanWrapper(String databaseName, String user, String password, 
    2.53 -			int port, String serverName, boolean checkForLockTable, List<List<String>> args) {
    2.54 +			int port, String serverName, boolean checkForLockTable, String dbBackend, List<List<String>> args) {
    2.55  		this.serverName = serverName;
    2.56  		this.port = port;
    2.57  		this.databaseName = databaseName;
    2.58  		this.user = user;
    2.59  		this.password = password;
    2.60  		this.checkForLockTable = checkForLockTable;
    2.61 +		this.dbBackend = dbBackend;
    2.62  		this.entries = new ArrayList<StrabonBeanWrapper.Entry>(args.size());
    2.63  		
    2.64  		Iterator<List<String>> entryit = args.iterator();
    2.65 @@ -107,7 +106,7 @@
    2.66  			
    2.67  			while (it.hasNext()) {
    2.68  				int items = 0;
    2.69 -				String label = "", bean = "'", statement = "", format = ""; 
    2.70 +				String label = "", bean = "", statement = "", format = ""; 
    2.71  	
    2.72  				if (it.hasNext()) {
    2.73  					bean = it.next();
    2.74 @@ -139,12 +138,27 @@
    2.75  	private boolean init() {
    2.76  		if (this.strabon == null) {
    2.77  			try {
    2.78 -				logger.warn("Strabon not initialized yet.");
    2.79 -				logger.warn("Initializing strabon.");
    2.80 -				logger.info(this.getDetails());
    2.81 -				this.strabon = new Strabon(databaseName, user, password, port, serverName, checkForLockTable);
    2.82 +				logger.warn("[StrabonEndpoint] Strabon not initialized yet.");
    2.83 +				logger.warn("[StrabonEndpoint] Initializing Strabon.");
    2.84 +				logger.info("[StrabonEndpoint]\n" + this.getDetails());
    2.85 +				
    2.86 +				// initialize Strabon according to user preference
    2.87 +				if (DBBACKEND_MONETDB.equalsIgnoreCase(dbBackend)) {
    2.88 +					this.strabon = new eu.earthobservatory.runtime.monetdb.Strabon(databaseName, user, password, port, serverName, checkForLockTable);
    2.89 +					
    2.90 +				} else {
    2.91 +					// check whether the user typed wrong database backend and report
    2.92 +					if (!DBBACKEND_POSTGIS.equalsIgnoreCase(dbBackend)) {
    2.93 +						logger.warn("[StrabonEndpoint] Unknown database backend \""+dbBackend+"\". Assuming PostGIS.");
    2.94 +					}
    2.95 +					
    2.96 +					// use PostGIS as the default database backend
    2.97 +					this.strabon = new eu.earthobservatory.runtime.postgis.Strabon(databaseName, user, password, port, serverName, checkForLockTable);	
    2.98 +				}
    2.99 +				
   2.100 +				
   2.101  			} catch (Exception e) {
   2.102 -				logger.error("Exception occured while creating Strabon.\n"+this.getDetails(), e);
   2.103 +				logger.error("[StrabonEndpoint] Exception occured while creating Strabon.\n" + this.getDetails(), e);
   2.104  				return false;
   2.105  			}
   2.106  		}
   2.107 @@ -152,11 +166,6 @@
   2.108  		return true;
   2.109  	}
   2.110  
   2.111 -	public StrabonBeanWrapper(String databaseName, String user, String password, int port, String serverName) 
   2.112 -	throws SQLException, ClassNotFoundException {
   2.113 -		this.strabon = new Strabon(databaseName, user, password, port, serverName, true);
   2.114 -	}
   2.115 -
   2.116  	public Strabon getStrabon() {
   2.117  		return strabon;
   2.118  	}
     3.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/Strabon.java	Mon Jun 04 22:19:39 2012 +0300
     3.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/Strabon.java	Tue Jun 05 00:18:25 2012 +0300
     3.3 @@ -18,7 +18,6 @@
     3.4  		super(databaseName, user, password, port, serverName, checkForLockTable);
     3.5  	}
     3.6  
     3.7 -
     3.8  	protected void initiate(String databaseName, String user, String password, int port, String serverName) {
     3.9  		db_store = new MonetDBSqlStore();
    3.10  
    3.11 @@ -39,7 +38,8 @@
    3.12  	}
    3.13  
    3.14  
    3.15 -	protected void checkAndDeleteLock(String databaseName, String user, String password, int port, String serverName) throws SQLException, ClassNotFoundException {
    3.16 +	protected void checkAndDeleteLock(String databaseName, String user, String password, int port, String serverName)
    3.17 +	throws SQLException, ClassNotFoundException {
    3.18  		String url = "";
    3.19  		try {
    3.20  			logger.info("[Strabon] Cleaning...");
     4.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/Strabon.java	Mon Jun 04 22:19:39 2012 +0300
     4.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/Strabon.java	Tue Jun 05 00:18:25 2012 +0300
     4.3 @@ -12,7 +12,8 @@
     4.4  
     4.5  	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.runtime.postgis.Strabon.class);
     4.6  	
     4.7 -	public Strabon(String databaseName, String user, String password, int port, String serverName, boolean checkForLockTable) throws SQLException, ClassNotFoundException {
     4.8 +	public Strabon(String databaseName, String user, String password, int port, String serverName, boolean checkForLockTable) 
     4.9 +	throws SQLException, ClassNotFoundException {
    4.10  		super(databaseName, user, password, port, serverName, checkForLockTable);
    4.11  	}
    4.12