Guest User

Untitled

a guest
Jan 29th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. package org.arios.game.system.mysql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. import org.arios.game.system.SystemLogger;
  8. import org.arios.game.system.SystemManager;
  9. import org.arios.game.system.mysql.impl.ComponentSQLHandler;
  10. import org.arios.game.system.mysql.impl.GroundSpawnSQLHandler;
  11. import org.arios.game.system.mysql.impl.NPCConfigSQLHandler;
  12. import org.arios.game.system.mysql.impl.NPCDropSQLHandler;
  13. import org.arios.game.system.mysql.impl.NPCSpawnSQLHandler;
  14. import org.arios.game.system.mysql.impl.ShopSQLHandler;
  15.  
  16. /**
  17. * Manages the sql connections.
  18. *
  19. * @author Vexia
  20. * @from Splinter - Changed login info [Jun 3rd 2015]
  21. */
  22. public final class SQLManager {
  23.  
  24. /**
  25. * The database URL.
  26. */
  27. public static final String DATABASE_URL = "212.1.208.242/ospsorg_westbank_server";
  28.  
  29. /**
  30. * The username of the user.
  31. */
  32. private static final String USERNAME = "ospsorg_julius";
  33.  
  34. /**
  35. * The password of the user.
  36. */
  37. private static final String PASSWORD = "testtest";
  38.  
  39. /**
  40. * IF the sql manager is initialized.
  41. */
  42. private static boolean initialized;
  43.  
  44. /**
  45. * Constructs a new {@code SQLManager} {@code Object}
  46. */
  47. public SQLManager() {
  48. /**
  49. * empty.
  50. */
  51. }
  52.  
  53. /**
  54. * Initializes the sql manager.
  55. */
  56. public static void init() {
  57. try {
  58. Class.forName("com.mysql.jdbc.Driver");
  59. } catch (ClassNotFoundException e) {
  60. e.printStackTrace();
  61. initialized = false;
  62. return;
  63. }
  64. initialized = true;
  65. SystemManager.getSystemConfig().reload();
  66. }
  67.  
  68. public static void prePlugin() {
  69. try {
  70. new NPCConfigSQLHandler().parse();
  71. new ComponentSQLHandler().parse();
  72. } catch (SQLException e) {
  73. e.printStackTrace();
  74. }
  75. }
  76.  
  77. /**
  78. * Parses data from the database for the server post plugin loading.
  79. */
  80. public static void postPlugin() {
  81. try {
  82. new ShopSQLHandler().parse();
  83. new NPCDropSQLHandler().parse();
  84. new NPCSpawnSQLHandler().parse();
  85. new GroundSpawnSQLHandler().parse();
  86. } catch (SQLException e) {
  87. e.printStackTrace();
  88. }
  89. }
  90.  
  91. /**
  92. * Gets a connection from the pool.
  93. *
  94. * @return The connection.
  95. */
  96. public static Connection getConnection() {
  97. try {
  98. return DriverManager.getConnection("jdbc:mysql://" + DATABASE_URL, USERNAME, PASSWORD);
  99. } catch (SQLException e) {
  100. SystemLogger.error(SQLManager.class, "Error: Mysql error message=" + e.getMessage() + ".");
  101. }
  102. return null;
  103. }
  104.  
  105. /**
  106. * Releases the connection so it's available for usage.
  107. *
  108. * @param connection
  109. * The connection.
  110. */
  111. public static void close(Connection connection) {
  112. try {
  113. connection.close();
  114. } catch (SQLException e) {
  115. e.printStackTrace();
  116. }
  117. }
  118.  
  119. /**
  120. * Gets the initialized.
  121. *
  122. * @return the initialized
  123. */
  124. public static boolean isInitialized() {
  125. return initialized;
  126. }
  127.  
  128. /**
  129. * Sets the bainitialized.
  130. *
  131. * @param initialized
  132. * the initialized to set.
  133. */
  134. public static void setInitialized(boolean initialized) {
  135. SQLManager.initialized = initialized;
  136. }
  137.  
  138. }
Add Comment
Please, Sign In to add comment