73
73
/// And we also do not remove design documents in the database that
74
74
/// we no longer have in code.
76
public void SynchDesignDocuments() throws Exception
76
public void SynchDesignDocuments()
78
78
for (CouchDesignDocument doc: DesignDocuments)
82
} catch (CouchException e) {
196
199
/// <returns>Couch Document with new Rev set.</returns>
197
200
/// <remarks>This relies on the document to already have an id.</remarks>
198
201
public ICouchDocument
199
WriteDocument(ICouchDocument document) throws CouchException, JSONException
202
WriteDocument(ICouchDocument document) throws CouchException
201
204
return WriteDocument(document, false);
209
212
/// <param name="document">Couch document</param>
210
213
/// <returns>Couch Document with new Rev set and possibly an Id set.</returns>
211
public ICouchDocument SaveDocument(ICouchDocument document) throws CouchException, JSONException
214
public ICouchDocument SaveDocument(ICouchDocument document) throws CouchException
213
216
if (document.Id() == null)
224
227
/// <param name="batch">True if we don't want to wait for flush (commit).</param>
225
228
/// <returns>Couch Document with new Rev set.</returns>
226
229
/// <remarks>This relies on the document to already have an id.</remarks>
227
public ICouchDocument WriteDocument(ICouchDocument document, boolean batch) throws CouchException, JSONException
230
public ICouchDocument WriteDocument(ICouchDocument document, boolean batch) throws CouchException
229
232
if (document.Id() == null)
234
237
JSONObject result =
235
238
Request(document.Id()).Query(batch ? "?batch=ok" : null).Data(CouchDocument.WriteJson(document)).Put().Check("Failed to write document").Result();
236
document.Id(result.getString("id")); // Not really neeed
237
document.Rev(result.getString("rev"));
239
document.Id(result.optString("id")); // Not really neeed
240
document.Rev(result.optString("rev"));
247
250
/// <param name="mimeType">The MIME type for the attachment.</param>
248
251
/// <returns>The document.</returns>
249
252
/// <remarks>This relies on the document to already have an id.</remarks>
250
public ICouchDocument WriteAttachment(ICouchDocument document, String attachment, String mimeType) throws CouchException, JSONException
253
public ICouchDocument WriteAttachment(ICouchDocument document, String attachment, String mimeType) throws CouchException
252
255
if (document.Id() == null)
257
260
JSONObject result =
258
261
Request(document.Id() + "/attachment").Query("?rev=" + document.Rev()).Data(attachment).MimeType(mimeType).Put().Check("Failed to write attachment")
260
document.Id(result.getString("id")); // Not really neeed
261
document.Rev(result.getString("rev"));
263
document.Id(result.optString("id")); // Not really neeed
264
document.Rev(result.optString("rev"));
267
270
/// Read a ICouchDocument with an id even if it has not changed revision.
269
272
/// <param name="document">Document to fill.</param>
270
public void ReadDocument(ICouchDocument document) throws Exception
273
public void ReadDocument(ICouchDocument document)
272
document.ReadJson(ReadDocument(document.Id()));
276
document.ReadJson(ReadDocument(document.Id()));
277
} catch (Exception e) {
348
355
/// <param name="json">Json data to store.</param>
349
356
/// <returns>Couch document with data, id and rev set.</returns>
350
357
/// <remarks>POST which may be problematic in some environments.</remarks>
351
public CouchJsonDocument CreateDocument(String json) throws CouchException, JSONException
358
public CouchJsonDocument CreateDocument(String json) throws CouchException
353
360
return (CouchJsonDocument) CreateDocument(new CouchJsonDocument(json));
470
477
/// Get multiple documents.
472
479
/// <param name="documentIds">List of documents to get.</param>
473
public <T extends ICouchDocument> List<T> GetDocuments(Class<T> c, List<String> documentIds) throws JSONException, CouchException
480
public <T extends ICouchDocument> List<T> GetDocuments(Class<T> c, List<String> documentIds)
475
482
return GetDocuments(c, (String[])documentIds.toArray());
478
public List<CouchJsonDocument> GetDocuments(List<String> documentIds) throws JSONException, CouchException
480
return GetDocuments(CouchJsonDocument.class,documentIds);
483
public List<CouchJsonDocument> GetDocuments(String[] documentIds) throws JSONException, CouchException
485
return GetDocuments(CouchJsonDocument.class,documentIds);
488
public <T extends ICouchDocument> List<T> GetDocuments(Class<T> c, String[] documentIds) throws JSONException, CouchException
485
public List<CouchJsonDocument> GetDocuments(List<String> documentIds)
487
return GetDocuments(CouchJsonDocument.class,documentIds);
490
public List<CouchJsonDocument> GetDocuments(String[] documentIds)
492
return GetDocuments(CouchJsonDocument.class,documentIds);
495
public <T extends ICouchDocument> List<T> GetDocuments(Class<T> c, String[] documentIds)
490
497
CouchBulkKeys bulk = new CouchBulkKeys(documentIds);
491
return QueryAllDocuments().Data(CouchDocument.WriteJson(bulk)).IncludeDocuments().GetResult().Documents(c);
499
return QueryAllDocuments().Data(CouchDocument.WriteJson(bulk)).IncludeDocuments().GetResult().Documents(c);
500
} catch (CouchException e) {
501
return new ArrayList<T>();
494
public <T extends ICouchDocument> T GetDocument(Class<T> c, String documentId) throws Exception
505
public <T extends ICouchDocument> T GetDocument(Class<T> c, String documentId)
496
ICouchDocument doc = c.newInstance();
509
doc = c.newInstance();
510
} catch (Exception e1) {
497
513
doc.Id(documentId);
502
catch (CouchNotFoundException e)
591
600
/// revisions and then use them to post a bulk delete. Couch can not
592
601
/// delete documents without being told about their revisions.
594
public void DeleteDocuments(String startKey, String endKey) throws CouchException, Exception
603
public void DeleteDocuments(String startKey, String endKey) throws CouchException
596
605
List<CouchQueryDocument> docs = QueryAllDocuments().StartKey(startKey).EndKey(endKey).GetResult().RowDocuments();
597
606
DeleteDocuments((ICouchDocument[] )docs.toArray());