Package com.dp.nebula.wormhole.common

Examples of com.dp.nebula.wormhole.common.WormholeException


    Properties p = createProperties();
    try {
      DBSource.register(MysqlReader.class, this.ip, this.port, this.dbname, p);
      conn = DBSource.getConnection(MysqlReader.class, ip, port, dbname);
    } catch (Exception e) {
      throw new WormholeException(e, JobStatus.READ_CONNECTION_FAILED.getStatus() + MysqlReader.ERROR_CODE_ADD);
    }
    if(!preSql.isEmpty()) {
      try {
        DBUtils.dbPreCheck(preSql, conn);
      } catch (WormholeException e) {
        e.setStatusCode(e.getStatusCode() + MysqlReader.ERROR_CODE_ADD);
        throw e;
      }
    }
    //autoIncKey and tableName is not empty, than use key splitter, do not need count item number
    if(countSql.isEmpty()&&!sql.isEmpty() && needSplit && (autoIncKey.isEmpty() || tableName.isEmpty())) {
      countSql = format(SQL_COUNT_PATTERN, sql);
    }
    if(countSql.isEmpty()) {
      logger.info("Count sql is empty.");
      return;
    }
    ResultSet rs = null;
    try {
      logger.info("Count sql:" + countSql);
      rs = DBUtils.query(conn, countSql);
      rs.next();
      int size = rs.getInt(1);
      param.putValue(DATA_AMOUNT_KEY, Integer.toString(size));
      counter.setSourceLines(size);
      logger.info("Source data size: " + size + " lines.");
    } catch (Exception e) {
      logger.error("Cannot get result set size!" );
      throw new WormholeException(e,JobStatus.READ_FAILED.getStatus()+MysqlReader.ERROR_CODE_ADD);
    }finally {
      if (null != rs) {
          try {
          DBUtils.closeResultSet(rs);
        } catch (SQLException e) {
          logger.error("MysqlReader close resultset error " );
          throw new WormholeException(e,JobStatus.READ_FAILED.getStatus()+MysqlReader.ERROR_CODE_ADD)
        }
            }
          try {
          conn.close();
        } catch (SQLException e) {
View Full Code Here


  public List<IParam> split() {
    List<IParam> paramList = new ArrayList<IParam>() ;
    if(sql.isEmpty()) {
      if(tableName.isEmpty()||columns.isEmpty()) {
        logger.error("Mysql reader sql is empty");
        throw new WormholeException("Mysql reader sql is empty",JobStatus.CONF_FAILED.getStatus()+MysqlReader.ERROR_CODE_ADD);
      }
      if(!where.isEmpty()) {
        sql = String.format(SQL_WITH_WHERE_PATTEN, columns, tableName, where);
      } else {
        sql = String.format(SQL_WITHOUT_WHERE_PATTEN, columns, tableName);
View Full Code Here

    }
    logger.info("Mysql reader start to split");
    try {
      conn = DBSource.getConnection(MysqlReader.class, ip, port, dbname);
    } catch (Exception e) {
      throw new WormholeException(e, JobStatus.READ_CONNECTION_FAILED.getStatus() + MysqlReader.ERROR_CODE_ADD);
    }
    String rangeSql = "";
    if(!where.isEmpty()) {
      rangeSql = String.format(RANGE_SQL_WITH_WHERE_PATTERN, autoIncKey,autoIncKey,tableName,where);
    } else {
      rangeSql = String.format(RANGE_SQL_WITHOUT_WHERE_PATTERN, autoIncKey,autoIncKey,tableName);
    }
    long min=0,max=0;
   
    try {
      logger.debug("RangeSql: " + rangeSql);
      ResultSet rs = DBUtils.query(conn, rangeSql);
      rs.next();
      min = rs.getInt(1);
      max = rs.getInt(2);
      rs.close();
    } catch (Exception e) {
      logger.error(e.getMessage(),e);
      throw new WormholeException(e,JobStatus.READ_FAILED.getStatus()+MysqlReader.ERROR_CODE_ADD);
    }
    long start = min - 1;
    long end = min - 1 + blockSize;
    StringBuilder []sqlArray = new StringBuilder[concurrency];
    for(long i = 0; i <= (max-min)/blockSize; i++){
View Full Code Here

  @Override
  public void connection() {
    try {
      conn = DBSource.getConnection(this.getClass(), ip, port, dbname);
    } catch (Exception e) {
      throw new WormholeException(e, JobStatus.READ_CONNECTION_FAILED.getStatus() + ERROR_CODE_ADD);
    }
  }
View Full Code Here

    DBResultSetSender proxy = DBResultSetSender.newSender(lineSender);
    proxy.setMonitor(getMonitor());
    proxy.setDateFormatMap(genDateFormatMap());
    if(sql.isEmpty()){
      logger.error("Sql for mysqlReader is empty.");
      throw new WormholeException("Sql for mysqlReader is empty.",JobStatus.READ_FAILED.getStatus()+ERROR_CODE_ADD);
    }
    logger.debug(String.format("MysqlReader start to query %s .", sql));
    for(String sqlItem:sql.split(";")){
      sqlItem = sqlItem.trim();
      if(sqlItem.isEmpty()) {
        continue;
      }
      logger.debug(sqlItem);
      ResultSet rs = null;
      try {
        rs = DBUtils.query(conn, sqlItem);
        proxy.sendToWriter(rs);
        proxy.flush();
      } catch (SQLException e) {
        logger.error("Mysql read failed",e);
        throw new WormholeException(e,JobStatus.READ_FAILED.getStatus()+ERROR_CODE_ADD);
      } catch (WormholeException e1) {
        e1.setStatusCode(e1.getStatusCode() + ERROR_CODE_ADD);
        throw e1;
      } finally {
        if (null != rs) {
            try {
            DBUtils.closeResultSet(rs);
          } catch (SQLException e) {
            logger.error("MysqlReader close resultset error ");
            throw new WormholeException(e,JobStatus.READ_FAILED.getStatus()+ERROR_CODE_ADD)
          }
              }
      }
    }
  }
View Full Code Here

        param.putValue(ParamKey.username, props.getProperty(connectProps + "." + ParamKey.username).trim());
        param.putValue(ParamKey.password, props.getProperty(connectProps + "." + ParamKey.password).trim());
        param.putValue(ParamKey.dbname, props.getProperty(connectProps + "." + ParamKey.dbname).trim());
      } catch (Exception e) {
        s_logger.error(e.getMessage(),e);
        throw new WormholeException(e,JobStatus.CONF_FAILED.getStatus())
      }
    }
  }
View Full Code Here

          p.putValue(ParamKey.dataDir, fileStatus.getPath()
              .toString());
          result.add(p);
        }
      } catch (Exception e) {
        throw new WormholeException(e,
            JobStatus.READ_FAILED.getStatus());
      } finally {
        if (fs != null) {
          try {
            fs.close();
View Full Code Here

    Properties p = createProperties(param.getValue(ParamKey.url, null));
    try {
      DBSource.register(SqlserverReader.class, this.ip, this.port, this.dbname, p);
      conn = DBSource.getConnection(SqlserverReader.class, ip, port, dbname);
    } catch (Exception e) {
      throw new WormholeException(e, JobStatus.READ_CONNECTION_FAILED.getStatus() + SqlserverReader.ERROR_CODE_ADD);
    }
  }
View Full Code Here

      rs = DBUtils.query(conn, preSql);
      rs.next();
      flag = rs.getInt(1);
    } catch (Exception e) {
      logger.error("Pre check sql has error" );
      throw new WormholeException(e,JobStatus.PRE_CHECK_FAILED.getStatus())
    } finally {
            if (null != rs) {
          try {
          DBUtils.closeResultSet(rs);
        } catch (SQLException e) {
          throw new WormholeException(e,JobStatus.PRE_CHECK_FAILED.getStatus())
        }
            }        
    }
    if(flag != 1) {
      logger.error("Pre check condition is not satisfied." );
      throw new WormholeException(JobStatus.PRE_CHECK_FAILED.getStatus());
    }
  }
View Full Code Here

  @Override
  public void connection() {
    try {
      conn = DBSource.getConnection(this.getClass(), ip, port, dbname);
    } catch (Exception e) {
      throw new WormholeException(e, JobStatus.READ_CONNECTION_FAILED.getStatus() + ERROR_CODE_ADD);
    }
  }
View Full Code Here

TOP

Related Classes of com.dp.nebula.wormhole.common.WormholeException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.