#!/bin/sh
#
# creating batch for beginners
#

# ********* Optional step javaExe : specifies the location of your JRE. Note that if java is installed in your machine, you can access to jre simply with JAVA
javaExe=java

# ********* Optional step buildPath : specifies the location of the CASTDBExtractor and CASTDBDeliveryTool. 
# - With this example, location of extractor and delivery is the actual batch's path => this variable becomes useless
buildPath=.

# ********* Step 1 url : specifies the target Oracle server for connection purposes
# url form : jdbc:oracle:thin:@SERVERNAME:PORT:SERVICENAME
# SERVERNAME: replace with the name or IP address of the server hosting your Oracle server
# PORT: specify the port number on which your Oracle instance is running. By default this is 1521 but this may have been changed in your environment
# SERVICENAME: replace with the name of your Oracle instance
#
# url=jdbc:oracle:thin:@SERVERNAME:PORT:SERVICENAME
url=jdbc:oracle:thin:@teamsgbd03:1521:O102

# ********* Step 2 user and password : 
# dbuser	: tells the Extraction tool what username to use to access the Oracle server
# dbpassword 	: tells the Extraction tool what password to use to access the Oracle server (corresponds to the username specified above)
dbuser=SQUIRREL_ACCEPTANCE
dbpassword=cast

# ********* Step 3 platform : specifies the version of the Oracle server you want to deliver
# MUST BE ONE OF THE FOLLOWING : Oracle11g - Oracle10g - Oracle9i - Oracle8
platform=Oracle10g
case $platform in
	Oracle11g);;
	Oracle10g);;
	Oracle9i);;
	Oracle8);;
	*) echo $0 : Bad platform name. It MUST BE ONE OF THE FOLLOWING : Oracle11g - Oracle10g - Oracle9i - Oracle8.; exit;;
esac

# ********* Step 4 out_dir : specifies the folder you would like the Extractor to output the results to (the resulting file will be a .zip file)
# - In this example, out_dir : "Results" is a folder in the same dir of actual batch. 
out_dir=./Results
if ! test -d $out_dir
then
	mkdir $out_dir
fi
# ********* Step 5 container : specifies the schema you would like to extract
# - If you intend to extract an entire instance and all schemas, #ove this entire parameter from the batch file.
# - If you intend to extract multiple schemas you can list them separated with a comma (",")
# - extFile : This will be a .zip file,  containing results of extraction
# - logFile : an output file for logging purposes. You can name the file anything you like. (only for extractor)
container=SQUIRREL_PMT
extFile=$out_dir/$container
logFile=$out_dir/output_$container.log

# ********* Optional step timing :display information about resources
timing=time
# Run extractor : generate zip files
$timing "$javaExe" -jar $buildPath/CASTDBExtractor.jar -url $url -user $dbuser -password $dbpassword -platform $platform -parameters schema=$container -target $extFile -l $logFile
err=$?
# no error at the extractor step
if [ $err -eq 0 ]
then
	# Run injector : generate uax files
	$timing "$javaExe" -Xmx512M -jar $buildPath/CASTDBDeliveryTool.jar -source $extFile  -target $extFile -relativepaths
	err=$?
	# error at the injector step
	if [ $err -ne 0 ]
	then
		echo "$0 : An error occurs at the Injector step."
	fi
else
	echo "$0 : An error occurs at the Extractor step : see log ($logFile) for more informations"
fi
exit $err

