package com.campmongoose.serversaturday.common;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class MySQLHandler {

    private final String database;
    private final String hostname;
    private final String password;
    private final String port;
    private final String user;
    private Connection connection;

    public MySQLHandler(String database, String hostname, String password, String port, String user) {
        this.connection = null;
        this.database = database;
        this.hostname = hostname;
        this.password = password;
        this.port = port;
        this.user = user;
    }

    private boolean checkConnection() {
        return connection != null;
    }

    public void closeConnection() throws SQLException {
        if (connection != null) {
            connection.close();
        }
    }

    public Connection getConnection() {
        return connection;
    }

    private Connection openConnection() throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Drive");
        connection = DriverManager.getConnection("jdbc:mysql://" + hostname + ":" + port + "/" + database, user, password);
        return connection;
    }

    public ResultSet querySQL(String query) throws ClassNotFoundException, SQLException {
        Connection c;
        if (checkConnection()) {
            c = getConnection();
        }
        else {
            c = openConnection();
        }

        Statement s = c.createStatement();
        ResultSet rset = s.executeQuery(query);
        s.close();
        closeConnection();
        return rset;
    }

    public void updateSQL(String update) throws ClassNotFoundException, SQLException {
        Connection c;
        if (checkConnection()) {
            c = getConnection();
        }
        else {
            c = openConnection();
        }

        Statement s = c.createStatement();
        s.executeUpdate(update);
        s.close();
        closeConnection();
    }
}

@@ -184,16 +184,49 @@
 atement;
+%0Aimport javax.annotation.Nonnull;
 %0A%0Apublic
@@ -475,16 +475,25 @@
 Handler(
+@Nonnull 
 String d
@@ -500,16 +500,25 @@
 atabase,
+ @Nonnull
  String 
@@ -526,16 +526,25 @@
 ostname,
+ @Nonnull
  String 
@@ -552,16 +552,25 @@
 assword,
+ @Nonnull
  String 
@@ -574,16 +574,25 @@
 ng port,
+ @Nonnull
  String 
@@ -1005,32 +1005,45 @@
        %7D%0A    %7D%0A%0A
+    @Nonnull%0A
     public Conne
@@ -1383,32 +1383,45 @@
 nection;%0A    %7D%0A%0A
+    @Nonnull%0A
     public Resul
@@ -1430,24 +1430,33 @@
 et querySQL(
+@Nonnull 
 String query
@@ -1818,32 +1818,32 @@
 rn rset;%0A    %7D%0A%0A
-
     public void 
@@ -1852,16 +1852,25 @@
 dateSQL(
+@Nonnull 
 String u

Add Guava annotations.