/**
   * @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;
  }
  /**
   * save sqlhistory
   *
   * @param user_seq
   * @param userDB
   * @param sqlType
   * @param sqlHistoryDAO
   */
  public static void saveExecuteSQUeryResource(
      int user_seq,
      UserDBDAO userDB,
      PublicTadpoleDefine.EXECUTE_SQL_TYPE sqlType,
      SQLHistoryDAO sqlHistoryDAO)
      throws Exception {
    if (PublicTadpoleDefine.YES_NO.YES.name().equals(userDB.getIs_profile())) {
      ExecutedSqlResourceDAO executeSQLResourceDao = new ExecutedSqlResourceDAO();
      executeSQLResourceDao.setDb_seq(userDB.getSeq());
      executeSQLResourceDao.setUser_seq(user_seq);
      executeSQLResourceDao.setTypes(sqlType.toString());

      executeSQLResourceDao.setStartDateExecute(sqlHistoryDAO.getStartDateExecute());
      executeSQLResourceDao.setEndDateExecute(sqlHistoryDAO.getEndDateExecute());
      long duration =
          sqlHistoryDAO.getEndDateExecute().getTime()
              - sqlHistoryDAO.getStartDateExecute().getTime();
      executeSQLResourceDao.setDuration(Integer.parseInt("" + duration));

      executeSQLResourceDao.setRow(sqlHistoryDAO.getRows());
      executeSQLResourceDao.setResult(sqlHistoryDAO.getResult());
      executeSQLResourceDao.setMessage(
          sqlHistoryDAO
              .getMesssage()); // ""+(sqlHistoryDAO.getEndDateExecute().getTime() -
                               // sqlHistoryDAO.getStartDateExecute().getTime()));
      executeSQLResourceDao.setIpAddress(sqlHistoryDAO.getIpAddress());
      // 기존에 등록 되어 있는지 검사한다
      SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleSystemInitializer.getUserDB());
      ExecutedSqlResourceDAO executeSQL =
          (ExecutedSqlResourceDAO)
              sqlClient.insert(
                  "userExecuteSQLResourceInsert", executeSQLResourceDao); // $NON-NLS-1$

      insertResourceData(executeSQL, sqlHistoryDAO.getStrSQLText());
    }
  }
  @Override
  protected void handleDrop() {
    String[] arrayDragSourceData = null;
    try {
      arrayDragSourceData =
          StringUtils.splitByWholeSeparator(
              ((String) getCurrentEvent().data), PublicTadpoleDefine.DELIMITER);

      int sourceDBSeq = Integer.parseInt(arrayDragSourceData[0]);
      if (userDB.getSeq() != sourceDBSeq) {
        MessageDialog.openError(
            null, "Error", Messages.TableTransferDropTargetListener_1); // $NON-NLS-1$
        return;
      }
    } catch (Exception e) {
      logger.error("dragger error", e); // $NON-NLS-1$
      MessageDialog.openError(
          null, "Error", "Draging exception : " + e.getMessage()); // $NON-NLS-1$
      return;
    }

    String tableName = arrayDragSourceData[1];
    String refTableNames = "'" + tableName + "',"; // $NON-NLS-1$ //$NON-NLS-2$

    // 이미 editor 상에 테이블 정보를 가져온다.
    Map<String, Table> mapDBTables = new HashMap<String, Table>();
    for (Table table : db.getTables()) {
      mapDBTables.put(table.getName(), table);
      refTableNames += "'" + table.getName() + "',"; // $NON-NLS-1$ //$NON-NLS-2$
    }
    refTableNames = StringUtils.chompLast(refTableNames, ","); // $NON-NLS-1$

    // 이미 등록되어 있는 것이 아니라면
    if (mapDBTables.get(tableName) == null) {
      // 테이블 모델 생성
      Table tableModel = tadpoleFactory.createTable();
      tableModel.setName(tableName);
      tableModel.setDb(db);

      if (userDB.getDBDefine() == DBDefine.SQLite_DEFAULT) {
        tableModel.setComment("");
      } else {
        String tableComment = arrayDragSourceData[2];
        tableComment = StringUtils.substring("" + tableComment, 0, 10);
        tableModel.setComment(tableComment);
      }

      tableModel.setConstraints(new Rectangle(getDropLocation().x, getDropLocation().y, -1, -1));

      try {
        // 컬럼 모델 생성
        for (TableColumnDAO columnDAO : getColumns(tableName)) {
          Column column = tadpoleFactory.createColumn();

          column.setDefault(columnDAO.getDefault());
          column.setExtra(columnDAO.getExtra());
          column.setField(columnDAO.getField());
          column.setNull(columnDAO.getNull());
          column.setKey(columnDAO.getKey());
          column.setType(columnDAO.getType());

          String strComment = columnDAO.getComment();
          if (strComment == null) strComment = "";
          else strComment = StringUtils.substring("" + strComment, 0, 10);
          column.setComment(strComment);

          column.setTable(tableModel);
          tableModel.getColumns().add(column);
        }
        mapDBTables.put(tableName, tableModel);
        RelationUtil.calRelation(
            userDB,
            mapDBTables,
            db,
            refTableNames); // RelationUtil.getReferenceTable(userDB, refTableNames));

      } catch (Exception e) {
        logger.error("GEF Table Drag and Drop Exception", e); // $NON-NLS-1$

        Status errStatus =
            new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$
        ExceptionDetailsErrorDialog.openError(
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            "Error",
            Messages.TadpoleModelUtils_2,
            errStatus); //$NON-NLS-1$
      }

      transferFactory.setTable(tableModel);
    } else {
      transferFactory.setTable(mapDBTables.get(tableName));
    }

    super.handleDrop();
  }