双唯一性验证

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();

            }

        }

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容