Hiya,
Last evening I was trying to create a JDBC Data Source using WLST for one of my colleagues. After a lot of hit-n-trial I was able to do it, so thought I would share it here. May come handing sometime while writing scripts to automate domain creations. ;)
# This python program would create a DataSource named 'DS1' and targets it to (AdminServer and MS).
# Please change the code as per your environment and needs:
# Change the username and password with admin username and password.
#please change the localhost:7001 with he ip address:portnumber
print('Starting...')
connect('weblogic','weblogic','t3://localhost:7001')
print('Starting a edit session')
edit()
startEdit()
# Create a new Mbean ( a JDBC resource)
cd('/')
cmo.createJDBCSystemResource('DS1')
#Naming the datasource
cd('/JDBCSystemResources/DS1/JDBCResource/DS1')
cmo.setName('DS1')
#Setting JNDI name
cd('/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCDataSourceParams/DS1')
set('JNDINames',jarray.array([String('DS1')], String))
cd('/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCDriverParams/DS1')
cmo.setUrl('jdbc:pointbase:server://localhost:9092/demo')
cmo.setDriverName('com.pointbase.xa.xaDataSource')
cmo.setPassword('PBPUBLIC')
#Set Connection Pool specific parameters
# refer: e-docs.bea.com/wls/docs92/wlsmbeanref/mbeans/JDBCConnectionPoolParamsBean.html
cd('/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCConnectionPoolParams/DS1')
cmo.setTestConnectionsOnReserve(true)
cmo.setTestTableName('SYSTABLES')
cmo.setConnectionReserveTimeoutSeconds(25)
cmo.setMaxCapacity(20)
cmo.setConnectionReserveTimeoutSeconds(10)
cmo.setTestFrequencySeconds(360)
# Setting the user name
cd('/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCDriverParams/DS1/Properties/DS1')
cmo.createProperty('user')
cd('/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCDriverParams/DS1/Properties/DS1/Properties/user')
cmo.setValue('PBPUBLIC')
# Setting the database name
cd('/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCDriverParams/DS1/Properties/DS1')
cmo.createProperty('databaseName')
cd('/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCDriverParams/DS1/Properties/DS1/Properties/databaseName')
cmo.setValue('jdbc:pointbase:server://localhost:9092/demo')
# Transaction
cd('/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCDataSourceParams/DS1')
cmo.setGlobalTransactionsProtocol('TwoPhaseCommit')
cd('/JDBCSystemResources/DS1')
# targets the DS1 to Servers(AdminServer,MS)
set('Targets',jarray.array([ObjectName('com.bea:Name=AdminServer,Type=Server'), ObjectName('com.bea:Name=MS,Type=Server')], ObjectName))
activate()
print('Exiting...')
exit()
# Code written by:
# Unnikrishnan Pillai
Cheers:)
Unni