Clover coverage report - Replica - 1.0-Alpha
Coverage timestamp: Dom Fev 1 2004 17:00:58 WET
file stats: LOC: 129   Methods: 9
NCLOC: 82   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
JDBCHandle.java 0% 0% 0% 0%
coverage
 1   
 package nmp.dbms.JDBC;
 2   
 
 3   
 import java.io.FileWriter;
 4   
 import java.io.IOException;
 5   
 import java.io.PrintWriter;
 6   
 import java.sql.SQLException;
 7   
 
 8   
 import nmp.dbms.SQLVectorResult;
 9   
 
 10   
 public class JDBCHandle
 11   
 //    implements DBHandle
 12   
 {
 13   
     Jdbc_Sql database;
 14   
     String dbName;
 15   
     
 16  0
     public JDBCHandle( String driverName, String dbName, String url, String user, String passwd)
 17   
             throws Exception {
 18  0
         this.dbName = dbName;
 19  0
         database = new Jdbc_Sql( driverName, url, user, passwd, true, true, new PrintWriter( new FileWriter( "\\tmp\\SQLdebug.log", true), true), 1);
 20   
     }
 21   
     
 22   
     /**
 23   
      * Returns the name of the associated database
 24   
      */
 25  0
     public String dbName() {
 26  0
         return dbName;
 27   
     }
 28   
 
 29   
     /**
 30   
      * Executes a SQL query, returning all found rows
 31   
      */
 32  0
     public SQLVectorResult executeQuery( String sqlstring)
 33   
             throws SQLException {
 34  0
         return database.executeQuery ( sqlstring);
 35   
     }
 36   
 
 37   
     /**
 38   
      * Executes a SQL query, returning the first maxcount rows
 39   
      */
 40  0
     public SQLVectorResult executeQuery( String sqlstring, int maxcount)
 41   
             throws SQLException {
 42  0
         return database.executeQuery ( sqlstring, maxcount);
 43   
     }
 44   
         
 45   
     /**
 46   
      * Gets more rows that conform to the executed query
 47   
      */
 48  0
     public boolean executeQuery( SQLVectorResult result, int maxcount)
 49   
             throws SQLException {
 50  0
         return database.executeQuery ( result, maxcount);
 51   
     }
 52   
 
 53   
     /**
 54   
      * Executes a SQL update, returning the number of modified rows
 55   
      */
 56  0
     public int executeUpdate(String sqlstring)
 57   
             throws SQLException {
 58  0
         return database.executeUpdate ( sqlstring);
 59   
     }
 60   
 
 61   
     
 62   
     /**
 63   
      * Serialize the state of the database
 64   
      * 
 65   
      * @param oos Output stream to serialize state
 66   
      * @param tables Name of the table from which the state should be serialized
 67   
      */
 68  0
     public void serialize( java.io.ObjectOutputStream oos, String[] tables)
 69   
             throws IOException {
 70  0
         for( int i = 0; i < tables.length; i++) {
 71  0
             try {
 72  0
                 SQLVectorResult result = executeQuery( "select * from " + tables[i] + ";", 100);
 73  0
                 while( result != null && result.rows != null) {
 74  0
                     String baseStr = "insert into " + tables[i] + "(";
 75  0
                     for( int j = 0; j < result.columnName.length; j++)
 76  0
                         if( j > 0)
 77  0
                             baseStr = baseStr + "," + result.columnName[j];
 78   
                         else
 79  0
                             baseStr = baseStr + result.columnName[j];
 80  0
                     baseStr = baseStr + ") values (";
 81  0
                     for( int j = 0; j < result.rows.size(); j++) {
 82  0
                         String str = baseStr;
 83  0
                         Object[] row = (Object[])result.rows.elementAt( j);
 84  0
                         for( int k = 0; k < row.length; k++) 
 85  0
                             if( k > 0)
 86  0
                                 str = str + ", '" + row[k] + "'";
 87   
                             else
 88  0
                                 str = str + " '" + row[k] + "'";
 89  0
                         str = str + ");";
 90  0
                         oos.writeUTF( str);
 91   
                     }
 92  0
                     if( ! executeQuery( result, 100))
 93  0
                         break;
 94   
                 }
 95   
             } catch( SQLException ex) {
 96   
                 /* do nothing */
 97   
             }
 98   
         }
 99  0
         oos.writeUTF( "");
 100   
     }
 101   
 
 102   
     /**
 103   
      * De-serialize the state of the database
 104   
      * 
 105   
      * @param oos Output stream to serialize state
 106   
      */
 107  0
     public void unserialize( java.io.ObjectInputStream ois)
 108   
             throws IOException {
 109  0
         for( ; ; ) {
 110  0
             String str = ois.readUTF();
 111  0
             if( str.equals( ""))
 112  0
                 break;
 113  0
             try {
 114  0
                 executeUpdate( str);
 115   
             }catch( SQLException ex) {
 116   
                 /* do nothing */
 117   
             }
 118   
         }
 119   
     }
 120   
 
 121   
     /**
 122   
      * Closes this handle. After calling this method no other DB method should be called.
 123   
      */
 124  0
     public void close() {
 125  0
         database.closeAll();
 126   
     }
 127   
 
 128   
 }
 129