}
NSDictionary jdbcInfoDictionary = null;
if (jdbcInfo != null && jdbcInfo.length() > 0 && jdbcInfo.charAt(0) == '^') {
String modelName = jdbcInfo.substring(1, jdbcInfo.length());
EOModel modelForCopy = model.modelGroup().modelNamed(modelName);
if (modelForCopy != null && modelForCopy != model) {
jdbcInfoDictionary = (NSDictionary) modelForCopy.connectionDictionary().objectForKey("jdbc2Info");
}
else {
log.warn("Unable to find model named \"" + modelName + "\"");
jdbcInfo = null;
}
}
String plugin = getProperty(aModelName + ".DBPlugin", "dbConnectPluginGLOBAL");
// build the URL if we have a Postgresql plugin
if ("Postgresql".equals(plugin) && ERXStringUtilities.stringIsNullOrEmpty(url) && !ERXStringUtilities.stringIsNullOrEmpty(serverName) && !ERXStringUtilities.stringIsNullOrEmpty(h)) {
url = "jdbc:postgresql://" + h + "/" + serverName;
}
NSDictionary connectionDictionary = model.connectionDictionary();
if (connectionDictionary == null) {
connectionDictionary = new NSMutableDictionary();
model.setConnectionDictionary(connectionDictionary);
}
NSMutableDictionary newConnectionDictionary = new NSMutableDictionary(connectionDictionary);
if (adaptor != null) {
model.setAdaptorName(adaptor);
}
if (url != null)
newConnectionDictionary.setObjectForKey(url, "URL");
if (userName != null)
newConnectionDictionary.setObjectForKey(userName, "username");
if (passwd != null)
newConnectionDictionary.setObjectForKey(passwd, "password");
if (driver != null)
newConnectionDictionary.setObjectForKey(driver, "driver");
if (jdbcInfoDictionary != null) {
newConnectionDictionary.setObjectForKey(jdbcInfoDictionary, "jdbc2Info");
}
else if (jdbcInfo != null) {
NSDictionary d = (NSDictionary) NSPropertyListSerialization.propertyListFromString(jdbcInfo);
if (d != null)
newConnectionDictionary.setObjectForKey(d, "jdbc2Info");
else
newConnectionDictionary.removeObjectForKey("jdbc2Info");
}
if (plugin != null) {
newConnectionDictionary.setObjectForKey(plugin, "plugin");
}
// set the information for ERXJDBCConnectionBroker
newConnectionDictionary.addEntriesFromDictionary(poolingDictionary);
if (newConnectionDictionary.count() == 0) {
ERXModelGroup.log.warn("The EOModel '" + model.name() + "' has an empty connection dictionary.");
}
String removeJdbc2Info = getProperty(aModelName + ".removeJdbc2Info", "dbRemoveJdbc2InfoGLOBAL", "true");
if (ERXValueUtilities.booleanValue(removeJdbc2Info)) {
newConnectionDictionary.removeObjectForKey("jdbc2Info");
}
// We want to clean up our connection dictionaries so all our models match. When EOF
// compares connection dictionaries, undefined plugin is not the same as plugin = ""
// even though it semantically is the same. So we are normalizing our connection
// dictionaries here by removing blank keys that we know about.
String pluginCheck = (String)newConnectionDictionary.objectForKey("plugin");
if (pluginCheck != null && pluginCheck.length() == 0){
newConnectionDictionary.removeObjectForKey("plugin");
}
String driverCheck = (String)newConnectionDictionary.objectForKey("driver");
if (driverCheck != null && driverCheck.length() == 0){
newConnectionDictionary.removeObjectForKey("driver");
}
model.setConnectionDictionary(newConnectionDictionary);
// we want to be a bit more aggressive here
String[] keysThatMatter = { "URL", "username" };
Enumeration modelsEnum = model.modelGroup().models().objectEnumerator();
while (modelsEnum.hasMoreElements()) {
EOModel otherModel = (EOModel)modelsEnum.nextElement();
if (otherModel != model) {
NSDictionary otherConnectionDictionary = otherModel.connectionDictionary();
if (otherConnectionDictionary != null && ObjectUtils.equals(newConnectionDictionary.objectForKey("adaptorName"), otherConnectionDictionary.objectForKey("adaptorName"))) {
boolean valuesThatMatterMatch = true;
for (int keyNum = 0; valuesThatMatterMatch && keyNum < keysThatMatter.length; keyNum ++) {
String thisValue = (String)newConnectionDictionary.objectForKey(keysThatMatter[keyNum]);
String otherValue = (String)otherConnectionDictionary.objectForKey(keysThatMatter[keyNum]);
valuesThatMatterMatch = ERXStringUtilities.stringEqualsString(thisValue, otherValue);
}
if (valuesThatMatterMatch && !newConnectionDictionary.equals(otherConnectionDictionary)) {
if (!isPrototypeModel(model) && !isPrototypeModel(otherModel)) {
String message = "The connection dictionaries for " + model.name() + " and " + otherModel.name() + " have the same URL and username, but the connection dictionaries are not equal. Check your connection dictionaries carefully! This problem is often caused by jdbc2Info not matching between the two. One fix for this is to set " + model.name() + ".removeJdbc2Info=true and " + otherModel.name() + ".removeJdbc2Info=true in your Properties file. (" + model.name() + "=" + newConnectionDictionary + "; and " + otherModel.name() + "=" + otherConnectionDictionary + ").";
if (!raiseOnUnmatchingConnectionDictionaries) {
// was intentionally switched off, so log only
log.warn(message);
}
else {
throw new IllegalArgumentException(message);
}
}
log.info("The connection dictionaries for " + model.name() + " and " + otherModel.name() + " have the same URL and username, but at least one of them is a prototype model, so it shouldn't be a problem.");
}
}
}
}
}