# Jython Script to create MINE web data-source and JDBC provider.
#
#Import Statements
import os
import re
import sys
# Create JDBC provider for MINE oracle database.
def createMINEJDBCProvider():
server = '/Server:server1'
# Set the Node ID
serverID = AdminConfig.getid(server)
print 'Server ID:' + serverID
#Configuring J2c auth
userAlias='test/MINEDBUser'
alias = ['alias', userAlias]
userid = ['userId', 'MINEDB']
password = ['password', 'MINEpass']
jaasAttrs = [alias, userid, password]
security = AdminConfig.getid('/Security:/')
print 'security:'+security
j2cUser=AdminConfig.create('JAASAuthData', security, jaasAttrs)
AdminConfig.save()
print 'Creating MINE User sucessfull'
# Test to see if the provider has already been created.
MINEJDBCprovider = AdminConfig.getid('/JDBCProvider:Oracle JDBC Driver/')
if len(MINEJDBCprovider) == 0:
providerName='Oracle JDBC Driver'
print 'creating Oracle JDBC provider on server:'+serverID
print 'JDBC provider Name:'+providerName
MINEJDBCprop1 = ['name', providerName]
MINEJDBCprop2 = ['description','Oracle JDBC Driver for MINE Application']
MINEJDBCprop3 = ['implementationClassName','oracle.jdbc.pool.OracleConnectionPoolDataSource']
MINEJDBCprop4 = ['classpath','${ORACLE_JDBC_DRIVER_PATH}/ojdbc6.jar']
MINEJDBCprops=[MINEJDBCprop1,MINEJDBCprop2,MINEJDBCprop3,MINEJDBCprop4]
providerID = AdminConfig.create('JDBCProvider', serverID, MINEJDBCprops)
AdminConfig.save()
print 'Creating Oracle JDBC provider on server sucessfull with provider:'+providerID
createMINEDataSource()
else:
print 'oracle provider exists:'+MINEJDBCprovider
def createMINEDataSource():
providerName='Oracle JDBC Driver'
userAlias='test/MINEDBUser'
MINEJDBCprovider = AdminConfig.getid('/JDBCProvider:Oracle JDBC Driver/')
MINEDataSource = AdminConfig.getid('/JDBCProvider:'+providerName+'/DataSource:MINEDB/')
if len(MINEDataSource) == 0:
# Set the datasource attributes
MINEDSprop1 = ['name', 'MINEDB']
MINEDSprop2 = ['jndiName', 'jdbc/MINEdb']
MINEDSprop3 = ['description', 'MINE database']
MINEDSprop4 = ['datasourceHelperClassname', 'com.ibm.websphere.rsadapter.Oracle11gDataStoreHelper']
MINEDSprop5 = ['authDataAlias' , userAlias]
mapConfigprop=["mappingConfigAlias", "DefaultPrincipalMapping"]
mapConfigs=[MINEDSprop5 , mapConfigprop]
mappingConfig=["mapping", mapConfigs]
MINEDSprops = [MINEDSprop1, MINEDSprop2, MINEDSprop3, MINEDSprop4, MINEDSprop5, mappingConfig]
MINEDataSource = AdminConfig.create('DataSource', MINEJDBCprovider, MINEDSprops)
#Set the DB URL
propSet = AdminConfig.create('J2EEResourcePropertySet', MINEDataSource, [])
AdminConfig.create('J2EEResourceProperty', propSet, [["name", "URL"], ["value", "jdbc:oracle:thin:@myserver:1523:MINED2"]])
AdminConfig.save()
print 'Creating MINE JDBC Datasource on server sucessfull with datasource:'+MINEDataSource
else:
print 'MINE Datasource already exists in the server:'+MINEDataSource
print 'Testing datasource connection'
print AdminControl.testConnection(MINEDataSource)
try:
print 'start'
createMINEJDBCProvider()
createMINEDataSource()
print 'end'
except:
print "***** Unexpected error while creating JDBC datasource:", sys.exc_info(), " *****"
raise