Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 92   Methods: 4
NCLOC: 32   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
XUpdateQueryServiceImpl.java - 83.3% 100% 87.5%
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: XUpdateQueryServiceImpl.java 541508 2007-05-25 01:54:12Z vgritsenko $
 18    */
 19   
 20    package org.apache.xindice.client.xmldb.services;
 21   
 22    import org.w3c.dom.Document;
 23    import org.xmldb.api.base.ErrorCodes;
 24    import org.xmldb.api.base.XMLDBException;
 25    import org.xmldb.api.modules.XMLResource;
 26    import org.xmldb.api.modules.XUpdateQueryService;
 27   
 28    /**
 29    * XML:DB XUpdateQueryService implementation that uses XML-RPC communication
 30    * with server
 31    *
 32    * @author <a href="mailto:james.bates@amplexor.com">James Bates</a>
 33    * @version $Revision: 541508 $, $Date: 2007-05-24 18:54:12 -0700 (Thu, 24 May 2007) $
 34    */
 35    public class XUpdateQueryServiceImpl extends QueryService implements XUpdateQueryService {
 36   
 37    /**
 38    * Creates new XUpdateQueryService
 39    */
 40  3418 public XUpdateQueryServiceImpl() {
 41   
 42  3418 super();
 43  3418 queryLang = "XUpdate";
 44    }
 45   
 46    /**
 47    * Extracts modified count from the pseudo-result returned from query
 48    */
 49  12 private long getResultCount(XMLResource resource) throws XMLDBException {
 50   
 51  12 Document doc = (Document) resource.getContentAsDOM();
 52   
 53    /**
 54    * Modified by tlr - server sends:
 55    * <src:modified xmlns:src="http://xml.apache.org/xindice/Query">1</src:modified>
 56    * which is not properly decoded by original code (drills one level too deep)
 57    // Get the src:modified element
 58    Node node = doc.getDocumentElement().getFirstChild();
 59   
 60    // The count is a text node within the element.
 61    String count = node.getFirstChild().getNodeValue();
 62    **/
 63  12 String count = null;
 64  12 try {
 65  12 count = doc.getDocumentElement().getFirstChild().getNodeValue();
 66    } catch (Exception e) {
 67  0 throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Unable to retrieve <src:modified> element content from server result", e);
 68    }
 69   
 70  12 try {
 71  12 return Long.parseLong(count);
 72    } catch (Exception e) {
 73  0 throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "<src:modified> in server result did not contain a valid count", e);
 74    }
 75    }
 76   
 77    /**
 78    * Performs an XUpdate operation on the entire collection
 79    */
 80  6 public long update(String query) throws XMLDBException {
 81   
 82  6 return getResultCount((XMLResource) query(query).getResource(0));
 83    }
 84   
 85    /**
 86    * Preforms an XUpdate operation on the specified document
 87    */
 88  6 public long updateResource(String name, String query) throws XMLDBException {
 89   
 90  6 return getResultCount((XMLResource) queryResource(name, query).getResource(0));
 91    }
 92    }