/**
* Determines the most reasonable default DataSource choice.
*/
protected DBConnectionInfo preferredDataSource() {
DataNodeDescriptor node = getPreferredNode();
// no current node...
if (node == null) {
return null;
}
// if node has local DS set, use it
DataNodeDefaults nodeDefaults = (DataNodeDefaults) getApplication()
.getCayenneProjectPreferences()
.getProjectDetailObject(
DataNodeDefaults.class,
getProjectController().getPreferenceForDataDomain().node(
"DataNode").node(node.getName()));
String key = (nodeDefaults != null) ? nodeDefaults.getLocalDataSource() : null;
if (key != null) {
DBConnectionInfo info = (DBConnectionInfo) getApplication()
.getCayenneProjectPreferences()
.getDetailObject(DBConnectionInfo.class)
.getObject(key);
if (info != null) {
return info;
}
}
// extract data from the node
if (!XMLPoolingDataSourceFactory.class.getName().equals(
node.getDataSourceFactoryType())) {
return null;
}
// create transient object..
DBConnectionInfo nodeInfo = new DBConnectionInfo();
nodeInfo.copyFrom(node.getDataSourceDescriptor());
nodeInfo.setDbAdapter(node.getAdapterType());
return nodeInfo;
}