Hi,
recently there was a post re. custom configuration.
We had a similar problem, using JNDI for regular application configuration
and needing to pass custom datasource/schema parameters for local work and
unit tests.
Thought I'd share some code we use to do this with the rest of the world:
DataSource dataSource;
if (driverClassName != null && databaseUrl != null && user != null &&
password != null)
{
LogUtil.info(getClass(), "Using local data source: driver = $0,
database = $1, user =$2, password = $3",
new Object []
{ driverClassName, databaseUrl, user, password });
dataSource = new PoolManager(driverClassName, databaseUrl, 1, 5,
user, password);
}
else
{
dataSource = null;
}
if (schema != null)
{
LogUtil.info(getClass(), "Using local schema $0", new Object []
{ schema });
}
// Configuration.initializeSharedConfiguration(TestConfiguration.class);
Configuration config = Configuration.getSharedConfiguration();
DataDomain domain = config.getDomain();
for (Iterator itNodes = domain.getDataNodes().iterator();
itNodes.hasNext();)
{
DataNode node = (DataNode) itNodes.next();
if (dataSource != null)
{
node.setDataSource(dataSource);
}
Collection dataMaps = node.getDataMaps();
CustomEntitySorter customEntitySorter = new
CustomEntitySorter(dataMaps);
node.setEntitySorter(customEntitySorter);
if (schema != null)
{
for (Iterator itMaps = dataMaps.iterator(); itMaps.hasNext();)
{
DataMap dataMap = (DataMap) itMaps.next();
dataMap.setDefaultSchema(schema);
Map dbEntities = dataMap.getDbEntityMap();
for (Iterator itEntities =
dbEntities.values().iterator(); itEntities.hasNext();)
{
DbEntity entity = (DbEntity) itEntities.next();
entity.setSchema(schema);
}
}
}
}
Best,
-- Heiko Erhardt
This archive was generated by hypermail 2.0.0 : Fri Jan 27 2006 - 09:42:09 EST