Comment.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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.communityserver.model;
  16. import java.sql.PreparedStatement;
  17. import java.util.logging.Logger;
  18. import com.l2jserver.communityserver.L2DatabaseFactory;
  19. import com.l2jserver.communityserver.model.Topic.ConstructorType;
  20. public class Comment
  21. {
  22. private static Logger _log = Logger.getLogger(Comment.class.getName());
  23. private final int _sqlDPId;
  24. private int _commentId;
  25. private int _commentOwnerId;
  26. private long _commentDate;
  27. private int _commentPostId;
  28. private int _commentTopicId;
  29. private int _commentForumId;
  30. private String _commentTxt;
  31. /**
  32. * @param restore
  33. * @param t
  34. */
  35. //public enum ConstructorType {REPLY, CREATE };
  36. public Comment(ConstructorType ct, final int sqlDPId, int commentId, int commentOwnerID, long date, int pid, int tid,int commentForumID, String txt)
  37. {
  38. _sqlDPId = sqlDPId;
  39. _commentId = commentId;
  40. _commentOwnerId = commentOwnerID;
  41. _commentDate = date;
  42. _commentPostId = pid;
  43. _commentTopicId = tid;
  44. _commentForumId = commentForumID;
  45. _commentTxt = txt;
  46. if (ct == ConstructorType.CREATE)
  47. {
  48. insertindb();
  49. }
  50. }
  51. public void insertindb()
  52. {
  53. java.sql.Connection con = null;
  54. try
  55. {
  56. con = L2DatabaseFactory.getInstance().getConnection();
  57. PreparedStatement statement = con.prepareStatement("INSERT INTO comments (serverId, comment_id,comment_ownerid,comment_date,comment_post_id,comment_topic_id,comment_forum_id,comment_txt) values (?,?,?,?,?,?,?,?)");
  58. statement.setInt(1, _sqlDPId);
  59. statement.setInt(2, _commentId);
  60. statement.setInt(3, _commentOwnerId);
  61. statement.setLong(4, _commentDate);
  62. statement.setInt(5, _commentPostId);
  63. statement.setInt(6, _commentTopicId);
  64. statement.setInt(7, _commentForumId);
  65. statement.setString(8, _commentTxt);
  66. statement.execute();
  67. statement.close();
  68. }
  69. catch (Exception e)
  70. {
  71. _log.warning("error while saving new Post to db " + e);
  72. }
  73. finally
  74. {
  75. try
  76. {
  77. con.close();
  78. }
  79. catch (Exception e)
  80. {
  81. }
  82. }
  83. }
  84. public void deleteme()
  85. {
  86. java.sql.Connection con = null;
  87. try
  88. {
  89. con = L2DatabaseFactory.getInstance().getConnection();
  90. PreparedStatement statement = con.prepareStatement("DELETE FROM comments WHERE serverId=? AND comment_forum_id=? AND comment_topic_id=? AND comment_Post_id=? AND comment_id=?");
  91. statement.setInt(1, _sqlDPId);
  92. statement.setInt(2, _commentForumId);
  93. statement.setInt(3, _commentTopicId);
  94. statement.setInt(4, _commentPostId);
  95. statement.setInt(5, _commentId);
  96. statement.execute();
  97. statement.close();
  98. }
  99. catch (Exception e)
  100. {
  101. e.printStackTrace();
  102. }
  103. finally
  104. {
  105. try
  106. {
  107. con.close();
  108. }
  109. catch (Exception e)
  110. {
  111. }
  112. }
  113. }
  114. /**
  115. *
  116. */
  117. /**
  118. * @return
  119. */
  120. public int getID()
  121. {
  122. return _commentId;
  123. }
  124. public String getText()
  125. {
  126. return _commentTxt;
  127. }
  128. public int getOwnerId()
  129. {
  130. return _commentOwnerId;
  131. }
  132. public Long getDate()
  133. {
  134. return _commentDate;
  135. }
  136. }