public override void AfterPut(string key, RavenJObject document, RavenJObject metadata, System.Guid etag, TransactionInformation transactionInformation) { if (key.StartsWith("Raven/")) { return; } var entityName = metadata.Value<string>(Constants.RavenEntityName) + "/"; var properties = metadata.Value<RavenJArray>(Constants.EnsureUniqueConstraints); if (properties == null || properties.Length <= 0) return; var constraintMetaObject = new RavenJObject { { Constants.IsConstraintDocument, true } }; constraintMetaObject.EnsureSnapshot(); foreach (var property in properties) { var propName = ((RavenJValue)property).Value.ToString(); var uniqueValue = document.Value<string>(propName); if(uniqueValue == null) continue; string documentName = "UniqueConstraints/" + entityName + propName + "/" +Util.EscapeUniqueValue(uniqueValue); Database.Put( documentName, null, RavenJObject.FromObject(new { RelatedId = key }), (RavenJObject)constraintMetaObject.CreateSnapshot(), transactionInformation); } }
static Constants() { InDatabaseKeyVerificationDocumentContents = new RavenJObject { { "Text", "The encryption is correct." } }; InDatabaseKeyVerificationDocumentContents.EnsureSnapshot(); }
static Constants() { InDatabaseKeyVerificationDocumentContents = new RavenJObject { {"Text", "The encryption is correct."} }; InDatabaseKeyVerificationDocumentContents.EnsureSnapshot(); }
public PutResult Put(string key, Etag etag, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation) { WorkContext.MetricsCounters.DocsPerSecond.Mark(); key = string.IsNullOrWhiteSpace(key) ? Guid.NewGuid().ToString() : key.Trim(); RemoveReservedProperties(document); RemoveMetadataReservedProperties(metadata); Etag newEtag = Etag.Empty; using (Database.DocumentLock.Lock()) { TransactionalStorage.Batch(actions => { if (key.EndsWith("/")) { key += GetNextIdentityValueWithoutOverwritingOnExistingDocuments(key, actions); } AssertPutOperationNotVetoed(key, metadata, document, transactionInformation); if (transactionInformation == null) { if (Database.InFlightTransactionalState.IsModified(key)) { throw new ConcurrencyException("PUT attempted on : " + key + " while it is being locked by another transaction"); } Database.PutTriggers.Apply(trigger => trigger.OnPut(key, document, metadata, null)); var addDocumentResult = actions.Documents.AddDocument(key, etag, document, metadata); newEtag = addDocumentResult.Etag; Database.Indexes.CheckReferenceBecauseOfDocumentUpdate(key, actions); metadata[Constants.LastModified] = addDocumentResult.SavedAt; metadata.EnsureSnapshot( "Metadata was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?"); document.EnsureSnapshot( "Document was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?"); actions.AfterStorageCommitBeforeWorkNotifications(new JsonDocument { Metadata = metadata, Key = key, DataAsJson = document, Etag = newEtag, LastModified = addDocumentResult.SavedAt, SkipDeleteFromIndex = addDocumentResult.Updated == false }, documents => Database.Prefetcher.AfterStorageCommitBeforeWorkNotifications(PrefetchingUser.Indexer, documents)); if (addDocumentResult.Updated) { Database.Prefetcher.AfterUpdate(key, addDocumentResult.PrevEtag); } Database.PutTriggers.Apply(trigger => trigger.AfterPut(key, document, metadata, newEtag, null)); TransactionalStorage .ExecuteImmediatelyOrRegisterForSynchronization(() => { Database.PutTriggers.Apply(trigger => trigger.AfterCommit(key, document, metadata, newEtag)); var newDocumentChangeNotification = new DocumentChangeNotification { Id = key, Type = DocumentChangeTypes.Put, TypeName = metadata.Value <string>(Constants.RavenClrType), CollectionName = metadata.Value <string>(Constants.RavenEntityName), Etag = newEtag }; Database.Notifications.RaiseNotifications(newDocumentChangeNotification, metadata); }); WorkContext.ShouldNotifyAboutWork(() => "PUT " + key); } else { var doc = actions.Documents.DocumentMetadataByKey(key); newEtag = Database.InFlightTransactionalState.AddDocumentInTransaction(key, etag, document, metadata, transactionInformation, doc == null ? Etag.Empty : doc.Etag, UuidGenerator); } }); Log.Debug("Put document {0} with etag {1}", key, newEtag); return(new PutResult { Key = key, ETag = newEtag }); } }
public PutResult Put(string key, Etag etag, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation) { workContext.DocsPerSecIncreaseBy(1); key = string.IsNullOrWhiteSpace(key) ? Guid.NewGuid().ToString() : key.Trim(); RemoveReservedProperties(document); RemoveMetadataReservedProperties(metadata); Etag newEtag = Etag.Empty; lock (putSerialLock) { TransactionalStorage.Batch(actions => { if (key.EndsWith("/")) { key += GetNextIdentityValueWithoutOverwritingOnExistingDocuments(key, actions, transactionInformation); } AssertPutOperationNotVetoed(key, metadata, document, transactionInformation); if (transactionInformation == null) { PutTriggers.Apply(trigger => trigger.OnPut(key, document, metadata, null)); var addDocumentResult = actions.Documents.AddDocument(key, etag, document, metadata); newEtag = addDocumentResult.Etag; CheckReferenceBecauseOfDocumentUpdate(key, actions); metadata[Constants.LastModified] = addDocumentResult.SavedAt; metadata.EnsureSnapshot("Metadata was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?"); document.EnsureSnapshot("Document was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?"); PutTriggers.Apply(trigger => trigger.AfterPut(key, document, metadata, newEtag, null)); actions.AfterStorageCommitBeforeWorkNotifications(new JsonDocument { Metadata = metadata, Key = key, DataAsJson = document, Etag = newEtag, LastModified = addDocumentResult.SavedAt, SkipDeleteFromIndex = addDocumentResult.Updated == false }, indexingExecuter.PrefetchingBehavior.AfterStorageCommitBeforeWorkNotifications); TransactionalStorage .ExecuteImmediatelyOrRegisterForSynchronization(() => { PutTriggers.Apply(trigger => trigger.AfterCommit(key, document, metadata, newEtag)); RaiseNotifications(new DocumentChangeNotification { Id = key, Type = DocumentChangeTypes.Put, Etag = newEtag, }); }); } else { newEtag = actions.Transactions.AddDocumentInTransaction(key, etag, document, metadata, transactionInformation); } workContext.ShouldNotifyAboutWork(() => "PUT " + key); }); } log.Debug("Put document {0} with etag {1}", key, newEtag); return new PutResult { Key = key, ETag = newEtag }; }
public PutResult Put(string key, Etag etag, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation) { WorkContext.MetricsCounters.DocsPerSecond.Mark(); key = string.IsNullOrWhiteSpace(key) ? Guid.NewGuid().ToString() : key.Trim(); RemoveReservedProperties(document); RemoveMetadataReservedProperties(metadata); Etag newEtag = Etag.Empty; using (Database.DocumentLock.Lock()) { TransactionalStorage.Batch(actions => { if (key.EndsWith("/")) { key += GetNextIdentityValueWithoutOverwritingOnExistingDocuments(key, actions); } AssertPutOperationNotVetoed(key, metadata, document, transactionInformation); if (transactionInformation == null) { if (Database.InFlightTransactionalState.IsModified(key)) throw new ConcurrencyException("PUT attempted on : " + key + " while it is being locked by another transaction"); Database.PutTriggers.Apply(trigger => trigger.OnPut(key, document, metadata, null)); var addDocumentResult = actions.Documents.AddDocument(key, etag, document, metadata); newEtag = addDocumentResult.Etag; Database.Indexes.CheckReferenceBecauseOfDocumentUpdate(key, actions); metadata[Constants.LastModified] = addDocumentResult.SavedAt; metadata.EnsureSnapshot( "Metadata was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?"); document.EnsureSnapshot( "Document was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?"); actions.AfterStorageCommitBeforeWorkNotifications(new JsonDocument { Metadata = metadata, Key = key, DataAsJson = document, Etag = newEtag, LastModified = addDocumentResult.SavedAt, SkipDeleteFromIndex = addDocumentResult.Updated == false }, documents => { if(Database.IndexDefinitionStorage.IndexesCount == 0 || Database.WorkContext.RunIndexing == false) return; Database.Prefetcher.AfterStorageCommitBeforeWorkNotifications(PrefetchingUser.Indexer, documents); }); if (addDocumentResult.Updated) Database.Prefetcher.AfterUpdate(key, addDocumentResult.PrevEtag); Database.PutTriggers.Apply(trigger => trigger.AfterPut(key, document, metadata, newEtag, null)); TransactionalStorage .ExecuteImmediatelyOrRegisterForSynchronization(() => { Database.PutTriggers.Apply(trigger => trigger.AfterCommit(key, document, metadata, newEtag)); var newDocumentChangeNotification = new DocumentChangeNotification { Id = key, Type = DocumentChangeTypes.Put, TypeName = metadata.Value<string>(Constants.RavenClrType), CollectionName = metadata.Value<string>(Constants.RavenEntityName), Etag = newEtag }; Database.Notifications.RaiseNotifications(newDocumentChangeNotification, metadata); }); WorkContext.ShouldNotifyAboutWork(() => "PUT " + key); } else { var doc = actions.Documents.DocumentMetadataByKey(key); newEtag = Database.InFlightTransactionalState.AddDocumentInTransaction(key, etag, document, metadata, transactionInformation, doc == null ? Etag.Empty : doc.Etag, UuidGenerator); } }); Log.Debug("Put document {0} with etag {1}", key, newEtag); return new PutResult { Key = key, ETag = newEtag }; } }
public PutResult Put(string key, Guid? etag, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation) { workContext.DocsPerSecIncreaseBy(1); key = string.IsNullOrWhiteSpace(key) ? Guid.NewGuid().ToString() : key.Trim(); RemoveReservedProperties(document); RemoveReservedProperties(metadata); Guid newEtag = Guid.Empty; lock (putSerialLock) { TransactionalStorage.Batch(actions => { if (key.EndsWith("/")) { key += GetNextIdentityValueWithoutOverwritingOnExistingDocuments(key, actions, transactionInformation); } AssertPutOperationNotVetoed(key, metadata, document, transactionInformation); if (transactionInformation == null) { PutTriggers.Apply(trigger => trigger.OnPut(key, document, metadata, null)); var addDocumentResult = actions.Documents.AddDocument(key, etag, document, metadata); newEtag = addDocumentResult.Etag; PutTriggers.Apply(trigger => trigger.AfterPut(key, document, metadata, newEtag, null)); metadata.EnsureSnapshot(); document.EnsureSnapshot(); actions.AfterCommit(new JsonDocument { Metadata = metadata, Key = key, DataAsJson = document, Etag = newEtag, LastModified = addDocumentResult.SavedAt, SkipDeleteFromIndex = addDocumentResult.Updated == false }, indexingExecuter.AfterCommit); TransactionalStorage .ExecuteImmediatelyOrRegisterForSyncronization(() => { PutTriggers.Apply(trigger => trigger.AfterCommit(key, document, metadata, newEtag)); RaiseNotifications(new DocumentChangeNotification { Name = key, Type = DocumentChangeTypes.Put, Etag = newEtag, }); }); } else { newEtag = actions.Transactions.AddDocumentInTransaction(key, etag, document, metadata, transactionInformation); } workContext.ShouldNotifyAboutWork(() => "PUT " + key); }); } log.Debug("Put document {0} with etag {1}", key, newEtag); return new PutResult { Key = key, ETag = newEtag }; }