txManager = new TransactionManager(config);
} catch (Exception e) {
if (e instanceof SqlMapException) {
throw (SqlMapException) e;
} else {
throw new SqlMapException(
"Error initializing TransactionManager. Could not instantiate TransactionConfig. Cause: "
+ e, e);
}
}
state.getConfig().setTransactionManager(txManager);
}
});
parser.addNodelet("/sqlMapConfig/transactionManager/dataSource/property", new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps());
String name = attributes.getProperty("name");
String value = NodeletUtils.parsePropertyTokens(attributes.getProperty("value"), state.getGlobalProps());
state.getDsProps().setProperty(name, value);
}
});
parser.addNodelet("/sqlMapConfig/transactionManager/dataSource/end()", new Nodelet() {
public void process(Node node) throws Exception {
state.getConfig().getErrorContext().setActivity("configuring the data source");
Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps());
String type = attributes.getProperty("type");
Properties props = state.getDsProps();
type = state.getConfig().getTypeHandlerFactory().resolveAlias(type);
try {
state.getConfig().getErrorContext().setMoreInfo("Check the data source type or class.");
DataSourceFactory dsFactory = (DataSourceFactory) Resources.instantiate(type);
state.getConfig().getErrorContext()
.setMoreInfo("Check the data source properties or configuration.");
dsFactory.initialize(props);
state.setDataSource(dsFactory.getDataSource());
state.getConfig().getErrorContext().setMoreInfo(null);
} catch (Exception e) {
if (e instanceof SqlMapException) {
throw (SqlMapException) e;
} else {
throw new SqlMapException(
"Error initializing DataSource. Could not instantiate DataSourceFactory. Cause: " + e,
e);
}
}
}