Skip to content

Instantly share code, notes, and snippets.

@lol768
Forked from natemort/Database
Created January 11, 2015 17:22
Show Gist options
  • Save lol768/0e20dae19378decd65cb to your computer and use it in GitHub Desktop.
Save lol768/0e20dae19378decd65cb to your computer and use it in GitHub Desktop.
public @interface Database {
public DatabaseType value();
}
public interface DatabaseManager {
public void doStuff();
}
public enum DatabaseType {
SQLITE,
MYSQL,
;
}
@Database(DatabaseType.MYSQL)
@PluginService
public class MysqlDatabaseManager implements DatabaseManager {
public void doStuff() {
System.out.println("Doing stuff in mysql");
}
}
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();
}
}
@Database(DatabaseType.SQLITE)
@PluginService
public class SqliteDatabaseManager implements DatabaseManager {
public void doStuff() {
System.out.println("Doing stuff in sqlite");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment