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 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
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 | |
|
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 | |
|
67 | |
|
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 | |
} |