Search code examples
javapythonwebspherejythonwsadmin

Jython - JDBC DS settings


I want to update to true an existing property called "SendStringParametersAsUnicode" in custom properties on my datasource.

2- I want to set maximum connections to 50 within connection pools in data source

dsid = AdminTask.createDatasource('provider_id, '[-name [Team Server Datasource] -jndiName jdbc/ilogDataSource -dataStoreHelperClassName com.ibm.websphere.rsadapter.DB2DataStoreHelper -componentManagedAuthenticationAlias RES_db2conn -containerManagedPersistence true -xaRecoveryAuthAlias RES_db2conn -configureResourceProperties [[databaseName java.lang.String ' + str(databaseName) + '] [driverType java.lang.Integer ' + str(driverType) + '] [serverName java.lang.String ' + str(serverName) + '] [portNumber java.lang.Integer ' + portNumber + ']]]')

AdminConfig.create('MappingModule', dsid , '[[authDataAlias RES_db2conn [mappingConfigAlias ""]]')

AdminConfig.save()

print "Configuration changes saved."

import time
time.sleep(10) # Delay for 10 seconds.

AdminControl.testConnection(dsid)

Anyone knows the jython code for that?

Last update :

#provider_id=AdminConfig.getid('/Cell:E1DSCell/JDBCProvider:DB2 XA provider/')

#jdbcProvider1 = AdminConfig.getid('/JDBCProvider:myJdbcProvider/')
provider_id = AdminConfig.getid('/JDBCProvider:Microsoft SQL Server JDBC Driver/')

# dataStoreHelperClassName com.ibm.websphere.rsadapter.MicrosoftSQLServerDataStoreHelper
# componentManagedAuthenticationAlias TEMP-HRZEMM01Node01/PlatformDataSource 
# 
print "Creating DataSource"

dsid = AdminTask.createDatasource(provider_id, '[-name [Team Server Datasource] -jndiName jdbc/ilogDataSource -dataStoreHelperClassName com.ibm.websphere.rsadapter.MicrosoftSQLServerDataStoreHelper -componentManagedAuthenticationAlias TEMP-HRZEMM01Node01/PlatformDataSource -containerManagedPersistence true -xaRecoveryAuthAlias TEMP-HRZEMM01Node01/PlatformDataSource -configureResourceProperties [[databaseName java.lang.String Compass] [portNumber java.lang.Integer 1433] [serverName java.lang.String SQLSVR1]]]')

AdminConfig.create('MappingModule', dsid , '[[authDataAlias TEMP-HRZEMM01Node01/PlatformDataSource] [mappingConfigAlias ""]]')

ds_name = 'Team Server Datasource' #Name copied from your question, update if required
provider_id = AdminConfig.getid('/JDBCProvider:Microsoft SQL Server JDBC Driver/')

#Get the list of datasources
dsList = AdminConfig.list('DataSource', provider_id).splitlines()

for ds in dsList:
    if (ds_name == AdminConfig.showAttribute(ds, "name")):
        #Modify Connection Pool
        AdminConfig.modify(AdminConfig.showAttribute(ds, 'connectionPool'), '[[maxConnections "50"]]')
        #Modify SendStringParametersAsUnicode property if it exists
        propSet = AdminConfig.list("J2EEResourcePropertySet", ds)
        for prop in AdminConfig.list("J2EEResourceProperty", propSet).splitlines():
            if (AdminConfig.showAttribute(prop, "name") == 'SendStringParametersAsUnicode'):
                AdminConfig.modify(prop, [["value", "true"]])

AdminConfig.save()

print "Configuration changes saved."

import time
time.sleep(10) # Delay for 10 seconds.

#ds = AdminConfig.getid('/DataSource:SQA MOTOR/')
#print ds #variable displaying

AdminControl.testConnection(dsid)

Solution

  • Try running the below snippet using wsadmin - jython interface:

    ds_name = 'Team Server Datasource' #Name copied from your question, update if required
    provider_id = #Use the same provider id used for creating the datasource (provider_id used in dsid = AdminTask.createDatasource('provider_id, '[-name [Team Server Datasource] ...)
    
    #Get the list of datasources
    dsList = AdminConfig.list('DataSource', provider_id).splitlines()
    
    for ds in dsList:
        if (ds_name == AdminConfig.showAttribute(ds, "name")):
            #Modify Connection Pool
            AdminConfig.modify(AdminConfig.showAttribute(ds, 'connectionPool'), '[[maxConnections "50"]]')
            #Modify SendStringParametersAsUnicode property if it exists
            propSet = AdminConfig.list("J2EEResourcePropertySet", ds)
            for prop in AdminConfig.list("J2EEResourceProperty", propSet).splitlines():
                if (AdminConfig.showAttribute(prop, "name") == 'SendStringParametersAsUnicode'):
                    AdminConfig.modify(prop, [["value", "true"]])
    
    AdminConfig.save()