Creating Datasource Providers
Probably the most common action most developers will do with any JEE container is to create and manage a Datasource. There are two steps that need to be accomplished in regards to connecting to databases. First you need to create the Datasource Provider, which mainly consists of telling the container where your JDBC Jar is located, and second you need to actually configure the datasource. I will split this example in to two posts. The first post will concentrate on the method we use to create the Provider and the second post will show you how we create the data source itself. For the examples below the helper methods/classes (You can place multiple “classes” within a single Jython file) are below.
#####################################################################################################
# Method that creates a JDBC DB2 Database Provider
# expects ${APP_PROJECTS_ROOT} WAS variable to exist.
# This provider IS NOT XA, if you need transactional support, you
# have to create an additional provider (or change XA to True)
#####################################################################################################
def createJDBCProviderDB2(self):
# You are logging, right?
log = Log(“DataSourceConfig.createJDBCProviderDB2”);
params = WASConfigParams();
params.add(“name”, WASConfigName.JDBC_PROVIDER_DB2_UNIVERSAL);
params.add(“description”, “DB2 Universal JDBC Driver-compliant Provider.”);
params.add(“providerType”, “DB2 Universal JDBC Driver Provider”);
params.add(“implementationClassName”, “com.ibm.db2.jcc.DB2ConnectionPoolDataSource”);
params.add(“xa”, “false”);
params.add(“classpath”, “${APP_PROJECTS_ROOT}/jdbc_drivers/db2jcc.jar;${APP_PROJECTS_ROOT}/jdbc_drivers/db2jcc_license_cu.jar”);
p = AdminConfig.create(WASConfigType.JDBC_PROVIDER, self.wasDef.getServerId(), params.asList());
# Again, make sure you are logging, Homer!
log.val(“Created DB2 JDBC Provider”, p);
#####################################################################################################
# Simple utility to compose parameter strings or lists used for sending to wsadmin object methods.
# They are usualy of the string form “[ -nameA valueA -nameB valueB ]”
# or of the list of lists form [[nameA,valueA],[nameB,valueB]].
#####################################################################################################
class WASConfigParams:
def __init__(self):
self.params = [];
#returns this object.
#specify quote=1 if u want to quote the param value.
def add(self, paramName, paramValue, quote=0):
if quote == 1:
paramValue = ‘”‘ + paramValue + ‘”‘;
self.params.append([paramName, paramValue]);
return self;
def asString(self):
paramStr = “”;
for p in self.params:
paramStr = paramStr + ” -” + str(p[0]) + ” ” + str(p[1]);
paramStr = “[” + paramStr + ” ]”;
return paramStr;
def asList(self):
return self.params;
#####################################################################################################
# Provides names of configuration items generally used.
# These names must be of a type identified in WASConfigType.
# These are for names for configurations already existing e.g Providers.
# For new configurations added by you – use the names you assigned.
#####################################################################################################
class WASConfigName:
JDBC_PROVIDER_DB2_UNIVERSAL = “DB2 Universal JDBC Driver Provider”;
JDBC_PROVIDER_DB2_UNIVERSAL_XA = “DB2 Universal JDBC Driver Provider (XA)”;
DATASOURCE_DB2_UNIVERSAL = “DB2 Universal JDBC Driver DataSource”;
DATASOURCE_DB2_UNIVERSAL_XA = “DB2 Universal JDBC Driver XA DataSource”;
JDBC_PROVIDER_AS400_XA = “DB2 UDB for iSeries (Toolbox XA)”;
DATASOURCE_AS400_XA = “DB2 UDB for iSeries (Toolbox XA) DataSource”;
One thought on “Scripting Websphere 6.1 configurations, Part 3”