public void save(String id, Object document) { Assert.notNull(document, "document must not be null for save"); HttpEntity<?> httpEntity = createHttpEntity(document); try { ResponseEntity<Map> response = restOperations.exchange(defaultDocumentUrl, HttpMethod.PUT, httpEntity, Map.class, id); // TODO update the document revision id on the object from the returned value // TODO better exception translation } catch (RestClientException e) { throw new UncategorizedCouchDataAccessException(e); } }
public <T> T findOne(URI uri, Class<T> targetClass) { Assert.state(uri != null, "uri must be set to use this method"); try { return restOperations.getForObject(uri, targetClass); // TODO check this exception translation and centralize. } catch (HttpClientErrorException clientError) { if (clientError.getStatusCode() == HttpStatus.NOT_FOUND) { throw new DocumentRetrievalFailureException(uri.getPath()); } throw new CouchUsageException(clientError); } catch (HttpServerErrorException serverError) { throw new CouchServerResourceUsageException(serverError); } catch (RestClientException otherError) { throw new UncategorizedCouchDataAccessException(otherError); } }