Topic.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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.BB;
  16. import java.sql.Connection;
  17. import java.sql.PreparedStatement;
  18. import java.util.logging.Logger;
  19. import com.l2jserver.L2DatabaseFactory;
  20. import com.l2jserver.gameserver.communitybbs.Manager.TopicBBSManager;
  21. public class Topic
  22. {
  23. private static Logger _log = Logger.getLogger(Topic.class.getName());
  24. public static final int MORMAL = 0;
  25. public static final int MEMO = 1;
  26. private int _id;
  27. private int _forumId;
  28. private String _topicName;
  29. private long _date;
  30. private String _ownerName;
  31. private int _ownerId;
  32. private int _type;
  33. private int _cReply;
  34. /**
  35. * @param restaure
  36. * @param i
  37. * @param j
  38. * @param string
  39. * @param k
  40. * @param string2
  41. * @param l
  42. * @param m
  43. * @param n
  44. */
  45. public Topic(ConstructorType ct, int id, int fid, String name, long date, String oname, int oid, int type, int Creply)
  46. {
  47. _id = id;
  48. _forumId = fid;
  49. _topicName = name;
  50. _date = date;
  51. _ownerName = oname;
  52. _ownerId = oid;
  53. _type = type;
  54. _cReply = Creply;
  55. TopicBBSManager.getInstance().addTopic(this);
  56. if (ct == ConstructorType.CREATE)
  57. {
  58. insertindb();
  59. }
  60. }
  61. /**
  62. *
  63. */
  64. public void insertindb()
  65. {
  66. Connection con = null;
  67. try
  68. {
  69. con = L2DatabaseFactory.getInstance().getConnection();
  70. PreparedStatement statement = con.prepareStatement("INSERT INTO topic (topic_id,topic_forum_id,topic_name,topic_date,topic_ownername,topic_ownerid,topic_type,topic_reply) values (?,?,?,?,?,?,?,?)");
  71. statement.setInt(1, _id);
  72. statement.setInt(2, _forumId);
  73. statement.setString(3, _topicName);
  74. statement.setLong(4, _date);
  75. statement.setString(5, _ownerName);
  76. statement.setInt(6, _ownerId);
  77. statement.setInt(7, _type);
  78. statement.setInt(8, _cReply);
  79. statement.execute();
  80. statement.close();
  81. }
  82. catch (Exception e)
  83. {
  84. _log.warning("error while saving new Topic to db " + e);
  85. }
  86. finally
  87. {
  88. try
  89. {
  90. con.close();
  91. }
  92. catch (Exception e)
  93. {
  94. }
  95. }
  96. }
  97. public enum ConstructorType
  98. {
  99. RESTORE,
  100. CREATE
  101. }
  102. /**
  103. * @return
  104. */
  105. public int getID()
  106. {
  107. return _id;
  108. }
  109. public int getForumID()
  110. {
  111. return _forumId;
  112. }
  113. /**
  114. * @return
  115. */
  116. public String getName()
  117. {
  118. // TODO Auto-generated method stub
  119. return _topicName;
  120. }
  121. public String getOwnerName()
  122. {
  123. // TODO Auto-generated method stub
  124. return _ownerName;
  125. }
  126. /**
  127. *
  128. */
  129. public void deleteme(Forum f)
  130. {
  131. TopicBBSManager.getInstance().delTopic(this);
  132. f.rmTopicByID(getID());
  133. Connection con = null;
  134. try
  135. {
  136. con = L2DatabaseFactory.getInstance().getConnection();
  137. PreparedStatement statement = con.prepareStatement("DELETE FROM topic WHERE topic_id=? AND topic_forum_id=?");
  138. statement.setInt(1, getID());
  139. statement.setInt(2, f.getID());
  140. statement.execute();
  141. statement.close();
  142. }
  143. catch (Exception e)
  144. {
  145. e.printStackTrace();
  146. }
  147. finally
  148. {
  149. try
  150. {
  151. con.close();
  152. }
  153. catch (Exception e)
  154. {
  155. }
  156. }
  157. }
  158. /**
  159. * @return
  160. */
  161. public long getDate()
  162. {
  163. return _date;
  164. }
  165. }