ForumsBBSManager.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.communitybbs.Manager;
  16. import java.sql.Connection;
  17. import java.sql.PreparedStatement;
  18. import java.sql.ResultSet;
  19. import java.util.List;
  20. import java.util.logging.Level;
  21. import java.util.logging.Logger;
  22. import com.l2jserver.L2DatabaseFactory;
  23. import com.l2jserver.gameserver.communitybbs.BB.Forum;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import javolution.util.FastList;
  26. public class ForumsBBSManager extends BaseBBSManager
  27. {
  28. private static Logger _log = Logger.getLogger(ForumsBBSManager.class.getName());
  29. private List<Forum> _table;
  30. private int _lastid = 1;
  31. /**
  32. * @return
  33. */
  34. public static ForumsBBSManager getInstance()
  35. {
  36. return SingletonHolder._instance;
  37. }
  38. private ForumsBBSManager()
  39. {
  40. _table = new FastList<Forum>();
  41. Connection con = null;
  42. try
  43. {
  44. con = L2DatabaseFactory.getInstance().getConnection();
  45. PreparedStatement statement = con.prepareStatement("SELECT forum_id FROM forums WHERE forum_type=0");
  46. ResultSet result = statement.executeQuery();
  47. while (result.next())
  48. {
  49. int forumId = result.getInt("forum_id");
  50. Forum f = new Forum(forumId, null);
  51. addForum(f);
  52. }
  53. result.close();
  54. statement.close();
  55. }
  56. catch (Exception e)
  57. {
  58. _log.log(Level.WARNING, "Data error on Forum (root): " + e.getMessage(), e);
  59. }
  60. finally
  61. {
  62. L2DatabaseFactory.close(con);
  63. }
  64. }
  65. public void initRoot()
  66. {
  67. for (Forum f : _table)
  68. f.vload();
  69. _log.info("Loaded " + _table.size() + " forums. Last forum id used: " + _lastid);
  70. }
  71. public void addForum(Forum ff)
  72. {
  73. if (ff == null)
  74. return;
  75. _table.add(ff);
  76. if (ff.getID() > _lastid)
  77. {
  78. _lastid = ff.getID();
  79. }
  80. }
  81. @Override
  82. public void parsecmd(String command, L2PcInstance activeChar)
  83. {
  84. }
  85. /**
  86. * @param string
  87. * @return
  88. */
  89. public Forum getForumByName(String Name)
  90. {
  91. for (Forum f : _table)
  92. {
  93. if (f.getName().equals(Name))
  94. {
  95. return f;
  96. }
  97. }
  98. return null;
  99. }
  100. /**
  101. * @param name
  102. * @param forumByName
  103. * @return
  104. */
  105. public Forum createNewForum(String name, Forum parent, int type, int perm, int oid)
  106. {
  107. Forum forum = new Forum(name, parent, type, perm, oid);
  108. forum.insertIntoDb();
  109. return forum;
  110. }
  111. /**
  112. * @return
  113. */
  114. public int getANewID()
  115. {
  116. return ++_lastid;
  117. }
  118. /**
  119. * @param idf
  120. * @return
  121. */
  122. public Forum getForumByID(int idf)
  123. {
  124. for (Forum f : _table)
  125. {
  126. if (f.getID() == idf)
  127. {
  128. return f;
  129. }
  130. }
  131. return null;
  132. }
  133. @Override
  134. public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
  135. {
  136. }
  137. @SuppressWarnings("synthetic-access")
  138. private static class SingletonHolder
  139. {
  140. protected static final ForumsBBSManager _instance = new ForumsBBSManager();
  141. }
  142. }