-
-
Save lol768/0e20dae19378decd65cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public @interface Database { | |
public DatabaseType value(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface DatabaseManager { | |
public void doStuff(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum DatabaseType { | |
SQLITE, | |
MYSQL, | |
; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Database(DatabaseType.MYSQL) | |
@PluginService | |
public class MysqlDatabaseManager implements DatabaseManager { | |
public void doStuff() { | |
System.out.println("Doing stuff in mysql"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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