###
### set_ds_custom_properties.jacl
###
###
### tethys:dev:wsdev3
###
### Usage: 
###
### wsadmin.sh -username system \
###            -password password \
###            -f set_ds_custom_properties.jacl URL
###
###
###
### For example: 
###
### wsadmin.sh -username system \
###            -password password \
###            -f set_ds_custom_properties.jacl jdbc:oracle:thin:@hostname:1521:SID
###
###
###


proc ds_custom_properties {URL} {

#puts "URL: $URL"


###
### set up globals
###

global AdminConfig
global AdminControl
global AdminApp


set dsId [$AdminConfig getid "/DataSource:NAP_DATASOURCE/"]

set ps [$AdminConfig showAttribute $dsId propertySet]
set rps [lindex [$AdminConfig showAttribute $ps resourceProperties] 0]



### 
### Right now this program is only updating URL
### The following properties are available for modification 
### 
###     driverType
###     oraclelogPrintMask
###     oraclelogModuleMask
###     oraclelogCategoryMask
###     TNSEntryName
###     networkProtocol
###     databaseName
###     serverName
###     portNumber
###     dataSourceName
###     URL
###     loginTimeout
###     description
###     enableMultithreadedAccessDetection
###     transactionBranchesLooselyCoupled
###     preTestSQLString
###     user
###     password




foreach rp $rps {

   #puts $rp

   if {[regexp URL $rp] == 1} {
       puts " "
       puts "Setting URL to $URL"

       ### Note:  For some reason, using the $URL variable with AdminConfig
       ### Does not work.  Value gets set to "$URL" rather than the value of
       ### $URL.  Settings value explicitely is the workaround.
       #$AdminConfig modify $rp {{value $URL}}
       $AdminConfig modify $rp {{value jdbc:oracle:thin:@tethys:1521:dev}}
   }
}


$AdminConfig save

}



###
### Main
###


if { !($argc == 1) } {
   puts " "
   #puts "Usage: "
   #puts " "
   #puts "wsadmin.sh -username system -password password -f set_ds_custom_properties.jacl URL"
} else { 
   set URL [lindex $argv 0] 
   ds_custom_properties $URL
}