/*
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!															!!
!!	 oracle-jutils for Oracle 11g (JSDK 1.5 required same as Oracle one)                                 !!
!!															!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/

/*
This script is the install script for oracle-jutils project, to provide a very easy to use PL/SQL
API on various domains, like BLOBS, mail, .., on Oracle 11g (i will use the JDK15), as i'll strongly rely
on Java native and third parties libraries.
For more details/questions, or event just to say "Thank you ;-p", you can contact me
at Adrien.Sales@gmail.com, or by visiting the sourceforge site.


   Copyright (C) 2009  <Adrien Sales>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/*++++++++++++++++++++++++++++++++++++++++++++++++++
	Install the XMPP schema with minimal rights
+++++++++++++++++++++++++++++++++++++++++++++++++++*/
sqlplus /nolog
conn / as sysdba

PROMPT Creating dedicated tablespace to store jars
CREATE TABLESPACE TS_OJUTILS
DATAFILE 'C:\app\didi\oradata\DIDI\TS_OJUTILS.dbf' size 50M;

PROMPT Creating OJUTILS/OJUTILS schema
drop user OJUTILS cascade;
create user OJUTILS identified by OJUTILS
default tablespace TS_OJUTILS
temporary tablespace TEMP
quota unlimited on TS_OJUTILS;

PROMPT Performing grants to OJUTILS
grant connect, create session, resource, create public synonym, create view to OJUTILS;
exec dbms_java.grant_permission( 'OJUTILS','SYS:java.lang.RuntimePermission', 'getClassLoader', '' );
commit;

PROMPT Create and grant rights on OJUTIL working directory
exec dbms_java.grant_permission('OJUTILS', 'java.io.FilePermission','D:\myopensource\oracle-jutils\*','write, read, delete');
-- Add recursive privileges
exec dbms_java.grant_permission( 'OJUTILS', 'SYS:java.io.FilePermission', 'D:\myopensource\oracle-jutils\-', 'read' );
commit;


create role R_OJUTILS;

call dbms_java.grant_permission('OJUTILS', 'java.net.SocketPermission', '*', 'accept, connect,listen, resolve');
call dbms_java.grant_permission('OJUTILS', 'java.net.NetPermission', '*', 'accept, connect,listen, resolve');
call dbms_java.grant_permission('OJUTILS', 'SYS:java.lang.RuntimePermission', 'getClassLoader', '' );
-- Replace $ORACLE_HOME with the right value
call dbms_java.grant_permission( 'OJUTILS','SYS:java.io.FilePermission', '$ORACLE_HOME/javavm/lib/security/cacerts', 'read' );
--call dbms_java.grant_permission( 'OJUTILS','SYS:java.io.FilePermission', 'C:\app\didi\product\11.1.0\db_1\javavm\lib\security\cacerts', 'read' );
commit;

exit


/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	Load jars in the OJUTILS schema
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

cd $OJUTILS_HOME
loadjava -v -u OJUTILS/OJUTILS -resolve lib/jmxtools.jar
loadjava -v -u OJUTILS/OJUTILS -resolve lib/log4j-1.2.16.jar
loadjava -v -u OJUTILS/OJUTILS -resolve lib/logkit.jar
loadjava -v -u OJUTILS/OJUTILS -resolve lib/avalon-logkit-2.1.jar
loadjava -v -u OJUTILS/OJUTILS -resolve lib/avalon-framework.jar
loadjava -v -u OJUTILS/OJUTILS -resolve lib/javax.servlet.jar
loadjava -v -u OJUTILS/OJUTILS -resolve lib/commons-logging-1.1.1.jar
loadjava -v -u OJUTILS/OJUTILS -resolve lib/jakarta-oro-2.0.8.jar
loadjava -v -u OJUTILS/OJUTILS -resolve lib/jmimemagic-0.1.0.jar

loadjava -v -u OJUTILS/OJUTILS -resolve lib/CartridgeServices.jar
loadjava -v -u OJUTILS/OJUTILS -resolve lib/ODCI.jar

loadjava -v -u OJUTILS/OJUTILS -resolve lib/smack.jar
loadjava -v -u OJUTILS/OJUTILS -resolve lib/smackx.jar

loadjava -v -u OJUTILS/OJUTILS -resolve lib/jacksum.jar

loadjava -v -u OJUTILS/OJUTILS -resolve lib/commons-codec-1.4.jar
loadjava -v -u OJUTILS/OJUTILS -resolve lib/commons-compress-1.0.jar


loadjava -v -u OJUTILS/OJUTILS -resolve dist/oracle-jutils.jar

cd doc
cd files

sqlplus OJUTILS/OJUTILS @install.sql
