Index by: file name |
procedure name |
procedure call |
annotation
installDataSource_proc.tcl
(annotations | original source)
#
# Install Datasource Proc.
#
####################################################################
# Patrick Finnegan 11/01/2005. V1.
####################################################################
proc installDataSource { propertiesFile } {
global AdminConfig
set procName [ lindex [ info level 0 ] 0 ]
putsLog "## proc - $procName"
foreach i [ info args $procName ] {
upvar 0 $i ilocal
set propertiesArray($i) $ilocal
}
putsLog "procedure arguments are................."
foreach { a b } [ array get propertiesArray ] {
putsLog [ format "%-35s %s" "$a" "$b" ]
}
putsLog "JDBC Driver properties are: ............"
if { [ catch { hashMapList $propertiesFile } r ] == 0 } {
set propertiesList $r
foreach a $propertiesList {
putsLog [ format "%-5s %-20s %-s" " " [ lindex $a 0 ] [ lindex $a 1 ] ]
}
} else {
return -code error $r
}
# call the hashMap proc which returns a Property object populated with property file values.
if { [ catch { hashMap $propertiesFile } r ] == 0 } {
set PropertyI $r
} else {
return -code error $r
}
# leading/trailing spaces cause problems. Use trim.
set serverName [ string trim [ $PropertyI getProperty datasource.serverName ] ]
set dbDescription [ string trim [ $PropertyI getProperty datasource.dbDescription ] ]
set portNumber [ string trim [ $PropertyI getProperty datasource.portNumber ] ]
set driverType [ string trim [ $PropertyI getProperty datasource.driverType ] ]
set databaseName [ string trim [ $PropertyI getProperty datasource.databaseName ] ]
set dataSourceName [ string trim [ $PropertyI getProperty datasource.dataSourceName ] ]
set authDataAlias [ string trim [ $PropertyI getProperty datasource.authDataAlias ] ]
set jndiName [ string trim [ $PropertyI getProperty datasource.jndiName ] ]
set dbDriver [ string trim [ $PropertyI getProperty datasource.dbDriver ] ]
set dataSources [ $AdminConfig list DataSource ]
putsLog "Installed datasources are................"
showList $dataSources
# get attribute name of each dataSource and add to a list.
foreach i $dataSources { lappend nameList [ $AdminConfig showAttribute $i name ] }
catch { lsearch $nameList $dataSourceName } r
if { $r == -1 } {
set continue true
} else {
putsLog "datasource $dataSourceName already exists"
if { [ catch { deleteDataSource $dataSourceName } r ] == 0 } {
putsLog "datasource $dataSourceName deleted successfully"
} else {
return -code error $r
}
}
if { [ catch { setDataSourceProperties $authDataAlias $dbDescription $dataSourceName $jndiName } r ] == 0 } {
set dataSourceAttributes $r
} else {
return -code error $r
}
# install the datasource under the database driver id with general properties.
if { [ catch { $AdminConfig getid /JDBCProvider:$dbDriver/ } r ] == 0 } {
if { $r == {} } {
putsLog "ERROR: JDBCProvider $dbDriver not found"
return -code error
} else {
putsLog "db driver is $r"
set jdbcDriverId $r
}
} else {
return -code error $r
}
# get the template id for the datasource.
set template [ string trim [ $PropertyI getProperty datasource.template ] ]
if { [ catch { $AdminConfig listTemplates DataSource $template } r ] == 0 } {
if { $r == {} } {
putsLog "ERROR: $template template does not exist"
putsLog " Checking existing templates using \"$AdminConfig listTemplates DataSource\" from the command line"
return -code error
} else {
set templateId $r
}
}
puts "$dataSourceAttributes"
if { [ catch { $AdminConfig createUsingTemplate DataSource $jdbcDriverId $dataSourceAttributes $templateId } r ] == 0 } {
putsLog "datasource $dataSourceName created successfully"
} else {
putsLog "ERROR: failed to create $dataSourceName"
return -code error $r
}
# get the id of the newly created datasource
if { [ catch { $AdminConfig getid /DataSource:$dataSourceName/ } r ] == 0 } {
putsLog "dataSource id is $r"
set dataSourceId $r
} else {
return -code error $r
}
# marshall the local properties in list format.
set localProperties [ setCustomProps $databaseName $portNumber $dbDescription $serverName $portNumber ]
# get the propertyset id for the DataSource. This will have been created by the template.
if { [ catch { $AdminConfig showAttribute $dataSourceId propertySet } r ] == 0 } {
putsLog "propertySet is $r"
set propertySetId $r
} else {
putsLog "ERROR: cannot find existing propertyset for datasource created by template"
return -code error $r
}
# modify the custom properties of the datasouce which were inserted by the template.
## marshall the properties for the property set.
## setCustomProps returns a list.
set customPropsList [ lindex [ lindex [ $AdminConfig showall $propertySetId ] 0 ] 1 ]
foreach i $customPropsList {
# the description element of the custom property is not quoted properly by wsadmin.
# comes back as {description "The type of the driver. The possible values are: thin, oci8."}
# should come back as {description {The type of the driver. The possible values are: thin, oci8.}}
# wsadmin throws an error when the a new property is added
# properly quote the description field and replace each description in the $i list.
set description [ list [ lindex [ lindex $i 0 ] 0 ] [ lindex [ lindex $i 0 ] 1 ] ]
#puts "description is $description"
set g [ lreplace $i 0 0 $description ]
# loop through the properties we intend to change and replace the default values with the new values.
set patternMatch "*[ lindex [ lindex $g 1 ] 1 ]*"
#puts "pattern match = $patternMatch"
foreach e $localProperties {
#puts "local property is $e "
if { [ string match $patternMatch [ join $e ] ] == 1 } {
lappend newCustomPropsList $e
set matchTrue "true"
#puts "****** match ************"
break
} else {
set matchTrue "false"
}
}
if { $matchTrue != "true" } {
lappend newCustomPropsList $g
}
unset matchTrue
}
set newCustomPropsList [ list $newCustomPropsList ]
# remove the existing propertySet.
if { [ catch { $AdminConfig remove $propertySetId } r ] == 0 } {
putsLog "propertySet deleted: $propertySetId "
} else {
putsLog "ERROR: could not delete property set: $propertySetId"
return -code error $r
}
# create a new property set
#set propertySetId [ $AdminConfig create J2EEResourcePropertySet $dataSourceId {} ]
if { [ catch { $AdminConfig create J2EEResourcePropertySet $dataSourceId {} } r ] == 0 } {
set newPropertySetId $r
putsLog "propertySet created : $r"
} else {
putsLog "ERROR: could not create property set"
return -code error $r
}
#populate the new property set
foreach e [ lindex $newCustomPropsList 0 ] {
# puts "### new property is $e"
if { [ catch { $AdminConfig create J2EEResourceProperty $newPropertySetId $e } r ] == 0 } {
putsLog "created property set element: $e"
} else {
putsLog "ERROR: failed to create property set element: $e"
return -code error $r
}
}
}
####################################################################
# Set general properties for DataSource.
####################################################################
proc setDataSourceProperties { authDataAlias dbDescription dataSourceName jndiName } {
global alias
set procName [ lindex [ info level 0 ] 0 ]
putsLog "## proc - $procName"
foreach i [ info args $procName ] {
upvar 0 $i ilocal
set propertiesArray($i) $ilocal
}
putsLog "procedure arguments are................."
foreach { a b } [ array get propertiesArray ] {
putsLog [ format "%-35s %s" "$a" "$b" ]
}
set statementCacheSize [ list statementCacheSize 100 ]
set datasourceHelperClassname [ list datasourceHelperClassname "com.ibm.websphere.rsadapter.OracleDataStoreHelper" ]
set relationalResourceAdapter [ list relationalResourceAdapter "WebSphere Relational Resource Adapter" ]
set authDataAlias [ list authDataAlias $authDataAlias ]
set name [ list name $dataSourceName ]
set jndiName [ list jndiName $jndiName ]
set description [ list description $dbDescription]
# set connection pool attributes.
set agedTimeout [ list agedTimeout 0 ]
set connectionTimeout [ list connectionTimeout 1800 ]
set maxConnections [ list maxConnections 20 ]
set minConnections [ list minConnections 1 ]
set purgePolicy [ list purgePolicy "FailingConnectionOnly"]
set reapTime [ list reapTime 180 ]
set unusedTimeout [ list unusedTimeout 1800 ]
set connectionPoolList [list $agedTimeout \
$connectionTimeout \
$maxConnections \
$minConnections \
$purgePolicy \
$reapTime \
$unusedTimeout ]
set attributesList [ list $statementCacheSize \
$name \
$authDataAlias \
$jndiName \
$datasourceHelperClassname \
$description \
[ list connectionPool $connectionPoolList ] ]
return $attributesList
}
####################################################################
# Set custom properties.
####################################################################
proc setCustomProps {databaseName portNumber dbDescription serverName portNumber } {
set procName [ lindex [ info level 0 ] 0 ]
putsLog "## proc - $procName"
foreach i [ info args $procName ] {
upvar 0 $i ilocal
set propertiesArray($i) $ilocal
}
putsLog "procedure arguments are................."
foreach { a b } [ array get propertiesArray ] {
putsLog [ format "%-35s %s" "$a" "$b" ]
}
# set the URL attributes.
append url jdbc:oracle:thin
append url :
append url "@"
append url $serverName
append url :
append url $portNumber
append url :
append url $databaseName
putsLog "connection URL is: $url"
set name [ list name URL ]
set required [ list required true ]
set type [ list type "java.lang.String" ]
set value [ list value $url ]
set custom1 [ list $name $required $type $value ]
#set name [ list name databaseName ]
#set required [ list required true ]
#set type [ list type "java.lang.String" ]
#set value [ list value $dataSourceName ]
#set custom2 [ list $name $required $type $value ]
set name [ list name enableSQLJ ]
set required [ list required false ]
set type [ list type java.lang.Boolean ]
set value [ list value false ]
set custom3 [ list $name $required $type $value ]
set name [ list name description ]
set required [ list required false ]
set type [ list type java.lang.String ]
set value [ list value $dbDescription ]
set custom4 [ list $name $required $type $value ]
set name [ list name portNumber ]
set required [ list required false ]
set type [ list type java.lang.Integer ]
set value [ list value $portNumber ]
set custom5 [ list $name $required $type $value ]
set name [ list name connectionAttribute ]
set required [ list required false ]
set type [ list type java.lang.String ]
set value [ list value cursorhold=0 ]
set custom6 [ list $name $required $type $value ]
set name [ list name loginTimeout ]
set required [ list required false ]
set type [ list type java.lang.Integer ]
set value [ list value 0 ]
set custom7 [ list $name $required $type $value ]
set name [ list name enableMultithreadedAccessDetection]
set required [ list required false ]
set type [ list type java.lang.Boolean ]
set value [ list value false ]
set custom8 [ list $name $required $type $value ]
set name [ list name preTestSQLString ]
set required [ list required false ]
set type [ list type java.lang.String ]
set value [ list value " " ]
set custom9 [ list $name $required $type $value ]
#set customPropsList [ list $custom1 $custom2 $custom3 $custom4 $custom5 $custom6 $custom7 $custom8 $custom9 ]
set customPropsList [ list $custom1 $custom3 $custom4 $custom5 $custom6 $custom7 $custom8 $custom9 ]
return $customPropsList
}
Index by: file name |
procedure name |
procedure call |
annotation
File generated 2007-08-07 at 13:42.