Exemple #1
0
  public static void main(String[] args) throws Exception {

    ClassPathXmlApplicationContext applicationContext =
        new ClassPathXmlApplicationContext("classpath:ApplicationContext.xml");

    SqlSessionTemplate template =
        applicationContext.getBean("sqlSessionTemplate", SqlSessionTemplate.class);
    FileInputStream stream = new FileInputStream(new File("/Users/yanzhao/Desktop/gg.html"));
    InputStreamReader reader = new InputStreamReader(stream, "utf-8");
    BufferedReader bufferedReader = new BufferedReader(reader);

    String line = null;
    Map<String, Content> map = new HashMap<String, Content>();
    List<String>[] tcodes = new List[10];
    while ((line = bufferedReader.readLine()) != null) {
      String[] params = line.split(" ");
      Basedata basedata = new Basedata();
      basedata.setCode(params[2]);
      basedata.setLink(params[0]);
      basedata.setName(params[1]);
      basedata.setZs(Long.parseLong(params[4]));
      basedata.setZsabbre(params[3]);
      System.out.println(JSON.toJSON(basedata));

      template.insert("mybatis/mapper.BasedataMapper.insert", basedata);
    }
  }
  @SuppressWarnings("unchecked")
  @Override
  public <R> List<R> executeQuery(
      String sqlNamespace, String queryName, Object parameterObj, int offset, int limit) {
    if (offset < 0 || offset == Integer.MAX_VALUE) {
      throw new IllegalArgumentException("Query result offset must be zero or greater.");
    }

    if (limit <= 0) {
      throw new IllegalArgumentException("Query results limit must be greater than zero.");
    }

    String query = makeQueryName(sqlNamespace, queryName);
    try {
      List<R> result;
      if ((offset == 0) && (limit == Integer.MAX_VALUE)) {
        result = (List<R>) template.selectList(query, parameterObj);
      } else {
        RowBounds bounds = new RowBounds(offset, limit);
        result = (List<R>) template.selectList(query, parameterObj, bounds);
      }

      // Done
      if (logger.isDebugEnabled()) {
        logger.debug(
            "Executed query: \n"
                + "   Query:  "
                + query
                + "\n"
                + "   Params: "
                + parameterObj
                + "\n"
                + "   Result: "
                + result);
      }
      return result;
    } catch (ClassCastException e) {
      throw new IllegalArgumentException("Return type of query does not match expected type.", e);
    } catch (Throwable e) {
      throw new QueryException(
          "Failed to execute query: \n"
              + "   Namespace: "
              + sqlNamespace
              + "\n"
              + "   queryName: "
              + queryName
              + "\n"
              + "   Parameter: "
              + parameterObj
              + "\n"
              + "   Offset:    "
              + offset
              + "\n"
              + "   Limit:     "
              + limit,
          e);
    }
  }
 /**
  * @name : updateOk
  * @date : 2015. 6. 25.
  * @author : 이명진
  * @description : 회원정보수정 시 입력된 데이터로 member테이블을 수정하는 메소드
  */
 @Override
 public int updateOk(MemberDto member) {
   // TODO Auto-generated method stub
   if (member.getMemberFileName() != null) {
     return sqlSession.update("member.dao.mapper.updateOkFile", member);
   } else {
     return sqlSession.update("member.dao.mapper.updateOk", member);
   }
 }
 /**
  * @name : registerOk
  * @date : 2015. 6. 25.
  * @author : 이명진
  * @description : 회원가입시 입력된 데이터를 member 테이블에 저장하기 위한 메소드
  */
 @Override
 public int registerOk(MemberDto memberDto) {
   // TODO Auto-generated method stub
   if (memberDto.getMemberFileName() != null) {
     return sqlSession.insert("member.dao.mapper.registerOkFile", memberDto);
   } else {
     return sqlSession.insert("member.dao.mapper.registerOk", memberDto);
   }
 }
 public boolean deleteReq(int uidx) {
   UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
   if (userMapper != null) {
     try {
       userMapper.deleteRequest(uidx);
       sqlSession.commit();
       return true;
     } catch (Exception e) {
       return false;
     }
   }
   return false;
 }
  public boolean createAccount(UserInfo userInfo) {

    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    if (userMapper != null) {
      try {
        userMapper.createAccount(userInfo);
        sqlSession.commit();
        return true;
      } catch (Exception e) {
        return false;
      }
    }
    return false;
  }
Exemple #7
0
  /**
   * @name : blogWrite
   * @date : 2015. 7. 02.
   * @author : 황준
   * @description : 블로그 작성
   */
  @Override
  public HashMap<String, Object> blogWrite(HashMap<String, Object> hashMap) {
    logger.info("BoardDao blogWrite  DAO-------------------------");
    int check = sqlSession.insert("dao.BoardMapper.blogWrite", hashMap);

    if (check > 0) {
      check = sqlSession.insert("dao.BoardMapper.blogWrite_addr", hashMap);
      if (check > 0) {
        check = sqlSession.insert("dao.BoardMapper.blogWrite_point", hashMap);
      }
    }
    hashMap.put("check", check);
    return hashMap;
  }
  @Override
  public void select(
      final String statementName, final Object parameterObject, final ResultHandler handler) {
    if (isSqlAuditorBehaviorEnabled()) {
      getSqlAuditor()
          .audit(
              statementName,
              getSqlByStatementName(statementName, parameterObject),
              parameterObject);
    }
    if (isPartitioningBehaviorEnabled()) {
      SortedMap<String, DataSource> dsMap =
          lookupDataSourcesByRouter(statementName, parameterObject);
      if (dsMap != null && !dsMap.isEmpty()) {
        SqlSessionCallback action =
            new SqlSessionCallback() {
              @Override
              public Object doInSession(SqlSession sqlSession) {
                sqlSession.select(statementName, parameterObject, handler);
                return null;
              }
            };

        if (dsMap.size() == 1) {
          executeWith(dsMap.get(dsMap.firstKey()), action);
        } else {
          executeInConcurrency(action, dsMap);
        }
      }
    }
    super.select(statementName, parameterObject, handler);
  }
Exemple #9
0
 /**
  * @name : getCoupon
  * @date : 2015. 7. 15.
  * @author : 황준
  * @description :쿠폰 조회
  */
 @Override
 public int getCoupon(String member_id, String coupon_no) {
   HashMap<String, Object> hMap = new HashMap<String, Object>();
   hMap.put("member_id", member_id);
   hMap.put("coupon_no", coupon_no);
   return sqlSession.insert("dao.BoardMapper.insertCouponIssue", hMap);
 }
 /**
  * 分页归类查询 <br>
  * ps:如果要实现物理分页,需要添加分页插件
  *
  * @param statement SQL语句的Id号(命名空间+name)
  * @param parameter 参数
  * @param mapKey 归类的键名称
  * @param pageNumber 当前页
  * @param pageSize 每页大小
  */
 public <K, V> Map<K, V> paginate(
     String statement, Object parameter, String mapKey, int pageNumber, int pageSize) {
   int offset = (pageNumber - 1) * pageSize;
   Map<K, V> retMap =
       sqlSession.selectMap(statement, parameter, mapKey, new RowBounds(offset, pageSize));
   return retMap;
 }
Exemple #11
0
 @Override
 public ServicePara getService(String name, Integer appId) {
   Map<String, Object> map = new HashMap<String, Object>();
   map.put("name", name);
   map.put("appId", appId);
   return (ServicePara) sqlSession.selectOne("getServiceByName", map);
 }
  /**
   * @함수이름 : infoInsert @작성일 : 2015. 12. 7. @개발자 : 전현준 @함수설명 : xml 파일에 넘겨서 관리자 페이지 회사정보 등록 - (footer
   * 부분)
   */
  @Override
  public int infoInsert(AdminInfoDto adminInfoDto) {
    int value = 0;

    value = sessionTemplate.insert("dao.adminInfoMapper.infoInsert", adminInfoDto);
    return value;
  }
 public List<SysApplication> getSysApplicationsByQueryCriteria(
     int start, int pageSize, SysApplicationQuery query) {
   RowBounds rowBounds = new RowBounds(start, pageSize);
   List<SysApplication> rows =
       sqlSessionTemplate.selectList("getSysApplications", query, rowBounds);
   return rows;
 }
  @Override
  public <R> void executeQuery(
      String sqlNamespace,
      String queryName,
      Object parameterObj,
      int offset,
      int limit,
      ResultHandler<R> handler) {
    if (offset < 0 || offset == Integer.MAX_VALUE) {
      throw new IllegalArgumentException("Query result offset must be zero or greater.");
    }

    if (limit <= 0) {
      throw new IllegalArgumentException("Query results limit must be greater than zero.");
    }

    String query = makeQueryName(sqlNamespace, queryName);
    ResultHandlerTranslator<R> resultHandler = new ResultHandlerTranslator<R>(handler);
    try {
      if ((offset == 0) && (limit == Integer.MAX_VALUE)) {
        template.select(query, parameterObj, resultHandler);
      } else {
        RowBounds bounds = new RowBounds(offset, limit);
        template.select(query, parameterObj, bounds, resultHandler);
      }
    } catch (ClassCastException e) {
      throw new IllegalArgumentException("Return type of query does not match expected type.", e);
    } catch (Throwable e) {
      throw new QueryException(
          "Failed to execute query: \n"
              + "   Namespace: "
              + sqlNamespace
              + "\n"
              + "   queryName: "
              + queryName
              + "\n"
              + "   Parameter: "
              + parameterObj
              + "\n"
              + "   Offset:    "
              + offset
              + "\n"
              + "   Limit:     "
              + limit,
          e);
    }
  }
Exemple #15
0
  public void reply_insert(BoardDTO dto) {
    logger.info("\nBoardDAO class reply_insert(BoardDTO)");
    logger.info("BoardDAO replyname = " + dto.getReply_name());
    logger.info("BoardDAO replycontent =" + dto.getReply_content());
    logger.info("BoardDAO hobby_no =" + dto.getHobby_no());

    sqlSession.insert("reply_add", dto);
  } // end reply_insert
Exemple #16
0
  public List<BoardDTO> dbSelect(int start, int end, String skey, String sval) {
    logger.info("\nBoardDAO class List<BoardDTO> dbSelect()");

    dto.setStart(start);
    dto.setEnd(end);
    dto.setSkey(skey);
    dto.setSval(sval);
    return sqlSession.selectList("selectAll", dto);
  } // end dbSelect
Exemple #17
0
 public void dbInsert(BoardDTO dto) {
   logger.info("\nBoardDAO class dbInsert(BoardDTO)");
   logger.info("BoardDAO name = " + dto.getName());
   logger.info("BoardDAO title =" + dto.getTitle());
   logger.info("BoardDAO content =" + dto.getContent());
   logger.info("BoardDAO gender =" + dto.getGender());
   logger.info("BoardDAO hobby =" + dto.getHobby());
   logger.info("BoardDAO filename=" + dto.getImg_file_name());
   sqlSession.insert("add", dto);
 } // end dbInsert
  /** @함수이름 : myPageHistoryListSelect @작성일 : 2015. 12. 11. @개발자 : 오주석 @설명 : */
  @Override
  public List<UserOrderDto> myPageHistoryListSelect(int startRow, int endRow, String member_id) {

    HashMap<String, Object> hMap = new HashMap<String, Object>();
    hMap.put("startRow", startRow);
    hMap.put("endRow", endRow);
    hMap.put("member_id", member_id);

    return sqlSessionTemplate.selectList("dao.myPageMapper.myPageHistoryListSelect", hMap);
  }
Exemple #19
0
  /**
   * 根据查询条件得到集合,支持自定义范围
   *
   * @param statementName 查询使用的sql_id,不包含包名
   * @param condition 查询的条件
   * @param offset 记录起始位置,第一条记录
   * @param limit 结果集大小
   * @return 查询到的结果集List
   */
  @SuppressWarnings("rawtypes")
  public List findList(String statementName, Object condition, int offset, int limit) {
    RowBounds rb = new RowBounds(offset, limit);
    List list = null;

    list =
        sqlSessionTemplate.selectList(
            getMbatisMapperNamesapce() + "." + statementName, condition, rb);

    return list;
  }
 @SuppressWarnings("unchecked")
 @Override
 public <R> R executeQueryUnique(String sqlNamespace, String queryName, Object parameterObj) {
   String query = makeQueryName(sqlNamespace, queryName);
   Object obj = template.selectOne(query, parameterObj);
   try {
     return (R) obj;
   } catch (ClassCastException e) {
     throw new IllegalArgumentException("Return type of query does not match expected type.", e);
   }
 }
Exemple #21
0
  /**
   * @name : checkCoupon
   * @date : 2015. 7. 15.
   * @author : 황준
   * @description :쿠폰 등록한 업체 체크
   */
  @Override
  public int checkCoupon(String member_id, String coupon_no) {
    HashMap<String, Object> hMap = new HashMap<String, Object>();
    hMap.put("member_id", member_id);
    hMap.put("coupon_no", coupon_no);

    int check = 0;
    String checkId = sqlSession.selectOne("dao.BoardMapper.checkCoupon", hMap);
    if (checkId != null) check = 2;

    return check;
  }
Exemple #22
0
 public int getAllRownum() {
   UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
   if (userMapper != null) {
     try {
       int num = userMapper.getAllRownum();
       return num;
     } catch (Exception e) {
       return -999;
     }
   }
   return -999;
 }
Exemple #23
0
 public int getSequence() {
   UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
   if (userMapper != null) {
     try {
       int seq = userMapper.getSequence();
       return seq;
     } catch (Exception e) {
       return -999;
     }
   }
   return -999;
 }
Exemple #24
0
  /**
   * @name : blogWrite_attach
   * @date : 2015. 7. 02.
   * @author : 황준
   * @description : 블로그 작성(첨부이미지)
   */
  @Override
  public int blogWrite_attach(HashMap<String, Object> hashMap) {
    logger.info("BoardDao blogWrite_attach  DAO-------------------------");

    ArrayList<Attach_fileDto> attachList = (ArrayList<Attach_fileDto>) hashMap.get("attachList");
    logger.info("attachList:" + attachList.size());
    for (int i = 0; i < attachList.size(); i++) {
      logger.info(attachList.get(i).getFile_path());
    }

    int check = sqlSession.insert("dao.BoardMapper.blogWrite_attach", hashMap);
    return check;
  }
Exemple #25
0
 /*
  * for Encrypt password
  */
 public boolean encryptPassword(UserInfo userInfo) {
   UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
   if (userMapper != null) {
     try {
       userMapper.encryptSha512(userInfo);
       return true;
     } catch (Exception e) {
       e.toString();
       return false;
     }
   } else {
     return false;
   }
 }
Exemple #26
0
 public boolean approveReq(int uidx) {
   UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
   if (userMapper != null) {
     try {
       userMapper.approveRequest(uidx);
       userMapper.updateUpdate(uidx);
       userMapper.deleteRequest(uidx);
       return true;
     } catch (Exception e) {
       e.toString();
       return false;
     }
   } else {
     return false;
   }
 }
  /* (non-Javadoc)
   * @see com.delmar.core.dao.SqlSessionForLog#delete(java.lang.String, java.lang.Object)
   */
  public int delete(String statement, CoreModel model) {
    Integer id = null;
    try {
      id = (Integer) PropertyUtils.getProperty(model, "id");

    } catch (IllegalAccessException e) {
      logger.error(e, e);
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      logger.error(e, e);
      e.printStackTrace();
    } catch (NoSuchMethodException e) {
      logger.error(e, e);
      e.printStackTrace();
    }
    writeLog(model, SessionContent.OPERATE_DELETE);
    return sqlSessionTemplate.delete(statement, model);
  }
  /**
   * {@inheritDoc}
   *
   * <p>Only one return value is allowed and is checked to prevent <tt>null</tt> returns.
   */
  @Override
  public Long executeCountQuery(String sqlNamespace, String queryName, Object parameterObj) {
    String query = makeQueryName(sqlNamespace, queryName);
    try {
      Long result = template.selectOne(query, parameterObj);
      if (result == null) {
        result = 0L;
      }

      // Done
      if (logger.isDebugEnabled()) {
        logger.debug(
            "Executed query: \n"
                + "   Query:  "
                + query
                + "\n"
                + "   Params: "
                + parameterObj
                + "\n"
                + "   Result: "
                + result);
      }
      return result;
    } catch (ClassCastException e) {
      throw new QueryException(
          "Count query results must return exactly one Long value: \n"
              + "   Query:  "
              + query
              + "\n"
              + "   Params: "
              + parameterObj,
          e);
    } catch (Throwable e) {
      throw new QueryException(
          "Failed to execute query: \n"
              + "   Query:  "
              + query
              + "\n"
              + "   Params: "
              + parameterObj,
          e);
    }
  }
Exemple #29
0
 public UserInfo2 getUser(int uidx) throws SQLException {
   UserInfo2 userInfo2;
   UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
   if (userMapper != null) {
     userInfo2 = userMapper.getUser(uidx);
     if (userInfo2 == null) {
       userInfo2 = new UserInfo2();
       userInfo2.setErrorCode(Configuration.ErrorCodes.ER1001.getCodeName());
       userInfo2.setSubscribe_kor(Configuration.ErrorCodes.ER1001.getSubtitleKor());
       return userInfo2;
     } else {
       userInfo2.setErrorCode(Configuration.ErrorCodes.Success.getCodeName());
       userInfo2.setSubscribe_kor(Configuration.ErrorCodes.Success.getSubtitleKor());
       return userInfo2;
     }
   } else {
     userInfo2 = new UserInfo2();
     userInfo2.setErrorCode(Configuration.ErrorCodes.ER0000.getCodeName());
     userInfo2.setSubscribe_kor(Configuration.ErrorCodes.ER0000.getSubtitleKor());
     return userInfo2;
   }
 }
Exemple #30
0
  public UserInfo login(LoginInfo loginInfo) throws SQLException {
    UserInfo userInfo;

    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    if (userMapper != null) {
      userInfo = userMapper.getData(loginInfo);
      if (userInfo == null) {
        userInfo = new UserInfo();
        userInfo.setErrorCode(Configuration.ErrorCodes.ER1001.getCodeName());
        userInfo.setSubscribe_kor(Configuration.ErrorCodes.ER1001.getSubtitleKor());
        return userInfo;
      } else {
        userInfo.setErrorCode(Configuration.ErrorCodes.Success.getCodeName());
        userInfo.setSubscribe_kor(Configuration.ErrorCodes.Success.getSubtitleKor());
        return userInfo;
      }
    } else {
      userInfo = new UserInfo();
      userInfo.setErrorCode(Configuration.ErrorCodes.ER0000.getCodeName());
      userInfo.setSubscribe_kor(Configuration.ErrorCodes.ER0000.getSubtitleKor());
      return userInfo;
    }
  }