CAS Unit Tests
Clover coverage report - CAS Unit Tests
Coverage timestamp: Mon Jul 4 2005 18:13:17 CDT
file stats: LOC: 136   Methods: 2
NCLOC: 110   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DatabaseDelete.java 41.7% 29% 100% 32.9%
coverage 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   
 17    import java.io.IOException;
 18    import java.io.FileInputStream;
 19    import java.io.FileNotFoundException;
 20   
 21    import java.util.Properties;
 22   
 23    public class DatabaseDelete {
 24   
 25  2 public static void main(String[] args) throws Exception {
 26   
 27  2 if (args.length < 1) {
 28  0 System.out.println("Usage: DatabaseDelete dbPropFile");
 29  0 System.exit(0);
 30    }
 31   
 32  2 Properties prop = new Properties();
 33  2 try {
 34  2 prop.load(new FileInputStream(args[0]));
 35    } catch (FileNotFoundException fnfe) {
 36  0 System.err.println("Error: Database properties file "
 37    + args[0] + " not found");
 38  0 System.exit(-1);
 39    } catch (IOException ioe) {
 40  0 System.err.println("Error loading file " + args[0] + "\n"
 41    + ioe.getMessage());
 42  0 System.exit(-1);
 43    }
 44   
 45  2 CasDBOptions casDbOption =
 46    new CasDBOptions(prop.getProperty("dbDriver"),
 47    prop.getProperty("dbConnectionURL"),
 48    prop.getProperty("dbUsername"),
 49    prop.getProperty("dbPassword"));
 50  2 String val = prop.getProperty("activeConnections");
 51  2 if (val != null) {
 52  0 casDbOption.setActiveConnections((new Integer(val)).intValue());
 53    }
 54   
 55  2 val = prop.getProperty("onExhaustAction");
 56  2 if (val != null) {
 57  0 casDbOption.setOnExhaustAction((new Integer(val)).byteValue());
 58    }
 59   
 60  2 val = prop.getProperty("maxWait");
 61  2 if (val != null) {
 62  0 casDbOption.setMaxWait((new Integer(val)).longValue());
 63    }
 64   
 65  2 val = prop.getProperty("idleConnections");
 66  2 if (val != null) {
 67  0 casDbOption.setIdleConnections((new Integer(val)).intValue());
 68    }
 69   
 70  2 try {
 71  2 CasDBStorage.setupDBConnection(casDbOption);
 72    } catch (CasDBException exp) {
 73  0 System.err.println("Erorr initializing database "
 74    + exp.getMessage());
 75  0 System.exit(-1);
 76    }
 77  2 try {
 78  2 deleteAllEntries();
 79    } catch (CasDBException exp) {
 80  0 System.err.println("Erorr deleting entries in database "
 81    + exp.getMessage());
 82  0 System.exit(-1);
 83    }
 84   
 85  0 System.out.println("Database entries succesfully deleted");
 86    }
 87   
 88  2 private static void deleteAllEntries() throws CasDBException {
 89   
 90  2 Connection connection = CasDBStorage.getDBConnection();
 91  0 Statement statement = null;
 92  0 try {
 93  0 statement = connection.createStatement();
 94  0 statement.addBatch("delete from " + CasDBConstants.TABLE_OBJECT);
 95  0 statement.addBatch("delete from " +
 96    CasDBConstants.TABLE_OBJECTGP_ENTRY);
 97  0 statement.addBatch("delete from " + CasDBConstants.TABLE_OBJECTGP);
 98  0 statement.addBatch("delete from "
 99    + CasDBConstants.TABLE_NAMESPACE);
 100  0 statement.addBatch("delete from "
 101    + CasDBConstants.TABLE_USERGP_ENTRY);
 102  0 statement.addBatch("delete from " + CasDBConstants.TABLE_USERGP);
 103  0 statement.addBatch("delete from " + CasDBConstants.TABLE_USER);
 104  0 statement.addBatch("delete from "
 105    + CasDBConstants.TABLE_TRUSTANCHOR);
 106  0 statement.addBatch("delete from " +
 107    CasDBConstants.TABLE_SERVICEACTIONGP_ENTRY);
 108  0 statement.addBatch("delete from " +
 109    CasDBConstants.TABLE_SERVICEACTIONGP);
 110  0 statement.addBatch("delete from " +
 111    CasDBConstants.TABLE_SERVICETYPE_ACTION);
 112  0 statement.addBatch("delete from "
 113    + CasDBConstants.TABLE_SERVICETYPE);
 114  0 statement.addBatch("delete from " + CasDBConstants.TABLE_POLICY);
 115    // sequence
 116  0 statement.addBatch("drop sequence service_action_seq");
 117  0 statement.addBatch("drop sequence object_seq");
 118  0 statement.addBatch("drop sequence policy_seq");
 119  0 statement.addBatch("create sequence service_action_seq");
 120  0 statement.addBatch("create sequence object_seq");
 121  0 statement.addBatch("create sequence policy_seq");
 122  0 statement.executeBatch();
 123    } catch (SQLException exp) {
 124  0 throw new CasDBException(exp.getMessage(), exp);
 125    } finally {
 126  0 CasDBStorage.returnDBConnection(connection);
 127  0 try {
 128  0 if (statement != null)
 129  0 statement.close();
 130    }
 131    catch (SQLException exp) {
 132  0 System.err.println("Error closing stament");
 133    }
 134    }
 135    }
 136    }