public List<BasicDocumentRevision> createTwoDBObjects( CouchClientWrapper remoteDb, String id1, String id2) { List<BasicDocumentRevision> objects = new ArrayList<BasicDocumentRevision>(); DocumentRevisionBuilder builder = new DocumentRevisionBuilder(); builder.setDocId(id1); builder.setRevId(CouchUtils.getFirstRevisionId()); builder.setBody(bodyOne); BasicDocumentRevision todo1 = builder.build(); objects.add(todo1); DocumentRevisionBuilder builder2 = new DocumentRevisionBuilder(); builder2.setDocId(id2); builder2.setRevId(CouchUtils.getFirstRevisionId()); builder2.setBody(bodyTwo); BasicDocumentRevision tdo2 = builder2.build(); objects.add(tdo2); return objects; }
@Override public BasicDocumentRevision createDocument(String docId, final DocumentBody body) { 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; this.sqlDb.beginTransaction(); try { long docNumericID = insertDocumentID(docId); if (docNumericID < 0) { throw new IllegalArgumentException( "Can not insert new doc, likely the docId exists already: " + docId); } String revisionId = CouchUtils.getFirstRevisionId(); long newSequence = insertRevision(docNumericID, revisionId, -1l, false, true, body.asBytes(), true); if (newSequence < 0) { throw new IllegalStateException("Error inserting data, please checking data."); } BasicDocumentRevision doc = getDocument(docId, revisionId); documentCreated = new DocumentCreated(doc); Log.d(LOG_TAG, "New document created: " + doc.toString()); this.sqlDb.setTransactionSuccessful(); return doc; } finally { this.sqlDb.endTransaction(); if (documentCreated != null) { eventBus.post(documentCreated); } } }