Coverage Report - net.sourceforge.addam.ddlrun.custom.IDSRunLogger
 
Classes in this File Line Coverage Branch Coverage Complexity
IDSRunLogger
0%
0/25
0%
0/4
1.75
 
 1  
 //
 2  
 // Copyright (c) 2004, International Decision Systems
 3  
 // all rights reserved
 4  
 /*
 5  
  * Copyright (c) 2004 International Decision Systems, Inc.  All Rights Reserved.
 6  
  *
 7  
  * By using this Software, You acknowledge that the Software is a valuable asset
 8  
  * and trade secret of either International Decision Systems, Inc. ("IDSI") or a
 9  
  * third party supplier of IDSI and constitutes confidential and proprietary
 10  
  * information.
 11  
  *
 12  
  * NEITHER IDSI NOR ANY AGENT OR PERSON ACTING FOR OR WITH IDSI HAS MADE OR DOES
 13  
  * MAKE ANY STATEMENTS, AFFIRMATIONS, REPRESENTATIONS OR WARRANTIES WHATSOEVER
 14  
  * TO YOU, WHETHER EXPRESS OR IMPLIED, AS TO THE SOFTWARE, THE QUALITY OR
 15  
  * CONDITION OF THE SOFTWARE, OR THE OPERATING CHARACTERISTICS OR RELIABILITY OF
 16  
  * THE SOFTWARE, OR ITS SUITABILITY FOR ANY GENERAL OR PARTICULAR PURPOSE, OR AS
 17  
  * TO ANY OTHER MATTER WHATSOEVER; ANY AND ALL OTHER WARRANTIES INCLUDING
 18  
  * WITHOUT LIMITATION ANY WARRANTIES IMPLIED BY LAW, SUCH AS THE IMPLIED
 19  
  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND TITLE,
 20  
  * USE AND NON-INFRINGEMENT; ARE HEREBY EXPRESSLY DISCLAIMED AND EXCLUDED.
 21  
 */
 22  
 package net.sourceforge.addam.ddlrun.custom;
 23  
 
 24  
 
 25  
 import java.sql.Connection;
 26  
 import java.sql.PreparedStatement;
 27  
 import java.sql.SQLException;
 28  
 import java.sql.Timestamp;
 29  
 
 30  
 import net.sourceforge.addam.ddlrun.utils.RunLogger;
 31  
 
 32  
 /**
 33  
  * Logs events into a script table and updates the start point based on the group resource in another table.
 34  
  * The statements must include
 35  
  *
 36  
  * @author TIM3
 37  
  * @since Mar 6, 2005
 38  
  */
 39  
 public class IDSRunLogger implements RunLogger {
 40  
 
 41  
     public static final String INSERT_SCRIPT_LOG = "INSERT INTO SCRIPT_LOG(SCL_SCRIPT,SCL_RUN_DATE) VALUES(?,?)";
 42  
     public static final String UPDATE_VERSION = "UPDATE VERSION SET VRS_VERSION=?, VRS_START_FOLDER=?, VRS_MODIFIED_DATE=? WHERE VRS_TYPE='PF'";
 43  
     public static final String UNDEFINE_VERSION = "UPDATE VERSION SET VRS_VERSION='undefined', VRS_MODIFIED_DATE=? WHERE VRS_TYPE='PF'";
 44  
     private PreparedStatement undefineVersionStatement;
 45  
     private PreparedStatement insertScriptLogStatement;
 46  
     private PreparedStatement updateVersionStatement;
 47  
     private final Connection connection;
 48  
     private final String dbversion;
 49  
 
 50  
     /**
 51  
      * constructs a IDSRunLogger
 52  
      */
 53  0
     public IDSRunLogger(Connection connection, String version) {
 54  0
         this.connection = connection;
 55  0
         this.dbversion = (version != null) ? version : "not provided";
 56  0
     }
 57  
 
 58  
     public void logRunScript(String script, long time) throws SQLException {
 59  0
         if (insertScriptLogStatement == null) {
 60  0
             insertScriptLogStatement = connection.prepareStatement(INSERT_SCRIPT_LOG);
 61  
         }
 62  0
         insertScriptLogStatement.setString(1, script);
 63  0
         insertScriptLogStatement.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
 64  0
         insertScriptLogStatement.execute();
 65  0
         if (undefineVersionStatement == null) {
 66  
             // only mark the version undefined the first time you record a script run
 67  
             // it will later be marked with the correct version when we're done
 68  0
             undefineVersionStatement = connection.prepareStatement(UNDEFINE_VERSION);
 69  0
             undefineVersionStatement.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
 70  0
             undefineVersionStatement.execute();
 71  
         }
 72  0
         this.connection.commit();
 73  0
     }
 74  
 
 75  
     public void logRunComplete(String group, long time) throws Exception {
 76  0
         if (updateVersionStatement == null) {
 77  0
             updateVersionStatement = connection.prepareStatement(UPDATE_VERSION);
 78  
         }
 79  0
         updateVersionStatement.setString(1, dbversion);
 80  0
         updateVersionStatement.setString(2, group);
 81  0
         updateVersionStatement.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
 82  0
         updateVersionStatement.execute();
 83  0
         this.connection.commit();
 84  0
     }
 85  
 
 86  
     public void logRunFailure(String group, String script, Exception e) {
 87  0
         System.out.println("Execution failed for " + group + "/" + script);
 88  0
     }
 89  
 }