CAS Unit Tests
Clover coverage report - CAS Unit Tests
Coverage timestamp: Mon Jul 4 2005 18:13:17 CDT
file stats: LOC: 107   Methods: 4
NCLOC: 73   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ExactComparison.java 0% 0% 0% 0%
coverage
 1    /*
 2    * Portions of this file Copyright 1999-2005 University of Chicago
 3    * Portions of this file Copyright 1999-2005 The University of Southern California.
 4    *
 5    * This file or a portion of this file is licensed under the
 6    * terms of the Globus Toolkit Public License, found at
 7    * http://www.globus.org/toolkit/download/license.html.
 8    * If you redistribute this file, with or without
 9    * modifications, you must include this notice in the file.
 10    */
 11    package org.globus.cas.impl.databaseAccess;
 12   
 13    import java.sql.Connection;
 14    import java.sql.Statement;
 15    import java.sql.SQLException;
 16    import java.sql.ResultSet;
 17   
 18    import org.apache.commons.logging.Log;
 19    import org.apache.commons.logging.LogFactory;
 20   
 21    import org.globus.cas.types.ObjectData;
 22   
 23    import org.globus.cas.impl.service.ObjectComparison;
 24   
 25    import org.globus.util.I18n;
 26   
 27    /**
 28    * Exact matching
 29    */
 30    public class ExactComparison extends ObjectComparison {
 31   
 32    static Log logger = LogFactory.getLog(ExactComparison.class.getName());
 33   
 34    private static I18n i18n =
 35    I18n.getI18n("org.globus.cas.impl.databaseAccess.errors",
 36    ExactComparison.class.getClassLoader());
 37   
 38  0 public ObjectData[] matchingSubset(ObjectData objData)
 39    throws CasDBException {
 40  0 return null;
 41    }
 42   
 43  0 public ObjectData[] matchingSuperset(ObjectData objData)
 44    throws CasDBException {
 45  0 return null;
 46    }
 47   
 48    // Policy object, request object
 49  0 public boolean objectMatches(ObjectData policyObj, ObjectData requestObj)
 50    throws CasDBException {
 51   
 52    // if not same namespace return false
 53  0 if (!policyObj.getObjectNamespace().equals(
 54    requestObj.getObjectNamespace()))
 55  0 return false;
 56   
 57  0 if (!policyObj.getObjectName().equals(requestObj.getObjectName()))
 58  0 return false;
 59   
 60  0 return true;
 61    }
 62   
 63  0 public boolean objectExists(ObjectData reqObj)
 64    throws CasDBException {
 65   
 66  0 String query = "select * from" + CasDBConstants.TABLE_OBJECT
 67    + " where (" + CasDBConstants.COL_NS_NICKNAME + "='"
 68    + reqObj.getObjectNamespace() + "') and ("
 69    + CasDBConstants.COL_OBJECT_NAME + "='" + reqObj.getObjectName()
 70    + "')";
 71   
 72  0 Connection connection = CasDBStorage.getDBConnection();
 73  0 Statement statement = null;
 74  0 ResultSet resultSet = null;
 75  0 try {
 76  0 statement = connection.createStatement();
 77  0 resultSet = statement.executeQuery(query);
 78  0 if ((resultSet!=null) && (resultSet.next()))
 79  0 return true;
 80    }
 81    catch (SQLException exp) {
 82  0 logger.error(i18n.getMessage("existenceErr", new Object[]
 83    { "object", query} ),
 84    exp);
 85  0 throw new CasDBException(i18n.getMessage("objExistenceErr",
 86    new Object[] {
 87    "object", "" })
 88    + exp.getMessage(), exp);
 89    }
 90    finally {
 91    // retuning connection irrespective of whether stmt
 92    // and result set are closed or not.
 93  0 CasDBStorage.returnDBConnection(connection);
 94  0 try {
 95  0 if (resultSet != null)
 96  0 resultSet.close();
 97  0 if (statement != null)
 98  0 statement.close();
 99    }
 100    catch (SQLException exp) {
 101  0 logger.warn(i18n.getMessage("existenceCloseErr", "object"),
 102    exp);
 103    }
 104    }
 105  0 return false;
 106    }
 107    }