美文网首页
双唯一性验证

双唯一性验证

作者: kany1 | 来源:发表于2019-04-16 16:46 被阅读0次

public void update(AvatarAccessoryInfoEntity userAvatarAccessoryEntity) {

        //如果name 和图层相同可以直接更新

        AvatarAccessoryInfoEntity original = userAvatarAccessoryDao.findById(userAvatarAccessoryEntity.getId());

        if(userAvatarAccessoryEntity.getName().equals(original.getName()) &&

          Objects.equals(userAvatarAccessoryEntity.getLayer(),original.getLayer())){

            int row = userAvatarAccessoryDao.update(userAvatarAccessoryEntity);

            if (row != 1) {

                throw new AppRuntimeException("更新失败!");

            }

            return;

        } else if(Objects.equals(userAvatarAccessoryEntity.getLayer(),original.getLayer()) ){

            int name = userAvatarAccessoryDao.getName(userAvatarAccessoryEntity.getName());

            if (name == 1) {

                    throw new AppRuntimeException("挂饰名称已经被创建");

                }

            int row = userAvatarAccessoryDao.update(userAvatarAccessoryEntity);

            if (row != 1) {

                throw new AppRuntimeException("更新失败!");

            }

            return;

        }else if (userAvatarAccessoryEntity.getName().equals(original.getName())) {

            int layer = userAvatarAccessoryDao.getLayer(userAvatarAccessoryEntity.getLayer());

            if (layer == 1) {

                throw new AppRuntimeException("挂件图片图层位置重复");

            }

            int row = userAvatarAccessoryDao.update(userAvatarAccessoryEntity);

            if (row != 1) {

                throw new AppRuntimeException("更新失败!");

            }

            return;

        }

        UNIQUENESS_CHECK.lock();

//            名称唯一查询

            try {

                int name = userAvatarAccessoryDao.getName(userAvatarAccessoryEntity.getName());

                int layer = userAvatarAccessoryDao.getLayer(userAvatarAccessoryEntity.getLayer());

                if (name == 1) {

                    throw new AppRuntimeException("挂饰名称已经被创建");

                }

                if (layer == 1) {

                    throw new AppRuntimeException("挂件图片图层位置重复");

                }

                int row = userAvatarAccessoryDao.update(userAvatarAccessoryEntity);

                if (row != 1) {

                    throw new AppRuntimeException("更新失败!");

                }

            } finally {

                UNIQUENESS_CHECK.unlock();

            }

        }

相关文章

网友评论

      本文标题:双唯一性验证

      本文链接:https://www.haomeiwen.com/subject/wszbwqtx.html