I have a situation where I am on a server with a valid DataSource file (reproduced below) for connection to a local database which works fine. I also have a host of other machines with the exact same credentials except their ip addresses are different (which I also have). I would like to read in my localhost DataSource object and update the connection url with a different ipaddress. How do I do this? I’m using JBoss 4.2.3 for my deployment (which I cannot change).
Here is the method that I would like to create
/**
* This gets a DataSource for a specified IP address using pacsDS as a template.
* @param ipaddress
* @return
*/
public static DataSource getDataSource(Context context, String ipaddress) throws NamingException {
DataSource ds = (DataSource)context.lookup("java:/pacsDS");
// Update ds to make use of supplied ipaddress
// ...
return ds;
}
Here is the data source xml file
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===================================================================== -->
<!-- -->
<!-- JBoss Server Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- $Id: pacs-postgres-ds.xml 5174 2007-09-26 21:05:41Z gunterze $ -->
<!-- ==================================================================== -->
<!-- Datasource config for Postgres -->
<!-- ==================================================================== -->
<datasources>
<local-tx-datasource>
<jndi-name>pacsDS</jndi-name>
<connection-url>jdbc:postgresql://localhost/pacsdb</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>postgres</user-name>
<password></password>
<!-- sql to call when connection is created. Can be anything, select 1 is valid for PostgreSQL
<new-connection-sql>select 1</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool. Can be anything, select 1 is valid for PostgreSQL
<check-valid-connection-sql>select 1</check-valid-connection-sql>
-->
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>PostgreSQL 7.2</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
You can parameterize your JBoss config files.
See https://community.jboss.org/wiki/SystemPropertiesInConfigFiles?_sscc=t