package net.ghostrealms.ticket;

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

/**
 * Created by River on 2/23/2015.
 * DataManager for the Ticket System * 
 */
public class DataManager {

    private Connection connection = null;
    private SupportTicket instance;
    
    public DataManager(DataManagerContext context, SupportTicket plugin) {
        instance = plugin;
        switch(context) {
            case MYSQL:
                connection = getSQLConnection();
                break;
            case H2:
                connection = geth2Connection();
                break;
            case SQLITE:
                connection = getSQLiteConnection();
                break;
            default:
                connection = null;
        }
    }



    public Connection getConnection() {
        return connection;
    }
    
    public void write(String sql) {
        
    }
    
    public void write(String sql, int retry) {

    }
    
    private Connection getSQLConnection() {
        String url = "jdbc:mysql://" + instance.sql_host + ":" + instance.sql_port + "/" + instance.sql_database;
        try {
            return DriverManager.getConnection(url, instance.sql_user, instance.sql_password);
        } catch (SQLException ex) {
            ex.printStackTrace();
            return null;
        }
    }
    
    private Connection geth2Connection() {
        return null;
    }
    
    private Connection getSQLiteConnection() {
        return null;
    }
    
    
}

enum DataManagerContext {
    MYSQL,
    SQLITE,
    H2;
}

@@ -26,16 +26,96 @@
 icket;%0A%0A
+import org.bukkit.Bukkit;%0Aimport org.bukkit.Location;%0Aimport org.bukkit.World;%0A%0A
 import j
@@ -1063,24 +1063,1225 @@
 ry) %7B%0A%0A    %7D
+%0A%0A    /**%0A     * Convert a Location object to a store-able string * %0A     * @param location to serialize%0A     * @return string value of location%0A     */%0A    public String serializeLocation(Location location) %7B%0A        String world = location.getWorld().getName();%0A        double x = location.getX();%0A        double y = location.getY();%0A        double z = location.getZ();%0A        float yaw = location.getYaw();%0A        float pitch = location.getPitch();%0A        %0A        return world + %22:%22 + x + %22:%22 + y + %22:%22 + z + %22:%22 + yaw + %22:%22 + pitch;%0A    %7D%0A%0A    /**%0A     * Convert serialized string objects back to Bukkit location objects.* %0A     * @param string to convert%0A     * @return Bukkit location object%0A     */%0A    public Location deserializeLocation(String string) %7B%0A        World w;%0A        double x, y, z;%0A        float yaw, pitch;%0A        String%5B%5D strings = string.split(%22:%22);%0A        w = Bukkit.getWorld(strings%5B0%5D);%0A        x = Double.parseDouble(strings%5B1%5D);%0A        y = Double.parseDouble(strings%5B2%5D);%0A        z = Double.parseDouble(strings%5B3%5D);%0A        yaw = Float.parseFloat(strings%5B4%5D);%0A        pitch = Float.parseFloat(strings%5B5%5D);%0A        return new Location(w, x, y, z, yaw, pitch);%0A    %7D
 %0A    %0A    pr

add location serializer and deserializer for simlified storage in the mysql database