Skip to content

Instantly share code, notes, and snippets.

@lol768
Forked from natemort/Database
Created January 11, 2015 17:22
Show Gist options
  • Select an option

  • Save lol768/0e20dae19378decd65cb to your computer and use it in GitHub Desktop.

Select an option

Save lol768/0e20dae19378decd65cb to your computer and use it in GitHub Desktop.

Revisions

  1. lol768 revised this gist Jan 11, 2015. 5 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
  2. @natemort natemort revised this gist Jan 11, 2015. 3 changed files with 17 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions DatabaseManager
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    public interface DatabaseManager {
    public void doStuff();
    }
    7 changes: 7 additions & 0 deletions MysqlDatabaseManager
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    @Database(DatabaseType.MYSQL)
    @PluginService
    public class MysqlDatabaseManager implements DatabaseManager {
    public void doStuff() {
    System.out.println("Doing stuff in mysql");
    }
    }
    7 changes: 7 additions & 0 deletions SqliteDatabaseManager
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    @Database(DatabaseType.SQLITE)
    @PluginService
    public class SqliteDatabaseManager implements DatabaseManager {
    public void doStuff() {
    System.out.println("Doing stuff in sqlite");
    }
    }
  3. @natemort natemort created this gist Jan 11, 2015.
    3 changes: 3 additions & 0 deletions Database
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    public @interface Database {
    public DatabaseType value();
    }
    5 changes: 5 additions & 0 deletions DatabaseType
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    public enum DatabaseType {
    SQLITE,
    MYSQL,
    ;
    }
    8 changes: 8 additions & 0 deletions Plugin
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    public class Plugin extends JavaPlugin {
    public void onEnable() {
    BukkitGuice guice = new BukkitGuice(this);
    // In a real application you'd read the DatabaseType from the config and compare the value to that.
    guice.addConstraint(Database.class, database -> database.value() == DatabaseType.SQLITE);
    guice.start();
    }
    }