/** * Synchronizes a design document to the Database. * * <p>This method will first try to find a document in the database with the same id as the given * document, if it is not found then the given document will be saved to the database. * * <p>If the document was found in the database, it will be compared with the given document using * {@code equals()}. If both documents are not equal, then the given document will be saved to the * database and updates the existing document. * * @param document The design document to synchronize * @return {@link Response} as a result of a document save or update, or returns {@code null} if * no action was taken and the document in the database is up-to-date with the given document. */ public Response synchronizeWithDb(DesignDocument document) { assertNotEmpty(document, "Document"); DesignDocument documentFromDb = null; try { documentFromDb = getFromDb(document.getId()); } catch (NoDocumentException e) { return dbc.save(document); } if (!document.equals(documentFromDb)) { document.setRevision(documentFromDb.getRevision()); return dbc.update(document); } return null; }