#!/usr/bin/ksh
#
# NAME:  processCommittedLevelsForRelease database release
# WHERE: database = DB2|db2 or INFORMIX|informix or ORACLE|oracle
#        release  = the desired CMVC release
#
# An example of the usage is:
#   processCommittedLevelsForRelease db2 track-full-1.3
#
# PURPOSE:
#   For a given release, the committed levels are sorted by
#   the time stamp in which each one was committed. Then, for
#   each level, the following script is invoked in order to
#   populate the new CommittedVersions table:
#
#      createCommittedVersions database release level log
#
# 5765-207 (C) COPYRIGHT International Business Machines Corp. 1993,2001
# 5765-202 (C) COPYRIGHT International Business Machines Corp. 1993,2001
# 5765-397 (C) COPYRIGHT International Business Machines Corp. 1994,2001
# All Rights Reserved
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADF Schedule Contract with IBM Corp.
#----------------------------------------------------------------------+


#------------------------------------------------------+
#  Main program
#------------------------------------------------------+

if [ "$#" -ne 2 ]
then
  print "Usage: processCommittedLevelsForRelease database release"
  print "where: database = DB2|db2 or INFORMIX|informix or ORACLE|oracle"
  print "       release  = the desired CMVC release "
  exit 1
fi

# Parsing and validation of input parameters

typeset -u DATABASE=$1
releaseName=$2

if [ -z "$CMVC_FAMILY" ]
then
  echo "The CMVC family must be set with the CMVC_FAMILY environment variable."
  exit 1
else
  FAMILY=`echo $CMVC_FAMILY | cut -d"@" -f1`
fi

# Validating the database type

case "$DATABASE" in

  DB2|db2)
  DATABASE=DB2
  ;;

  INFORMIX|informix)
  DATABASE=INFORMIX
  ;;

  ORACLE|oracle)
  DATABASE=ORACLE
  ;;

 *)
  print "Unrecognized database $DATABASE"
  exit 1
  ;;

esac

print "processCommittedLevelsForRelease: begin "
print ""
print "The family name is:      $FAMILY"
print "The database is:         $DATABASE"
print "The release name is:     $releaseName"

rc=0  # assume that everything is fine.

print "Report -raw -view  LevelView  -where ""releaseName in ('$releaseName') and state in ('complete') order by addDate"" "
Report -raw -view  LevelView  -where "releaseName in ('$releaseName') and state in ('complete') order by addDate"  > /tmp/cv$$

while read line
do
   levelName=`echo $line | cut -d'|' -f1 `  # The levelName is field 1
   print ""
   print "Invoking: createCommittedVersions $DATABASE $releaseName $levelName log-$releaseName-$levelName"
   createCommittedVersions $DATABASE $releaseName $levelName log-$releaseName-$levelName

done < /tmp/cv$$

print "processCommittedLevelsForRelease: end! "

exit 0

# end of file
