kevinross 2003/07/14 11:31:57
Modified: java/src/org/apache/xindice/core Database.java Log: started refactoring for: -javabeans naming -reduce double checks for log levels when not doing an expensive logging operation Revision Changes Path 1.20 +43 -39 xml-xindice/java/src/org/apache/xindice/core/Database.java Index: Database.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/core/Database.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- Database.java 10 Jul 2003 21:41:05 -0000 1.19 +++ Database.java 14 Jul 2003 18:31:57 -0000 1.20 @@ -70,6 +70,7 @@ import org.apache.xindice.core.meta.TimeRecord; import org.apache.xindice.core.query.QueryEngine; import org.apache.xindice.util.Configuration; +import org.apache.xindice.util.ConfigurationException; import org.apache.xindice.util.Named; import org.apache.xindice.util.XindiceException; import org.w3c.dom.Document; @@ -78,7 +79,6 @@ /** * Database is the primary container for the Xindice Database Engine. */ - public final class Database extends Collection implements Named { public static final String DBROOT = "dbroot"; private static final String QUERYENGINE = "queryengine"; @@ -95,9 +95,9 @@ private DocumentCache docCache = new DocumentCache(); - private SystemCollection sysCol = null; + private SystemCollection systemCollection = null; - private MetaSystemCollection metaCol = null; + private MetaSystemCollection metaSystemCollection = null; private boolean sysInit = false; private boolean metaInit = false; @@ -107,6 +107,13 @@ private QueryEngine engine = new QueryEngine(this); + /** + * This will merely return an instance of a Database for the given + * name if one has already been loaded. + * + * @param name + * @return Database + */ public static Database getDatabase(String name) { Database database = (Database) databases.get(name); @@ -120,15 +127,21 @@ return database; } + /** + * This will return an instance of a Database for the given + * name if one has already been loaded, otherwise it will + * create a new instance. + * + * @param config + * @return Database + */ public static Database getDatabase(Configuration config) { String name = config.getAttribute(Database.NAME); // no name in the config file ... can't the database if (null == name) { - log.error("Database configuration didn't contain a database name"); - - return null; + throw new ConfigurationException("Database configuration didn't contain a database name"); } Database database = (Database) databases.get(name); @@ -156,7 +169,7 @@ public void setConfig(Configuration config) { this.config = config; - name = config.getAttribute(NAME); + this.name = config.getAttribute(NAME); setCanonicalName('/' + getName()); String dbroot = config.getAttribute(DBROOT); @@ -171,50 +184,45 @@ try { Configuration queryCfg = config.getChild(QUERYENGINE); if (queryCfg != null) - engine.setConfig(queryCfg); + this.engine.setConfig(queryCfg); } catch (Exception e) { - if (log.isDebugEnabled()) { - log.debug("No message", e); - } + + log.warn(e); } if (!sysInit) { - sysCol = new SystemCollection(this); + this.systemCollection = new SystemCollection(this); try { - sysCol.init(); + this.systemCollection.init(); } catch (XindiceException e) { - if (log.isDebugEnabled()) { - log.debug("No message", e); - } + log.warn(e); } - collections.put(sysCol.getName(), sysCol); - sysInit = true; + this.collections.put(systemCollection.getName(), systemCollection); + this.sysInit = true; } try { // Bootstrap from the database itself... This is accomplished // by intercepting the setConfig call and using a Configuration // retrieved from the database instead of the standard config - Document colDoc = sysCol.getCollection(SystemCollection.CONFIGS).getDocument(COLKEY); + Document colDoc = systemCollection.getCollection(SystemCollection.CONFIGS).getDocument(COLKEY); if (colDoc == null) { DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); colDoc = db.newDocument(); Element root = colDoc.createElement(DATABASE); root.setAttribute(NAME, name); colDoc.appendChild(root); - sysCol.getCollection(SystemCollection.CONFIGS).setDocument(COLKEY, colDoc); + systemCollection.getCollection(SystemCollection.CONFIGS).setDocument(COLKEY, colDoc); } super.setConfig(new Configuration(colDoc.getDocumentElement(), false)); } catch (Exception e) { - if (log.isDebugEnabled()) { - log.debug("No message", e); - } + log.warn(e); } // Register the Database with the VM @@ -226,22 +234,18 @@ if (metaCfg.equalsIgnoreCase("on")) { metaEnabled = true; if (!metaInit) { - metaCol = new MetaSystemCollection(this); + this.metaSystemCollection = new MetaSystemCollection(this); try { - metaCol.init(); + this.metaSystemCollection.init(); } catch (XindiceException e) { - if (log.isDebugEnabled()) { - log.debug("Error initializing the meta collection", e); - } + log.warn("Error initializing the meta collection", e); } // should this attach the meta collection to the database? - collections.put(metaCol.getName(), metaCol); + collections.put(metaSystemCollection.getName(), metaSystemCollection); metaInit = true; - if (log.isInfoEnabled()) { - log.info("Meta information initialized"); - } + log.info("Meta information initialized"); } } @@ -250,7 +254,7 @@ } public SystemCollection getSystemCollection() { - return sysCol; + return systemCollection; } /** @@ -260,7 +264,7 @@ * @return MetaSystemCollection */ public MetaSystemCollection getMetaSystemCollection() { - return metaCol; + return metaSystemCollection; } /** @@ -280,15 +284,15 @@ * properly flushed to disk after a modification. */ public void flushConfig() { + try { Document d = config.getElement().getOwnerDocument(); - sysCol.getCollection(SystemCollection.CONFIGS).setDocument(COLKEY, d); + systemCollection.getCollection(SystemCollection.CONFIGS).setDocument(COLKEY, d); } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("Error Writing Configuration '" + name + "', for database " + getName(), e); - } + log.error("Error Writing Configuration '" + name + "', for database " + getName(), e); } + // observer DBObserver.getInstance().flushDatabaseConfig(this, config); }