コード例 #1
0
 @Override
 public int create(Config config) {
   Config configFound = configDao.findConfigByKey(config.getKey());
   if (configFound != null) {
     Project project = projectDao.getProject(configFound.getProjectId());
     throw new RuntimeBusinessException(
         "该配置项已存在(project: "
             + (project != null ? project.getName() : "***")
             + ", desc: "
             + configFound.getDesc()
             + ")!");
   }
   Integer currentUserId = SecurityUtils.getCurrentUserId();
   int projectId = config.getProjectId();
   if (config.getCreateUserId() == null) {
     config.setCreateUserId(currentUserId);
   }
   if (config.getModifyUserId() == null) {
     config.setModifyUserId(currentUserId);
   }
   projectDao.lockProject(projectId);
   if (!config.isPrivatee()) {
     config.setPrivatee(isSharedProject(projectId));
   }
   config.setSeq(configDao.getMaxSeq(projectId) + 1);
   return configDao.create(config);
 }
コード例 #2
0
 @Override
 public void moveUp(int projectId, Integer configId) {
   Config config = getConfig(configId);
   if (config == null) {
     throw new EntityNotFoundException("Config[id=" + configId + "] not found.");
   }
   projectDao.lockProject(projectId);
   Config prevConfig = configDao.getPrevConfig(configId);
   if (prevConfig != null) {
     try {
       int seq = config.getSeq();
       config.setSeq(prevConfig.getSeq());
       prevConfig.setSeq(seq);
       configDao.update(config);
       configDao.update(prevConfig);
     } finally {
       cacheClient.remove(ServiceConstants.CACHE_CONFIG_PREFIX + config.getId());
       cacheClient.remove(ServiceConstants.CACHE_CONFIG_PREFIX + config.getKey());
       cacheClient.remove(ServiceConstants.CACHE_CONFIG_PREFIX + prevConfig.getId());
       cacheClient.remove(ServiceConstants.CACHE_CONFIG_PREFIX + prevConfig.getKey());
     }
   }
 }
コード例 #3
0
 @Override
 public void moveDown(int projectId, int configId) {
   Config config = getConfig(configId);
   if (config == null) {
     throw new EntityNotFoundException("Config[id=" + configId + "] not found.");
   }
   projectDao.lockProject(projectId); // 锁定指定projectId,避免同一项目下的config出现相同的seq值
   Config nextConfig = configDao.getNextConfig(configId);
   if (nextConfig != null) {
     try {
       int seq = config.getSeq();
       config.setSeq(nextConfig.getSeq());
       nextConfig.setSeq(seq);
       configDao.update(config);
       configDao.update(nextConfig);
     } finally {
       cacheClient.remove(ServiceConstants.CACHE_CONFIG_PREFIX + config.getId());
       cacheClient.remove(ServiceConstants.CACHE_CONFIG_PREFIX + config.getKey());
       cacheClient.remove(ServiceConstants.CACHE_CONFIG_PREFIX + nextConfig.getId());
       cacheClient.remove(ServiceConstants.CACHE_CONFIG_PREFIX + nextConfig.getKey());
     }
   }
 }