private void addDocument(final Txn transaction, final DBBroker broker, final DocumentImpl doc, final DocumentImpl oldDoc) throws PermissionDeniedException {
if(oldDoc == null) {
/* create */
if(!getPermissionsNoLock().validate(broker.getSubject(), Permission.WRITE)) {
throw new PermissionDeniedException("Permission to write to Collection denied for " + this.getURI());
}
} else {
/* update-replace */
if(!oldDoc.getPermissions().validate(broker.getSubject(), Permission.WRITE)) {
throw new PermissionDeniedException("Permission to write to overwrite document: " + oldDoc.getURI());
}
}
if (doc.getDocId() == DocumentImpl.UNKNOWN_DOCUMENT_ID) {
try {