### ### ex9.jacl ### ### ### Create JDBCProvider, DataSource, and CMPConnectorFactory objects. ### ### Example invocation: ### ### wsadmin -f ex9.jacl ### nodename ### "DB2 JDBC Provider (XA)" ### $SQLLIB/java/db2java.jar ### datasource ### connectionfactory ### DBName ### ### Parameters: ### ### Node name ### Template name for JDBCProvider ### Fully-qualified path to the driver ### JDBC provider name ### Datasource name ### CMP Connection factory name ### Database name ### proc ex9 {nodeName templateName driverPath jdbcname dsname cfname dbname } { ### ### set up globals ### global AdminConfig set CONT_ALIAS "hostManager/DB2Alias" set DEFAULT_PRINCIPAL_MAPPING DefaultPrincipalMapping ### ### Get the config id for a JDBC Template ### ### Use "lindex" in case there is more than one matching templates ### we just get the first one. ### puts "Getting the JDBCProvider template whose name is $templateName" set template [lindex [$AdminConfig listTemplates JDBCProvider $templateName] 0] if {[llength $template] == 0} { puts "Could not find a JDBCProvider template using $templateName" return } ### ### Get the config id for the node ### puts "Getting the confid id for node $nodeName" set node [$AdminConfig getid /Node:$nodeName/] if {[llength $node] == 0} { puts "Could not find node $nodeName" return } ### ### Create a new JDBCProvider using template ### puts "Create a new JDBCProvider object named $jdbcname" set classpath_attr [list classpath $driverPath] set name_attr [list name $jdbcname] set attrs [list $name_attr $classpath_attr] set new1 [$AdminConfig createUsingTemplate JDBCProvider $node $attrs $template] ### ### For this example, we do not need the WAS40DataSource object, but ### we do want to modify the DataSource object. ### Note that the template for this JDBCProvider does not give ### names to the WAS40DataSource and DataSource objects associated with ### it. We can use "getid" to retrieve ids for objects that do not have ### names as shown below. ### puts "Remove the WAS40DataSource object created via the template" set was40ds [$AdminConfig getid /JDBCProvider:$jdbcname/WAS40DataSource:/] $AdminConfig remove $was40ds ### ### Modify the DataSource - give it a name and a jndiName, and remove ### existing properties created by the template ### A collection of objects (such as the resourceProperties attribute of the ### propertySet attribute) can only be added to. To completely replace ### the collection we need to delete the old one first. ### puts "Modify the datasource object -- name, jndiName; remove old properties." set ds [$AdminConfig getid /JDBCProvider:$jdbcname/DataSource:/] set name_attr [list name $dsname] set jndiName_attr [list jndiName jdbc/$dsname] set ps_attr [list propertySet {}] set attrs [list $name_attr $jndiName_attr $ps_attr] $AdminConfig modify $ds $attrs ### ### Add desired properties to the DataSource. ### puts "Modify the datasource object -- name, jndiName, properties." set dbname_attr [list [list name databaseName] [list value $dbname] [list type java.lang.String] [list description "This is a required property"]] set desc_attr [list [list name description] [list value ""] [list type java.lang.String]] set password_attr [list [list name password] [list value ""] [list type java.lang.String]] set connattr_attr [list [list name connectionAttribute] [list value 0] [list type java.lang.String]] set loginTO_attr [list [list name loginTimeout] [list value 0] [list type java.lang.Integer]] set newprops [list $dbname_attr $desc_attr $password_attr $connattr_attr $loginTO_attr] set resprops [list resourceProperties $newprops] set ps_attr [list propertySet [list $resprops]] set attrs [list $ps_attr] $AdminConfig modify $ds $attrs ### ### Modify the DataSource to give it a relational resource adapter. ### We use the built-in rra on the node. ### puts "Modify the datasource object -- relationalResourceAdapter" set rra [$AdminConfig getid "/Node:$nodeName/J2CResourceAdapter:WebSphere Relational Resource Adapter/"] set rra_attr [list relationalResourceAdapter $rra] set attrs [list $rra_attr] $AdminConfig modify $ds $attrs ### ### Create a CMPConnectorFactory, using the datasource from earlier ### puts "Create a new CMPConnectorFactory object named $cfname" set name_attr [list name $cfname] set authmech_attr [list authMechanismPreference BASIC_PASSWORD] set cmpds_attr [list cmpDatasource $ds] set p_trans_res [list [list name TransactionResourceRegistration] [list type java.lang.String] [list value dynamic] [list description "Type of transaction resource registration (enlistment). Valid values are either static (immediate) or dynamic (deferred)."]] set newprops [list $p_trans_res] set resprops [list resourceProperties $newprops] set ps_attr [list propertySet [list $resprops]] set map_auth_attr [list authDataAlias $CONT_ALIAS] set map_configalias_attr [list mappingConfigAlias $DEFAULT_PRINCIPAL_MAPPING] set map_attrs [list $map_auth_attr $map_configalias_attr] set mapping_attr [list mapping $map_attrs] set attrs [list $name_attr $authmech_attr $cmpds_attr $ps_attr $mapping_attr] set newcf [$AdminConfig create CMPConnectorFactory $rra $attrs] ### ### Save all the changes ### puts "Saving the configuration" $AdminConfig save } ### ### Main ### if { !($argc == 7) } { puts "This script requires 6 parameters: " puts " 1) the name of the node under which to create resources," puts " 2) the name of a JDBCProvider template to use," puts " 3) the fully-qualified path to the DB driver," puts " 4) the name of the JDBCProvider to create," puts " 5) the name of the datasource to create," puts " 6) the name of the CMPConnectionFactory to create," puts " 7) and the name of the database to use." puts "" puts "e.g.: ex9 nodename \"DB2 JDBC Provider (XA)\" $SQLLIB/java/db2java.jar datasource connectionfactory DBName" } else { set nodeName [lindex $argv 0] set templateName [lindex $argv 1] set driverPath [lindex $argv 2] set jdbcname [lindex $argv 3] set dsname [lindex $argv 4] set cfname [lindex $argv 5] set dbname [lindex $argv 6] ex9 $nodeName $templateName $driverPath $jdbcname $dsname $cfname $dbname }