Database driver

For use of my database driver you can best look at the page in the bukkit forums resources section. As it is mostly the same! :) There is however 1 major change, which is related to the way you obtain the database driver!

Hooking into the database driver

Now that we have hooked into GiantCore already, we can continue with using that object to hook into the database driver of our choice! :) This part does not differ too much from the normal database driver.

public class MyEpicPlugin extends JavaPlugin {
    
    private static MyEpicPlugin instance;

    private Database db;

    @Override
    public void onEnable() {
        GiantCore gc = GiantCore.getInstance();
        if(gc == null) {
            getLogger().severe("Failed to hook into required GiantCore!");
            this.getPluginLoader().disablePlugin(this);
            return;
        }
	
        // Optional protocol version check.
        if(gc.getProtocolVersion() != 0.1) {
            getLogger().severe("The GiantCore version you are using is not compatible with this plugin!");
            this.getPluginLoader().disablePlugin(this);
            return;
        }
	
        // Set instance for easier obtaining from other classes.
        MyEpicPlugin.instance = this;
        
        // Hook into SQLite using the default instance
        HashMap<String, String> dbConf = new HashMap<String, String>();
        dbConf.put("driver", "SQLite");
        dbConf.put("database", "myepicdatabase");
        dbConf.put("prefix", "mep_");

        this.db = gc.getDB(this, null, dbConf);
    }

    public Database getDB() {
        return this.db;
    }

    public static MyEpicPlugin getInstance() {
        return MyEpicPlugin.instance;
    }
}

Using the database driver

And now we have arrived at the point where the change is most noticeable from the normal database driver. As you can no longer simply do "Database.Obtain()".

public class MyEpicCommandExecutor implements CommandExecutor {
    private MyEpicPlugin plugin;
    public MyEpicCommandExecutor(MyEpicPlugin plugin) {
        this.plugin = plugin;
    }
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        if(sender instanceof Player) {
            iDriver db = this.plugin.getDB().getEngine();
            // From this point on, you can use the database driver as normal!
            QueryResult QRes = db.select("myepicfield").from("#__myepictable").execQuery();
        }
        return true;
    }
}