| 1 |
|
|---|
| 2 | package de.ugoe.cs.cpdp.eval;
|
|---|
| 3 |
|
|---|
| 4 | import java.sql.Connection;
|
|---|
| 5 | import java.sql.DriverManager;
|
|---|
| 6 | import java.sql.ResultSet;
|
|---|
| 7 | import java.sql.SQLException;
|
|---|
| 8 | import java.sql.Statement;
|
|---|
| 9 |
|
|---|
| 10 | import de.ugoe.cs.util.console.Console;
|
|---|
| 11 |
|
|---|
| 12 | public 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 | }
|
|---|