Strabon

changeset 219:aa01c5a89aa6

initial and incomplete version of strabon script, the command-line frontend of Strabon main classes, such as QueryOp.
author Babis Nikolaou <charnik@di.uoa.gr>
date Thu May 31 21:56:48 2012 +0300 (2012-05-31)
parents 56e02a58c9f2
children 92abbe36feab
files scripts/strabon
line diff
     1.1 --- a/scripts/strabon	Thu May 31 21:14:12 2012 +0300
     1.2 +++ b/scripts/strabon	Thu May 31 21:56:48 2012 +0300
     1.3 @@ -1,28 +1,170 @@
     1.4 -#! /bin/bash
     1.5 +#!/bin/bash
     1.6 +#
     1.7 +# Script for running the main classes of Strabon. The main classes of Strabon comprises
     1.8 +# QueryOp, StoreOp, etc.
     1.9 +#
    1.10 +# Author: Charalampos (Babis) Nikolaou <charnik@di.uoa.gr>
    1.11 +#
    1.12  
    1.13 -dbName=$1
    1.14 -dirs=$2
    1.15 +# absolute directory name of this command
    1.16 +LOC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
    1.17  
    1.18 -# Evaluates a query using Strabon that is stored in $dir
    1.19 -#dir='/home/ggarbis/workspaces/Strabon-workspace/Strabon/jars/target'
    1.20 -dir='/home/kkyzir/teleios/nkua/Strabon/jars/target'
    1.21 +RUNTIME="`readlink -f ${LOC}/../runtime`"
    1.22  
    1.23 -# Arguments for QueryDir
    1.24 -HOST='localhost'
    1.25 -PORT='50000'
    1.26 -DATABASE=$dbName
    1.27 -USERNAME='monetdb'
    1.28 -PASSWORD='monetdb'
    1.29 -FORMAT=''
    1.30 -DIRS=$2
    1.31 -EXT=$3
    1.32 +function help() {
    1.33 +	echo "Usage: `basename ${0}` [OPTIONS] COMMAND ARGS"
    1.34 +	echo
    1.35 +	echo "Interface to execute the main classes of Strabon, such as QueryOp, StoreOp, UpdateOp, etc."
    1.36 +	echo
    1.37 +	echo "	COMMAND	 : one of \`query', \`update', \`store', or \`help'"
    1.38 +	echo "	ARGS	 : arguments according to selected command"
    1.39 +	echo 
    1.40 +#	echo "OPTIONS can be any of the following"
    1.41 +#	echo "	-d	 : don't run, just print what shall be executed"
    1.42 +}
    1.43  
    1.44 -# Construct classpath with dependencies
    1.45 -cd $dir &&
    1.46 -for file in `ls -1 *.jar`;
    1.47 -do 
    1.48 -	myVar=$myVar./$file":";
    1.49 -done;
    1.50 +# runtime package
    1.51 +PKG="eu.earthobservatory.runtime"
    1.52  
    1.53 -# Evaluate a query
    1.54 -java -Xmx5000M -cp $myVar eu.earthobservatory.runtime.monetdb.QueryDir $HOST $PORT $DATABASE $USERNAME $PASSWORD "$DIRS" "$EXT" $FORMAT
    1.55 +# the underlying database to use (one of postgis or monetdb)
    1.56 +DATABASE="postgis"
    1.57 +
    1.58 +# the main class to run
    1.59 +CLASS="QueryOp"
    1.60 +
    1.61 +# the hostname at which the database runs
    1.62 +HOST="localhost"
    1.63 +
    1.64 +# the port at which the database listens
    1.65 +PORT=5432
    1.66 +
    1.67 +# the database name to connect to
    1.68 +DB="endpoint"
    1.69 +
    1.70 +# the username for the database connection
    1.71 +DBUSER="charnik"
    1.72 +
    1.73 +# the password for the database connection
    1.74 +DBPASS="charnik"
    1.75 +
    1.76 +# the query to run
    1.77 +QUERY="select (count(*) as ?c) where {?s ?p ?o}"
    1.78 +
    1.79 +# debug option for log4j configuration:
    1.80 +#-Dlog4j.debug
    1.81 +#-Dlog4j.configuration=\"${RUNTIME}/log4j.properties\"
    1.82 +
    1.83 +CMD="(cd ${RUNTIME} && java -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${QUERY}\")"
    1.84 +
    1.85 +eval $CMD
    1.86 +exit 1
    1.87 +
    1.88 +case "${1}" in
    1.89 +#	-d)
    1.90 +#		shift
    1.91 +#		DEBUG=1
    1.92 +#		;;
    1.93 +#esac
    1.94 +
    1.95 +case "${1}" in
    1.96 +	help)
    1.97 +		shift
    1.98 +		if test $# -eq 1; then
    1.99 +			case "${1}" in
   1.100 +				query)
   1.101 +					help_query
   1.102 +					;;
   1.103 +				update)
   1.104 +					help_update
   1.105 +					;;
   1.106 +				store)
   1.107 +					help_store
   1.108 +					;;
   1.109 +				*)
   1.110 +					help
   1.111 +					;;
   1.112 +			esac
   1.113 +			exit 1
   1.114 +		fi
   1.115 +		help
   1.116 +		exit 0
   1.117 +		;;
   1.118 +	query)
   1.119 +		shift
   1.120 +		if ! test $# -eq 2; then
   1.121 +			help_query
   1.122 +			exit 1
   1.123 +		fi
   1.124 +		URL="${1}/Query"
   1.125 +		QUERY="${2}"
   1.126 +
   1.127 +		# predefined queries
   1.128 +		case "${QUERY}" in
   1.129 +			size)
   1.130 +				QUERY="SELECT (count(*) as ?c) WHERE {?s ?p ?o}"
   1.131 +				;;
   1.132 +		esac
   1.133 +
   1.134 +		# TODO: make it an argument
   1.135 +		FORMAT="XML"
   1.136 +
   1.137 +		CMD="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode SPARQLQuery='${QUERY}' ${URL}"
   1.138 +		;;
   1.139 +	update)
   1.140 +		shift
   1.141 +		if ! test $# -eq 2; then
   1.142 +			help_update
   1.143 +			exit 1
   1.144 +		fi
   1.145 +		URL="${1}/Update"
   1.146 +		QUERY="${2}"
   1.147 +		
   1.148 +		# predefined queries
   1.149 +		case "${QUERY}" in
   1.150 +			clear)
   1.151 +				QUERY="DELETE {?s ?p ?o} WHERE {?s ?p ?o}"
   1.152 +				;;
   1.153 +		esac
   1.154 +
   1.155 +		CMD="curl ${CURL_OPTS} --data-urlencode SPARQLQuery='${QUERY}' ${URL}"
   1.156 +		;;
   1.157 +	store)
   1.158 +		shift
   1.159 +		if ! test $# -eq 4; then
   1.160 +			help_store
   1.161 +			exit 1
   1.162 +		fi
   1.163 +		URL="${1}/Store"
   1.164 +		FORMAT="${2}"
   1.165 +		case "${3}" in
   1.166 +			-t)
   1.167 +				TRIPLES="${4}"
   1.168 +				CMD="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode data='${TRIPLES}' ${URL}"
   1.169 +				;;
   1.170 +			-u)
   1.171 +				URL_TRIPLES="${4}"
   1.172 +				CMD="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode url='${URL_TRIPLES}' -d fromurl='' ${URL}"
   1.173 +				;;
   1.174 +			 *)
   1.175 +				help_store
   1.176 +				exit 1
   1.177 +				;;
   1.178 +		esac
   1.179 +		;;
   1.180 +	*) 
   1.181 +		help
   1.182 +		echo
   1.183 +		echo "ERROR: Unknown command \"${1}\"."
   1.184 +		exit 1
   1.185 +		;;
   1.186 +esac
   1.187 +
   1.188 +# execute or debug
   1.189 +if test $DEBUG -eq 1; then
   1.190 +	echo "`basename ${0}`: Debug is ON"
   1.191 +	echo "`basename ${0}`: Printing command for execution"	
   1.192 +	echo "	$CMD"
   1.193 +else
   1.194 +	eval ${CMD}
   1.195 +fi
   1.196 +