CAS Unit Tests
Clover coverage report - CAS Unit Tests
Coverage timestamp: Mon Jul 4 2005 18:13:17 CDT
file stats: LOC: 241   Methods: 4
NCLOC: 182   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ServiceTypeDataHandler.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.ResultSet;
 15    import java.sql.Statement;
 16    import java.sql.SQLException;
 17   
 18    import java.util.Vector;
 19   
 20    import org.apache.commons.logging.Log;
 21    import org.apache.commons.logging.LogFactory;
 22   
 23    import org.globus.cas.impl.CasConstants;
 24   
 25    import org.globus.cas.types.CasObjectData;
 26    import org.globus.cas.types.ArrayOfString;
 27    import org.globus.cas.types.ServiceTypeData;
 28   
 29    import org.globus.util.I18n;
 30   
 31    /**
 32    * Describes the data needed for service type
 33    */
 34    public class ServiceTypeDataHandler {
 35   
 36    static Log logger =
 37    LogFactory.getLog(ServiceTypeDataHandler.class.getName() );
 38   
 39    private static I18n i18n =
 40    I18n.getI18n("org.globus.cas.impl.databaseAccess.errors",
 41    ServiceTypeDataHandler.class.getClassLoader());
 42   
 43    /**
 44    * Insert into service type table
 45    */
 46  0 public static String storeObject(ServiceTypeData serviceTypeData)
 47    throws CasDBException {
 48   
 49  0 logger.debug("Service type data storeObject called");
 50  0 Connection connection = CasDBStorage.getDBConnection();
 51  0 String serviceTypeName = serviceTypeData.getName();
 52    // Store service type data
 53  0 String query = "insert into " + CasDBConstants.TABLE_SERVICETYPE + " ("
 54    + CasDBConstants.COL_SERVICETYPE_NAME + ") values ('"
 55    + serviceTypeName + "')";
 56  0 Statement statement = null;
 57  0 try {
 58  0 statement = connection.createStatement();
 59  0 logger.debug("store query is " + query);
 60  0 statement.executeUpdate(query);
 61    }
 62    catch (SQLException exp) {
 63  0 logger.error(i18n.getMessage("storeErr", new Object[] {
 64    "service type", query }), exp);
 65  0 throw new CasDBException(i18n.getMessage("storeErr", new Object[] {
 66    "service type", exp.getMessage() }), exp);
 67    }
 68    finally {
 69    // returning connection irrespective of whether stmt
 70    // and result set are closed or not.
 71  0 CasDBStorage.returnDBConnection(connection);
 72  0 try {
 73  0 if (statement != null)
 74  0 statement.close();
 75    }
 76    catch (SQLException exp) {
 77  0 logger.warn(i18n.getMessage("storeErrClose", "service type "),
 78    exp);
 79    }
 80    }
 81  0 return serviceTypeName;
 82    }
 83   
 84    /**
 85    * List of service type
 86    */
 87  0 public static String[] list() throws CasDBException {
 88   
 89  0 String query = "select" + CasDBConstants.COL_SERVICETYPE_NAME + " from"
 90    + CasDBConstants.TABLE_SERVICETYPE;
 91  0 return CasDBStorage.runListQuery(query,
 92    CasDBConstants.COL_SERVICETYPE_NAME);
 93    }
 94   
 95    /**
 96    * Retieves service type data
 97    * Picks up values from service type table and service type action table
 98    */
 99  0 public static CasObjectData retrieveObject(String name)
 100    throws CasDBException {
 101   
 102  0 ServiceTypeData returnObject = null;
 103  0 Vector actionNames = null;
 104  0 Connection connection = CasDBStorage.getDBConnection();
 105   
 106  0 String query = "select" + CasDBConstants.COL_ACTION_NAME + " from"
 107    + CasDBConstants.TABLE_SERVICETYPE_ACTION + " where"
 108    + CasDBConstants.COL_SERVICETYPE_NAME + "='" + name.trim() + "'";
 109   
 110  0 Statement statement = null;
 111  0 ResultSet resultSet = null;
 112  0 try {
 113  0 statement = connection.createStatement();
 114  0 resultSet = statement.executeQuery(query);
 115  0 if ((resultSet!=null) && (resultSet.next())) {
 116  0 actionNames = new Vector(resultSet.getFetchSize());
 117  0 do {
 118  0 actionNames.add(resultSet.getString(
 119    CasDBConstants.COL_ACTION_NAME.trim()));
 120  0 } while (resultSet.next());
 121    }
 122    }
 123    catch (SQLException exp) {
 124  0 CasDBStorage.returnDBConnection(connection);
 125  0 logger.error(i18n.getMessage("retrieveErr", new Object[] {
 126    "service type", query }), exp);
 127  0 throw new CasDBException(i18n.getMessage("retrieveErr",
 128    new Object[] { "service type", exp.getMessage()}), exp);
 129    }
 130    finally {
 131  0 try {
 132  0 if (resultSet != null)
 133  0 resultSet.close();
 134  0 if (statement != null)
 135  0 statement.close();
 136    }
 137    catch (SQLException exp) {
 138  0 logger.warn(i18n.getMessage("retrieveErrClose",
 139    "service type"), exp);
 140    }
 141    }
 142   
 143  0 ArrayOfString arrayOfActionNames = null;
 144  0 if (actionNames != null) {
 145  0 String stringActionNames[] = new String[actionNames.size()];
 146  0 actionNames.toArray(stringActionNames);
 147  0 arrayOfActionNames = new ArrayOfString(stringActionNames);
 148    }
 149   
 150  0 query = "select * from" + CasDBConstants.TABLE_SERVICETYPE + " where"
 151    + CasDBConstants.COL_SERVICETYPE_NAME + " = '" + name.trim() + "'";
 152   
 153  0 try {
 154  0 statement = connection.createStatement();
 155  0 resultSet = statement.executeQuery(query);
 156  0 if (resultSet!=null) {
 157  0 if (resultSet.next()) {
 158  0 returnObject = new ServiceTypeData();
 159  0 returnObject.setName(resultSet.getString(
 160    CasDBConstants.COL_SERVICETYPE_NAME.trim()));
 161  0 returnObject.setActionNames(arrayOfActionNames);
 162    }
 163    }
 164    }
 165    catch (SQLException exp) {
 166  0 logger.error("Error retrieving service type data\n" + query, exp);
 167  0 logger.error(i18n.getMessage("retrieveErr", new Object[] {
 168    "service type", query }), exp);
 169  0 throw new CasDBException(i18n.getMessage("retrieveErr",
 170    new Object[] { "service type", exp.getMessage()}), exp);
 171    }
 172    finally {
 173    // returning connection irrespective of whether stmt
 174    // and result set are closed or not.
 175  0 CasDBStorage.returnDBConnection(connection);
 176  0 try {
 177  0 if (resultSet != null)
 178  0 resultSet.close();
 179  0 if (statement != null)
 180  0 statement.close();
 181    }
 182    catch (SQLException exp) {
 183  0 logger.warn(i18n.getMessage("retrieveErrClose",
 184    "service type"), exp);
 185    }
 186    }
 187  0 return returnObject;
 188    }
 189   
 190    /**
 191    * Deletes service type data
 192    * Manipulates service type table
 193    */
 194  0 public static void deleteObject(String serviceName) throws CasDBException {
 195   
 196    // Service type can be a member of object group, no SQL constraint
 197    // defines that. So check.
 198  0 if (ObjectGroupDataHandler.isMember(serviceName.trim(),
 199    CasConstants.SERVICETYPE_SPEC)) {
 200  0 String errMesg = i18n.getMessage("memberOfGpErr", new Object[] {
 201    "Service type", serviceName.trim(), "object"});
 202  0 logger.debug(errMesg);
 203  0 throw new CasDBException(errMesg);
 204    }
 205   
 206  0 Connection connection = CasDBStorage.getDBConnection();
 207  0 String query = "delete from" + CasDBConstants.TABLE_SERVICETYPE
 208    + " where" + CasDBConstants.COL_SERVICETYPE_NAME + " ='"
 209    + serviceName.trim() + "'";
 210  0 Statement statement = null;
 211  0 int result = -1;
 212  0 try {
 213  0 statement = connection.createStatement();
 214  0 result = statement.executeUpdate(query);
 215    }
 216    catch (SQLException exp) {
 217  0 logger.error(i18n.getMessage("delObjErr", new Object[] {
 218    "servicetype", query }), exp);
 219  0 throw new CasDBException(i18n.getMessage("delObjErr",
 220    new Object[] { "servicetype", exp.getMessage()}), exp);
 221    }
 222    finally {
 223    // returning connection irrespective of whether stmt
 224    // and result set are closed or not.
 225  0 CasDBStorage.returnDBConnection(connection);
 226  0 try {
 227  0 if (statement != null)
 228  0 statement.close();
 229    }
 230    catch (SQLException exp) {
 231  0 logger.warn(i18n.getMessage("delObjErrClose", "servicetype"),
 232    exp);
 233    }
 234    }
 235  0 if (result <= 0) {
 236  0 String err = i18n.getMessage("serviceTypeDelError", serviceName);
 237  0 logger.error(err);
 238  0 throw new CasDBException(err);
 239    }
 240    }
 241    }