source: trunk/CrossPare/src/de/ugoe/cs/cpdp/eval/MySQLResultStorage.java @ 70

Last change on this file since 70 was 69, checked in by sherbold, 9 years ago
  • updated new result storage concept and cross-project experiments to first check if a result is available. If this is the case, the experiment is not executed.
  • Property svn:mime-type set to text/plain
File size: 3.9 KB
Line 
1
2package de.ugoe.cs.cpdp.eval;
3
4import java.sql.Connection;
5import java.sql.DriverManager;
6import java.sql.ResultSet;
7import java.sql.SQLException;
8import java.sql.Statement;
9
10import de.ugoe.cs.util.console.Console;
11
12public class MySQLResultStorage implements IResultStorage {
13    private Connection con = null;
14   
15    public MySQLResultStorage() {
16        this("localhost", "3306", "crosspare", "crosspare", "benchmark");
17    }
18   
19    public MySQLResultStorage(String dbHost, String dbPort, String dbName, String dbUser, String dbPass) {
20        try {
21            Class.forName("com.mysql.jdbc.Driver");
22            con = DriverManager.getConnection("jdbc:mysql://" + dbHost + ":" + dbPort + "/" +
23                    dbName + "?" + "user=" + dbUser + "&" + "password=" + dbPass);
24        }
25        catch (ClassNotFoundException e) {
26            Console.printerr("JDBC driver not found");
27        }
28        catch (SQLException e) {
29            Console.printerr("Problem with MySQL connection: ");
30            Console.printerr("SQLException: " + e.getMessage());
31            Console.printerr("SQLState: " + e.getSQLState());
32            Console.printerr("VendorError: " + e.getErrorCode());
33        }
34    }
35
36    public void addResult(ExperimentResult result) {
37        StringBuilder sql = new StringBuilder();
38        sql.append("INSERT INTO crosspare.results VALUES (NULL,");
39        sql.append("\'" + result.getConfigurationName()+"\',");
40        sql.append("\'" + result.getProductName()+"\',");
41        sql.append("\'" + result.getClassifier()+"\',");
42        sql.append(result.getSizeTestData()+",");
43        sql.append(result.getSizeTrainingData()+",");
44        sql.append(result.getSuccHe()+",");
45        sql.append(result.getSuccZi()+",");
46        sql.append(result.getSuccG75()+",");
47        sql.append(result.getSuccG60()+",");
48        sql.append(result.getError()+",");
49        sql.append(result.getRecall()+",");
50        sql.append(result.getPrecision()+",");
51        sql.append(result.getFscore()+",");
52        sql.append(result.getGscore()+",");
53        sql.append(result.getMcc()+",");
54        sql.append(result.getAuc()+",");
55        sql.append(result.getAucec()+",");
56        sql.append(result.getTpr()+",");
57        sql.append(result.getTnr()+",");
58        sql.append(result.getFpr()+",");
59        sql.append(result.getFnr()+",");
60        sql.append(result.getTp()+",");
61        sql.append(result.getFn()+",");
62        sql.append(result.getTn()+",");
63        sql.append(result.getFp()+");");
64       
65        Statement stmt;
66        try {
67            stmt = con.createStatement();
68            stmt.executeUpdate(sql.toString().replace("NaN", "NULL"));
69        }
70        catch (SQLException e) {
71            Console.printerr("Problem with MySQL connection: ");
72            Console.printerr("SQLException: " + e.getMessage());
73            Console.printerr("SQLState: " + e.getSQLState());
74            Console.printerr("VendorError: " + e.getErrorCode());
75            return;
76        }
77    }
78   
79    @Override
80    public boolean containsResult(String experimentName, String productName) {
81        String sql = "SELECT COUNT(*) as cnt FROM crosspare.results WHERE configurationName=\'" + experimentName + "\' AND productName=\'" + productName + "\';";
82        Statement stmt;
83        boolean contained = false;
84        try {
85            stmt = con.createStatement();
86            ResultSet results = stmt.executeQuery(sql);
87            results.next();
88            int count = results.getInt("cnt");
89            contained = count>0;
90        }
91        catch (SQLException e) {
92            Console.printerr("Problem with MySQL connection: \n");
93            Console.printerr("SQLException: " + e.getMessage() + "\n");
94            Console.printerr("SQLState: " + e.getSQLState() + "\n");
95            Console.printerr("VendorError: " + e.getErrorCode() + "\n");
96        }
97        return contained;
98    }
99}
Note: See TracBrowser for help on using the repository browser.