// Get basic information
String strType = config.getImplClassName();
String strKey = config.getKey();
// retrieve dbserver for db
WGDatabaseServer server = getDatabaseServers().get(config.getDbServer());
if (server == null) {
log.error("Could not open database for key " + strKey.toLowerCase() + ": The server " + config.getDbServer() + " is unknown");
return null;
}
// TODO this should be done in configuration validation not here
if (strKey.equalsIgnoreCase("start") || strKey.equalsIgnoreCase("bi") || strKey.equalsIgnoreCase("static") || strKey.equalsIgnoreCase("statictml")) {
String message = "Cannot map " + dbType + " to key \"" + strKey + "\" - This is a predefined key not available for content databases";
log.error(message);
dbConnectionFailures.put(strKey, message);
return null;
}
// TODO this should be done in configuration validation not here
if (strKey.startsWith(PluginConfig.PLUGIN_DBKEY_PREFIX)) {
String message = "Cannot map " + dbType + " to key \"" + strKey + "\" - The key prefix \"" + PluginConfig.PLUGIN_DBKEY_PREFIX + "\" is reserved for WGA plugins";
log.error(message);
dbConnectionFailures.put(strKey, message);
return null;
}
// Look if the server is able and allowed to instantiate this db type
Class<WGDatabaseCore> typeClass;
try {
Class theClass = WGFactory.getImplementationLoader().loadClass(strType);
if (!WGDatabaseCore.class.isAssignableFrom(theClass)) {
String message = "Cannot map " + dbType + " to key \"" + strKey + "\" - Database implementation class \"" + strType + "\" is no WGDatabaseCore implementation.";
return null;
}
typeClass = theClass;
}
catch (ClassNotFoundException e) {
String message = "Cannot map " + dbType + " to key \"" + strKey + "\" - Database implementation class \"" + strType + "\" not available.";
log.error(message);
dbConnectionFailures.put(strKey, message);
return null;
}
catch (NoClassDefFoundError e) {
String message = "Cannot map " + dbType + " to key \"" + strKey + "\" - Database implementation class or dependent class for type \"" + strType + "\" not found: \"" + e.getMessage();
log.error(message);
dbConnectionFailures.put(strKey, message);
return null;
}
catch (VerifyError e) {
String message = "Cannot map " + dbType + "to key \"" + strKey + "\" - Verify error: " + e.getMessage();
log.error(message);
dbConnectionFailures.put(strKey, message);
return null;
}
if (!isDBAllowed(typeClass, strKey)) {
String message = "Cannot map " + dbType + " to key \"" + strKey + "\" - Your server license type is not allowed to use this database type";
log.error(message);
dbConnectionFailures.put(strKey, message);
return null;
}
// Evaluate title
String title = config.getTitle();
// Evaluate domain
/*
Element domainElement = (Element) databaseElement.selectSingleNode("domain");
DomainConfiguration domainConfig = new DomainConfiguration();
if (domainElement != null) {
domainConfig = getDomainConfig(domainElement.getStringValue());
}*/
Domain domain = getWgaConfiguration().getDomain(config.getDomain());
DomainConfiguration domainConfig = getDomainConfig(domain);
// Collect db options from global, server, database
HashMap<String, String> dbOptions = new HashMap<String, String>();
dbOptions.put(WGDatabase.COPTION_USERCACHELATENCY, String.valueOf(_wgaConfiguration.getUserCacheLatencyMinutes()));
dbOptions.putAll(_globalDbOptions);
dbOptions.putAll(config.getDatabaseOptions());
// We collect those options that were added on database level in here
// and add this set as database attribute
// so we can tell them later from lower priority options
Set<String> firstLevelDBOptions = new HashSet<String>();
firstLevelDBOptions.addAll(config.getDatabaseOptions().keySet());
// Mandatory db options
dbOptions.put(WGDatabase.COPTION_DBREFERENCE, strKey.toLowerCase());
// get the database object
WGDatabase db = null;
try {
if (config.isLazyConnecting()) {
db = server.prepareDatabase(typeClass, dbOptions);
}
else {
db = server.openDatabase(typeClass, dbOptions);
}
}
catch (Throwable e1) {
String message = "Could not open database for key " + strKey.toLowerCase();
log.error(message, e1);