//Element databaseRoot = (Element) this.configDocument.getRootElement().selectSingleNode("contentdbs");
//List databaseElements = databaseRoot.selectNodes("contentdb");
//Element databaseElement;
ContentDatabase databaseConfig;
WGDatabase db;
Set<String> currentDBs = new HashSet<String>();
// db connection errors mapped by dbkey
Map<String, Serializable> dbConnectionFailures = new HashMap<String, Serializable>();
List<ContentDatabase> databases = _wgaConfiguration.getContentDatabases();
// Map new databases and update current databases
for (int idxDB = 0; idxDB < databases.size(); idxDB++) {
databaseConfig = databases.get(idxDB);
String dbKey = databaseConfig.getKey();
// ignore disabled dbs
if (!databaseConfig.isEnabled()) {
continue;
}
DatabaseServer serverConfig = (DatabaseServer) _wgaConfiguration.getByUid(databaseConfig.getDbServer());
if (serverConfig != null && !serverConfig.isEnabled()) {
continue;
}
// Get or create database object
boolean isNewDB = false;
if (this.contentdbs.containsKey(dbKey) == false) {
try {
db = retrieveContentDB(databaseConfig, dbConnectionFailures);
if (db == null) {
continue;
}
this.contentdbs.put(dbKey, db);
isNewDB = true;
newConnectedDBKeys.add(dbKey);
}
catch (Throwable e) {
getLog().error("Exception connecting database " + dbKey, e);
if (this.contentdbs.containsKey(dbKey)) {
this.contentdbs.remove(dbKey);
}
continue;
}
}
else {
db = this.contentdbs.get(dbKey);
}
currentDBs.add(dbKey);
// Update stored queries
/*
Element queryRoot = (Element) databaseElement.selectSingleNode("storedqueries");
if (queryRoot != null) {
updateStoredQueries(db, queryRoot);
}*/
// Update field mappings
/*
Element mappingRoot = (Element) databaseElement.selectSingleNode("fieldmappings");
if (mappingRoot != null) {
}*/
updateFieldMappings(db, databaseConfig.getFieldMappings());
// Update client restrictions
if (databaseConfig.isClientRestrictionsEnabled()) {
db.setAttribute(DBATTRIB_CLIENTRESTRICTIONS, IPv4Restriction.getRestrictions(databaseConfig.getClientRestrictions(), databaseConfig.getKey(), getLog()));
} else {
// if not enabled remove clientRestrictions from db
db.removeAttribute(DBATTRIB_CLIENTRESTRICTIONS);
}
// Operations only for newly connected databases
if (isNewDB) {
performNewDBOperations(db);