}
});
}
private void addTransactionManagerNodelets() {
parser.addNodelet("/sqlMapConfig/transactionManager/end()", new Nodelet() {
public void process(Node node) throws Exception {
vars.errorCtx.setActivity("configuring the transaction manager");
Properties attributes = NodeletUtils.parseAttributes(node, vars.properties);
String type = attributes.getProperty("type");
type = vars.typeHandlerFactory.resolveAlias(type);
TransactionManager txManager = null;
try {
vars.errorCtx.setMoreInfo("Check the transaction manager type or class.");
TransactionConfig config = (TransactionConfig) Resources.instantiate(type);
config.setDataSource(vars.dataSource);
config.setMaximumConcurrentTransactions(vars.client.getDelegate().getMaxTransactions());
vars.errorCtx.setMoreInfo("Check the transactio nmanager properties or configuration.");
config.initialize(vars.txProps);
vars.errorCtx.setMoreInfo(null);
txManager = new TransactionManager(config);
txManager.setForceCommit("true".equals(attributes.getProperty("commitRequired")));
} catch (Exception e) {
if (e instanceof SqlMapException) {
throw (SqlMapException) e;
} else {
throw new SqlMapException("Error initializing TransactionManager. Could not instantiate TransactionConfig. Cause: " + e, e);
}
}
vars.client.getDelegate().setTxManager(txManager);
}
});
parser.addNodelet("/sqlMapConfig/transactionManager/property", new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(node, vars.properties);
String name = attributes.getProperty("name");
String value = NodeletUtils.parsePropertyTokens(attributes.getProperty("value"), vars.properties);
vars.txProps.setProperty(name, value);
}
});
parser.addNodelet("/sqlMapConfig/transactionManager/dataSource", new Nodelet() {
public void process(Node node) throws Exception {
vars.dsProps = new Properties();
}
});
parser.addNodelet("/sqlMapConfig/transactionManager/dataSource/end()", new Nodelet() {
public void process(Node node) throws Exception {
vars.errorCtx.setActivity("configuring the data source");
Properties attributes = NodeletUtils.parseAttributes(node, vars.properties);
String type = attributes.getProperty("type");
type = vars.typeHandlerFactory.resolveAlias(type);
try {
vars.errorCtx.setMoreInfo("Check the data source type or class.");
DataSourceFactory dsFactory = (DataSourceFactory) Resources.instantiate(type);
vars.errorCtx.setMoreInfo("Check the data source properties or configuration.");
dsFactory.initialize(vars.dsProps);
vars.dataSource = dsFactory.getDataSource();
vars.errorCtx.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);
}
}
}
});
parser.addNodelet("/sqlMapConfig/transactionManager/dataSource/property", new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(node, vars.properties);
String name = attributes.getProperty("name");
String value = NodeletUtils.parsePropertyTokens(attributes.getProperty("value"), vars.properties);
vars.dsProps.setProperty(name, value);