Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 157   Methods: 7
NCLOC: 82   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SystemCollection.java 66.7% 86.2% 85.7% 83.3%
coverage coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: SystemCollection.java 568786 2007-08-23 00:40:57Z vgritsenko $
 18    */
 19   
 20    package org.apache.xindice.core;
 21   
 22    import org.apache.commons.logging.Log;
 23    import org.apache.commons.logging.LogFactory;
 24    import org.apache.xindice.util.Configuration;
 25    import org.apache.xindice.xml.SymbolTable;
 26    import org.apache.xindice.xml.SymbolTableSymbols;
 27    import org.apache.xindice.xml.dom.DOMParser;
 28   
 29    import org.w3c.dom.Document;
 30   
 31    /**
 32    * SystemCollection represents the System Collection. Beyond
 33    * standard Collection operations, this class will provide facilities
 34    * for Schema and SymbolTable management among other things.
 35    *
 36    * @version $Revision: 568786 $, $Date: 2007-08-22 17:40:57 -0700 (Wed, 22 Aug 2007) $
 37    */
 38    public final class SystemCollection extends Collection {
 39   
 40    private static final Log log = LogFactory.getLog(SystemCollection.class);
 41   
 42    public static final String SYSCOL = "system";
 43    public static final String SYMBOLS = "SysSymbols";
 44    public static final String OBJECTS = "SysObjects";
 45    public static final String CONFIGS = "SysConfig";
 46    public static final String USERS = "SysUsers";
 47    public static final String GROUPS = "SysGroups";
 48    public static final String ACCESS = "SysAccess";
 49   
 50    private static String SYSCOL_DEFINITION
 51    = "<collection name='" + SYSCOL + "'>"
 52    // System Collections
 53    + " <collections>"
 54    // Symbol Tables Collection
 55    + " <collection name='" + SYMBOLS + "' compressed='true'>"
 56    + " <filer class='org.apache.xindice.core.filer.BTreeFiler'/>"
 57    // Textual Representation of Hard-coded Symbol Table
 58    + SymbolTableSymbols.getDefinition()
 59    + " <indexes/>"
 60    + " </collection>"
 61    // System Configuration Collection
 62    + " <collection name='" + CONFIGS + "' compressed='false'>"
 63    + " <filer class='org.apache.xindice.core.filer.BTreeFiler' pagecount='16'/>"
 64    + " <indexes/>"
 65    + " </collection>"
 66    + " </collections>"
 67    + "</collection>";
 68   
 69    /**
 70    * @param db Its database
 71    */
 72  123 public SystemCollection(Database db) {
 73  123 super(db);
 74    }
 75   
 76  123 void init() throws DBException {
 77    // Bootstrap the System Collection
 78  123 try {
 79  123 Document sysDoc = DOMParser.toDocument(SYSCOL_DEFINITION);
 80  123 Configuration sysCfg = new Configuration(sysDoc, false);
 81  123 setConfig(sysCfg);
 82    } catch (Exception e) {
 83  0 log.fatal("Failed to generate system collection '" + SYSCOL + "'", e);
 84   
 85    // TODO: System.exit() CANNOT be good here.
 86  0 System.exit(1);
 87    }
 88    }
 89   
 90  3135 private String getSymbolTableName(Collection col) {
 91  3135 String name = col.getCanonicalName();
 92    // Strip database name
 93  3135 int idx = name.indexOf('/', 1);
 94  3135 name = name.substring(idx + 1);
 95   
 96  3135 return name.replace('/', '_');
 97    }
 98   
 99    /**
 100    * loadSymbols retrieves the SymbolTable for the specified Collection.
 101    *
 102    * @param collection The Collection whose SymbolTable is required
 103    * @return The requested SymbolTable
 104    * @throws DBException if unable to load symbols
 105    */
 106  1158 public SymbolTable loadSymbols(Collection collection) throws DBException {
 107  1158 String name = getSymbolTableName(collection);
 108   
 109  1158 Collection symCol = getCollection(SYMBOLS);
 110   
 111  1158 SymbolTable symbols = (SymbolTable) symCol.getObject(name);
 112  1158 if (symbols == null) {
 113  1039 symbols = new SymbolTable();
 114    }
 115  1158 return symbols;
 116    }
 117   
 118    /**
 119    * saveSymbols save the SymbolTable for the specified Collection.
 120    *
 121    * @param collection The Collection that owns the SymbolTable
 122    * @param symbols The SymbolTable
 123    * @throws DBException if unable to save symbols
 124    */
 125  941 public void saveSymbols(Collection collection, SymbolTable symbols) throws DBException {
 126  941 if (symbols != null) {
 127  941 String name = getSymbolTableName(collection);
 128  941 getCollection(SYMBOLS).setObject(name, symbols);
 129  941 symbols.resetDirty();
 130    }
 131    }
 132   
 133    /**
 134    * dropSymbols drop the SymbolTable for the specified Collection.
 135    *
 136    * @param collection The Collection that owns the SymbolTable
 137    * @throws DBException if unable to drop symbols
 138    */
 139  1036 public void dropSymbols(Collection collection) throws DBException {
 140  1036 String name = getSymbolTableName(collection);
 141   
 142  1036 Collection symCol = getCollection(SYMBOLS);
 143  1036 try {
 144  1036 symCol.remove(name);
 145    } catch (DBException e) {
 146  233 if (e.faultCode == FaultCodes.COL_DOCUMENT_NOT_FOUND) {
 147    // ignore
 148  233 return;
 149    }
 150  0 throw e;
 151    }
 152    }
 153   
 154  0 public static String getDefinition() {
 155  0 return SYSCOL_DEFINITION;
 156    }
 157    }