예제 #1
0
  private void removePosts(List posts) {
    PreparedStatement post = null;
    PreparedStatement text = null;

    try {
      post =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.deletePost"));

      text =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.deletePostText"));

      for (Iterator iter = posts.iterator(); iter.hasNext(); ) {
        Post p = (Post) iter.next();

        post.setInt(1, p.getId());
        text.setInt(1, p.getId());

        text.executeUpdate();
        post.executeUpdate();

        SearchFacade.delete(p);
      }
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(post);
      DbUtils.close(text);
    }
  }
예제 #2
0
 /**
  * @see net.jforum.dao.security.SecurityDAO#addRole(int, net.jforum.security.Role,
  *     net.jforum.security.RoleValueCollection)
  */
 public void addRole(int id, Role role, RoleValueCollection roleValues) {
   this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("PermissionControl.lastGeneratedRoleId"));
   SecurityCommon.executeAddRole(
       SystemGlobals.getSql("PermissionControl.addGroupRole"),
       id,
       role,
       roleValues,
       this.supportAutoGeneratedKeys(),
       this.getAutoGeneratedKeysQuery());
 }
예제 #3
0
  public int countUserPosts(int userId) {
    int total = 0;

    PreparedStatement p = null;
    ResultSet rs = null;
    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(
                  SystemGlobals.getSql("PostModel.countUserPosts")
                      .replaceAll(":fids:", ForumRepository.getListAllowedForums()));
      p.setInt(1, userId);

      rs = p.executeQuery();

      if (rs.next()) {
        total = rs.getInt(1);
      }

      return total;
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }
  }
예제 #4
0
  /** @see net.jforum.dao.PostDAO#selectByUserByLimit(int, int, int) */
  public List selectByUserByLimit(int userId, int startFrom, int count) {
    String sql = SystemGlobals.getSql("PostModel.selectByUserByLimit");
    sql = sql.replaceAll(":fids:", ForumRepository.getListAllowedForums());

    PreparedStatement p = null;
    ResultSet rs = null;
    try {
      p = JForumExecutionContext.getConnection().prepareStatement(sql);

      p.setInt(1, userId);
      p.setInt(2, startFrom);
      p.setInt(3, count);

      rs = p.executeQuery();
      List l = new ArrayList();

      while (rs.next()) {
        l.add(this.makePost(rs));
      }

      return l;
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }
  }
예제 #5
0
  /** @see net.jforum.dao.PostDAO#selectAllBytTopicByLimit(int, int, int) */
  public List selectAllByTopicByLimit(int topicId, int startFrom, int count) {
    List l = new ArrayList();

    String sql = SystemGlobals.getSql("PostModel.selectAllByTopicByLimit");

    PreparedStatement p = null;
    ResultSet rs = null;

    try {
      p = JForumExecutionContext.getConnection().prepareStatement(sql);
      p.setInt(1, topicId);
      p.setInt(2, startFrom);
      p.setInt(3, count);

      rs = p.executeQuery();

      while (rs.next()) {
        l.add(this.makePost(rs));
      }

      return l;
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }
  }
예제 #6
0
  protected void addNewPost(Post post) {
    PreparedStatement p = null;
    try {
      p = this.getStatementForAutoKeys("PostModel.addNewPost");

      p.setInt(1, post.getTopicId());
      p.setInt(2, post.getForumId());
      p.setLong(3, post.getUserId());
      p.setTimestamp(4, new Timestamp(post.getTime().getTime()));
      p.setString(5, post.getUserIp());
      p.setInt(6, post.isBbCodeEnabled() ? 1 : 0);
      p.setInt(7, post.isHtmlEnabled() ? 1 : 0);
      p.setInt(8, post.isSmiliesEnabled() ? 1 : 0);
      p.setInt(9, post.isSignatureEnabled() ? 1 : 0);
      p.setInt(10, post.isModerationNeeded() ? 1 : 0);

      this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("PostModel.lastGeneratedPostId"));
      int postId = this.executeAutoKeysQuery(p);
      post.setId(postId);
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(p);
    }
  }
예제 #7
0
  protected void updatePostsTable(Post post) {
    PreparedStatement p = null;

    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.updatePost"));
      p.setInt(1, post.getTopicId());
      p.setInt(2, post.getForumId());
      p.setInt(3, post.isBbCodeEnabled() ? 1 : 0);
      p.setInt(4, post.isHtmlEnabled() ? 1 : 0);
      p.setInt(5, post.isSmiliesEnabled() ? 1 : 0);
      p.setInt(6, post.isSignatureEnabled() ? 1 : 0);
      p.setTimestamp(7, new Timestamp(System.currentTimeMillis()));
      p.setInt(8, post.getEditCount() + 1);
      p.setString(9, post.getUserIp());
      p.setInt(10, post.getId());

      p.executeUpdate();
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(p);
    }
  }
예제 #8
0
  /** @see net.jforum.model.PostModel#deleteByTopic(int) */
  public void deleteByTopic(int topicId) {
    PreparedStatement p = null;
    ResultSet rs = null;

    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.deleteByTopic"));
      p.setInt(1, topicId);
      rs = p.executeQuery();

      List posts = new ArrayList();

      while (rs.next()) {
        Post post = new Post();
        post.setId(rs.getInt("post_id"));
        post.setUserId(rs.getInt("user_id"));

        posts.add(post);
      }

      this.removePosts(posts);
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }
  }
예제 #9
0
  /** @see net.jforum.model.PostModel#countPreviousPosts(int) */
  public int countPreviousPosts(int postId) {
    int total = 0;

    PreparedStatement p = null;
    ResultSet rs = null;
    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.countPreviousPosts"));
      p.setInt(1, postId);
      p.setInt(2, postId);

      rs = p.executeQuery();

      if (rs.next()) {
        total = rs.getInt(1);
      }

      return total;
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }
  }
예제 #10
0
  public List selectHotForRSS(int limit) {
    List l = new ArrayList();

    PreparedStatement p = null;
    ResultSet rs = null;

    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.selectHotForRSS"));
      p.setInt(1, limit);

      rs = p.executeQuery();

      while (rs.next()) {
        Post post = this.buildPostForRSS(rs);
        l.add(post);
      }

    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }

    return l;
  }
예제 #11
0
  protected RoleCollection loadRoles(int[] groupIds) {
    String sql = SystemGlobals.getSql("PermissionControl.loadGroupRoles");
    String groupIdAsString = SecurityCommon.groupIdAsString(groupIds);

    if ("".equals(groupIdAsString)) {
      // We suppose there is no "negative" group ids
      sql = sql.replaceAll("#IN#", "-1");
    } else {
      sql = sql.replaceAll("#IN#", groupIdAsString);
    }

    RoleCollection roles = new RoleCollection();

    PreparedStatement p = null;
    ResultSet rs = null;

    try {
      p = JForumExecutionContext.getConnection().prepareStatement(sql);
      rs = p.executeQuery();

      roles = SecurityCommon.loadRoles(rs);
    } catch (Exception e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }

    return roles;
  }
예제 #12
0
  private List selectForumRoles(int forumId) {
    List l = new ArrayList();

    PreparedStatement p = null;
    ResultSet rs = null;

    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PermissionControl.selectForumRoles"));
      p.setString(1, String.valueOf(forumId));

      rs = p.executeQuery();

      while (rs.next()) {
        l.add(new Integer(rs.getInt("role_id")));
      }
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }

    return l;
  }
예제 #13
0
  public void deleteForumRoles(int forumId) {
    PreparedStatement p = null;

    List roleIds = this.selectForumRoles(forumId);

    try {
      StringBuffer ids = new StringBuffer();

      for (Iterator iterator = roleIds.iterator(); iterator.hasNext(); ) {
        Integer id = (Integer) iterator.next();
        ids.append(id).append(',');
      }

      ids.append("-1");

      // Role values
      String sql = SystemGlobals.getSql("PermissionControl.deleteRoleValues");
      sql = StringUtils.replace(sql, "#IDS#", ids.toString());

      p = JForumExecutionContext.getConnection().prepareStatement(sql);
      p.setString(1, String.valueOf(forumId));
      p.executeUpdate();
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(p);
    }
  }
예제 #14
0
  /**
   * @see net.jforum.dao.GroupSecurityDAO#addRoleValue(int, net.jforum.security.Role,
   *     net.jforum.security.RoleValueCollection)
   */
  public void addRoleValue(int groupId, Role role, RoleValueCollection rvc) {
    PreparedStatement p = null;
    ResultSet rs = null;

    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PermissionControl.getRoleIdByName"));
      p.setString(1, role.getName());
      p.setInt(2, groupId);

      int roleId = -1;

      rs = p.executeQuery();
      if (rs.next()) {
        roleId = rs.getInt("role_id");
      }

      rs.close();
      rs = null;
      p.close();
      p = null;

      if (roleId == -1) {
        this.addRole(groupId, role, rvc);
      } else {
        p =
            JForumExecutionContext.getConnection()
                .prepareStatement(SystemGlobals.getSql("PermissionControl.addRoleValues"));
        p.setInt(1, roleId);

        for (Iterator iter = rvc.iterator(); iter.hasNext(); ) {
          RoleValue rv = (RoleValue) iter.next();
          p.setString(2, rv.getValue());
          p.executeUpdate();
        }
      }
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }
  }
예제 #15
0
파일: Main.java 프로젝트: dgkim11/examples
  private String getSql(String queryName) {
    String query = SystemGlobals.getSql(queryName);

    query =
        StringUtils.replace(query, "${phpbb}", SystemGlobals.getValue(ConfigKeys.DATABASE_PHPBB));
    query =
        StringUtils.replace(
            query, "${table.prefix}", SystemGlobals.getValue(ConfigKeys.PHPBB_TABLE_PREFIX));

    return query;
  }
예제 #16
0
  /** @see net.jforum.dao.security.SecurityDAO#deleteAllRoles(int) */
  public void deleteAllRoles(int groupId) {
    PreparedStatement p = null;

    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PermissionControl.deleteAllRoleValues"));
      p.setInt(1, groupId);
      p.executeUpdate();
      p.close();

      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PermissionControl.deleteAllGroupRoles"));
      p.setInt(1, groupId);
      p.executeUpdate();
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(p);
    }
  }
예제 #17
0
 /** @see net.jforum.dao.SmilieDAO#delete(int) */
 public void delete(int id) {
   PreparedStatement pstmt = null;
   try {
     pstmt =
         JForumExecutionContext.getConnection()
             .prepareStatement(SystemGlobals.getSql("SmiliesModel.delete"));
     pstmt.setInt(1, id);
     pstmt.executeUpdate();
   } catch (SQLException e) {
     throw new DatabaseException(e);
   } finally {
     DbUtils.close(pstmt);
   }
 }
예제 #18
0
  protected void addNewPostText(Post post) throws Exception {
    PreparedStatement p = null;
    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.addNewPostText"));
      int cIndex = 1;
      p.setInt(cIndex++, post.getId());
      p.setString(cIndex++, post.getText());
      p.setString(cIndex++, post.getSubject());

      p.executeUpdate();
    } finally {
      DbUtils.close(p);
    }
  }
예제 #19
0
  protected void updatePostsTextTable(Post post) {
    PreparedStatement p = null;

    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.updatePostText"));
      p.setString(1, post.getText());
      p.setString(2, post.getSubject());
      p.setInt(3, post.getId());

      p.executeUpdate();
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(p);
    }
  }
예제 #20
0
  /** @see net.jforum.dao.SmilieDAO#update(net.jforum.entities.Smilie) */
  public void update(Smilie smilie) {
    PreparedStatement pstmt = null;
    try {
      pstmt =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("SmiliesModel.update"));
      pstmt.setString(1, smilie.getCode());
      pstmt.setString(2, smilie.getUrl());
      pstmt.setString(3, smilie.getDiskName());
      pstmt.setInt(4, smilie.getId());

      pstmt.executeUpdate();
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(pstmt);
    }
  }
예제 #21
0
  /** @see net.jforum.dao.SmilieDAO#addNew(net.jforum.entities.Smilie) */
  public int addNew(Smilie smilie) {
    PreparedStatement pstmt = null;
    try {
      pstmt = this.getStatementForAutoKeys("SmiliesModel.addNew");

      pstmt.setString(1, smilie.getCode());
      pstmt.setString(2, smilie.getUrl());
      pstmt.setString(3, smilie.getDiskName());

      this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("SmiliesModel.lastGeneratedSmilieId"));

      return this.executeAutoKeysQuery(pstmt);
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(pstmt);
    }
  }
예제 #22
0
  /** @see net.jforum.dao.SmilieDAO#selectAll() */
  public List<Smilie> selectAll() {
    List<Smilie> l = new ArrayList<Smilie>();

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("SmiliesModel.selectAll"));
      rs = pstmt.executeQuery();
      while (rs.next()) {
        l.add(this.getSmilie(rs));
      }

      return l;
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, pstmt);
    }
  }
예제 #23
0
  /** @see net.jforum.dao.ApiDAO#isValid(java.lang.String) */
  public boolean isValid(final String apiKey) {
    boolean status = false;

    PreparedStatement pstmt = null;
    ResultSet resultSet = null;

    try {
      pstmt =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("ApiModel.isValid"));
      pstmt.setString(1, apiKey);

      resultSet = pstmt.executeQuery();
      status = resultSet.next();
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(resultSet, pstmt);
    }

    return status;
  }
예제 #24
0
  /** @see net.jforum.dao.SmilieDAO#selectById(int) */
  public Smilie selectById(int id) {
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("SmiliesModel.selectById"));
      pstmt.setInt(1, id);

      Smilie s = new Smilie();

      rs = pstmt.executeQuery();
      if (rs.next()) {
        s = this.getSmilie(rs);
      }

      return s;
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, pstmt);
    }
  }
예제 #25
0
  /** @see net.jforum.dao.PostDAO#selectById(int) */
  public Post selectById(int postId) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.selectById"));
      p.setInt(1, postId);

      rs = p.executeQuery();

      Post post = new Post();

      if (rs.next()) {
        post = this.makePost(rs);
      }

      return post;
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }
  }