kevinross    2003/07/10 14:41:05

  Modified:    java/src/org/apache/xindice/core Database.java
  Log:
  formatting, organize imports
  added log message
  
  Revision  Changes    Path
  1.19      +209 -205  
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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Database.java     9 Jul 2003 16:35:12 -0000       1.18
  +++ Database.java     10 Jul 2003 21:41:05 -0000      1.19
  @@ -58,57 +58,56 @@
    *
    * $Id$
    */
  -
  -import org.apache.xindice.core.query.QueryEngine;
  -import org.apache.xindice.util.Configuration;
  -import org.apache.xindice.util.Named;
  -import org.apache.xindice.util.XindiceException;
  -import org.apache.xindice.core.meta.TimeRecord;
  -
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
  -
  -import org.w3c.dom.*;
  -
   import java.io.File;
   import java.util.HashMap;
   import java.util.Map;
  +
   import javax.xml.parsers.DocumentBuilder;
   import javax.xml.parsers.DocumentBuilderFactory;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +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.Named;
  +import org.apache.xindice.util.XindiceException;
  +import org.w3c.dom.Document;
  +import org.w3c.dom.Element;
  +
   /**
    * 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";
  -   private static final String DATABASE = "database";
  -   private static final String COLKEY = "database.xml";
  -   private static final String METADATA = "use-metadata";
  -   public static final String NAME = "name";
  +     public static final String DBROOT = "dbroot";
  +     private static final String QUERYENGINE = "queryengine";
  +     private static final String DATABASE = "database";
  +     private static final String COLKEY = "database.xml";
  +     private static final String METADATA = "use-metadata";
  +     public static final String NAME = "name";
   
  -   private static Log log = LogFactory.getLog("org.apache.xindice.core");
  +     private static Log log = LogFactory.getLog("org.apache.xindice.core");
   
  -   public static final String PROP_XINDICE_HOME = "xindice.home";
  +     public static final String PROP_XINDICE_HOME = "xindice.home";
   
  -   private static final Map databases = new HashMap(); // String to Database
  +     private static final Map databases = new HashMap(); // String to 
Database
   
  -   private DocumentCache docCache = new DocumentCache();
  +     private DocumentCache docCache = new DocumentCache();
   
  -   private SystemCollection sysCol = null;
  +     private SystemCollection sysCol = null;
   
  -   private MetaSystemCollection metaCol = null;
  +     private MetaSystemCollection metaCol = null;
   
  -   private boolean sysInit = false;
  -   private boolean metaInit = false;
  -   private boolean metaEnabled = false;
  -   // key = canonical name, value = timerecord
  -   private Map timestamps = new HashMap();
  +     private boolean sysInit = false;
  +     private boolean metaInit = false;
  +     private boolean metaEnabled = false;
  +     // key = canonical name, value = timerecord
  +     private Map timestamps = new HashMap();
   
  -   private QueryEngine engine = new QueryEngine(this);
  +     private QueryEngine engine = new QueryEngine(this);
   
  -   public static Database getDatabase(String name) {
  +     public static Database getDatabase(String name) {
   
                Database database = (Database) databases.get(name);
                if (null == database) {
  @@ -148,197 +147,202 @@
                }
   
                return database;
  -   }
  +     }
  +
  +     public static String[] listDatabases() {
  +             return (String[]) databases.keySet().toArray(new String[0]);
  +     }
  +
  +     public void setConfig(Configuration config) {
  +             this.config = config;
  +
  +             name = config.getAttribute(NAME);
  +             setCanonicalName('/' + getName());
  +
  +             String dbroot = config.getAttribute(DBROOT);
  +             File dbrootDir = new File(dbroot);
  +             if (!dbrootDir.isAbsolute()) {
  +                     dbrootDir = new 
File(System.getProperty(PROP_XINDICE_HOME), dbroot);
  +             }
  +             setCollectionRoot(dbrootDir);
  +             log.info("Database points to " + dbrootDir.getAbsolutePath());
  +             log.debug("Database dir exists: " + (dbrootDir == null ? false 
: dbrootDir.exists()));
  +
  +             try {
  +                     Configuration queryCfg = config.getChild(QUERYENGINE);
  +                     if (queryCfg != null)
  +                             engine.setConfig(queryCfg);
  +             }
  +             catch (Exception e) {
  +                     if (log.isDebugEnabled()) {
  +                             log.debug("No message", e);
  +                     }
  +             }
   
  -   public static String[] listDatabases() {
  -      return (String[]) databases.keySet().toArray(new String[0]);
  -   }
  -
  -   public void setConfig(Configuration config) {
  -      this.config = config;
  -
  -      name = config.getAttribute(NAME);
  -      setCanonicalName('/' + getName());
  -
  -      String dbroot = config.getAttribute(DBROOT);
  -      File dbrootDir = new File(dbroot);
  -      if (!dbrootDir.isAbsolute()) {
  -         dbrootDir = new File(System.getProperty( PROP_XINDICE_HOME ), 
dbroot);
  -      }
  -      setCollectionRoot(dbrootDir);
  -      if (log.isInfoEnabled()) {
  -         log.info("Database points to " + dbrootDir.getAbsolutePath());
  -      }
  -
  -      try {
  -         Configuration queryCfg = config.getChild(QUERYENGINE);
  -         if ( queryCfg != null )
  -            engine.setConfig(queryCfg);
  -             } catch (Exception e) {
  -         if (log.isDebugEnabled()) {
  -            log.debug("No message", e);
  -         }
  -      }
  -
  -      if ( !sysInit ) {
  -         sysCol = new SystemCollection(this);
  -
  -         try {
  -            sysCol.init();
  -                     } catch (XindiceException e) {
  -            if (log.isDebugEnabled()) {
  -               log.debug("No message", e);
  -            }
  -         }
  -
  -         collections.put(sysCol.getName(), sysCol);
  -         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);
  -         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);
  -         }
  -
  -         super.setConfig(new Configuration(colDoc.getDocumentElement(), 
false));
  -             } catch (Exception e) {
  -         if (log.isDebugEnabled()) {
  -            log.debug("No message", e);
  -         }
  -      }
  +             if (!sysInit) {
  +                     sysCol = new SystemCollection(this);
  +
  +                     try {
  +                             sysCol.init();
  +                     }
  +                     catch (XindiceException e) {
  +                             if (log.isDebugEnabled()) {
  +                                     log.debug("No message", e);
  +                             }
  +                     }
  +
  +                     collections.put(sysCol.getName(), sysCol);
  +                     sysInit = true;
  +             }
   
  -      // Register the Database with the VM
  +             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);
  +                     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);
  +                     }
  +
  +                     super.setConfig(new 
Configuration(colDoc.getDocumentElement(), false));
  +             }
  +             catch (Exception e) {
  +                     if (log.isDebugEnabled()) {
  +                             log.debug("No message", e);
  +                     }
  +             }
  +
  +             // Register the Database with the VM
                // databases.put(getName(), this);
   
  -      // initialize the meta collection
  -      // but only if it's turned on in the config.
  -      String metaCfg = config.getAttribute(METADATA);
  +             // initialize the meta collection
  +             // but only if it's turned on in the config.
  +             String metaCfg = config.getAttribute(METADATA);
                if (metaCfg.equalsIgnoreCase("on")) {
  -         metaEnabled = true;
  +                     metaEnabled = true;
                        if (!metaInit) {
  -            metaCol = new MetaSystemCollection(this);
  -            try {
  -               metaCol.init();
  -                             } catch (XindiceException e) {
  -               if (log.isDebugEnabled()) {
  -                  log.debug("Error initializing the meta collection", e);
  -               }
  -            }
  -            // should this attach the meta collection to the database?
  -
  -            collections.put(metaCol.getName(), metaCol);
  -            metaInit = true;
  -            if (log.isInfoEnabled()) {
  -               log.info("Meta information initialized");
  -            }
  -         }
  -      }
  -
  -      // observer
  -      DBObserver.getInstance().setDatabaseConfig(this, collections, config);
  -   }
  -
  -   public SystemCollection getSystemCollection() {
  -      return sysCol;
  -   }
  -
  -   /**
  -    * Return the MetaSystem collection for this database.
  -    * 
  -    * It will return null if metadata is not enabled on this database.
  -    * @return MetaSystemCollection
  -    */
  -   public MetaSystemCollection getMetaSystemCollection() {
  -      return metaCol;
  -   }
  -   
  -   /**
  -    * Return whether or not metadata is enabled on this database.
  -    * @return boolean
  -    */
  +                             metaCol = new MetaSystemCollection(this);
  +                             try {
  +                                     metaCol.init();
  +                             }
  +                             catch (XindiceException e) {
  +                                     if (log.isDebugEnabled()) {
  +                                             log.debug("Error initializing 
the meta collection", e);
  +                                     }
  +                             }
  +                             // should this attach the meta collection to 
the database?
  +
  +                             collections.put(metaCol.getName(), metaCol);
  +                             metaInit = true;
  +                             if (log.isInfoEnabled()) {
  +                                     log.info("Meta information 
initialized");
  +                             }
  +                     }
  +             }
  +
  +             // observer
  +             DBObserver.getInstance().setDatabaseConfig(this, collections, 
config);
  +     }
  +
  +     public SystemCollection getSystemCollection() {
  +             return sysCol;
  +     }
  +
  +     /**
  +      * Return the MetaSystem collection for this database.
  +      * 
  +      * It will return null if metadata is not enabled on this database.
  +      * @return MetaSystemCollection
  +      */
  +     public MetaSystemCollection getMetaSystemCollection() {
  +             return metaCol;
  +     }
  +
  +     /**
  +      * Return whether or not metadata is enabled on this database.
  +      * @return boolean
  +      */
        public boolean isMetaEnabled() {
  -      return metaEnabled;
  -   }
  +             return metaEnabled;
  +     }
   
  -   public Database getDatabase() {
  -      return this;
  -   }
  -
  -   /**
  -    * flushConfig ensures that the Collection configuration has been
  -    * properly flushed to disk after a modification.
  -    */
  -   public void flushConfig() {
  -      try {
  -         Document d = config.getElement().getOwnerDocument();
  -         sysCol.getCollection(SystemCollection.CONFIGS).setDocument(COLKEY, 
d);
  -             } catch (Exception e) {
  -         if (log.isErrorEnabled()) {
  -            log.error("Error Writing Configuration '"+name+"', for database 
"+getName(), e);
  -         }
  -      }
  -      // observer
  -      DBObserver.getInstance().flushDatabaseConfig(this, config);
  -   }
  +     public Database getDatabase() {
  +             return this;
  +     }
   
  -   public boolean close() throws DBException {
  -      flushConfig();
  +     /**
  +      * flushConfig ensures that the Collection configuration has been
  +      * properly flushed to disk after a modification.
  +      */
  +     public void flushConfig() {
  +             try {
  +                     Document d = config.getElement().getOwnerDocument();
  +                     
sysCol.getCollection(SystemCollection.CONFIGS).setDocument(COLKEY, d);
  +             }
  +             catch (Exception e) {
  +                     if (log.isErrorEnabled()) {
  +                             log.error("Error Writing Configuration '" + 
name + "', for database " + getName(), e);
  +                     }
  +             }
  +             // observer
  +             DBObserver.getInstance().flushDatabaseConfig(this, config);
  +     }
  +
  +     public boolean close() throws DBException {
  +             flushConfig();
   
                synchronized (databases) {
  -      databases.remove( getName() );
  +                     databases.remove(getName());
                }
   
  -      return true;
  -   }
  +             return true;
  +     }
   
  -   /**
  -    * getDocumentCache returns the Database-level Document Cache.
  -    *
  -    * @return The DocumentCache
  -    */
  -   public DocumentCache getDocumentCache() {
  -      return docCache;
  -   }
  -
  -   /**
  -    * getQueryEngine returns a reference to the Database's current
  -    * operating QueryEngine implementation.
  -    *
  -    * @return The QueryEngine instance
  -    */
  -   public QueryEngine getQueryEngine() {
  -      return engine;
  -   }
  +     /**
  +      * getDocumentCache returns the Database-level Document Cache.
  +      *
  +      * @return The DocumentCache
  +      */
  +     public DocumentCache getDocumentCache() {
  +             return docCache;
  +     }
  +
  +     /**
  +      * getQueryEngine returns a reference to the Database's current
  +      * operating QueryEngine implementation.
  +      *
  +      * @return The QueryEngine instance
  +      */
  +     public QueryEngine getQueryEngine() {
  +             return engine;
  +     }
   
  -   // methods for recording the times when meta data is enabled.
  +     // methods for recording the times when meta data is enabled.
        public synchronized void recordTime(String path, long created, long 
modified) {
  -      TimeRecord rec = (TimeRecord)timestamps.get(path);
  -      if( null == rec ) {
  -         rec = new TimeRecord(created, modified);
  -         timestamps.put(path, rec);
  -             } else {
  -         if( created > 0 )
  -            rec.setCreatedTime(created);
  -         if( modified > 0 )
  -            rec.setModifiedTime(modified);
  -      }
  -   }
  +             TimeRecord rec = (TimeRecord) timestamps.get(path);
  +             if (null == rec) {
  +                     rec = new TimeRecord(created, modified);
  +                     timestamps.put(path, rec);
  +             }
  +             else {
  +                     if (created > 0)
  +                             rec.setCreatedTime(created);
  +                     if (modified > 0)
  +                             rec.setModifiedTime(modified);
  +             }
  +     }
   
        public synchronized void removeTime(String path) {
  -      timestamps.remove(path);
  -   }
  +             timestamps.remove(path);
  +     }
   
        public synchronized TimeRecord getTime(String path) {
  -      TimeRecord rec = (TimeRecord)timestamps.get(path);
  -      return rec;
  -   }
  +             TimeRecord rec = (TimeRecord) timestamps.get(path);
  +             return rec;
  +     }
   }
  
  
  

Reply via email to