List of usage examples for org.springframework.data.mongodb.core MongoDataIntegrityViolationException getWriteResult
public WriteResult getWriteResult()
From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageLogService.java
private ShsMessageEntry saveShsMessageEntry(ShsMessageEntry entry) { if (entry.getLabel() == null) throw new IllegalArgumentException("Label must not be null"); entry.setState(MessageState.NEW);//from w w w .ja v a 2s .c om entry.setStateTimeStamp(new Date()); entry.setArrivalTimeStamp(entry.getStateTimeStamp()); ShsMessageEntry newEntry; ShsLabel label = entry.getLabel(); try { newEntry = messageLogRepository.save(entry); } catch (MongoDataIntegrityViolationException e) { if (e.getWriteResult().getCachedLastError().getException() instanceof MongoException.DuplicateKey) { throw new MessageAlreadyExistsException(label, new Date(0)); } else { throw e; } } catch (DuplicateKeyException e) { throw new MessageAlreadyExistsException(label, new Date(0)); } return newEntry; }