@echo off
rem CopyRight(C) 2003，NTT All rights reserved
rem
rem 	XMS2データベースの作成処理
rem 		変更履歴
rem 			2004.01.08 新規作成 haga
rem 	次の処理を実行します
rem 	① XMS2表領域の作成
rem 	② XMS2ユーザの作成
rem		③ XMS2ユーザ用テーブルの作成
rem		④ XMS2ユーザ用テーブルへINDEXを作成
rem 	⑤ XMS2初期データの挿入
rem

set CmsDbUser=%USER_NAME%
set CmsDbPassword=%USER_PASSWORD%
set CmsNetServiceName=%NET_SERVICE_NAME%
set CmsXms2User=%XMS2_USER_NAME%
set CmsXms2UserPassword=%XMS2_USER_PASSWORD%
set CmsDir=%XMS2_DIR%
set SMTFInstFlag=%SMTF_INST_FLAG%
set PCTInstFlag=%PCT_INST_FLAG%
set OFLInstFlag=%OFL_INST_FLAG%
set UpdNew_Flg=%UPDNEWFLG%

sqlplus -s %CmsDbUser%/%CmsDbPassword%@%CmsNetServiceName% @%CmsDir%\Ora_CreateTablespace.sql
set CRE_TBS=%errorlevel%
if not %CRE_TBS% == 0  exit

if %UpdNew_Flg%==OFF (
	sqlplus -s %CmsDbUser%/%CmsDbPassword%@%CmsNetServiceName% @%CmsDir%\Ora_CreateUser.sql
) else (
	sqlplus -s %CmsDbUser%/%CmsDbPassword%@%CmsNetServiceName% @%CmsDir%\Ora_AlterUser.sql
)
set user_exist_check=%errorlevel%
if %user_exist_check% == 1918 (
	sqlplus -s %CmsDbUser%/%CmsDbPassword%@%CmsNetServiceName% @%CmsDir%\Ora_CreateUser.sql
)
set user_exist_check2=%errorlevel%
if %user_exist_check2% == 1920 (
	sqlplus -s %CmsDbUser%/%CmsDbPassword%@%CmsNetServiceName% @%CmsDir%\Ora_AlterUser.sql
	sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_DropTB.sql
)

if %UpdNew_Flg%==ON (
	sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_DropTB.sql
)

sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_CreateTB.sql
sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_CreateIDX.sql

sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_CreateView.sql


sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_InsertTB_GroupAndPeople.sql
sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_InsertTB_Groups.sql
sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_InsertTB_LO.sql
sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_InsertTB_LORelation.sql
sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_InsertTB_LOType.sql

IF %SMTFInstFlag%==OFF GOTO NEXT1
	sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_InsertTB_LOType_SMTF.sql
:NEXT1

IF %PCTInstFlag%==OFF GOTO NEXT2
	sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_InsertTB_LOType_PCT.sql
:NEXT2

IF %OFLInstFlag%==OFF GOTO NEXT3
	sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_InsertTB_LOType_OFL.sql
:NEXT3

sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_InsertTB_People.sql
sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_InsertTB_RoleAssignments.sql
sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_InsertTB_Roles.sql
sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_InsertTB_RolesFunction.sql
sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_InsertTB_XMOEntry.sql
sqlplus -s %CmsXms2User%/%CmsXms2UserPassword%@%CmsNetServiceName% @%CmsDir%\Ora_InsertTB_XmoRelation.sql
