Source:
private BasicDocumentRevision createDocument(SQLDatabase db,String docId, final DocumentBody body) throws AttachmentException, ConflictException { Preconditions.checkState(this.isOpen(), "Database is closed"); CouchUtils.validateDocumentId(docId); Preconditions.checkNotNull(body, "Input document body can not be null"); this.validateDBBody(body); DocumentCreated documentCreated = null; InsertRevisionOptions options = new InsertRevisionOptions(); BasicDocumentRevision potentialParent = null; try { potentialParent = this.getDocumentInQueue(db, docId, null); } catch (DocumentNotFoundException e) { } if (potentialParent != null) { if (!potentialParent.isDeleted()) { throw new IllegalArgumentException("Can not insert new doc, likely the docId exists already: " + docId); } this.setCurrent(db,potentialParent, false); options.revId = CouchUtils.generateNextRevisionId(potentialParent.getRevision()); options.docNumericId = potentialParent.getInternalNumericId(); options.parentSequence = potentialParent.getSequence(); } else { long docNumericId = insertDocumentID(db,docId); options.revId = CouchUtils.getFirstRevisionId(); options.docNumericId = docNumericId; options.parentSequence = -1l; } options.deleted = false; options.current = true; options.data = body.asBytes(); options.available = true; options.copyAttachments = false; insertRevision(db, options); try { BasicDocumentRevision doc = getDocumentInQueue(db, docId, options.revId); logger.finer("New document created: " + doc.toString()); return doc; } catch (DocumentNotFoundException e){ throw new RuntimeException("Programming error we just inserted it so we should have it",e); } }

Target:
private BasicDocumentRevision createDocument(SQLDatabase db,String docId, final DocumentBody body) throws AttachmentException, ConflictException, DatastoreException { Preconditions.checkState(this.isOpen(), "Database is closed"); CouchUtils.validateDocumentId(docId); Preconditions.checkNotNull(body, "Input document body can not be null"); this.validateDBBody(body); InsertRevisionOptions options = new InsertRevisionOptions(); BasicDocumentRevision potentialParent = null; try { potentialParent = this.getDocumentInQueue(db, docId, null); } catch (DocumentNotFoundException e) { } if (potentialParent != null) { if (!potentialParent.isDeleted()) { throw new ConflictException(String.format("Cannot create doc, document with id %s already exists " , docId)); } this.setCurrent(db, potentialParent, false); options.revId = CouchUtils.generateNextRevisionId(potentialParent.getRevision()); options.docNumericId = potentialParent.getInternalNumericId(); options.parentSequence = potentialParent.getSequence(); } else { long docNumericId = insertDocumentID(db,docId); options.revId = CouchUtils.getFirstRevisionId(); options.docNumericId = docNumericId; options.parentSequence = -1l; } options.deleted = false; options.current = true; options.data = body.asBytes(); options.available = true; insertRevision(db, options); try { BasicDocumentRevision doc = getDocumentInQueue(db, docId, options.revId); logger.finer("New document created: " + doc.toString()); return doc; } catch (DocumentNotFoundException e){ throw new RuntimeException(String.format("Couldn't get document we just inserted " + "(id: %s); this shouldn't happen, please file an issue with as much detail " + "as possible.", docId), e); } }