ArgumentChecker.notNull(document.getUniqueId(), "document.uniqueId");
ArgumentChecker.notNull(document.getPosition(), "document.position");
final UniqueId uniqueId = document.getUniqueId();
final Instant now = Instant.now();
final PositionDocument storedDocument = _store.get(uniqueId.getObjectId());
if (storedDocument == null) {
throw new DataNotFoundException("Position not found: " + uniqueId);
}
final PositionDocument clonedDoc = clonePositionDocument(document);
removeTrades(storedDocument.getPosition().getTrades());
setVersionTimes(document, clonedDoc, now, null, now, null);
if (_store.replace(uniqueId.getObjectId(), storedDocument, clonedDoc) == false) {
throw new IllegalArgumentException("Concurrent modification");
}
storeTrades(clonedDoc.getPosition().getTrades(), document.getPosition().getTrades(), uniqueId);
_changeManager.entityChanged(ChangeType.CHANGED, document.getObjectId(), storedDocument.getVersionFromInstant(), document.getVersionToInstant(), now);
return document;
}