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) {