Example usage for java.lang Byte equals

List of usage examples for java.lang Byte equals

Introduction

In this page you can find the example usage for java.lang Byte equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares this object to the specified object.

Usage

From source file:com.youanmi.scrm.core.account.service.org.OrgInfoService.java

/**
 * //from   ww w.ja v  a 2s  . c  o m
 */
@Transactional
@Override
public Long addOrg(AddOrgDto dto) {
    OrgInfoPo parent = getOrg(dto.getParentId());
    if (parent == null) {
        ValidateViewExceptionUtils.throwDataNotExistException();
    }
    if (!parent.getTopOrgId().equals(dto.getOperatorTopOrgId())) {
        ValidateViewExceptionUtils.throwIllegalOperationException("?,???");
    }
    if (parent.getOrgLevel().equals(AccountTableConstants.Org.TOP_LEVEL)) {
        ValidateViewExceptionUtils.throwIllegalOperationException("??");
    }

    if (parent.getOrgLevel() >= AccountConstants.Org.MAX_ORG_LEVEL) {
        ValidateViewExceptionUtils.throwIllegalOperationException("?,??");
    }

    Byte childOrgType = getOrgChildOrgType(parent.getId());
    // ??,??
    if (childOrgType != null && !childOrgType.equals(AccountTableConstants.Org.ORG_TYPE_CHAIN_DEPART)) {
        ValidateViewExceptionUtils
                .throwIllegalOperationException(", ???");
    }

    OrgInfoPo po = new OrgInfoPo();
    po.setOrgName(dto.getName());
    po.setOrgFullName(dto.getName());
    po.setParentOrgId(dto.getParentId());
    po.setCreateTime(System.currentTimeMillis());
    po.setUpdateTime(po.getCreateTime());
    po.setOrgLevel((byte) (parent.getOrgLevel() + 1));
    po.setOrgType(AccountTableConstants.Org.ORG_TYPE_CHAIN_DEPART);
    po.setTopOrgId(parent.getTopOrgId());

    if (parent.getOrgPath().endsWith(",")) {
        po.setOrgPath(parent.getOrgPath() + parent.getId() + ",");
    } else {
        po.setOrgPath(parent.getOrgPath() + "," + parent.getId() + ",");
    }

    Long id = baseDAO.findForObject(MappersConstants.Org.SELECT_ID_BY_TOP_ORG_AND_NAME, po);
    if (id != null) {
        throw new ViewExternalDisplayException(ResultCode.System.NAME_EXIST);
    }
    baseDAO.save(MappersConstants.Org.ADD_ORG, po);
    return po.getId();

}

From source file:de.uniwue.info6.webapp.lists.ExGroupTableBean.java

/**
 *
 *
 * @param ex// w  w  w . ja v  a2s  .  c  o  m
 * @return
 */
public String getLastUserEntryErrorText(Exercise ex) {
    UserEntry entry = userEntryDao.getLastUserEntry(ex);
    Byte credits = ex.getCredits();

    if (entry != null && showResults(ex.getExerciseGroup())) {
        UserResult result = userResultDao.getLastUserResultFromEntry(entry);

        User corrector = result.getUser();
        Byte userCredits = result.getCredits();

        if (result != null && result.getComment() != null && !result.getComment().trim().isEmpty()) {
            if (credits != null && userCredits != null) {
                if (credits.equals(userCredits)) {
                    if (corrector == null) {
                        return null;
                    }
                }
            }
            return result.getComment();
        }
    }
    return null;
}

From source file:com.youanmi.scrm.smp.facade.org.OrgInfoFacade.java

/**
 * ?//from  w  w w. jav a  2 s .c  om
 * 
 * @param shopDetailInfo ?
 * @author liubing
 */
public void addOrg(ShopDetailInfoParam shopDetailInfo) {

    checkParam(shopDetailInfo);
    /*
     * ??
     */
    /*
     * if (!varifyCodeService.getCodeValue(shopDetailInfo.getVerifyValue()))
     * { // ?? throw new
     * ViewExternalDisplayException(ResultCode.System.VERIFY_CODE_ERROR); }
     */
    /*
     * ???
     */
    OrgInfoDto orgById = orgInfoService.getOrgById(shopDetailInfo.getParentOrgId());
    if (null == orgById || !UserTokenThreadLocal.get().getTopOrgId().equals(orgById.getTopOrgId())) {
        throw new ViewExternalDisplayException(ResultCode.Org.DEPARTMENT_NOT_EXIST);
    }
    /*
     * ?
     */
    Byte orgChildOrgType = orgInfoService.getOrgChildOrgType(shopDetailInfo.getParentOrgId());
    if (null != orgChildOrgType && orgChildOrgType.equals(AccountTableConstants.Org.ORG_TYPE_CHAIN_DEPART)) {
        throw new ViewExternalDisplayException(ResultCode.Org.DIRECT_ORG_HAS_DEPART);
    }
    /*
     * ??????
     */
    List<Long> shopByTopOrgAndName = orgInfoService
            .getShopByTopOrgAndName(UserTokenThreadLocal.get().getTopOrgId(), shopDetailInfo.getOrgName());
    if (AssertUtils.notNull(shopByTopOrgAndName)) {
        throw new ViewExternalDisplayException(ResultCode.Org.ORG_NAME_REPEAT);
    }
    try {
        OrgInfoDto orgInfo = BeanCopyUtils.map(shopDetailInfo, OrgInfoDto.class);
        // ?
        orgInfo.setOrgType(AccountTableConstants.Org.ORG_TYPE_CHAIN_SHOP);
        // ?
        Long topOrgId = UserTokenThreadLocal.get().getTopOrgId();
        String orgAccount = userInfoService.getCommercialTenantCode(topOrgId);
        orgInfo.setOrgAccount(orgAccount);
        /*
         * ??
         */
        Long orgId = orgInfoService.addShopOrg(orgInfo);
        OrgDetailInfoDto detailInfoDto = BeanCopyUtils.map(shopDetailInfo, OrgDetailInfoDto.class);
        detailInfoDto.setOrgId(orgId);
        orgDetailInfoService.addOrgDetailInfo(detailInfoDto);

        /*
         * ????
         */
        addAdminOrManager(orgId, topOrgId, AccountTableConstants.User.USER_TYPE_SPECIAL,
                AccountTableConstants.Post.ADMIN, AccountTableConstants.Post.POST_TYPE_ADMIN,
                shopDetailInfo.getOrgName(), orgAccount);
        /*
         * 
         */
        addAdminOrManager(orgId, topOrgId, AccountTableConstants.User.USER_TYPE_GENERAL,
                AccountTableConstants.Post.MANAGER, AccountTableConstants.Post.POST_TYPE_SHOP_MANAGER,
                shopDetailInfo.getManager(), userInfoService.getCommercialTenantCode(topOrgId));

    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new ViewExternalDisplayException(ResultCode.Org.ADD_ORG_FAIL);
    }
}

From source file:com.youanmi.scrm.smp.facade.org.OrgInfoFacade.java

/**
 * //from  ww w .  j a v a2 s . c  om
 * 
 * 
 * @param param ?
 */
public void orgDetailEdit(OrgDetailParam param) {
    Long currentTimeStamp = System.currentTimeMillis();

    // Long orgId = param.getOrgId();
    Long topOrgId = UserTokenThreadLocal.get().getTopOrgId();
    Long orgId = UserTokenThreadLocal.get().getOrgId();
    String name = param.getName();
    Long provinceId = param.getProvinceId();
    Long cityId = param.getCityId();
    Long areaId = param.getAreaId();
    String address = param.getAddress();
    String businessLicense = param.getBusinessLicense(); // ?
    Long parentOrgId = param.getParentOrgId(); // id
    // 1.
    if (orgId == null) {
        throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "id");
    }
    if (StringUtils.isBlank(name)) {
        throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "??");
    }
    if (StringUtils.isBlank(businessLicense)) {
        throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "??");
    }
    if (provinceId == null) {
        throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "?");
    }
    if (cityId == null) {
        throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "");
    }
    if (areaId == null) {
        throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "");
    }
    if (StringUtils.isBlank(address)) {
        throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "?");
    }

    if (parentOrgId == null) {
        throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "");
    }

    // ???
    if (!MatcherUtils.matcherString(businessLicense, "^[0-9a-zA-Z\\S]+$")) {
        throw new ViewExternalDisplayException(ResultCode.orgDetail.BUSINESS_LICENSE_ILLEGAL);
    }
    // ??50
    if (address.length() > AccountTableConstants.Org.MAX_DETAIL_ADDRESS_LENGTH) {
        throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_LENGTH_BEYOND, "?");
    }

    // ?
    Byte orgChildOrgType = orgInfoService.getOrgChildOrgType(parentOrgId);
    if (null != orgChildOrgType && orgChildOrgType.equals(AccountTableConstants.Org.ORG_TYPE_CHAIN_DEPART)) {
        throw new ViewExternalDisplayException(ResultCode.Org.DIRECT_ORG_HAS_DEPART);
    }

    // ???
    Long parentTopOrgId = null;
    OrgInfoDto parentOrgInfoDto = orgInfoService.getOrgById(parentOrgId);
    if (parentOrgInfoDto != null) {
        parentTopOrgId = parentOrgInfoDto.getTopOrgId();
    }

    if (!topOrgId.equals(parentTopOrgId)) {
        throw new ViewExternalDisplayException(ResultCode.System.ILLEGALITY_REQUEST);
    }

    // ??????
    boolean flag = uniqueneShopOrgName(name, orgId, topOrgId);
    if (!flag) {
        throw new ViewExternalDisplayException(ResultCode.Org.ORG_NAME_REPEAT);
    }
    //checkOrgName(orgId, name);

    // 2.?
    OrgDetailInfoDto dto = new OrgDetailInfoDto();
    dto.setOrgId(orgId);
    dto.setProvinceId(provinceId);
    dto.setCityId(cityId);
    dto.setAreaId(areaId);
    dto.setAddress(address);
    dto.setBusinessLicense(businessLicense);

    String provinceName = null;
    GeogProvincePo provincePo = geogProvinceService.selectByPrimaryKey(provinceId.intValue());
    if (provincePo != null) {
        provinceName = provincePo.getName();
        dto.setProvinceName(provinceName);
    }

    String cityName = null;
    GeogCityPo cityPo = geogCityService.selectByPrimaryKey(cityId.intValue());
    if (cityPo != null) {
        cityName = cityPo.getName();
        dto.setCityName(cityName);
    }

    String areaName = null;
    GeogAreaPo areaPo = geogAreaService.selectByPrimaryKey(areaId.intValue());
    if (areaPo != null) {
        areaName = areaPo.getName();
        dto.setAreaName(areaName);
    }

    // ????
    if (StringUtils.isBlank(provinceName) || StringUtils.isBlank(cityName) || StringUtils.isBlank(areaName)) {
        throw new ViewExternalDisplayException(ResultCode.System.ILLEGALITY_REQUEST);
    }

    dto.setUpdateTime(currentTimeStamp);
    orgDetailInfoService.updateByParam(dto);

    // 3.org
    OrgInfoDto updateOrgInfoDto = new OrgInfoDto();
    updateOrgInfoDto.setId(orgId);
    updateOrgInfoDto.setOrgName(name);
    updateOrgInfoDto.setParentOrgId(parentOrgId);
    updateOrgInfoDto.setUpdateTime(currentTimeStamp);
    orgInfoService.updateByPrimaryKeySelective(updateOrgInfoDto);

}

From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryFieldPanel.java

/**
 * @return/*from   ww w.  j  av  a2s.  co  m*/
*/
public SortElement getOrderSpec(int pos) {
    Byte sortType;
    if (ownerQuery.isPromptMode()) {
        sortType = (byte) sortCheckbox.getState();
    } else {
        sortType = queryField.getSortType();
    }
    if (sortType.equals(SpQueryField.SORT_NONE)) {
        return null;
    }

    int direction = sortType.equals(SpQueryField.SORT_ASC) ? SortElement.ASCENDING : SortElement.DESCENDING;
    return new SortElement(pos, direction);
}

From source file:edu.ku.brc.specify.conversion.ConvertVerifier.java

/**
 * @param oldNewIdStr//from w ww . ja  v  a2  s  . c  o m
 * @param newColInx
 * @param oldColInx
 * @return
 * @throws SQLException
 */
private StatusType compareDates(final String oldNewIdStr, final int newColInx, final int oldColInx)
        throws SQLException {
    PartialDateConv datePair = new PartialDateConv();

    Object newObj = newDBRS.getObject(newColInx);
    Object oldObj = oldDBRS.getObject(oldColInx);

    ResultSetMetaData newRsmd = newDBRS.getMetaData();
    ResultSetMetaData oldRsmd = oldDBRS.getMetaData();

    String newColName = newRsmd.getColumnName(newColInx);
    String oldColName = oldRsmd.getColumnName(oldColInx);

    if (newObj == null) {
        String clsName = newRsmd.getColumnClassName(newColInx);

        if (compareTo6DBs) {
            if (!clsName.equals("java.sql.Date") || oldObj != null) {
                String msg = "New Value was null and shouldn't have been for Key Value New  Field ["
                        + newColName + "] [" + oldObj + "]";
                log.error(msg);
                tblWriter.logErrors(newColName, msg);
                return StatusType.NEW_VAL_NULL;
            }

        } else if (oldObj != null) {
            if (oldObj instanceof Number && ((Number) oldObj).intValue() == 0) {
                return StatusType.COMPARE_OK;

            } else if (!clsName.equals("java.sql.Date")
                    || (!(oldObj instanceof String) && ((Number) oldObj).intValue() != 0)) {
                String msg = "New Value was null and shouldn't have been for Key Value New Field [" + newColName
                        + "] [" + oldObj + "]";
                log.error(msg);
                tblWriter.logErrors(newColName, msg);
                return StatusType.NEW_VAL_NULL;
            }
        } else {
            return StatusType.COMPARE_OK;
        }
    }

    StringBuilder errSB = new StringBuilder();

    //System.out.println(newObj.getClass().getName()+"  "+oldObj.getClass().getName());

    if (newObj instanceof java.sql.Date) {
        boolean isPartialDate = false;
        Byte partialDateType = null;
        if (StringUtils.contains(newRsmd.getColumnName(newColInx + 1), "DatePrecision")) {
            partialDateType = newDBRS.getByte(newColInx);
            isPartialDate = true;
        }

        if (compareTo6DBs) {
            Object dateObj = oldDBRS.getObject(oldColInx);

            boolean isPartialDate2 = false;
            Byte partialDateType2 = null;
            if (StringUtils.contains(oldRsmd.getColumnName(oldColInx + 1), "DatePrecision")) {
                partialDateType2 = newDBRS.getByte(oldColInx);
                isPartialDate2 = true;

            } else {
                log.error("Next isn't DatePrecision and can't be!");
                tblWriter.logErrors(oldNewIdStr, errSB.toString());
            }

            if (!newObj.equals(dateObj) || (isPartialDate2 && !partialDateType2.equals(partialDateType))) {
                errSB.insert(0, oldColName + "  ");
                errSB.append("[");
                errSB.append(datePair);
                errSB.append("][");
                errSB.append(dateFormatter.format((Date) newObj));
                errSB.append("] oldDate[");
                errSB.append(dateFormatter.format((Date) dateObj));
                errSB.append("]");
                log.error(errSB.toString());
                tblWriter.logErrors(oldNewIdStr, errSB.toString());
                return StatusType.BAD_DATE;
            }

        } else {
            int oldIntDate = oldDBRS.getInt(oldColInx);
            if (oldIntDate == 0) {
                return StatusType.NO_OLD_REC;
            }

            BasicSQLUtils.getPartialDate(oldIntDate, datePair, false);

            if (partialDateType != null) {
                if (Byte.parseByte(datePair.getPartial()) != partialDateType.byteValue()) {
                    errSB.append("Partial Dates Type do not match. Old[" + datePair.getPartial() + "]  New ["
                            + partialDateType.byteValue() + "]");
                    // error partial dates don't match
                }
            }

            Calendar cal = Calendar.getInstance();
            cal.setTime((Date) newObj);

            int year = Integer.parseInt(datePair.getDateStr().substring(0, 4));
            int mon = Integer.parseInt(datePair.getDateStr().substring(5, 7));
            int day = Integer.parseInt(datePair.getDateStr().substring(8, 10));

            if (mon > 0)
                mon--;

            boolean isYearOK = true;

            int yr = cal.get(Calendar.YEAR);
            if (year != yr) {
                errSB.append("Year mismatch Old[" + year + "]  New [" + yr + "] ");
                isYearOK = false;
            }

            if (mon != cal.get(Calendar.MONTH)) {
                errSB.append("Month mismatch Old[" + mon + "]  New [" + cal.get(Calendar.MONTH) + "] ");
            }

            if (day != cal.get(Calendar.DAY_OF_MONTH)) {
                errSB.append("Day mismatch Old[" + day + "]  New [" + cal.get(Calendar.DAY_OF_MONTH) + "] ");
            }

            if (errSB.length() > 0 && (!isYearOK || !isPartialDate)) {
                errSB.insert(0, oldColName + "  ");
                errSB.append("[");
                errSB.append(datePair);
                errSB.append("][");
                errSB.append(dateFormatter.format((Date) newObj));
                errSB.append("]");
                log.error(errSB.toString());
                tblWriter.logErrors(oldNewIdStr, errSB.toString());
                return StatusType.BAD_DATE;
            }
        }
    }

    return StatusType.COMPARE_OK;
}

From source file:edu.ku.brc.specify.conversion.ConvertVerifier.java

/**
 * @param oldSQL/*  w  w w.ja  v  a 2  s.co  m*/
 * @param newSQL
 * @return
 * @throws SQLException
 */
private StatusType compareRecords(final String desc, final String oldCatNumArg, final String newCatNumArg,
        final String oldSQLArg, final String newSQLArg, final boolean nullsAreOK, final boolean notRetarded)
        throws SQLException {
    boolean dbg = false;
    if (dbg) {
        System.out.println(oldSQLArg);
        System.out.println(newSQLArg);
    }
    if (dbg) {
        System.out.println("\n" + desc);
        dump(desc, oldDBConn, compareTo6DBs ? newSQLArg : oldSQLArg);
        dump(desc, newDBConn, newSQLArg);
    }

    String oldCatNum = oldCatNumArg;
    String newCatNum = newCatNumArg;
    if (compareTo6DBs) {
        oldCatNum = newCatNumArg;
    }

    if (notRetarded) {
        getResultSetsNotRetarded(oldSQLArg, newSQLArg, oldCatNum, newCatNum);
    } else {
        getResultSets(oldSQLArg, newSQLArg);
    }

    try {

        boolean hasOldRec = oldDBRS.next();
        boolean hasNewRec = newDBRS.next();

        if (!hasOldRec && !hasNewRec) {
            return StatusType.COMPARE_OK;
        }

        if (!hasOldRec) {
            if (nullsAreOK) {
                log.error(desc + " - No Old Record for [" + oldCatNum + "]");
                tblWriter.logErrors(oldCatNum, "No Old Record");
                return StatusType.NO_OLD_REC;
            }
            return StatusType.COMPARE_OK;
        }
        if (!hasNewRec) {
            log.error(desc + " - No New Record for [" + newCatNum + "]");
            tblWriter.logErrors(newCatNum, "No New Record");
            return StatusType.NO_NEW_REC;
        }

        //check number of rows, if not equal don't try to compare
        oldDBRS.last();
        newDBRS.last();
        if (oldDBRS.getRow() != newDBRS.getRow()) {
            String msg = desc + " Cat Num [" + oldCatNum + "]: Sp5 DB has " + oldDBRS.getRow()
                    + " related records. Sp6 DB has " + newDBRS.getRow();
            log.error(msg);
            tblWriter.logErrors(newCatNum, msg);
            return oldDBRS.getRow() < newDBRS.getRow() ? StatusType.NO_NEW_REC : StatusType.NO_OLD_REC;
        }
        oldDBRS.first();
        newDBRS.first();

        String oldNewIdStr = oldCatNum + " / " + newCatNum;

        boolean checkForAgent = newSQL.indexOf("a.LastName") > -1;

        ResultSetMetaData oldRsmd = oldDBRS.getMetaData();
        ResultSetMetaData newRsmd = newDBRS.getMetaData();

        PartialDateConv datePair = new PartialDateConv();
        Calendar cal = Calendar.getInstance();
        StringBuilder errSB = new StringBuilder();

        while (hasNewRec && hasOldRec) {
            errSB.setLength(0);

            int oldColInx = 0;
            int newColInx = 0;
            String idMsgStr = "";

            int numCols = newRsmd.getColumnCount();

            for (int col = 0; col < numCols; col++) {
                newColInx++;
                oldColInx++;

                if (dbg) {
                    System.out.println("\ncol       " + col + " / " + oldRsmd.getColumnCount());
                    System.out.println("newColInx " + newColInx);
                    System.out.println("oldColInx " + oldColInx);
                    System.out.println(oldRsmd.getColumnName(oldColInx));
                    System.out.println(newRsmd.getColumnName(newColInx));
                }

                Object newObj = newDBRS.getObject(newColInx);
                Object oldObj = oldDBRS.getObject(oldColInx);

                if (oldObj == null && newObj == null) {
                    String colName = newRsmd.getColumnName(newColInx);

                    if (StringUtils.contains(colName, "Date")
                            && StringUtils.contains(newRsmd.getColumnName(newColInx + 1), "DatePrecision")) {
                        newColInx++;
                        numCols--;
                        if (compareTo6DBs)
                            oldColInx++;
                    }
                    continue;
                }

                if (col == 0) {
                    idMsgStr = String.format(" - Rec Ids[%s / %s] ", (oldObj != null ? oldObj : -1),
                            (newObj != null ? newObj : -1));
                    continue;
                }

                String oldColName = oldRsmd.getColumnName(oldColInx);
                if (oldColName.equals("PreparationMethod") && newObj != null) {
                    String newObjStr = newObj.toString();
                    if ((oldObj == null && !newObjStr.equalsIgnoreCase("Misc"))
                            || (oldObj != null && !newObjStr.equalsIgnoreCase(oldObj.toString()))) {
                        String msg = idMsgStr + "Old Value was null and shouldn't have been for Old CatNum ["
                                + oldCatNum + "] Field [" + oldColName + "] oldObj[" + oldObj + "] newObj ["
                                + newObj + "]";
                        log.error(desc + " - " + msg);
                        tblWriter.logErrors(oldCatNum, msg);
                        return StatusType.OLD_VAL_NULL;
                    }
                    continue;
                }

                if (oldObj == null && !StringUtils.contains(oldColName, "LastName")) {
                    if (!oldColName.equals("PreparationMethod") || !newObj.equals("Misc")) {
                        String msg = idMsgStr + "Old Value was null and shouldn't have been for Old CatNum ["
                                + oldCatNum + "] Field [" + oldColName + "]  New Val[" + newObj + "]";
                        log.error(desc + " - " + msg);
                        tblWriter.logErrors(oldCatNum, msg);
                        return StatusType.OLD_VAL_NULL;
                    }
                }

                if (newObj == null) {
                    String clsName = newRsmd.getColumnClassName(newColInx);
                    String colName = newRsmd.getColumnName(newColInx);

                    if (compareTo6DBs) {
                        if (!clsName.equals("java.sql.Date") || oldObj != null) {
                            String msg = "New Value was null and shouldn't have been for Key Value New CatNo["
                                    + newCatNum + "] Field [" + colName + "] [" + oldObj + "]";
                            log.error(desc + " - " + msg);
                            tblWriter.logErrors(newCatNum, msg);
                            return StatusType.NEW_VAL_NULL;
                        }

                    } else {
                        if (!clsName.equals("java.sql.Date")
                                || (!(oldObj instanceof String) && ((Number) oldObj).intValue() != 0)) {
                            String msg = "New Value was null and shouldn't have been for Key Value New CatNo["
                                    + newCatNum + "] Field [" + colName + "] [" + oldObj + "]";
                            log.error(desc + " - " + msg);
                            if (tblWriter != null && newCatNum != null && msg != null)
                                tblWriter.logErrors(newCatNum, msg);
                            dbg = true;
                            return StatusType.NEW_VAL_NULL;
                        }
                    }

                    if (StringUtils.contains(colName, "Date")
                            && StringUtils.contains(newRsmd.getColumnName(newColInx + 1), "DatePrecision")) {
                        newColInx++;
                        numCols--;
                        if (compareTo6DBs)
                            oldColInx++;
                    }
                    continue;
                }

                //String colName = newRsmd.getColumnName(col);
                //System.out.println(newObj.getClass().getName()+"  "+oldObj.getClass().getName());

                if (newObj instanceof java.sql.Date) {
                    boolean isPartialDate = false;
                    Byte partialDateType = null;
                    if (StringUtils.contains(newRsmd.getColumnName(newColInx + 1), "DatePrecision")) {
                        newColInx++;
                        numCols--;
                        partialDateType = newDBRS.getByte(newColInx);
                        isPartialDate = true;
                    }

                    if (compareTo6DBs) {
                        Object dateObj = oldDBRS.getObject(oldColInx);

                        boolean isPartialDate2 = false;
                        Byte partialDateType2 = null;
                        if (StringUtils.contains(oldRsmd.getColumnName(oldColInx + 1), "DatePrecision")) {
                            oldColInx++;
                            partialDateType2 = newDBRS.getByte(oldColInx);
                            isPartialDate2 = true;

                        } else {
                            log.error("Next isn't DatePrecision and can't be!");
                            tblWriter.logErrors(oldNewIdStr, errSB.toString());
                        }

                        if (!newObj.equals(dateObj)
                                || (isPartialDate2 && !partialDateType2.equals(partialDateType))) {
                            errSB.insert(0, oldColName + "  ");
                            errSB.append("[");
                            errSB.append(datePair);
                            errSB.append("][");
                            errSB.append(dateFormatter.format((Date) newObj));
                            errSB.append("] oldDate[");
                            errSB.append(dateFormatter.format((Date) dateObj));
                            errSB.append("]");
                            log.error(errSB.toString());
                            tblWriter.logErrors(oldNewIdStr, errSB.toString());
                            return StatusType.BAD_DATE;
                        }

                    } else {
                        int oldIntDate = oldDBRS.getInt(oldColInx);
                        if (oldIntDate == 0) {
                            continue;
                        }

                        BasicSQLUtils.getPartialDate(oldIntDate, datePair, false);

                        if (partialDateType != null) {
                            boolean ok = StringUtils.isNotEmpty(datePair.getPartial())
                                    && StringUtils.isNumeric(datePair.getPartial());
                            if (!ok || (Byte.parseByte(datePair.getPartial()) != partialDateType.byteValue())) {
                                errSB.append("Partial Dates Type do not match. Old[" + datePair.getPartial()
                                        + "]  New [" + partialDateType.byteValue() + "]");
                                // error partial dates don't match
                            }
                        }

                        cal.setTime((Date) newObj);

                        if (StringUtils.isNotEmpty(datePair.getDateStr())
                                && !datePair.getDateStr().equalsIgnoreCase("null")) {
                            int year = Integer.parseInt(datePair.getDateStr().substring(0, 4));
                            int mon = Integer.parseInt(datePair.getDateStr().substring(5, 7));
                            int day = Integer.parseInt(datePair.getDateStr().substring(8, 10));

                            if (mon > 0)
                                mon--;

                            boolean isYearOK = true;

                            int yr = cal.get(Calendar.YEAR);
                            if (year != yr) {
                                errSB.append("Year mismatch Old[" + year + "]  New [" + yr + "] ");
                                isYearOK = false;
                            }

                            if (mon != cal.get(Calendar.MONTH)) {
                                errSB.append("Month mismatch Old[" + mon + "]  New [" + cal.get(Calendar.MONTH)
                                        + "] ");
                            }

                            if (day != cal.get(Calendar.DAY_OF_MONTH)) {
                                errSB.append("Day mismatch Old[" + day + "]  New ["
                                        + cal.get(Calendar.DAY_OF_MONTH) + "] ");
                            }

                            if (errSB.length() > 0 && (!isYearOK || !isPartialDate)) {
                                errSB.insert(0, oldColName + "  ");
                                errSB.append("[");
                                errSB.append(datePair);
                                errSB.append("][");
                                errSB.append(dateFormatter.format((Date) newObj));
                                errSB.append("]");
                                log.error(errSB.toString());
                                tblWriter.logErrors(oldNewIdStr, errSB.toString());
                                return StatusType.BAD_DATE;
                            }
                        } else {
                            //String msg = "Date contains the string 'NULL'";
                            //log.error(msg);
                            //tblWriter.logErrors(oldNewIdStr, msg);
                            //return StatusType.BAD_DATE;
                        }
                    }
                } else if (newObj instanceof Float || newObj instanceof Double) {
                    String s1 = String.format("%10.5f",
                            newObj instanceof Float ? (Float) newObj : (Double) newObj);
                    String s2 = String.format("%10.5f",
                            oldObj instanceof Float ? (Float) oldObj : (Double) oldObj);
                    if (!s1.equals(s2)) {
                        String msg = idMsgStr + "Columns don't compare[" + s1 + "][" + s2 + "]  ["
                                + newRsmd.getColumnName(col) + "][" + oldRsmd.getColumnName(oldColInx) + "]";
                        log.error(desc + " - " + msg);
                        tblWriter.logErrors(oldNewIdStr, msg);
                        return StatusType.NO_COMPARE;
                    }

                } else {
                    String newColName = newRsmd.getColumnName(newColInx);
                    if (checkForAgent && StringUtils.contains(newColName, "LastName")) {
                        String lastName = oldDBRS.getString(oldColInx);
                        String agentName = oldDBRS.getString(oldColInx + 1); // The 'Name' Column
                        String newLastName = newDBRS.getString(newColInx);
                        if (!newLastName.equals(lastName) && !newLastName.equals(agentName)) {
                            String msg = idMsgStr + "Name Columns don't compare[" + newObj + "][" + oldObj
                                    + "]  [" + newColName + "][" + oldColName + "]";
                            log.error(desc + " - " + msg);
                            tblWriter.logErrors(oldNewIdStr, msg);
                            log.error(oldSQLArg + "\n" + newSQLArg);
                            return StatusType.NO_COMPARE;
                        }

                    } else if (StringUtils.contains(newColName, "YesNo")) {
                        boolean yesNoNew = newDBRS.getBoolean(newColInx);
                        boolean yesNoOld = oldDBRS.getInt(oldColInx) != 0;

                        if (yesNoNew != yesNoOld) {
                            String msg = idMsgStr + "Columns don't Cat Num[" + oldCatNum + "] compare["
                                    + yesNoNew + "][" + yesNoOld + "]  [" + newColName + "][" + oldColName
                                    + "]";
                            log.error(desc + " - " + msg);
                            tblWriter.logErrors(oldNewIdStr, msg);
                            return StatusType.NO_COMPARE;
                        }

                    } else if (!newObj.equals(oldObj)) {
                        String msg = idMsgStr + "Columns don't Cat Num[" + oldCatNum + "] compare[" + newObj
                                + "][" + oldObj + "]  [" + newColName + "][" + oldColName + "]";
                        log.error(desc + " - " + msg);
                        tblWriter.logErrors(oldNewIdStr, msg);
                        return StatusType.NO_COMPARE;

                        /*boolean isOK = false;
                        if (oldObj instanceof String)
                        {
                        String oldStr = (String)oldObj;
                        String newStr = (String)newObj;
                        String lof    = "\\r\\n";
                        int    inx    = newStr.indexOf(lof);
                        if (inx > -1)
                        {
                            String tok = oldStr.substring(0, inx);
                            if (newStr.equals(tok))
                            {
                                isOK = true;
                            }
                        }
                        }
                        if (!isOK)
                        {
                        log.error(desc+ " - Columns don't compare["+newObj+"]["+oldObj+"]  ["+newRsmd.getColumnName(newColInx)+"]["+oldRsmd.getColumnName(oldColInx)+"]");
                        return false;
                        }*/
                    }
                }
            }

            hasOldRec = oldDBRS.next();
            hasNewRec = newDBRS.next();

            if (!hasOldRec && !hasNewRec) {
                return StatusType.COMPARE_OK;
            }

            if (!hasOldRec) {
                log.error(desc + idMsgStr + " - No Old Record for [" + oldCatNum + "]");
                tblWriter.logErrors(oldNewIdStr, "No Old Record for [" + oldCatNum + "]");
                return StatusType.NO_OLD_REC;
            }
            if (!hasNewRec) {
                log.error(desc + idMsgStr + " No New Record for [" + newCatNum + "]");
                tblWriter.logErrors(oldNewIdStr, "No New Record for [" + newCatNum + "]");
                return StatusType.NO_NEW_REC;
            }
        }
    } finally {
        doneWithRS();
    }

    return StatusType.COMPARE_OK;
}

From source file:org.apache.hadoop.hive.ql.optimizer.physical.GenSparkSkewJoinProcessor.java

@SuppressWarnings("unchecked")
public static void processSkewJoin(JoinOperator joinOp, Task<? extends Serializable> currTask,
        ReduceWork reduceWork, ParseContext parseCtx) throws SemanticException {

    SparkWork currentWork = ((SparkTask) currTask).getWork();
    if (currentWork.getChildren(reduceWork).size() > 0) {
        LOG.warn("Skip runtime skew join as the ReduceWork has child work and hasn't been split.");
        return;/*www.j  a v a2 s .  com*/
    }

    List<Task<? extends Serializable>> children = currTask.getChildTasks();

    Task<? extends Serializable> child = children != null && children.size() == 1 ? children.get(0) : null;

    Path baseTmpDir = parseCtx.getContext().getMRTmpPath();

    JoinDesc joinDescriptor = joinOp.getConf();
    Map<Byte, List<ExprNodeDesc>> joinValues = joinDescriptor.getExprs();
    int numAliases = joinValues.size();

    Map<Byte, Path> bigKeysDirMap = new HashMap<Byte, Path>();
    Map<Byte, Map<Byte, Path>> smallKeysDirMap = new HashMap<Byte, Map<Byte, Path>>();
    Map<Byte, Path> skewJoinJobResultsDir = new HashMap<Byte, Path>();
    Byte[] tags = joinDescriptor.getTagOrder();
    // for each joining table, set dir for big key and small keys properly
    for (int i = 0; i < numAliases; i++) {
        Byte alias = tags[i];
        bigKeysDirMap.put(alias, GenMRSkewJoinProcessor.getBigKeysDir(baseTmpDir, alias));
        Map<Byte, Path> smallKeysMap = new HashMap<Byte, Path>();
        smallKeysDirMap.put(alias, smallKeysMap);
        for (Byte src2 : tags) {
            if (!src2.equals(alias)) {
                smallKeysMap.put(src2, GenMRSkewJoinProcessor.getSmallKeysDir(baseTmpDir, alias, src2));
            }
        }
        skewJoinJobResultsDir.put(alias, GenMRSkewJoinProcessor.getBigKeysSkewJoinResultDir(baseTmpDir, alias));
    }

    joinDescriptor.setHandleSkewJoin(true);
    joinDescriptor.setBigKeysDirMap(bigKeysDirMap);
    joinDescriptor.setSmallKeysDirMap(smallKeysDirMap);
    joinDescriptor
            .setSkewKeyDefinition(HiveConf.getIntVar(parseCtx.getConf(), HiveConf.ConfVars.HIVESKEWJOINKEY));

    // create proper table/column desc for spilled tables
    TableDesc keyTblDesc = (TableDesc) reduceWork.getKeyDesc().clone();
    List<String> joinKeys = Utilities.getColumnNames(keyTblDesc.getProperties());
    List<String> joinKeyTypes = Utilities.getColumnTypes(keyTblDesc.getProperties());

    Map<Byte, TableDesc> tableDescList = new HashMap<Byte, TableDesc>();
    Map<Byte, RowSchema> rowSchemaList = new HashMap<Byte, RowSchema>();
    Map<Byte, List<ExprNodeDesc>> newJoinValues = new HashMap<Byte, List<ExprNodeDesc>>();
    Map<Byte, List<ExprNodeDesc>> newJoinKeys = new HashMap<Byte, List<ExprNodeDesc>>();
    // used for create mapJoinDesc, should be in order
    List<TableDesc> newJoinValueTblDesc = new ArrayList<TableDesc>();

    for (int i = 0; i < tags.length; i++) {
        newJoinValueTblDesc.add(null);
    }

    for (int i = 0; i < numAliases; i++) {
        Byte alias = tags[i];
        List<ExprNodeDesc> valueCols = joinValues.get(alias);
        String colNames = "";
        String colTypes = "";
        int columnSize = valueCols.size();
        List<ExprNodeDesc> newValueExpr = new ArrayList<ExprNodeDesc>();
        List<ExprNodeDesc> newKeyExpr = new ArrayList<ExprNodeDesc>();
        ArrayList<ColumnInfo> columnInfos = new ArrayList<ColumnInfo>();

        boolean first = true;
        for (int k = 0; k < columnSize; k++) {
            TypeInfo type = valueCols.get(k).getTypeInfo();
            String newColName = i + "_VALUE_" + k; // any name, it does not matter.
            ColumnInfo columnInfo = new ColumnInfo(newColName, type, alias.toString(), false);
            columnInfos.add(columnInfo);
            newValueExpr.add(new ExprNodeColumnDesc(columnInfo.getType(), columnInfo.getInternalName(),
                    columnInfo.getTabAlias(), false));
            if (!first) {
                colNames = colNames + ",";
                colTypes = colTypes + ",";
            }
            first = false;
            colNames = colNames + newColName;
            colTypes = colTypes + valueCols.get(k).getTypeString();
        }

        // we are putting join keys at last part of the spilled table
        for (int k = 0; k < joinKeys.size(); k++) {
            if (!first) {
                colNames = colNames + ",";
                colTypes = colTypes + ",";
            }
            first = false;
            colNames = colNames + joinKeys.get(k);
            colTypes = colTypes + joinKeyTypes.get(k);
            ColumnInfo columnInfo = new ColumnInfo(joinKeys.get(k),
                    TypeInfoFactory.getPrimitiveTypeInfo(joinKeyTypes.get(k)), alias.toString(), false);
            columnInfos.add(columnInfo);
            newKeyExpr.add(new ExprNodeColumnDesc(columnInfo.getType(), columnInfo.getInternalName(),
                    columnInfo.getTabAlias(), false));
        }

        newJoinValues.put(alias, newValueExpr);
        newJoinKeys.put(alias, newKeyExpr);
        tableDescList.put(alias, Utilities.getTableDesc(colNames, colTypes));
        rowSchemaList.put(alias, new RowSchema(columnInfos));

        // construct value table Desc
        String valueColNames = "";
        String valueColTypes = "";
        first = true;
        for (int k = 0; k < columnSize; k++) {
            String newColName = i + "_VALUE_" + k; // any name, it does not matter.
            if (!first) {
                valueColNames = valueColNames + ",";
                valueColTypes = valueColTypes + ",";
            }
            valueColNames = valueColNames + newColName;
            valueColTypes = valueColTypes + valueCols.get(k).getTypeString();
            first = false;
        }
        newJoinValueTblDesc.set((byte) i, Utilities.getTableDesc(valueColNames, valueColTypes));
    }

    joinDescriptor.setSkewKeysValuesTables(tableDescList);
    joinDescriptor.setKeyTableDesc(keyTblDesc);

    // create N-1 map join tasks
    HashMap<Path, Task<? extends Serializable>> bigKeysDirToTaskMap = new HashMap<Path, Task<? extends Serializable>>();
    List<Serializable> listWorks = new ArrayList<Serializable>();
    List<Task<? extends Serializable>> listTasks = new ArrayList<Task<? extends Serializable>>();
    for (int i = 0; i < numAliases - 1; i++) {
        Byte src = tags[i];
        HiveConf hiveConf = new HiveConf(parseCtx.getConf(), GenSparkSkewJoinProcessor.class);
        SparkWork sparkWork = new SparkWork(parseCtx.getConf().getVar(HiveConf.ConfVars.HIVEQUERYID));
        Task<? extends Serializable> skewJoinMapJoinTask = TaskFactory.get(sparkWork, hiveConf);
        skewJoinMapJoinTask.setFetchSource(currTask.isFetchSource());

        // create N TableScans
        Operator<? extends OperatorDesc>[] parentOps = new TableScanOperator[tags.length];
        for (int k = 0; k < tags.length; k++) {
            Operator<? extends OperatorDesc> ts = GenMapRedUtils
                    .createTemporaryTableScanOperator(rowSchemaList.get((byte) k));
            ((TableScanOperator) ts).setTableDesc(tableDescList.get((byte) k));
            parentOps[k] = ts;
        }

        // create the MapJoinOperator
        String dumpFilePrefix = "mapfile" + PlanUtils.getCountForMapJoinDumpFilePrefix();
        MapJoinDesc mapJoinDescriptor = new MapJoinDesc(newJoinKeys, keyTblDesc, newJoinValues,
                newJoinValueTblDesc, newJoinValueTblDesc, joinDescriptor.getOutputColumnNames(), i,
                joinDescriptor.getConds(), joinDescriptor.getFilters(), joinDescriptor.getNoOuterJoin(),
                dumpFilePrefix);
        mapJoinDescriptor.setTagOrder(tags);
        mapJoinDescriptor.setHandleSkewJoin(false);
        mapJoinDescriptor.setNullSafes(joinDescriptor.getNullSafes());
        // temporarily, mark it as child of all the TS
        MapJoinOperator mapJoinOp = (MapJoinOperator) OperatorFactory.getAndMakeChild(mapJoinDescriptor, null,
                parentOps);

        // clone the original join operator, and replace it with the MJ
        // this makes sure MJ has the same downstream operator plan as the original join
        List<Operator<?>> reducerList = new ArrayList<Operator<?>>();
        reducerList.add(reduceWork.getReducer());
        Operator<? extends OperatorDesc> reducer = Utilities.cloneOperatorTree(parseCtx.getConf(), reducerList)
                .get(0);
        Preconditions.checkArgument(reducer instanceof JoinOperator,
                "Reducer should be join operator, but actually is " + reducer.getName());
        JoinOperator cloneJoinOp = (JoinOperator) reducer;
        List<Operator<? extends OperatorDesc>> childOps = cloneJoinOp.getChildOperators();
        for (Operator<? extends OperatorDesc> childOp : childOps) {
            childOp.replaceParent(cloneJoinOp, mapJoinOp);
        }
        mapJoinOp.setChildOperators(childOps);

        // set memory usage for the MJ operator
        setMemUsage(mapJoinOp, skewJoinMapJoinTask, parseCtx);

        // create N MapWorks and add them to the SparkWork
        MapWork bigMapWork = null;
        Map<Byte, Path> smallTblDirs = smallKeysDirMap.get(src);
        for (int j = 0; j < tags.length; j++) {
            MapWork mapWork = PlanUtils.getMapRedWork().getMapWork();
            sparkWork.add(mapWork);
            // This code has been only added for testing
            boolean mapperCannotSpanPartns = parseCtx.getConf()
                    .getBoolVar(HiveConf.ConfVars.HIVE_MAPPER_CANNOT_SPAN_MULTIPLE_PARTITIONS);
            mapWork.setMapperCannotSpanPartns(mapperCannotSpanPartns);
            Operator<? extends OperatorDesc> tableScan = parentOps[j];
            String alias = tags[j].toString();
            ArrayList<String> aliases = new ArrayList<String>();
            aliases.add(alias);
            Path path;
            if (j == i) {
                path = bigKeysDirMap.get(tags[j]);
                bigKeysDirToTaskMap.put(path, skewJoinMapJoinTask);
                bigMapWork = mapWork;
            } else {
                path = smallTblDirs.get(tags[j]);
            }
            mapWork.getPathToAliases().put(path.toString(), aliases);
            mapWork.getAliasToWork().put(alias, tableScan);
            PartitionDesc partitionDesc = new PartitionDesc(tableDescList.get(tags[j]), null);
            mapWork.getPathToPartitionInfo().put(path.toString(), partitionDesc);
            mapWork.getAliasToPartnInfo().put(alias, partitionDesc);
            mapWork.setName("Map " + GenSparkUtils.getUtils().getNextSeqNumber());
        }
        // connect all small dir map work to the big dir map work
        Preconditions.checkArgument(bigMapWork != null, "Haven't identified big dir MapWork");
        // these 2 flags are intended only for the big-key map work
        bigMapWork
                .setNumMapTasks(HiveConf.getIntVar(hiveConf, HiveConf.ConfVars.HIVESKEWJOINMAPJOINNUMMAPTASK));
        bigMapWork
                .setMinSplitSize(HiveConf.getLongVar(hiveConf, HiveConf.ConfVars.HIVESKEWJOINMAPJOINMINSPLIT));
        // use HiveInputFormat so that we can control the number of map tasks
        bigMapWork.setInputformat(HiveInputFormat.class.getName());
        for (BaseWork work : sparkWork.getRoots()) {
            Preconditions.checkArgument(work instanceof MapWork,
                    "All root work should be MapWork, but got " + work.getClass().getSimpleName());
            if (work != bigMapWork) {
                sparkWork.connect(work, bigMapWork, new SparkEdgeProperty(SparkEdgeProperty.SHUFFLE_NONE));
            }
        }

        // insert SparkHashTableSink and Dummy operators
        for (int j = 0; j < tags.length; j++) {
            if (j != i) {
                insertSHTS(tags[j], (TableScanOperator) parentOps[j], bigMapWork);
            }
        }

        listWorks.add(skewJoinMapJoinTask.getWork());
        listTasks.add(skewJoinMapJoinTask);
    }
    if (children != null) {
        for (Task<? extends Serializable> tsk : listTasks) {
            for (Task<? extends Serializable> oldChild : children) {
                tsk.addDependentTask(oldChild);
            }
        }
    }
    if (child != null) {
        currTask.removeDependentTask(child);
        listTasks.add(child);
        listWorks.add(child.getWork());
    }
    ConditionalResolverSkewJoin.ConditionalResolverSkewJoinCtx context = new ConditionalResolverSkewJoin.ConditionalResolverSkewJoinCtx(
            bigKeysDirToTaskMap, child);

    ConditionalWork cndWork = new ConditionalWork(listWorks);
    ConditionalTask cndTsk = (ConditionalTask) TaskFactory.get(cndWork, parseCtx.getConf());
    cndTsk.setListTasks(listTasks);
    cndTsk.setResolver(new ConditionalResolverSkewJoin());
    cndTsk.setResolverCtx(context);
    currTask.setChildTasks(new ArrayList<Task<? extends Serializable>>());
    currTask.addDependentTask(cndTsk);
}