ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/reports/DBReporter2/DBReporter.java
(Generate patch)

Comparing projects/cms/source/reports/DBReporter2/DBReporter.java (file contents):
Revision 1.1 by pjm2, Sat Feb 3 14:56:14 2001 UTC vs.
Revision 1.5 by pjm2, Sat Feb 3 22:11:39 2001 UTC

# Line 1 | Line 1
1   import java.sql.*;
2   import java.util.*;
3 + import java.io.*;
4  
5 + // DBReporter class - establishes the database connection and is
6 + // used to run all of the reports.
7   public class DBReporter {
8      
9 +    // Constructor.
10      public DBReporter(long startTime, long endTime) {
11          _startTime = startTime;
12          _endTime = endTime;
13      }
14 <    
15 <    public void runReports(ReportList reports) throws SQLException, Exception {
14 >
15 >    // Runs all of the reports for each distinct machine name.    
16 >    public void runReports(ReportList reports, String webDir) throws SQLException, Exception {
17          
18          System.out.println("Preparing reports ...");
19  
20 <        // Establish the database connection.
20 >        // Get the MySQL DB driver.
21          try {
22              Class.forName("org.gjt.mm.mysql.Driver").newInstance();
23          }
24          catch (Exception e){
25              throw new Exception("Could not find the MySQL driver: " + e);
26          }
27 <        
27 >
28          try {
29              _conn = DriverManager.getConnection("jdbc:mysql://localhost/co600_10_db?user=co600_10&password=bung-i-scream");
30              _stmt = _conn.createStatement();
# Line 28 | Line 33 | public class DBReporter {
33              throw new SQLException("Could not connect to the database: " + e);
34          }
35          
31        
36          // This is essential to prevent temporary tables running out of
37          // physical memory for large reports.  With this set to 1, all
38          // temporary tables shall be written to disk.  This is a daily
# Line 42 | Line 46 | public class DBReporter {
46              System.out.println("Some of the following i-scream reports may fail if there is insufficient memory.");
47          }
48          
49 +        // Get a list of distinct machine names.
50          LinkedList machines = this.getDistinctMachines();
51          
52          System.out.println("Readying reports for " + machines.size() + " machines.");
53          
54 <        ReportMaker rm = null;
54 >        // Produce all of the reports for each machine.
55 >        ReportMaker rm = new ReportMaker(_stmt, webDir, DateUtils.shortDateString(_startTime), _startTime, _endTime);
56          Iterator machineIt = machines.iterator();
57          while (machineIt.hasNext()) {
52            rm = new ReportMaker(_stmt, DateUtils.shortDateString(_startTime), _startTime, _endTime);
58              String machine = (String)machineIt.next();
59              rm.produce(reports, machine);
60          }
61          
62 +        
63 +        
64 +        // Now output the files for PHP searching.
65 +        // - print report list stuff out to reports.inc
66 +        System.out.println("Writing report.inc");
67 +        File reportInc = new File(new File(webDir), "report.inc");
68 +        try {
69 +            BufferedWriter bw = new BufferedWriter(new FileWriter(reportInc));
70 +            Iterator reportIt = reports.iterator();
71 +            while (reportIt.hasNext()) {
72 +                Report report = (Report)reportIt.next();
73 +                bw.write("<option value=\"" + report.getReportField() + "\">" + report.getFriendlyName() + "</option>");
74 +            }
75 +            bw.flush();
76 +            bw.close();
77 +        }
78 +        catch (IOException e) {
79 +            System.out.println("Unable to create" + reportInc);
80 +        }
81 +        
82 +        
83 +        // - print machine list stuff out to machine_name.inc
84 +        System.out.println("Writing machine_name.inc");
85 +        File machineInc = new File(new File(webDir), "machine_name.inc");
86 +        try {
87 +            BufferedWriter bw = new BufferedWriter(new FileWriter(machineInc));
88 +            machineIt = machines.iterator();
89 +            while (machineIt.hasNext()) {
90 +                String machine = (String)machineIt.next();
91 +                bw.write("<option value=\"" + machine + "\">" + machine + "</option>");
92 +            }
93 +            bw.flush();
94 +            bw.close();
95 +        }
96 +        catch (IOException e) {
97 +            System.out.println("Unable to create" + machineInc);
98 +        }
99 +        
100 +        
101 +        // - print current day out to day.inc
102 +        System.out.println("Writing day.inc");
103 +        File dayInc = new File(new File(webDir), "day.inc");
104 +        try {
105 +            BufferedWriter bw = new BufferedWriter(new FileWriter(dayInc));
106 +            bw.write("<? $day = \"" + DateUtils.shortDateString(_startTime) + "\"; ?>");
107 +            bw.flush();
108 +            bw.close();
109 +        }
110 +        catch (IOException e) {
111 +            System.out.println("Unable to create" + dayInc);
112 +        }
113 +        
114 +        
115      }
116      
117 +    
118 +    // Returns a list of distinct machine names.
119      private LinkedList getDistinctMachines() throws SQLException {
120          
121          LinkedList machines = new LinkedList();
# Line 65 | Line 125 | public class DBReporter {
125                  String machine_name = rs.getString("machine_name");
126                  machines.add(machine_name);
127              }
128 +            rs.close();
129          }
130          catch (SQLException e) {
131              throw new SQLException("Unable to find distinct machine names: " + e);
# Line 72 | Line 133 | public class DBReporter {
133          
134          return machines;
135      }
136 +    
137 +    
138      
139      private long _startTime;
140      private long _endTime;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines