Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.arios.game.system.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import org.arios.game.system.SystemLogger;
- import org.arios.game.system.SystemManager;
- import org.arios.game.system.mysql.impl.ComponentSQLHandler;
- import org.arios.game.system.mysql.impl.GroundSpawnSQLHandler;
- import org.arios.game.system.mysql.impl.NPCConfigSQLHandler;
- import org.arios.game.system.mysql.impl.NPCDropSQLHandler;
- import org.arios.game.system.mysql.impl.NPCSpawnSQLHandler;
- import org.arios.game.system.mysql.impl.ShopSQLHandler;
- /**
- * Manages the sql connections.
- *
- * @author Vexia
- * @from Splinter - Changed login info [Jun 3rd 2015]
- */
- public final class SQLManager {
- /**
- * The database URL.
- */
- public static final String DATABASE_URL = "212.1.208.242/ospsorg_westbank_server";
- /**
- * The username of the user.
- */
- private static final String USERNAME = "ospsorg_julius";
- /**
- * The password of the user.
- */
- private static final String PASSWORD = "testtest";
- /**
- * IF the sql manager is initialized.
- */
- private static boolean initialized;
- /**
- * Constructs a new {@code SQLManager} {@code Object}
- */
- public SQLManager() {
- /**
- * empty.
- */
- }
- /**
- * Initializes the sql manager.
- */
- public static void init() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- initialized = false;
- return;
- }
- initialized = true;
- SystemManager.getSystemConfig().reload();
- }
- public static void prePlugin() {
- try {
- new NPCConfigSQLHandler().parse();
- new ComponentSQLHandler().parse();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- /**
- * Parses data from the database for the server post plugin loading.
- */
- public static void postPlugin() {
- try {
- new ShopSQLHandler().parse();
- new NPCDropSQLHandler().parse();
- new NPCSpawnSQLHandler().parse();
- new GroundSpawnSQLHandler().parse();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- /**
- * Gets a connection from the pool.
- *
- * @return The connection.
- */
- public static Connection getConnection() {
- try {
- return DriverManager.getConnection("jdbc:mysql://" + DATABASE_URL, USERNAME, PASSWORD);
- } catch (SQLException e) {
- SystemLogger.error(SQLManager.class, "Error: Mysql error message=" + e.getMessage() + ".");
- }
- return null;
- }
- /**
- * Releases the connection so it's available for usage.
- *
- * @param connection
- * The connection.
- */
- public static void close(Connection connection) {
- try {
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- /**
- * Gets the initialized.
- *
- * @return the initialized
- */
- public static boolean isInitialized() {
- return initialized;
- }
- /**
- * Sets the bainitialized.
- *
- * @param initialized
- * the initialized to set.
- */
- public static void setInitialized(boolean initialized) {
- SQLManager.initialized = initialized;
- }
- }
Add Comment
Please, Sign In to add comment