use of com.cloudant.client.org.lightcouch.NoDocumentException in project java-cloudant by cloudant.
the class ResponseTest method verifyDbNotFound.
@Test
public void verifyDbNotFound() {
try {
Database db2 = clientResource.get().database("non_existent_name", false);
db2.find("no_id");
db.find(Response.class, "no_id");
fail("A NoDocumentException should be thrown");
} catch (NoDocumentException e) {
exceptionAsserts(e, 404, "");
}
}
use of com.cloudant.client.org.lightcouch.NoDocumentException in project java-cloudant by cloudant.
the class DesignDocumentManager method put.
/**
* Synchronizes a design document to the Database.
* <p>This method will first try to find a document in the database with the same {@code _id}
* as the given document, if it is not found then the given document will be saved to the
* database.</p>
* <p>If the document was found in the database, it will be compared with the given document
* using {@link com.cloudant.client.api.model.DesignDocument#equals(Object)}. Both the
* {@code _rev} value and content must match for the given documents to be considered equal.
* This method will <strong>not</strong> update the revision of the local design document.</p>
* <ul>
* <li>If the documents are <i>equal</i> then no action is taken.</li>
* <li>If the documents are <i>not equal</i> then the given document will be saved to the
* database therefore updating the existing document.</li>
* </ul>
* <p>If the design document's {@code _id} is not prefixed with {@code _design/}, then the
* {@code _design/} prefix will be added.</p>
*
* @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 put(DesignDocument document) {
CouchDbUtil.assertNotEmpty(document, "DesignDocument");
// Ensure the _design prefix
ensureDesignPrefixObject(document);
DesignDocument documentFromDb;
try {
documentFromDb = get(document.getId());
} catch (NoDocumentException e) {
return db.save(document);
}
if (!document.equals(documentFromDb)) {
document.setRevision(documentFromDb.getRevision());
return db.update(document);
}
return null;
}
Aggregations