Пример #1
0
  /**
   * マップを削除する。
   *
   * @param mapId マップID
   * @return 削除結果
   */
  public ResponseDto removeMapById(final long mapId) {
    int count = 0;
    ResponseDto responseDto = new ResponseDto();
    try {
      count = mapInfoDao_.deleteById(mapId);
      if (count == 0) {
        String errorMessage = MessageUtil.getMessage("WEWD0166", new Object[] {});
        responseDto.setMessage(errorMessage);
        responseDto.setResult(ResponseConstants.RESULT_FAIL);
        return responseDto;
      }

      responseDto.setResult(ResponseConstants.RESULT_SUCCESS);
      return responseDto;
    } catch (PersistenceException pEx) {
      Throwable cause = pEx.getCause();
      if (cause instanceof SQLException) {
        SQLException sqlEx = (SQLException) cause;
        LOGGER.log(LogMessageCodes.SQL_EXCEPTION, sqlEx, sqlEx.getMessage());
      } else {
        LOGGER.log(LogMessageCodes.SQL_EXCEPTION, pEx, pEx.getMessage());
      }

      String errorMessage = MessageUtil.getMessage("WEWD0167", new Object[] {});
      responseDto.setMessage(errorMessage);
      responseDto.setResult(ResponseConstants.RESULT_FAIL);
      return responseDto;
    }
  }
Пример #2
0
  /**
   * マップを取得する。
   *
   * @param mapId Target mapId
   * @return 取得結果
   */
  public ResponseDto getById(final long mapId) {
    ResponseDto responseDto = new ResponseDto();
    try {
      MapInfo mapInfo = mapInfoDao_.selectById(mapId);
      if (mapInfo == null) {
        String errorMessage = MessageUtil.getMessage("WEWD0164", new Object[] {});
        responseDto.setMessage(errorMessage);
        responseDto.setResult(ResponseConstants.RESULT_FAIL);
        return responseDto;
      }

      Map<String, String> convertData = this.convertDataMap(mapInfo);
      responseDto.setResult(ResponseConstants.RESULT_SUCCESS);
      responseDto.setData(convertData);

      return responseDto;
    } catch (PersistenceException pEx) {
      Throwable cause = pEx.getCause();
      if (cause instanceof SQLException) {
        SQLException sqlEx = (SQLException) cause;
        LOGGER.log(LogMessageCodes.SQL_EXCEPTION, sqlEx, sqlEx.getMessage());
      } else {
        LOGGER.log(LogMessageCodes.SQL_EXCEPTION, pEx, pEx.getMessage());
      }

      String errorMessage = MessageUtil.getMessage("WEWD0165", new Object[] {});
      responseDto.setMessage(errorMessage);
      responseDto.setResult(ResponseConstants.RESULT_FAIL);
      return responseDto;
    }
  }
Пример #3
0
  /**
   * マップを更新する。
   *
   * @param mapInfo マップ情報
   * @return 更新結果電文
   */
  public ResponseDto update(final MapInfo mapInfo) {
    // 最終更新日時を設定
    mapInfo.lastUpdate = new Timestamp(Calendar.getInstance().getTimeInMillis());
    int count = 0;
    ResponseDto responseDto = new ResponseDto();
    try {
      count = mapInfoDao_.update(mapInfo);
      if (count > 0) {
        responseDto.setResult(ResponseConstants.RESULT_SUCCESS);
      } else {
        String errorMessage = MessageUtil.getMessage("WEWD0162", new Object[] {});
        responseDto.setResult(ResponseConstants.RESULT_FAIL);
        responseDto.setMessage(errorMessage);
      }

      return responseDto;
    } catch (PersistenceException pEx) {
      Throwable cause = pEx.getCause();
      if (cause instanceof SQLException) {
        SQLException sqlEx = (SQLException) cause;
        LOGGER.log(LogMessageCodes.SQL_EXCEPTION, sqlEx, sqlEx.getMessage());
      } else {
        LOGGER.log(LogMessageCodes.SQL_EXCEPTION, pEx, pEx.getMessage());
      }

      String errorMessage = MessageUtil.getMessage("WEWD0163", new Object[] {});
      responseDto.setMessage(errorMessage);
      responseDto.setResult(ResponseConstants.RESULT_FAIL);
      return responseDto;
    }
  }
Пример #4
0
 @Override
 @Transactional
 public <T, E extends Exception> T write(MutateWork<T, E> work) throws StorageException, E {
   try {
     return work.apply(storeProvider);
   } catch (PersistenceException e) {
     throw new StorageException(e.getMessage(), e);
   }
 }
Пример #5
0
 /**
  * マップを取得する。
  *
  * @param name マップ名
  * @return 取得結果
  */
 public List<MapInfo> getByName(final String name) {
   try {
     return mapInfoDao_.selectByName(name);
   } catch (PersistenceException pEx) {
     Throwable cause = pEx.getCause();
     if (cause instanceof SQLException) {
       SQLException sqlEx = (SQLException) cause;
       LOGGER.log(LogMessageCodes.SQL_EXCEPTION, sqlEx, sqlEx.getMessage());
     } else {
       LOGGER.log(LogMessageCodes.SQL_EXCEPTION, pEx, pEx.getMessage());
     }
     return new ArrayList<MapInfo>();
   }
 }
Пример #6
0
  @Test(expected = se.spagettikod.optimist.ModifiedByAnotherUserException.class)
  public void modifiedByAnotherUserDuringDelete() {
    SqlSession firstSession = MyBatisTestUtil.getSession();
    Entity entity = new Entity();
    entity.setValue("firstEdit");
    EntityMapper firstMapper = firstSession.getMapper(EntityMapper.class);
    firstMapper.insertEntity(entity);
    firstSession.commit();
    Assert.assertEquals(new Integer(0), entity.getVersion());

    // Load same entity in second session
    SqlSession secondSession = MyBatisTestUtil.getSession();
    Entity secondEntity = new Entity();
    Long identity = entity.getId();
    EntityMapper secondMapper = secondSession.getMapper(EntityMapper.class);
    secondEntity = secondMapper.getById(identity);
    Assert.assertEquals(new Integer(0), secondEntity.getVersion());

    // Modify entity in first session
    entity = firstMapper.getById(entity.getId());
    entity.setValue("secondEdit");
    firstMapper.updateEntity(entity);
    firstSession.commit();
    firstSession.close();
    Assert.assertEquals(new Integer(1), entity.getVersion());

    // Delete the entity after first session has modified
    try {
      secondMapper.deleteEntity(secondEntity);
    } catch (PersistenceException e) {
      if (e.getCause() instanceof ModifiedByAnotherUserException) {
        throw (ModifiedByAnotherUserException) e.getCause();
      } else {
        throw e;
      }
    } finally {
      if (secondSession != null) {
        secondSession.close();
      }
    }
  }
Пример #7
0
  /**
   * 全てのマップデータを返す。
   *
   * @return マップデータ
   */
  public List<Map<String, String>> getAllMap() {
    List<MapInfo> mapList = null;
    try {
      mapList = mapInfoDao_.selectAll();
    } catch (PersistenceException pe) {
      Throwable cause = pe.getCause();
      if (cause instanceof SQLException) {
        SQLException sqlEx = (SQLException) cause;
        LOGGER.log(LogMessageCodes.SQL_EXCEPTION, sqlEx, sqlEx.getMessage());
      }
      LOGGER.log(LogMessageCodes.SQL_EXCEPTION);
      return new ArrayList<Map<String, String>>();
    }

    List<Map<String, String>> resultList = new ArrayList<Map<String, String>>();
    for (MapInfo mapInfo : mapList) {
      Map<String, String> dataMap = this.convertDataMap(mapInfo);
      resultList.add(dataMap);
    }
    return resultList;
  }