Package org.springframework.dao

Examples of org.springframework.dao.DuplicateKeyException


    }
    if (ex instanceof NonUniqueResultException) {
      return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
    }
    if (ex instanceof NonUniqueObjectException) {
      return new DuplicateKeyException(ex.getMessage(), ex);
    }
    if (ex instanceof PropertyValueException) {
      return new DataIntegrityViolationException(ex.getMessage(), ex);
    }
    if (ex instanceof PersistentObjectException) {
View Full Code Here


          logTranslation(task, sql, sqlEx, false);
          return new InvalidResultSetAccessException(task, sql, sqlEx);
        }
        else if (Arrays.binarySearch(this.sqlErrorCodes.getDuplicateKeyCodes(), errorCode) >= 0) {
          logTranslation(task, sql, sqlEx, false);
          return new DuplicateKeyException(buildMessage(task, sql, sqlEx), sqlEx);
        }
        else if (Arrays.binarySearch(this.sqlErrorCodes.getDataIntegrityViolationCodes(), errorCode) >= 0) {
          logTranslation(task, sql, sqlEx, false);
          return new DataIntegrityViolationException(buildMessage(task, sql, sqlEx), sqlEx);
        }
View Full Code Here

    }
    if (ex instanceof NonUniqueResultException) {
      return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
    }
    if (ex instanceof NonUniqueObjectException) {
      return new DuplicateKeyException(ex.getMessage(), ex);
    }
    if (ex instanceof PropertyValueException) {
      return new DataIntegrityViolationException(ex.getMessage(), ex);
    }
    if (ex instanceof PersistentObjectException) {
View Full Code Here

    }
    if (ex instanceof NonUniqueResultException) {
      return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
    }
    if (ex instanceof NonUniqueObjectException) {
      return new DuplicateKeyException(ex.getMessage(), ex);
    }
    if (ex instanceof PropertyValueException) {
      return new DataIntegrityViolationException(ex.getMessage(), ex);
    }
    if (ex instanceof PersistentObjectException) {
View Full Code Here

          logTranslation(task, sql, sqlEx, false);
          return new InvalidResultSetAccessException(task, sql, sqlEx);
        }
        else if (Arrays.binarySearch(this.sqlErrorCodes.getDuplicateKeyCodes(), errorCode) >= 0) {
          logTranslation(task, sql, sqlEx, false);
          return new DuplicateKeyException(buildMessage(task, sql, sqlEx), sqlEx);
        }
        else if (Arrays.binarySearch(this.sqlErrorCodes.getDataIntegrityViolationCodes(), errorCode) >= 0) {
          logTranslation(task, sql, sqlEx, false);
          return new DataIntegrityViolationException(buildMessage(task, sql, sqlEx), sqlEx);
        }
View Full Code Here

    Iterator<Row> iterator = resultSet.iterator();
    if (iterator.hasNext()) {
      Row row = iterator.next();
      T result = readRowCallback.doWith(row);
      if (iterator.hasNext()) {
        throw new DuplicateKeyException("found two or more results in query " + query);
      }
      return result;
    }

    return null;
View Full Code Here

    Iterator<Row> iterator = resultSet.iterator();
    if (iterator.hasNext()) {
      Row row = iterator.next();
      T result = readRowCallback.doWith(row);
      if (iterator.hasNext()) {
        throw new DuplicateKeyException("found two or more results in query " + query);
      }
      return result;
    }

    return null;
View Full Code Here

          Iterator<Row> iterator = rs.iterator();
          if (iterator.hasNext()) {
            Row row = iterator.next();
            T result = new CassandraConverterRowCallback<T>(cassandraConverter, type).doWith(row);
            if (iterator.hasNext()) {
              throw new DuplicateKeyException("found two or more results in query " + query);
            }
            listener.onQueryComplete(result);
          }
        } catch (Exception e) {
          listener.onException(translateExceptionIfPossible(e));
View Full Code Here

  public DataAccessException translateExceptionIfPossible(RuntimeException ex) {

    // Check for well-known MongoException subclasses.

    if (ex instanceof DuplicateKey || ex instanceof DuplicateKeyException) {
      return new DuplicateKeyException(ex.getMessage(), ex);
    }

    if (ex instanceof Network || ex instanceof MongoSocketException) {
      return new DataAccessResourceFailureException(ex.getMessage(), ex);
    }

    if (ex instanceof CursorNotFound || ex instanceof MongoCursorNotFoundException) {
      return new DataAccessResourceFailureException(ex.getMessage(), ex);
    }

    if (ex instanceof MongoServerSelectionException) {
      return new DataAccessResourceFailureException(ex.getMessage(), ex);
    }

    if (ex instanceof MongoTimeoutException) {
      return new DataAccessResourceFailureException(ex.getMessage(), ex);
    }

    if (ex instanceof MongoInternalException) {
      return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
    }

    // All other MongoExceptions
    if (ex instanceof MongoException) {

      int code = ((MongoException) ex).getCode();

      if (code == 11000 || code == 11001) {
        throw new DuplicateKeyException(ex.getMessage(), ex);
      } else if (code == 12000 || code == 13440) {
        throw new DataAccessResourceFailureException(ex.getMessage(), ex);
      } else if (code == 10003 || code == 12001 || code == 12010 || code == 12011 || code == 12012) {
        throw new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
      }
View Full Code Here

    UserTagService mockUserTagService = mock(UserTagService.class);
    when(mockUserTagService.addMultiplyTags(any(User.class), anyString(), anyBoolean())).thenCallRealMethod();
    when(mockUserTagService.parseTags(anyString(), any(Errors.class))).thenCallRealMethod();
    try{
      doThrow(new TagNotFoundException()).when(mockUserTagService).favoriteAdd(eq(user), eq("uytutut"));
      doThrow(new DuplicateKeyException("duplicate")).when(mockUserTagService).favoriteAdd(eq(user), eq("tag3"));
    } catch (Exception e) {}

    List<String> strErrors = mockUserTagService.addMultiplyTags(user, "tag1, tag2, tag3, uytutut, @#$%$#", true);
    try{
      verify(mockUserTagService).favoriteAdd(eq(user), eq("tag1"));
      verify(mockUserTagService).favoriteAdd(eq(user), eq("tag2"));
      verify(mockUserTagService).favoriteAdd(eq(user), eq("uytutut"));
      verify(mockUserTagService, never()).favoriteAdd(eq(user), eq("@#$%$#"));
      verify(mockUserTagService, never()).ignoreAdd(any(User.class), anyString());
    } catch (Exception e) {}
    Assert.assertEquals(3, strErrors.size());

    reset(mockUserTagService);
    when(mockUserTagService.addMultiplyTags(any(User.class), anyString(), anyBoolean())).thenCallRealMethod();
    when(mockUserTagService.parseTags(anyString(), any(Errors.class))).thenCallRealMethod();
    try{
      doThrow(new TagNotFoundException()).when(mockUserTagService).ignoreAdd(eq(user), eq("uytutut"));
      doThrow(new DuplicateKeyException("duplicate")).when(mockUserTagService).ignoreAdd(eq(user), eq("tag3"));
    } catch (Exception e) {}

    strErrors = mockUserTagService.addMultiplyTags(user, "tag1, tag2, tag3, uytutut, @#$%$#", false);
    try{
      verify(mockUserTagService).ignoreAdd(eq(user), eq("tag1"));
View Full Code Here

TOP

Related Classes of org.springframework.dao.DuplicateKeyException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.