Topic.java 3.7 KB

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