Guest User

Untitled

a guest
Mar 10th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. public void connect() {
  2. try {
  3. this.connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database + "?autoReconnect=true", this.user, this.password);
  4. this.update("CREATE TABLE IF NOT EXISTS Clans (Name VARCHAR(16),Tag VARCHAR(4),Members TEXT, Owners TEXT, Invites TEXT)");
  5. this.update("CREATE TABLE IF NOT EXISTS FriendSystem (UUID VARCHAR(64),Name VARCHAR(16),Friends TEXT,Invites TEXT,Online INT(100),Notify INT(100),Message INT(100),Jump INT(100),Request INT(100))");
  6. this.update("CREATE TABLE IF NOT EXISTS Groups (Name TEXT,Displayname TEXT,Tabprefix TEXT,Chatprefix TEXT,Rankcolor TEXT,SortID INT, TeamSpeakID INT, Permissions TEXT)");
  7. this.update("CREATE TABLE IF NOT EXISTS Users (UUID VARCHAR(64), Name VARCHAR(16), Gruppe VARCHAR(100), Notify VARCHAR(100), FirstLogin VARCHAR(100), LastLogin VARCHAR(100), IP VARCHAR(100), NickName VARCHAR(100))");
  8. this.update("CREATE TABLE IF NOT EXISTS TeamSpeak (UUID VARCHAR(64), UID VARCHAR(64), RankID INT(5))");
  9. this.update("CREATE TABLE IF NOT EXISTS BanSystem (UUID VARCHAR(64),Map TEXT)");
  10. this.update("CREATE TABLE IF NOT EXISTS BanSystemTemplates (Name TEXT,Time TEXT)");
  11. this.update("CREATE TABLE IF NOT EXISTS MuteSystem (UUID VARCHAR(64),Map TEXT)");
  12. this.update("CREATE TABLE IF NOT EXISTS MuteSystemTemplates (Name TEXT ,Time TEXT)");
  13. this.update("CREATE TABLE IF NOT EXISTS ChatFilter (Map TEXT)");
  14. this.update("CREATE TABLE IF NOT EXISTS ReportSystem (UUID VARCHAR(64), Map TEXT)");
  15. this.update("CREATE TABLE IF NOT EXISTS ClanSystem (Name VARCHAR(16), Tag VARCHAR(5), Leader TEXT, Member TEXT, Invites TEXT)");
  16. ResultSet rs = this.asyncQuery("SELECT * FROM ChatFilter");
  17. if (!rs.next()) {
  18. this.update("INSERT INTO ChatFilter (Map) VALUES ('" + new Gson().toJson(new ArrayList()) + "')");
  19. }
  20. }
  21. catch (SQLException e) {
  22. this.connection = null;
  23. e.printStackTrace();
  24. }
  25. }
  26.  
  27. public void disconnect() {
  28. try {
  29. this.connection.close();
  30. this.connection = null;
  31. }
  32. catch (SQLException e) {
  33. e.printStackTrace();
  34. }
  35. }
  36.  
  37. public void update(String qry) {
  38. try {
  39. Throwable throwable = null;
  40. Object var3_5 = null;
  41. try {
  42. PreparedStatement preparedStatement = this.connection.prepareStatement(qry);
  43. try {
  44. preparedStatement.executeUpdate();
  45. }
  46. finally {
  47. if (preparedStatement != null) {
  48. preparedStatement.close();
  49. }
  50. }
  51. }
  52. catch (Throwable throwable2) {
  53. if (throwable == null) {
  54. throwable = throwable2;
  55. } else if (throwable != throwable2) {
  56. throwable.addSuppressed(throwable2);
  57. }
  58. throw throwable2;
  59. }
  60. }
  61. catch (SQLException e) {
  62. e.printStackTrace();
  63. }
  64. }
  65.  
  66. public void asyncUpdate(final String qry) {
  67. EXECUTOR_SERVICE.execute(new Runnable(){
  68.  
  69. @Override
  70. public void run() {
  71. MySQL.this.update(qry);
  72. }
  73. });
  74. }
  75.  
  76. public ResultSet query(String qry) {
  77. try {
  78. return this.connection.prepareStatement(qry).executeQuery();
  79. }
  80. catch (SQLException e) {
  81. e.printStackTrace();
  82. return null;
  83. }
  84. }
  85.  
  86. public ResultSet asyncQuery(final String qry) {
  87. Future future = EXECUTOR_SERVICE.submit(new Callable<ResultSet>(){
  88.  
  89. @Override
  90. public ResultSet call() throws Exception {
  91. return MySQL.this.query(qry);
  92. }
  93. });
  94. try {
  95. return (ResultSet)future.get();
  96. }
  97. catch (Exception e) {
  98. e.printStackTrace();
  99. return null;
  100. }
  101. }
  102.  
  103. public static MySQL getInstance() {
  104. return instance;
  105. }
  106.  
  107. public boolean isConnected() {
  108. if (this.connection != null) {
  109. return true;
  110. }
  111. return false;
  112. }
  113.  
  114. }
Add Comment
Please, Sign In to add comment