public int insert(Map map) throws IntegrationException {
    int count = 0;
    try {
      cn = MySqlConnectionManager.getInstance().getConnection();
      StringBuffer sql = new StringBuffer();
      sql.append("insert into users(login_id,user_name,");
      sql.append("user_name_kana,sex,sex_visible_flag,birth_date,");
      sql.append(
          "mail_address,password,fk_secret_question_id,secret_answer,admin_flag,user_status_flag) ");
      sql.append("values(?,?,?,?,?,?,?,?,?,?,?,'0')");
      pst = cn.prepareStatement(new String(sql));

      pst.setString(1, (String) map.get("loginId"));
      pst.setString(2, (String) map.get("userName"));
      pst.setString(3, (String) map.get("nameKana"));
      pst.setString(4, (String) map.get("sex"));
      pst.setString(5, (String) map.get("sexVisibleFlag"));
      pst.setString(6, (String) map.get("birthDate"));
      pst.setString(7, (String) map.get("mailAddress"));
      pst.setString(8, (String) map.get("password"));
      pst.setString(9, (String) map.get("quepstionId"));
      pst.setString(10, (String) map.get("secretAnswer"));
      pst.setString(11, (String) map.get("adminFlag"));

      pst.executeUpdate();

      StringBuffer idSql = new StringBuffer();
      idSql.append("select user_id from users where login_id=?");
      pst = cn.prepareStatement(new String(idSql));

      pst.setString(1, (String) map.get("loginId"));

      rs = pst.executeQuery();
      rs.next();

      count = rs.getInt(1);
      System.out.println("insert:" + count);
    } catch (SQLException e) {
      MySqlConnectionManager.getInstance().rollback();
      throw new IntegrationException(e.getMessage(), e);
    } finally {
      try {
        if (pst != null) {
          pst.close();
        }
      } catch (SQLException e) {
        throw new IntegrationException(e.getMessage(), e);
      }
    }
    return count;
  }
  public Bean read(Map map) throws IntegrationException {
    UserBean ub = new UserBean();
    PreparedStatement pst = null;
    try {
      Connection cn = null;
      cn = MySqlConnectionManager.getInstance().getConnection();
      StringBuffer sql = new StringBuffer();
      sql.append("select user_id,login_id,user_name,user_name_kana,sex,sex_visible_flag");
      sql.append(
          ",birth_date,mail_address,password,user_header_path,user_icon_path,admin_flag,last_login_date,");
      sql.append("admin_last_login_date,user_status_flag,user_lock_end_date,user_lock_start_date,");
      sql.append("fk_secret_question_id,user_profile,secret_answer from users ");
      sql.append((String) map.get("where"));
      pst = cn.prepareStatement(new String(sql));
      pst.setString(1, (String) map.get("value"));

      ResultSet rs = pst.executeQuery();

      if (rs.next()) {

        ub.setId(rs.getString("user_id"));
        ub.setLoginId(rs.getString("login_id"));
        ub.setUserName(rs.getString("user_name"));
        ub.setNameKana(rs.getString("user_name_kana"));
        ub.setSex(rs.getString("sex"));
        ub.setSexVisibleFlag(rs.getString("sex_visible_flag"));
        ub.setBirthDate(rs.getString("birth_date"));
        ub.setMailAddress(rs.getString("mail_address"));
        ub.setPassword(rs.getString("password"));
        ub.setHeaderPath(rs.getString("user_header_path"));
        ub.setIconPath(rs.getString("user_icon_path"));
        ub.setAdminFlag(rs.getString("admin_flag"));
        ub.setLastLoginDate(rs.getString("last_login_date"));
        ub.setAdminLastLoginDate(rs.getString("admin_last_login_date"));
        ub.setUserStatus(rs.getString("user_status_flag"));
        ub.setLockEndDate(rs.getString("user_lock_end_date"));
        ub.setLockStartDate(rs.getString("user_lock_start_date"));
        ub.setQuestionNo(rs.getString("fk_secret_question_id"));
        ub.setProfile(rs.getString("user_profile"));
        ub.setSecretAnswer(rs.getString("secret_answer"));

      } else {
        throw new NotLineException("0行が選択されました", null);
      }
      ;

    } catch (SQLException e) {
      throw new IntegrationException(e.getMessage(), e);
    } finally {
      try {
        if (pst != null) {
          pst.close();
        }
      } catch (SQLException e) {
        throw new IntegrationException(e.getMessage(), e);
      }
    }
    return ub;
  }
  public ResponseContext execute(ResponseContext resc) throws BusinessLogicException {
    try {
      RequestContext reqc = getRequestContext();

      String[] targets = reqc.getParameter("target");
      String[] status = reqc.getParameter("status");

      MySqlConnectionManager.getInstance().beginTransaction();

      AbstractDaoFactory factory = AbstractDaoFactory.getFactory("users");
      AbstractDao dao = factory.getAbstractDao();

      List users = new ArrayList();

      for (int i = 0; i < targets.length; i++) {
        Map params = new HashMap();
        params.put("value", targets[i]);
        params.put("where", "where user_id=?");

        UserBean ub = (UserBean) dao.read(params);

        params.put("userId", targets[i]);
        params.put("userbean", ub);
        params.put("userStatus", status[i]);

        dao.update(params);

        users.add(ub.getUserName());
      }

      MySqlConnectionManager.getInstance().commit();
      MySqlConnectionManager.getInstance().closeConnection();

      Map result = new HashMap();
      result.put("list", users);
      result.put("want", "削除");

      resc.setResult(result);
      resc.setTarget("AccountChangeResult");

      return resc;
    } catch (IntegrationException e) {
      throw new BusinessLogicException(e.getMessage(), e);
    }
  }
  public ResponseContext execute(ResponseContext resc) throws BusinessLogicException {
    try {
      RequestContext reqc = getRequestContext();
      String communityId = reqc.getParameter("communityId")[0];
      Map params = new HashMap();

      // 削除されていないコミュニティを取得するための条件
      params.put("where", "where community_id=? and community_delete_flag=0");
      params.put("communityId", reqc.getParameter("communityId")[0]);
      // DAOの中でキーの値が統一されていないため、同じ値を違うキーで入れています。
      // 犯人は土屋。
      params.put("commId", reqc.getParameter("communityId")[0]);

      MySqlConnectionManager.getInstance().beginTransaction();

      // コミュニティを取得
      AbstractDaoFactory factory = AbstractDaoFactory.getFactory("community");
      AbstractDao dao = factory.getAbstractDao();
      CommunityBean cb = (CommunityBean) dao.read(params);

      // コミュニティがもつトピックを取得
      factory = AbstractDaoFactory.getFactory("topic");
      dao = factory.getAbstractDao();
      cb.setTopics(dao.readAll(params));

      MySqlConnectionManager.getInstance().commit();

      resc.setResult(cb);
      resc.setTarget("topiclist");

      return resc;

    } catch (NullPointerException e) {
      throw new ParameterInvalidException("入力内容が足りません", e);
    } catch (IntegrationException e) {
      throw new BusinessLogicException(e.getMessage(), e);
    } finally {

      MySqlConnectionManager.getInstance().closeConnection();
    }
  }
  public ResponseContext execute(ResponseContext resc) throws BusinessLogicException {
    try {
      RequestContext reqc = getRequestContext();

      String[] articleId = reqc.getParameter("articleId");

      String status = reqc.getParameter("status")[0];

      Map params = new HashMap();

      params.put("status", status);

      AbstractDaoFactory factory = AbstractDaoFactory.getFactory("article");
      AbstractDao dao = factory.getAbstractDao();

      for (int i = 0; i < articleId.length; i++) {
        params.put("articleId", articleId[i]);

        MySqlConnectionManager.getInstance().beginTransaction();

        ArticleBean ab = (ArticleBean) dao.read(params);

        params.put("articlebean", ab);
        dao.update(params);

        MySqlConnectionManager.getInstance().commit();
        MySqlConnectionManager.getInstance().closeConnection();
      }

      resc.setTarget("publicationrangesetting");

      return resc;

    } catch (IntegrationException e) {
      throw new BusinessLogicException(e.getMessage(), e);
    }
  }
Beispiel #6
0
  public ResponseContext execute(ResponseContext resc) throws BusinessLogicException {
    try {
      RequestContext reqc = getRequestContext();

      Map result = new HashMap();

      MySqlConnectionManager.getInstance().beginTransaction();

      // TOPで表示する新着記事の取得
      AbstractDaoFactory factory = AbstractDaoFactory.getFactory("sort");
      AbstractDao dao = factory.getAbstractDao();
      Map param1 = new HashMap();
      param1.put("sortType", "0");
      List articles = dao.readAll(param1);
      Iterator itr = articles.iterator();

      while (itr.hasNext()) {
        ArticleBean ab = (ArticleBean) itr.next();
        param1.clear();
        param1.put("articleId", ab.getArticleId());
        factory = AbstractDaoFactory.getFactory("tag");
        dao = factory.getAbstractDao();

        ab.setTags(dao.readAll(param1));

        factory = AbstractDaoFactory.getFactory("comment");
        dao = factory.getAbstractDao();
        ab.setComments(dao.readAll(param1));
      }

      if (articles.size() <= 6) {
        result.put("article", sliceArticleBody(articles));
      } else {
        List nArticles = new ArrayList();
        for (int i = 0; i < 6; i++) {
          nArticles.add(articles.get(i));
        }
        result.put("article", sliceArticleBody(nArticles));
      }

      factory = AbstractDaoFactory.getFactory("blog");
      dao = factory.getAbstractDao();
      List blogs = dao.readAll(new HashMap());

      if (blogs.size() <= 3) {
        result.put("blog", blogs);
      } else {
        List nBlogs = new ArrayList();
        for (int i = 0; i < 3; i++) {
          nBlogs.add(blogs.get(i));
        }

        result.put("blog", nBlogs);
      }

      factory = AbstractDaoFactory.getFactory("community");
      dao = factory.getAbstractDao();

      Map param2 = new HashMap();
      param2.put("where", "Where community_delete_flag=0 ");
      param2.put("sort", " order by communities.community_created_date desc ");
      List communities = dao.readAll(param2);

      if (communities.size() <= 5) {
        result.put("community", communities);
      } else {
        List nCommunities = new ArrayList();
        for (int i = 0; i < 5; i++) {
          nCommunities.add(communities.get(i));
        }

        result.put("community", nCommunities);
      }

      // ブログタブで表示する学科ごとの新着記事の取得
      factory = AbstractDaoFactory.getFactory("users");
      dao = factory.getAbstractDao();
      Map param3 = new HashMap();
      param3.put("userStatus", "0");
      param3.put("where", " and admin_flag > ?");
      param3.put("value", "1");
      List users = dao.readAll(param3);
      factory = AbstractDaoFactory.getFactory("article");
      dao = factory.getAbstractDao();
      List departmentArticles = new ArrayList();
      for (int i = 0; i < users.size(); i++) {
        UserBean ub = (UserBean) users.get(i);
        Map param = new HashMap();
        param.put("userId", ub.getId());
        param.put("flag", "0");
        param.put("option", "limit 1 ");
        List departmentArticle = dao.readAll(param);
        departmentArticles.add((ArticleBean) departmentArticle.get(0));
      }
      result.put("department", sliceArticleBody(departmentArticles));

      MySqlConnectionManager.getInstance().commit();
      MySqlConnectionManager.getInstance().closeConnection();

      resc.setResult(result);
      resc.setTarget("top");

      return resc;

    } catch (NullPointerException e) {
      throw new ParameterInvalidException("入力内容が足りません", e);
    } catch (IntegrationException e) {
      throw new BusinessLogicException(e.getMessage(), e);
    }
  }
  public ResponseContext execute(ResponseContext resc) throws BusinessLogicException {
    try {
      RequestContext reqc = getRequestContext();

      String articleId = reqc.getParameter("articleId")[0];

      String title = reqc.getParameter("title")[0];
      // タグエスケープ
      title = title.replaceAll("<script", "&lt;script");
      title = title.replaceAll("</script>", "&lt;/script&gt;");
      title = title.replaceAll("<form", "&lt;form");
      title = title.replaceAll("</form>", "&lt;/form&gt;");
      title = title.replaceAll("<input", "&lt;/input");
      title = title.replaceAll("</input>", "&lt;/input&gt;");

      String body = reqc.getParameter("body")[0];
      // タグエスケープ
      body = body.replaceAll("<script", "&lt;script");
      body = body.replaceAll("</script>", "&lt;/script&gt;");
      body = body.replaceAll("<form", "&lt;form");
      body = body.replaceAll("</form>", "&lt;/form&gt;");
      body = body.replaceAll("<input", "&lt;/input");
      body = body.replaceAll("</input>", "&lt;/input&gt;");

      String status = reqc.getParameter("status")[0];

      String[] tags = null;
      // タグはチェックボックス等で複数来る事を想定してます

      boolean tagFlag = false;
      try {
        // tagパラメータがあるかのチェック、jsp変更前の例外防止
        tags = reqc.getParameter("tag[]");

        if (tags.length > 0) {
          tagFlag = true;
        }
      } catch (NullPointerException e) {

      }

      Calendar cal = Calendar.getInstance();
      SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm");
      String date = formatter.format(cal.getTime());

      Map params = new HashMap();
      params.put("articleId", articleId);
      params.put("title", title);
      params.put("body", body);
      params.put("status", status);
      params.put("date", date);

      MySqlConnectionManager.getInstance().beginTransaction();

      AbstractDaoFactory factory = AbstractDaoFactory.getFactory("article");
      AbstractDao dao = factory.getAbstractDao();
      ArticleBean ab = (ArticleBean) dao.read(params);

      params.put("articlebean", ab);
      dao.update(params);

      if (tagFlag) {
        params.clear();

        factory = AbstractDaoFactory.getFactory("tag");
        dao = factory.getAbstractDao();

        params.put("articleId", ab.getArticleId());
        dao.update(params);

        // 既に記事に付いているタグを保持しておくList

        params.clear();

        for (int i = 0; i < tags.length; i++) {

          params.put("articleId", ab.getArticleId());
          params.put("tag", tags[i]);
          dao.insert(params);
          params.clear();
        }
      }

      MySqlConnectionManager.getInstance().commit();

      return resc;

    } catch (NullPointerException e) {
      throw new ParameterInvalidException("入力内容が足りません", e);
    } catch (IntegrationException e) {
      throw new BusinessLogicException(e.getMessage(), e);
    } finally {
      MySqlConnectionManager.getInstance().closeConnection();
    }
  }
  public int update(Map map) throws IntegrationException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    ArrayList sqlList = new ArrayList();
    int result = 0;
    try {
      UserBean ub = (UserBean) map.get("userbean");
      Connection cn = MySqlConnectionManager.getInstance().getConnection();
      StringBuffer sql = new StringBuffer();
      sql.append("update users set ");

      // ユーザーの名前を変更
      if (map.containsKey("userName")) {
        sql.append("user_name=?, ");
        sqlList.add(map.get("userName"));
      }
      // ユーザーの名前(カナ)を変更
      if (map.containsKey("userNameKana")) {
        sql.append("user_name_kana=?, ");
        sqlList.add(map.get("userNameKana"));
      }
      // 性別の表示設定を変更
      if (map.containsKey("SexVisibleFlag")) {
        sql.append("sex_visible_flag=?, ");
        sqlList.add(map.get("SexVisibleFlag"));
      }
      // メールアドレスの変更
      if (map.containsKey("mailAddress")) {
        sql.append("mail_address=?, ");
        sqlList.add(map.get("mailAddress"));
      }
      // パスワードの変更
      if (map.containsKey("password")) {
        sql.append("password=?, ");
        sqlList.add(map.get("password"));
      }
      // ユーザーのヘッダー画像のパスを変更
      if (map.containsKey("headerPath")) {
        sql.append("user_header_path=?, ");
        sqlList.add(map.get("headerPath"));
      }
      // ユーザーのアイコン画像パスを変更
      if (map.containsKey("iconPath")) {
        sql.append("user_icon_path=?, ");
        sqlList.add(map.get("iconPath"));
      } else
      // ユーザーが最後にログインした日を変更
      if (map.containsKey("lastLoginDate")) {
        sql.append("admin_last_login_date=current_timestamp, ");
      }
      // ユーザーステータスを変更
      if (map.containsKey("userStatus")) {
        sql.append("user_status_flag=?, ");
        sqlList.add(map.get("userStatus"));
      }
      // ユーザのロック開始の日にちを変更
      if (map.containsKey("lockStartDate")) {
        sql.append("user_lock_start_date=?, ");
        sqlList.add(map.get("lockStartDate"));
      }
      // ユーザのロック終了日を変更
      if (map.containsKey("lockEndDate")) {
        sql.append("user_lock_end_date=?, ");
        sqlList.add(map.get("lockEndDate"));
      }
      // ユーザの自己紹介を変更
      if (map.containsKey("profile")) {
        sql.append("user_profile=?, ");
        sqlList.add(map.get("profile"));
      }
      // 管理者権限の変更
      if (map.containsKey("adminFlag")) {
        sql.append("admin_flag=?, ");
        sqlList.add(map.get("adminFlag"));
      }
      sql.deleteCharAt(sql.lastIndexOf(","));

      // WHERE
      if (map.containsKey("where")) {
        sql.append(map.get("where"));
        sqlList.add(map.get("value"));
      }
      pst = cn.prepareStatement(new String(sql));
      for (int i = 0; i < sqlList.size(); i++) {
        pst.setString(i + 1, (String) sqlList.get(i));
      }

      result = pst.executeUpdate();

      System.out.println("\t処理件数 : " + result);

    } catch (SQLException e) {
      MySqlConnectionManager.getInstance().rollback();
      throw new IntegrationException(e.getMessage(), e);
    } finally {
      try {
        if (pst != null) {
          pst.close();
        }
      } catch (SQLException e) {
        throw new IntegrationException(e.getMessage(), e);
      }
    }

    return result;
  }
  public List readAll(Map map) throws IntegrationException {
    List list = new ArrayList();
    try {
      cn = MySqlConnectionManager.getInstance().getConnection();
      StringBuffer sql = new StringBuffer();

      sql.append("select * from users ");

      if (map.containsKey("join")) {
        sql.append((String) map.get("join"));
      }

      if (map.containsKey("where")) {
        sql.append((String) map.get("where"));
      } else {
        sql.append("where user_status_flag=?");
      }
      pst = cn.prepareStatement(new String(sql));

      if (map.containsKey("userStatus")) {
        pst.setString(1, (String) map.get("userStatus"));
      }

      if (map.containsKey("value")) {
        pst.setString(2, (String) map.get("value"));
      }

      rs = pst.executeQuery();
      while (rs.next()) {
        UserBean ub = new UserBean();

        ub.setId(rs.getString(1));
        ub.setLoginId(rs.getString(2));
        ub.setUserName(rs.getString(3));
        ub.setNameKana(rs.getString(4));
        ub.setSex(rs.getString(5));
        ub.setSexVisibleFlag(rs.getString(6));
        ub.setBirthDate(rs.getString(7));
        ub.setMailAddress(rs.getString(8));
        ub.setPassword(rs.getString(9));
        // あとでなおしてね
        // ub.setQuestion(rs.getString(10));
        ub.setSecretAnswer(rs.getString(11));
        ub.setHeaderPath(rs.getString(12));
        ub.setIconPath(rs.getString(13));
        // あとでなおしてね
        // ub.setTitle(rs.getString(14));
        // ub.setHeadPhotoPath(rs.getString(15));
        ub.setAdminFlag(rs.getString(16));
        ub.setLastLoginDate(rs.getString(17));
        ub.setAdminLastLoginDate(rs.getString(18));
        ub.setUserStatus(rs.getString(19));
        ub.setLockStartDate(rs.getString(20));
        ub.setLockEndDate(rs.getString(21));
        // ub.setBlogExplanation(rs.getString(22));
        ub.setProfile(rs.getString(23));
        list.add(ub);
      }
      MySqlConnectionManager.getInstance().commit();
    } catch (SQLException e) {
      throw new IntegrationException(e.getMessage(), e);
    } finally {
      try {
        if (pst != null) {
          pst.close();
        }
      } catch (SQLException e) {
        throw new IntegrationException(e.getMessage(), e);
      }
    }
    return list;
  }