1 |
package tools.trunk; |
2 |
|
3 |
import tools.trunk.*; |
4 |
import java.sql.*; |
5 |
import java.io.*; |
6 |
|
7 |
public class Report { |
8 |
|
9 |
private Connection myConnection; |
10 |
private mySQLConnect SQLC; |
11 |
private PrintStream Log; |
12 |
private int reportLevel; |
13 |
private String reportTbl; |
14 |
private String hostName; |
15 |
private String clientName; |
16 |
|
17 |
public Report(String connFile, String logFile, int reportLevel) { |
18 |
|
19 |
SQLC = new mySQLConnect(); |
20 |
SQLC.readConnectionFile(connFile); |
21 |
myConnection = SQLC.openConnection(); |
22 |
|
23 |
try { |
24 |
Log = new PrintStream(new FileOutputStream(logFile)); |
25 |
} catch (Exception e) { |
26 |
System.out.println(e); |
27 |
} |
28 |
|
29 |
this.reportLevel = reportLevel; |
30 |
this.reportTbl = "report"; |
31 |
clientName = Machine.getClient(); |
32 |
hostName = SQLC.getHost(); |
33 |
|
34 |
} |
35 |
|
36 |
public Report(String connFile, String logFile, int reportLevel, String reportTable) { |
37 |
|
38 |
SQLC = new mySQLConnect(); |
39 |
SQLC.readConnectionFile(connFile); |
40 |
myConnection = SQLC.openConnection(); |
41 |
|
42 |
try { |
43 |
Log = new PrintStream(new FileOutputStream(logFile)); |
44 |
} catch (Exception e) { |
45 |
System.out.println(e); |
46 |
} |
47 |
|
48 |
this.reportLevel = reportLevel; |
49 |
this.reportTbl = reportTable; |
50 |
clientName = Machine.getClient(); |
51 |
hostName = SQLC.getHost(); |
52 |
|
53 |
} |
54 |
|
55 |
/** Sets the reportLevel, so that only messages below or equal the level given are displayed. |
56 |
The following levels are available: (0 is default - no messages) |
57 |
3 - talkative mode |
58 |
2 - normal mode |
59 |
1 - basic mode |
60 |
0 - silent mode |
61 |
This means by a higher level you get more detailed information, while on a reportLevel |
62 |
of 0 only the most basic results and errors are displayed */ |
63 |
public void setReportLevel(int newLevel) { reportLevel = newLevel; } |
64 |
|
65 |
public int getReportLevel() { return reportLevel; } |
66 |
|
67 |
public void print(String text, int level) { |
68 |
if (level<=reportLevel) { |
69 |
System.out.print(text); |
70 |
} // end if level of the curent message is above the current level |
71 |
} // end of report |
72 |
|
73 |
public void println(String text, int level) { |
74 |
if (level<=reportLevel) { |
75 |
System.out.println(text); |
76 |
} // end if level of the curent message is above the current level |
77 |
} // end of report |
78 |
|
79 |
public void printLog(String text, int level) { |
80 |
if (level<=reportLevel) { |
81 |
Log.print(text); |
82 |
} // end if level of the curent message is above the current level |
83 |
} // end of report |
84 |
|
85 |
public void printlnLog(String text, int level) { |
86 |
if (level<=reportLevel) { |
87 |
Log.println(text); |
88 |
} // end if level of the curent message is above the current level |
89 |
} // end of report |
90 |
|
91 |
public void newProc(String description, int level) { |
92 |
|
93 |
if (level<=reportLevel) { |
94 |
try { |
95 |
Statement S = myConnection.createStatement(); |
96 |
S.executeUpdate("INSERT INTO "+reportTbl+" (Client, Host, Description, Start) VALUES (\""+clientName+"\", \""+hostName+"\", \""+description+"\", NOW());"); |
97 |
S.close(); |
98 |
} catch (SQLException E) { |
99 |
System.out.println("SQLException:\t" + E.getMessage()); |
100 |
System.out.println("SQLState:\t" + E.getSQLState()); |
101 |
System.out.println("VendorError: \t" + E.getErrorCode()); |
102 |
} |
103 |
} |
104 |
|
105 |
} |
106 |
|
107 |
public void updateProc(int level) { |
108 |
|
109 |
if (level<=reportLevel) { |
110 |
try { |
111 |
Statement S = myConnection.createStatement(); |
112 |
S.executeUpdate("UPDATE "+reportTbl+" SET End = NOW(), Total = TIMEDIFF(End, Start) WHERE ID = LAST_INSERT_ID();"); |
113 |
S.close(); |
114 |
} catch (SQLException E) { |
115 |
System.out.println("SQLException:\t" + E.getMessage()); |
116 |
System.out.println("SQLState:\t" + E.getSQLState()); |
117 |
System.out.println("VendorError: \t" + E.getErrorCode()); |
118 |
} |
119 |
} |
120 |
|
121 |
} |
122 |
|
123 |
public void updateProc(String description, int level) { |
124 |
|
125 |
if (level<=reportLevel) { |
126 |
try { |
127 |
Statement S = myConnection.createStatement(); |
128 |
S.executeUpdate("UPDATE "+reportTbl+" SET End = NOW(), Total = TIMEDIFF(End, Start) WHERE (Client = \""+clientName+"\") AND (Host = \""+hostName+"\") AND (Description = \""+description+"\");"); |
129 |
S.close(); |
130 |
} catch (SQLException E) { |
131 |
System.out.println("SQLException:\t" + E.getMessage()); |
132 |
System.out.println("SQLState:\t" + E.getSQLState()); |
133 |
System.out.println("VendorError: \t" + E.getErrorCode()); |
134 |
} |
135 |
} |
136 |
|
137 |
} |
138 |
|
139 |
public void close() { |
140 |
|
141 |
SQLC.closeConnection(myConnection); |
142 |
Log.close(); |
143 |
|
144 |
} |
145 |
|
146 |
} |