1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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 public IDSRunLogger(Connection connection, String version) {
54 this.connection = connection;
55 this.dbversion = (version != null) ? version : "not provided";
56 }
57
58 public void logRunScript(String script, long time) throws SQLException {
59 if (insertScriptLogStatement == null) {
60 insertScriptLogStatement = connection.prepareStatement(INSERT_SCRIPT_LOG);
61 }
62 insertScriptLogStatement.setString(1, script);
63 insertScriptLogStatement.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
64 insertScriptLogStatement.execute();
65 if (undefineVersionStatement == null) {
66
67
68 undefineVersionStatement = connection.prepareStatement(UNDEFINE_VERSION);
69 undefineVersionStatement.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
70 undefineVersionStatement.execute();
71 }
72 this.connection.commit();
73 }
74
75 public void logRunComplete(String group, long time) throws Exception {
76 if (updateVersionStatement == null) {
77 updateVersionStatement = connection.prepareStatement(UPDATE_VERSION);
78 }
79 updateVersionStatement.setString(1, dbversion);
80 updateVersionStatement.setString(2, group);
81 updateVersionStatement.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
82 updateVersionStatement.execute();
83 this.connection.commit();
84 }
85
86 public void logRunFailure(String group, String script, Exception e) {
87 System.out.println("Execution failed for " + group + "/" + script);
88 }
89 }