/** * Replaces documents in the collection with given documents. This method is used to modify documents inside a collection by replacing existing documents with given documents. The field used to perform the replacement is the document unique identifier (_id). */ public int replaceDocuments(JArray documents, bool markDirty) { // get the shared manager JSONStoreSQLLite store = JSONStoreSQLLite.sharedManager(); if (store == null) { //JSONStoreLoggerError(@"Error: JSON_STORE_DATABASE_NOT_OPEN, code: %d", rc); throw new JSONStoreException(JSONStoreConstants.JSON_STORE_DATABASE_NOT_OPEN); } int numReplaced = 0; JArray failures = new JArray(); lock (JSONStore.lockThis) { if (!JSONStore.transactionInProgress) { //Start transaction store.startTransaction(); } foreach (JToken document in documents) { bool worked = store.replace(document, collectionName, markDirty); if (worked) { //It worked, increment the number of docs replaced numReplaced++; } else { //If we can't store all the data, we rollback and go //to the error callback numReplaced = JSONStoreConstants.JSON_STORE_PERSISTENT_STORE_FAILURE; failures.Add(document); break; } } if (numReplaced < 0) { if (!JSONStore.transactionInProgress) { store.rollbackTransaction(); } throw new JSONStoreException(JSONStoreConstants.JSON_STORE_REPLACE_DOCUMENTS_FAILURE, failures); } // things worked, commit if (!JSONStore.transactionInProgress) { store.commitTransaction(); } return(numReplaced); } }