<?xml version="1.0" encoding="windows-1252" ?>
<project default="NoRun">

  <path id="oracle.jdbc.path">
    <fileset dir="${jdeveloper.home}/jdbc/lib">
      <include name="*.jar"/>
    </fileset>
  </path>
  
  <property name="scriptHome" value="${srdemo.home}/DatabaseSchema/scripts"/>
  
  <target name="NoRun">
    <echo message=""/>
    <echo message="SRDemoSample Database Creation File"/>    
    <echo message="-----------------------------------"/>
    <echo message="Run the SRDemoSample database create using the"/>    
    <echo message="setupDB task in the main build.xml"/>        
    <echo message=""/>
  </target>
  
  <target name="all" depends="settings, dropSchema, createSchema, createSchemaObjects, createSeqTriggers, createContextPackage, insertData"/>

  <target name="resetData" depends="settings, dropSchemaObjects, createSchemaObjects, createSeqTriggers, insertData, purgeRecyclebin"/>
  
  <target name="settings" description="Prints out the connection info and accounts in use">
    <echo message=""/>
    <echo message="Setting up SRDemo database"/>
    <echo message="--------------------------"/>
    <echo message="The following settings will be used (from build.properties):"/>  
    <echo message=""/>
    <echo message="JDBC Driver Class: ${db.jdbc.driver}"/>
    <echo message="JDBC URL to target Database: ${db.jdbc.url}"/>
    <echo message=""/>
    <echo message=""/>    
    <echo message="DBA Account: ${db.adminAccount.user}"/>
    <echo message="DBA Password: **********"/>    
    <echo message=""/>  
    <echo message="SRDemo User Account: ${db.srdemo.user}"/>
    <echo message="SRDemo User Password: ${db.srdemo.password}"/>
    <echo message="Default Tablespace: ${db.srdemo.tablespace}"/>  
    <echo message="Temp Tablespace: ${db.srdemo.tempTablespace}"/>
    <echo message=""/>
    <echo message="Scripts read from: ${scriptHome}"/>    
    <echo message=""/>    
  </target>
  
  <target name="dropSchema" description="Drops (if existing) old version of the schema">
    <echo message="Dropping existing version of the schema"/>

    <sql driver="${db.jdbc.driver}"
         url="${db.jdbc.url}"
         userid="${db.adminAccount.user}"
         password="${db.adminAccount.password}"
         classpathref="oracle.jdbc.path"
         onerror="continue">

        DROP USER ${db.srdemo.user} CASCADE;

    </sql>     
  </target>

  <target name="createSchema" description="Creates the schema">
    <echo message="Creating SRDemo user ${db.srdemo.user}"/>
    <sql driver="${db.jdbc.driver}"
         url="${db.jdbc.url}"
         userid="${db.adminAccount.user}"
         password="${db.adminAccount.password}"
         classpathref="oracle.jdbc.path"
         onerror="abort">

        CREATE USER ${db.srdemo.user} IDENTIFIED BY ${db.srdemo.password} DEFAULT TABLESPACE ${db.srdemo.tablespace} TEMPORARY TABLESPACE ${db.srdemo.tempTablespace};
        
        GRANT CONNECT, RESOURCE, CREATE VIEW TO ${db.srdemo.user};
        
        ALTER USER ${db.srdemo.user} QUOTA UNLIMITED ON  ${db.srdemo.tablespace};
    </sql>     
  </target>
  
  <target name="createSchemaObjects"
          description="Creates the base tables and other objects">
    <echo message="Creating SRDemo tables and indexes"/>  
    <sql driver="${db.jdbc.driver}"
         url="${db.jdbc.url}"
         userid="${db.srdemo.user}"
         password="${db.srdemo.password}"
         classpathref="oracle.jdbc.path"         
         src="${scriptHome}/createSchemaObjects.sql"
         onerror="abort"/>      
  </target>
  
  <target name="createSeqTriggers" 
          description="Optional task to create table triggers for Sequence number generation">

    <echo message="Creating table triggers "/>

    <sql driver="${db.jdbc.driver}"
         url="${db.jdbc.url}"
         userid="${db.srdemo.user}"
         password="${db.srdemo.password}"
         classpathref="oracle.jdbc.path"
         onerror="abort"
         rdbms="oracle"
         delimiter="/"
         delimitertype="row"
         keepformat="yes"
         src="${scriptHome}/createSequenceTriggers.sql"/>       
  </target>

  <target name="createContextPackage" 
          description="Creates context package">

    <echo message="Creating context package"/>

    <sql driver="${db.jdbc.driver}"
         url="${db.jdbc.url}"
         userid="${db.srdemo.user}"
         password="${db.srdemo.password}"
         classpathref="oracle.jdbc.path"
         onerror="abort"
         rdbms="oracle"
         delimiter="/"
         delimitertype="row"
         keepformat="yes"
         src="${scriptHome}/createContextPackage.sql"/>       
    <sql driver="${db.jdbc.driver}"
         url="${db.jdbc.url}"
         userid="${db.srdemo.user}"
         password="${db.srdemo.password}"
         classpathref="oracle.jdbc.path"
         onerror="abort"
         rdbms="oracle"
         delimiter="/"
         delimitertype="row"
         keepformat="yes"
         src="${scriptHome}/createContextPackageBody.sql"/>       
  </target>
  
  <target name="insertData">
    <echo message="Populating demo tables with data"/>

    <sql driver="${db.jdbc.driver}"
         url="${db.jdbc.url}"
         userid="${db.srdemo.user}"
         password="${db.srdemo.password}"
         classpathref="oracle.jdbc.path"
         src="${scriptHome}/populateSchemaTables.sql"
         onerror="abort"/>
  </target>

  <target name="dropSchemaObjects">
    <echo message="Dropping schema objects"/>

    <sql driver="${db.jdbc.driver}"
         url="${db.jdbc.url}"
         userid="${db.srdemo.user}"
         password="${db.srdemo.password}"
         classpathref="oracle.jdbc.path"
         src="${scriptHome}/dropSchemaObjects.sql"
         onerror="continue"/>
  </target>  

  <target name="purgeRecyclebin">
    <echo message="Purging Oracle10g recyclebin"/>

    <sql driver="${db.jdbc.driver}"
         url="${db.jdbc.url}"
         userid="${db.srdemo.user}"
         password="${db.srdemo.password}"
         classpathref="oracle.jdbc.path"
         onerror="abort">
         PURGE RECYCLEBIN
    </sql>
  </target>  
  
  
</project>
