/**
   * 데이터 수정.
   *
   * @param userDB
   * @param title
   * @param desc
   * @param cronExp
   * @param listSchedule
   * @return
   * @throws Exception
   */
  public static ScheduleMainDAO modifySchedule(
      final UserDBDAO userDB, ScheduleMainDAO scheduleDao, List<ScheduleDAO> listSchedule)
      throws Exception {

    SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleSystemInitializer.getUserDB());
    sqlClient.update("scheduleMainUpdate", scheduleDao);

    // 기존 데이터를 삭제합니다.
    sqlClient.update("deleteSchedule", scheduleDao.getSeq());

    // save schedule
    for (ScheduleDAO scheduleDAO : listSchedule) {
      scheduleDAO.setSchedule_main_seq(scheduleDao.getSeq());
      ScheduleDAO retScheduleDAO = (ScheduleDAO) sqlClient.insert("scheduleInsert", scheduleDAO);

      // sql
      String[] sqls = SQLUtil.makeResourceDataArays(scheduleDAO.getSql());
      ScheduleDetailDAO detailDao = null;
      for (String sql : sqls) {
        detailDao = new ScheduleDetailDAO();
        detailDao.setSchedule_seq(retScheduleDAO.getSeq());
        detailDao.setDatas(sql);

        sqlClient.insert("scheduleDetailInsert", detailDao);
      }
    }

    return scheduleDao;
  }
  /**
   * seq
   *
   * @param seq {@link ScheduleDAO#getSeq()}
   * @return
   * @throws Exception
   */
  public static List<ScheduleDAO> findSchedule(final int seq) throws Exception {
    List<ScheduleDAO> listSchedule = new ArrayList<ScheduleDAO>();

    SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleSystemInitializer.getUserDB());
    listSchedule = sqlClient.queryForList("getSchedule", seq);
    for (ScheduleDAO scheduleDAO : listSchedule) {

      List<ScheduleDetailDAO> listDetail =
          sqlClient.queryForList("getScheduleDetail", scheduleDAO.getSeq());
      StringBuffer sbSQL = new StringBuffer();

      for (ScheduleDetailDAO scheduleDetailDAO : listDetail) {
        sbSQL.append(scheduleDetailDAO.getDatas());
      }
      scheduleDAO.setSql(sbSQL.toString());
    }

    return listSchedule;
  }
  /**
   * @param userDB
   * @param title
   * @param desc
   * @param cronExp
   * @param listSchedule
   */
  public static ScheduleMainDAO addSchedule(
      final UserDBDAO userDB,
      String title,
      String desc,
      String cronExp,
      List<ScheduleDAO> listSchedule)
      throws Exception {
    int userSeq = SessionManager.getUserSeq();

    ScheduleMainDAO dao = new ScheduleMainDAO();
    dao.setSeq(userSeq);
    dao.setUser_seq(SessionManager.getUserSeq());
    dao.setDb_seq(userDB.getSeq());
    dao.setTitle(title);
    dao.setDescription(desc);
    dao.setCron_exp(cronExp);

    SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleSystemInitializer.getUserDB());
    dao = (ScheduleMainDAO) sqlClient.insert("scheduleMainInsert", dao);

    // save schedule
    for (ScheduleDAO scheduleDAO : listSchedule) {
      scheduleDAO.setSchedule_main_seq(dao.getSeq());
      ScheduleDAO retScheduleDAO = (ScheduleDAO) sqlClient.insert("scheduleInsert", scheduleDAO);

      // sql
      String[] sqls = SQLUtil.makeResourceDataArays(scheduleDAO.getSql());
      ScheduleDetailDAO detailDao = null;
      for (String sql : sqls) {
        detailDao = new ScheduleDetailDAO();
        detailDao.setSchedule_seq(retScheduleDAO.getSeq());
        detailDao.setDatas(sql);

        sqlClient.insert("scheduleDetailInsert", detailDao);
      }
    }

    return dao;
  }