CreateNodeAction nodeBuilder = (CreateNodeAction) getApplication().getActionManager().getAction(
CreateNodeAction.class);
// this should make created node current, resulting in the new map being added
// to the node automatically once it is loaded
DataNodeDescriptor node = nodeBuilder.buildDataNode();
// configure node...
if ("JNDI".equalsIgnoreCase(adapter)) {
node.setDataSourceFactoryType(JNDIDataSourceFactory.class.getName());
node.setParameters((String) connection.get("serverUrl"));
}
else {
// guess adapter from plugin or driver
AdapterMapping adapterDefaults = getApplication().getAdapterMapping();
String cayenneAdapter = adapterDefaults.adapterForEOFPluginOrDriver(
(String) connection.get("plugin"),
(String) connection.get("driver"));
if (cayenneAdapter != null) {
try {
Class<DbAdapter> adapterClass = getApplication()
.getClassLoadingService()
.loadClass(DbAdapter.class, cayenneAdapter);
node.setAdapterType(adapterClass.toString());
}
catch (Throwable ex) {
// ignore...
}
}
node
.setDataSourceFactoryType(XMLPoolingDataSourceFactory.class
.getName());
DataSourceInfo dsi = node.getDataSourceDescriptor();
dsi.setDataSourceUrl(keyAsString(connection, "URL"));
dsi.setJdbcDriver(keyAsString(connection, "driver"));
dsi.setPassword(keyAsString(connection, "password"));
dsi.setUserName(keyAsString(connection, "username"));