vgritsenko    2003/08/21 11:14:53

  Modified:    java/src/org/apache/xindice/client/xmldb/xmlrpc
                        CollectionImpl.java
               java/src/org/apache/xindice/core Collection.java
  Log:
  More logging and exception messages tuning
  
  Revision  Changes    Path
  1.35      +3 -3      
xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java
  
  Index: CollectionImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- CollectionImpl.java       16 Aug 2003 03:47:36 -0000      1.34
  +++ CollectionImpl.java       21 Aug 2003 18:14:53 -0000      1.35
  @@ -141,7 +141,7 @@
           String xmlRpcURL = "http://"; + hostPort + serviceLocation;
           try {
               if (log.isDebugEnabled()) {
  -                log.debug("Using URL: '" + "http://"; + hostPort + 
serviceLocation + "'");
  +                log.debug("Using URL: '" + xmlRpcURL + "'");
               }
               client = new XmlRpcClient(xmlRpcURL);
   
  
  
  
  1.38      +132 -84   
xml-xindice/java/src/org/apache/xindice/core/Collection.java
  
  Index: Collection.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/Collection.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- Collection.java   15 Aug 2003 04:34:54 -0000      1.37
  +++ Collection.java   21 Aug 2003 18:14:53 -0000      1.38
  @@ -469,7 +469,7 @@
        * Retrieve a binary database entry by key.
        * This low-level method will not update non-inline metadata.
        *
  -     * @param docKey identifying the desired database entry
  +     * @param key identifying the desired database entry
        * @return byte[] containing the binary database entry
        * @throws DBException if inline-metadata is not enabled
        *         (binary resource cannot be stored in a collection
  @@ -477,27 +477,26 @@
        *         in case of backing store error, and in case of
        *         header corruption
        */
  -    public final byte[] getBinary(Object docKey) throws DBException {
  -
  +    public final byte[] getBinary(Object key) throws DBException {
           if (log.isDebugEnabled()) {
  -            log.debug(debugHeader() + "getBinary: docKey=<" + docKey + ">");
  +            log.debug(debugHeader() + "Get binary: " + key);
           }
   
           if (inlineMetaService != null) {
               throw new DBException(FaultCodes.COL_DOCUMENT_NOT_FOUND,
  -                                  "There are no binary resources in 
collection " + name +
  -                                  ": inline-metadata is not enabled.");
  +                                  "There are no binary resources in 
collection '"
  +                                  + getCanonicalName() + "': inline-metadata 
is not enabled.");
           }
   
  -        Object entry = getEntry(docKey);
  +        Object entry = getEntry(key);
           if (entry == null) {
               return null;
           }
   
           if (!(entry instanceof byte[])) {
               throw new DBException(FaultCodes.COL_INVALID_RESULT,
  -                                  "The resource associated with key '" + 
docKey +
  -                                  "' in collection '" + name + "'is not 
binary");
  +                                  "The resource associated with key '" + key 
+
  +                                  "' in collection '" + getCanonicalName() + 
"'is not binary.");
           }
   
           return (byte[]) entry;
  @@ -555,6 +554,7 @@
               }
               return meta;
           }
  +
           MetaSystemCollection metacol = getMetaSystemCollection();
           meta = metacol.getCollectionMeta(this);
           if (null == meta) {
  @@ -562,6 +562,7 @@
               meta = new MetaData(MetaData.COLLECTION, getCanonicalName(), 
now, now);
               metacol.setCollectionMeta(this, meta);
           }
  +
           return meta;
       }
   
  @@ -598,24 +599,23 @@
       /**
        * getDocument retrieves a Document by Key.
        *
  -     * @param docKey The Document Key
  +     * @param key The Document Key
        * @return The Document
        */
  -    public final Document getDocument(Object docKey) throws DBException {
  -
  -        if (log.isTraceEnabled()) {
  -            log.trace(debugHeader() + "getDocument: docKey=<" + docKey + 
">");
  +    public final Document getDocument(Object key) throws DBException {
  +        if (log.isDebugEnabled()) {
  +            log.debug(debugHeader() + "Get document: " + key);
           }
   
  -        Object entry = getEntry(docKey);
  +        Object entry = getEntry(key);
           if (entry == null) {
               return null;
           }
   
           if (!(entry instanceof Document)) {
               throw new DBException(FaultCodes.COL_INVALID_RESULT,
  -                                  "The resource associated with key '" + 
docKey +
  -                                  "' in collection '" + name + "' is not 
XML");
  +                                  "The resource associated with key '" + key 
+
  +                                  "' in collection '" + getCanonicalName() + 
"' is not XML document");
           }
   
           return (Document) entry;
  @@ -641,22 +641,21 @@
        * @param id the document whose metadata you want
        */
       public MetaData getDocumentMeta(String id) throws DBException {
  -        MetaData meta = null;
           if (!isMetaEnabled()) {
               if (log.isWarnEnabled()) {
                   log.warn("Meta information requested but not enabled in 
config!");
               }
  -            return meta;
  +            return null;
           }
  -        Document doc = getDocument(id);
  -        if (null == doc) {
  -            throw new DBException(FaultCodes.COL_DOCUMENT_NOT_FOUND, 
"Document " + id + " does not exist");
  +
  +        if (null == getDocument(id)) {
  +            throw new DBException(FaultCodes.COL_DOCUMENT_NOT_FOUND,
  +                                  "Document '" + id + "' does not exist " +
  +                                  "in collection '" + getCanonicalName() + 
"'");
           }
   
           MetaSystemCollection metacol = getMetaSystemCollection();
  -        meta = metacol.getDocumentMeta(this, id);
  -
  -        String path = getCanonicalDocumentName(id);
  +        MetaData meta = metacol.getDocumentMeta(this, id);
   
           /*
           TimeRecord rec = null;
  @@ -670,7 +669,7 @@
           // this is wrong.. but it should work for now...
           long now = System.currentTimeMillis();
           if (null == meta) {
  -            meta = new MetaData(MetaData.DOCUMENT, path, now, now);
  +            meta = new MetaData(MetaData.DOCUMENT, 
getCanonicalDocumentName(id), now, now);
               metacol.setDocumentMeta(this, id, meta);
           } else if (!meta.hasContext()) {
               meta.setContext(now, now);
  @@ -734,10 +733,10 @@
            */
           if (documentCache != null) {
               Document document = documentCache.getDocument(this, key);
  -            if (log.isDebugEnabled()) {
  -                log.debug(localDebugHeader + "Cache search returned: " + 
document);
  -            }
               if (document != null) {
  +                if (log.isTraceEnabled()) {
  +                    log.trace(localDebugHeader + "Returning cached: " + 
document);
  +                }
                   return document;
               }
           }
  @@ -747,44 +746,32 @@
               return null;
           }
   
  -        if (log.isDebugEnabled()) {
  -            log.debug(localDebugHeader + "Record value length=" + 
record.getValue().getLength());
  -        }
  -
           Value value;
           InlineMetaMap metaMap = null;
           if (inlineMetaService == null) {
  -            if (log.isDebugEnabled()) {
  -                log.debug(localDebugHeader + "Type is not available");
  -            }
  -
               value = record.getValue();
  -        } else {
  +
               if (log.isTraceEnabled()) {
  -                log.trace(localDebugHeader + "Decomposing header...");
  +                log.trace(localDebugHeader + "Type is not available, 
Length=" + value.getLength());
               }
  -
  +        } else {
               InlineMetaService.DatabaseEntry databaseEntry = 
inlineMetaService.readDatabaseEntry(record.getValue());
               metaMap = databaseEntry.map;
               value = databaseEntry.value;
   
  -            if (log.isDebugEnabled()) {
  -                log.debug(localDebugHeader + "Type=" + metaMap.get("type") + 
", Length=" + value.getLength());
  +            if (log.isTraceEnabled()) {
  +                log.trace(localDebugHeader + "Type=" + metaMap.get("type") + 
", Length=" + value.getLength());
               }
           }
   
           if (inlineMetaService == null || 
metaMap.get("type").equals(ResourceTypeReader.XML)) {
  -            if (log.isTraceEnabled()) {
  -                log.trace(localDebugHeader + "XML document");
  -            }
  -
               Document document;
               if (compressed) {
                   document = new DocumentImpl(value.getData(), symbols, new 
NodeSource(this, key));
                   flushSymbolTable();
   
  -                if (log.isDebugEnabled()) {
  -                    log.debug(localDebugHeader
  +                if (log.isTraceEnabled()) {
  +                    log.trace(localDebugHeader
                                 + "Compressed XML document=<" + 
TextWriter.toString(document) + ">");
                   }
   
  @@ -802,6 +789,10 @@
               DBObserver.getInstance().loadDocument(this, record, document);
               return document;
           } else {
  +            if (log.isTraceEnabled()) {
  +                log.trace(localDebugHeader + "Binary document");
  +            }
  +
               return value.getData();
           }
       }
  @@ -843,8 +834,7 @@
        *
        * @return MetaSystemCollection
        */
  -    private MetaSystemCollection getMetaSystemCollection() //throws 
DBException
  -    {
  +    private MetaSystemCollection getMetaSystemCollection() {
           return getDatabase().getMetaSystemCollection();
       }
   
  @@ -861,10 +851,12 @@
        * @return an Castable XMLSerializable Instance
        */
       public final XMLSerializable getObject(Object key) throws DBException {
  +        if (log.isDebugEnabled()) {
  +            log.debug(debugHeader() + "Get object: " + key);
  +        }
           String className = null;
   
           Document doc = getDocument(key);
  -
           if (doc != null) {
               NodeList childNodes = doc.getChildNodes();
               int size = childNodes.getLength();
  @@ -943,7 +935,6 @@
        *         error occurs while saving.
        */
       public Key insertBinary(byte[] bytes) throws DBException {
  -
           if (inlineMetaService == null) {
               throw new DBException(FaultCodes.COL_CANNOT_STORE,
                                     "Cannot insert a binary resource in 
collection " + name +
  @@ -951,31 +942,35 @@
           }
   
           Key key = createNewOID();
  +        if (log.isInfoEnabled()) {
  +            log.info(debugHeader() + "Insert binary. Key created: " + key);
  +        }
           putBinary(key, bytes, true);
   
  -        // update the meta information if necessary
  +        // Update the meta information if necessary
           updateCollectionMeta();
  -
           return key;
       }
   
       /**
        * insertBinary inserts a new binary object into a Xindice Collection.
        *
  -     * @param docKey The document Key
  +     * @param key The document Key
        * @param bytes The document to insert
        * @throws DBException if inline-metadata is not enabled, the key is
        *         already in the database, or an error occurs while saving.
        */
  -    public void insertBinary(Object docKey, byte[] bytes) throws DBException 
{
  -
  +    public void insertBinary(Object key, byte[] bytes) throws DBException {
           if (inlineMetaService == null) {
               throw new DBException(FaultCodes.COL_CANNOT_STORE,
                                     "Cannot insert a binary resource in 
collection " + name +
                                     ": inline-metadata is not enabled.");
           }
   
  -        putBinary(createNewKey(docKey), bytes, true);
  +        if (log.isInfoEnabled()) {
  +            log.info(debugHeader() + "Insert binary: " + key);
  +        }
  +        putBinary(createNewKey(key), bytes, true);
   
           // update the meta information if necessary
           updateCollectionMeta();
  @@ -989,7 +984,11 @@
        */
       public final Key insertDocument(Document document) throws DBException {
           Key key = createNewOID();
  +        if (log.isInfoEnabled()) {
  +            log.info(debugHeader() + "Insert document. Key created: " + key);
  +        }
           putDocument(key, document /*, true */);
  +
           // update the meta information if necessary
           updateCollectionMeta();
           return key;
  @@ -1002,7 +1001,11 @@
        * @param document The document to insert
        */
       public final void insertDocument(Object docKey, Document document) 
throws DBException {
  +        if (log.isInfoEnabled()) {
  +            log.info(debugHeader() + "Insert document: " + docKey);
  +        }
           putDocument(createNewKey(docKey), document /*, true */);
  +
           // update the meta information if necessary
           updateCollectionMeta();
       }
  @@ -1016,7 +1019,13 @@
        * @param obj The Object to insert
        */
       public final void insertObject(String key, XMLSerializable obj) throws 
DBException {
  +        if (log.isInfoEnabled()) {
  +            log.info(debugHeader() + "Insert object: " + key);
  +        }
           putObject(createNewKey(key), obj /*, true */);
  +
  +        // update the meta information if necessary
  +        updateCollectionMeta();
       }
   
       /**
  @@ -1029,7 +1038,13 @@
        */
       public final Key insertObject(XMLSerializable obj) throws DBException {
           Key key = createNewOID();
  +        if (log.isInfoEnabled()) {
  +            log.info(debugHeader() + "Insert object. Key created: " + key);
  +        }
           putObject(key, obj /*, true */);
  +
  +        // update the meta information if necessary
  +        updateCollectionMeta();
           return key;
       }
   
  @@ -1112,7 +1127,8 @@
                   documentCache.putDocument(this, key, b);
               }
           } catch (Exception e) {
  -            throw new DBException(FaultCodes.COL_DOCUMENT_MALFORMED, "Unable 
to parse Document", e);
  +            throw new DBException(FaultCodes.COL_DOCUMENT_MALFORMED,
  +                                  "Unable to parse document " + key, e);
           }
           return doc;
       }
  @@ -1122,7 +1138,6 @@
        * Does not update non-inline metadata.
        */
       private void putBinary(Key key, byte[] bytes, boolean create) throws 
DBException {
  -
           if (inlineMetaService == null) {
               throw new DBException(FaultCodes.COL_CANNOT_STORE,
                                     "Cannot store a binary resource in 
collection " + getCanonicalName() +
  @@ -1152,10 +1167,9 @@
        * It now does update non-inline metadata if the user has configured it.
        */
       private void putDocument(Key key, Document document) throws DBException {
  -
           final String localDebugHeader = debugHeader() + "putDocument: 
docKey=<" + key + ">: ";
  -        if (log.isDebugEnabled()) {
  -            log.debug(localDebugHeader + "document=<" + 
TextWriter.toString(document) + ">");
  +        if (log.isTraceEnabled()) {
  +            log.trace(localDebugHeader + "document=<" + 
TextWriter.toString(document) + ">");
           }
   
           checkFiler(FaultCodes.COL_NO_FILER);
  @@ -1188,21 +1202,32 @@
           if (compressed) {
               try {
                   packedDocument = DOMCompressor.Compress(document, symbols);
  -                log.debug(localDebugHeader + "length=" + 
packedDocument.length);
  +                if (log.isTraceEnabled()) {
  +                    log.trace(localDebugHeader + "length=" + 
packedDocument.length);
  +                }
   
                   // Why must it be re-created?
                   document = new DocumentImpl(packedDocument, symbols, new 
NodeSource(this, key));
   
  -                log.debug(localDebugHeader + "packedDocument: length=" + 
packedDocument.length + " document=<" + TextWriter.toString(document) + ">");
  +                if (log.isTraceEnabled()) {
  +                    log.trace(localDebugHeader + "packedDocument: length=" + 
packedDocument.length +
  +                              " document=<" + TextWriter.toString(document) 
+ ">");
  +                }
               } catch (Exception e) {
  -                throw new DBException(FaultCodes.COL_CANNOT_STORE, 
localDebugHeader + "Error compressing Document '" + key + "'", e);
  +                throw new DBException(FaultCodes.COL_CANNOT_STORE,
  +                                      localDebugHeader + "Error compressing 
Document '" + key + "'", e);
               }
           } else {
               try {
                   utf8Document = 
TextWriter.toString(document).getBytes("utf-8");
  -                log.debug(localDebugHeader + "utf8Document: length=" + 
utf8Document.length + " document=<" + new String(utf8Document, "utf-8") + ">");
  +                if (log.isTraceEnabled()) {
  +                    log.trace(localDebugHeader + "utf8Document: length=" + 
utf8Document.length +
  +                              " document=<" + new String(utf8Document, 
"utf-8") + ">");
  +                }
               } catch (UnsupportedEncodingException e) {
  -                throw new DBException(FaultCodes.GEN_FATAL_ERROR, "utf-8 
encoding not supported", e);
  +                // Should never happen
  +                throw new DBException(FaultCodes.GEN_FATAL_ERROR,
  +                                      "utf-8 encoding not supported", e);
               }
           }
   
  @@ -1254,16 +1279,14 @@
       }
   
       private void putObject(Key key, XMLSerializable obj) throws DBException {
  -
  -        final String localDebugHeader = debugHeader() + "putObject: key=<" + 
key + ">: ";
  +        if (log.isTraceEnabled()) {
  +            log.trace(debugHeader() + "putObject: key=<" + key + "> class=<" 
+ obj.getClass().getName() + ">");
  +        }
   
           Document doc = new DocumentImpl();
           ProcessingInstruction pi = 
doc.createProcessingInstruction(CLASSNAME, obj.getClass().getName());
           doc.appendChild(pi);
           Element elem = obj.streamToXML(doc);
  -        if (log.isDebugEnabled()) {
  -            log.debug(localDebugHeader + "elem=<" + 
TextWriter.toString(elem) + ">");
  -        }
           doc.appendChild(elem);
           putDocument(key, doc /*, create */);
       }
  @@ -1278,6 +1301,9 @@
        * @return The resulting NodeSet
        */
       public final NodeSet queryCollection(String style, String query, 
NamespaceMap nsMap) throws DBException {
  +        if (log.isInfoEnabled()) {
  +            log.info(debugHeader() + "Query collection, query " + query);
  +        }
           // a collection in which you are unable to file documents will have 
no filer
           // (for example the root collection). Rather than throwing an 
exception return
           // a constant result (nothing)
  @@ -1295,6 +1321,10 @@
        * @return The resulting NodeSet
        */
       public final NodeSet queryDocument(String style, String query, 
NamespaceMap nsMap, Object key) throws DBException {
  +        if (log.isInfoEnabled()) {
  +            log.info(debugHeader() + "Query document " + key + ", query: " + 
query);
  +        }
  +
           checkFiler(FaultCodes.QRY_STYLE_NOT_FOUND);
           Key[] k = null;
           if (key instanceof Key[]) {
  @@ -1312,6 +1342,10 @@
        * @param key The Object's Key
        */
       public final void remove(Object key) throws DBException {
  +        if (log.isInfoEnabled()) {
  +            log.info(debugHeader() + "Remove " + key);
  +        }
  +
           checkFiler(FaultCodes.COL_NO_FILER);
   
           Key objKey = createNewKey(key);
  @@ -1408,9 +1442,10 @@
           // Set parent
           if (parent != null) {
               setCanonicalName(parent.getCanonicalName() + '/' + name);
  -            log.debug(localDebugHeader + "Canonical name=<" + 
getCanonicalName() + ">");
               setCollectionRoot(new File(parent.getCollectionRoot(), name));
  -            log.debug(localDebugHeader + "Root=<" + getCollectionRoot() + 
">");
  +            if (log.isDebugEnabled()) {
  +                log.debug(localDebugHeader + "Root=<" + getCollectionRoot() 
+ ">");
  +            }
           }
   
           if (log.isDebugEnabled()) {
  @@ -1445,7 +1480,7 @@
                       symbols = new SymbolTable(symConfig.getElement());
                   } catch (Exception e) {
                       if (log.isWarnEnabled()) {
  -                        log.warn("Error building symbol table from internal 
symbols", e);
  +                        log.warn(localDebugHeader + "Error building symbol 
table from internal symbols", e);
                       }
                   }
               } else {
  @@ -1456,12 +1491,12 @@
                   try {
                       symbols = getSystemCollection().loadSymbols(this);
                       if (log.isDebugEnabled()) {
  -                        log.debug(localDebugHeader
  -                                  + "Loaded symbols=<" + 
TextWriter.toString(symbols.streamToXML(new DocumentImpl())) + ">");
  +                        log.debug(localDebugHeader + "Loaded symbols=<" +
  +                                  
TextWriter.toString(symbols.streamToXML(new DocumentImpl())) + ">");
                       }
                   } catch (Exception e) {
                       if (log.isWarnEnabled()) {
  -                        log.warn("Error building symbol table from system 
collection", e);
  +                        log.warn(localDebugHeader + "Error building symbol 
table from system collection", e);
                       }
                   }
               }
  @@ -1512,8 +1547,10 @@
        * @param document The Document
        */
       public final void setDocument(Object docKey, Document document) throws 
DBException {
  -        putDocument(createNewKey(docKey), document /*, false */
  -        );
  +        if (log.isInfoEnabled()) {
  +            log.info(debugHeader() + "Set document " + docKey);
  +        }
  +        putDocument(createNewKey(docKey), document /*, false */);
       }
   
       /**
  @@ -1542,6 +1579,9 @@
                                         "Mismatch type of meta data for 
document " + getCanonicalDocumentName(id));
               }
   
  +            if (log.isInfoEnabled()) {
  +                log.info(debugHeader() + "Set document meta " + id);
  +            }
               MetaSystemCollection metacol = getMetaSystemCollection();
               MetaData current = metacol.getDocumentMeta(this, id);
               current.copyDataFrom(meta);
  @@ -1565,6 +1605,9 @@
        * @param obj The Object to set
        */
       public final void setObject(Object key, XMLSerializable obj) throws 
DBException {
  +        if (log.isInfoEnabled()) {
  +            log.info(debugHeader() + "Set object " + key);
  +        }
           putObject(createNewKey(key), obj /*, false */ );
       }
   
  @@ -1587,7 +1630,9 @@
                   return;
               }
   
  -            log.info("Updating modified time for collection '" + 
getCanonicalName() + "'");
  +            if (log.isTraceEnabled()) {
  +                log.trace(debugHeader() + "Updating modified time for 
collection");
  +            }
               long now = System.currentTimeMillis();
               if (null == meta) {
                   meta = new MetaData(MetaData.COLLECTION, getCanonicalName(), 
now, now);
  @@ -1639,6 +1684,9 @@
           */
   
           // this is wrong.. but it should work for now...
  +        if (log.isTraceEnabled()) {
  +            log.trace(debugHeader() + "Updating modified time for document 
'" + id + "'");
  +        }
           long now = System.currentTimeMillis();
           if (null == meta) {
               meta = new MetaData(MetaData.DOCUMENT, path, now, now);
  
  
  

Reply via email to