package info.tregmine.database.db;

import java.io.*;
import java.util.*;
import java.sql.*;

import org.apache.commons.dbcp.BasicDataSource;

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;

import info.tregmine.database.DAOException;
import info.tregmine.database.IContextFactory;
import info.tregmine.database.IContext;

public class DBContextFactory implements IContextFactory
{
    private BasicDataSource ds;
    private Map<String, LoggingConnection.LogEntry> queryLog;

    public DBContextFactory(FileConfiguration config)
    {
        queryLog = new HashMap<>();

        String driver = config.getString("db.driver");
        if (driver == null) {
            driver = "com.mysql.jdbc.Driver";
        }

        try {
            Class.forName(driver).newInstance();
        } catch (ClassNotFoundException ex) {
            throw new RuntimeException(ex);
        } catch (IllegalAccessException ex) {
            throw new RuntimeException(ex);
        } catch (InstantiationException ex) {
            throw new RuntimeException(ex);
        }

        String user = config.getString("db.user");
        String password = config.getString("db.password");
        String url = config.getString("db.url");

        ds = new BasicDataSource();
        ds.setDriverClassName(driver);
        ds.setUrl(url);
        ds.setUsername(user);
        ds.setPassword(password);
        ds.setMaxActive(5);
        ds.setMaxIdle(5);
        ds.setDefaultAutoCommit(true);
    }

    public Map<String, LoggingConnection.LogEntry> getLog()
    {
        return queryLog;
    }

    @Override
    public IContext createContext()
    throws DAOException
    {
        try {
            // It's the responsibility of the context to make sure that the
            // connection is correctly closed
            Connection conn = ds.getConnection();
            try (Statement stmt = conn.createStatement()) {
                stmt.execute("SET NAMES latin1");
            }

            return new DBContext(new LoggingConnection(conn, queryLog));
        } catch (SQLException e) {
            throw new DAOException(e);
        }
    }
}

@@ -40,348 +40,400 @@
 ort 
-java.io.*;%0Aimport java.util.*;%0Aimport java.sql.*;%0A%0Aimport org.apache.commons.dbcp.BasicDataSource;%0A%0Aimport org.bukkit.configuration.ConfigurationSection;%0Aimport org.bukkit.configuration.file.FileConfiguration;%0A%0Aimport info.tregmine.database.DAOException
+info.tregmine.Tregmine;%0Aimport info.tregmine.database.DAOException;%0Aimport info.tregmine.database.IContext;%0Aimport info.tregmine.database.IContextFactory;%0A%0Aimport java.sql.Connection;%0Aimport java.sql.SQLException;%0Aimport java.sql.Statement;%0Aimport java.util.HashMap;%0Aimport java.util.Map
 ;%0A
+%0A
 import 
-info.tregmine.database.IContextFactory;%0Aimport info.tregmine.database.IContext
+org.apache.commons.dbcp.BasicDataSource;%0Aimport org.bukkit.configuration.file.FileConfiguration
 ;%0A%0Ap
@@ -583,16 +583,45 @@
 ueryLog;
+%0A    private Tregmine plugin;
 %0A%0A    pu
@@ -666,16 +666,35 @@
 n config
+, Tregmine instance
 )%0A    %7B%0A
@@ -1628,24 +1628,65 @@
 mmit(true);%0A
+        %0A        this.plugin = instance;%0A
     %7D%0A%0A    p
@@ -2239,16 +2239,24 @@
 ueryLog)
+, plugin
 );%0A     

Update DBContextFactory.java