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.3 by pjm2, Sat Feb 3 20:47:11 2001 UTC

# Line 1 | Line 1
1   import java.sql.*;
2   import java.util.*;
3  
4 + // DBReporter class - establishes the database connection and is
5 + // used to run all of the reports.
6   public class DBReporter {
7      
8 +    // Constructor.
9      public DBReporter(long startTime, long endTime) {
10          _startTime = startTime;
11          _endTime = endTime;
12      }
13 <    
14 <    public void runReports(ReportList reports) throws SQLException, Exception {
13 >
14 >    // Runs all of the reports for each distinct machine name.    
15 >    public void runReports(ReportList reports, String webDir) throws SQLException, Exception {
16          
17          System.out.println("Preparing reports ...");
18  
19 <        // Establish the database connection.
19 >        // Get the MySQL DB driver.
20          try {
21              Class.forName("org.gjt.mm.mysql.Driver").newInstance();
22          }
23          catch (Exception e){
24              throw new Exception("Could not find the MySQL driver: " + e);
25          }
26 <        
26 >
27          try {
28              _conn = DriverManager.getConnection("jdbc:mysql://localhost/co600_10_db?user=co600_10&password=bung-i-scream");
29              _stmt = _conn.createStatement();
# Line 28 | Line 32 | public class DBReporter {
32              throw new SQLException("Could not connect to the database: " + e);
33          }
34          
31        
35          // This is essential to prevent temporary tables running out of
36          // physical memory for large reports.  With this set to 1, all
37          // temporary tables shall be written to disk.  This is a daily
# Line 42 | Line 45 | public class DBReporter {
45              System.out.println("Some of the following i-scream reports may fail if there is insufficient memory.");
46          }
47          
48 +        // Get a list of distinct machine names.
49          LinkedList machines = this.getDistinctMachines();
50          
51          System.out.println("Readying reports for " + machines.size() + " machines.");
52          
53 <        ReportMaker rm = null;
53 >        // Produce all of the reports for each machine.
54 >        ReportMaker rm = new ReportMaker(_stmt, webDir, DateUtils.shortDateString(_startTime), _startTime, _endTime);
55          Iterator machineIt = machines.iterator();
56          while (machineIt.hasNext()) {
52            rm = new ReportMaker(_stmt, DateUtils.shortDateString(_startTime), _startTime, _endTime);
57              String machine = (String)machineIt.next();
58              rm.produce(reports, machine);
59          }
60          
61      }
62      
63 +    
64 +    // Returns a list of distinct machine names.
65      private LinkedList getDistinctMachines() throws SQLException {
66          
67          LinkedList machines = new LinkedList();
# Line 65 | Line 71 | public class DBReporter {
71                  String machine_name = rs.getString("machine_name");
72                  machines.add(machine_name);
73              }
74 +            rs.close();
75          }
76          catch (SQLException e) {
77              throw new SQLException("Unable to find distinct machine names: " + e);
# Line 72 | Line 79 | public class DBReporter {
79          
80          return machines;
81      }
82 +    
83 +    
84      
85      private long _startTime;
86      private long _endTime;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines