Skip to content

Commit

Permalink
RavenDB-281 - Hiding Database Commands and Async Database Commands - …
Browse files Browse the repository at this point in the history
…so they aren't hanging directly off the session
  • Loading branch information
ayende committed May 11, 2012
1 parent 02b5992 commit b914ba0
Show file tree
Hide file tree
Showing 31 changed files with 159 additions and 201 deletions.
4 changes: 2 additions & 2 deletions Bundles/Raven.Bundles.Tests/Authorization/Deleting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void WillAbortDeleteIfUserDoesNotHavePermissions()
{
s.SecureFor(UserId, "Company/Rename");

Assert.Throws<InvalidOperationException>(() => s.Advanced.DatabaseCommands.Delete(company.Id, null));
Assert.Throws<InvalidOperationException>(() => store.DatabaseCommands.Delete(company.Id, null));
}
}

Expand Down Expand Up @@ -84,7 +84,7 @@ public void WillDeleteIfUserHavePermissions()
company.Name = "Stampading Rhinos";
s.Store(company);

Assert.DoesNotThrow(() => s.Advanced.DatabaseCommands.Delete(company.Id, null));
Assert.DoesNotThrow(() => store.DatabaseCommands.Delete(company.Id, null));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public void Can_find_book_with_similar_name()
new MoreLikeThisQueryParameters
{
MapGroupFields = new NameValueCollection()
{
{"BookId", JavascriptBookId}
},
{
{"BookId", JavascriptBookId}
},
MinimumTermFrequency = 1,
MinimumDocumentFrequency = 1
});
Expand All @@ -91,9 +91,9 @@ public void Can_find_book_with_similar_author()
new MoreLikeThisQueryParameters
{
MapGroupFields = new NameValueCollection()
{
{"BookId", EclipseBookId}
},
{
{"BookId", EclipseBookId}
},
MinimumTermFrequency = 1,
MinimumDocumentFrequency = 1
});
Expand Down
18 changes: 9 additions & 9 deletions Bundles/Raven.Bundles.Tests/UniqueConstraints/DeleteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public void Deletes_constraint_document_when_base_document_is_deleted()
session.SaveChanges();

// Ensures constraint was created
Assert.NotNull(session.Advanced.DatabaseCommands.Get("UniqueConstraints/Users/Email/foo@bar.com"));
Assert.NotNull(session.Advanced.DatabaseCommands.Get("users/1"));
Assert.NotNull(DocumentStore.DatabaseCommands.Get("UniqueConstraints/Users/Email/foo@bar.com"));
Assert.NotNull(DocumentStore.DatabaseCommands.Get("users/1"));

session.Advanced.DatabaseCommands.Delete("users/1", null);
DocumentStore.DatabaseCommands.Delete("users/1", null);

// Both docs should be deleted
Assert.Null(session.Advanced.DatabaseCommands.Get("UniqueConstraints/Users/Email/foo@bar.com"));
Assert.Null(session.Advanced.DatabaseCommands.Get("users/1"));
Assert.Null(DocumentStore.DatabaseCommands.Get("UniqueConstraints/Users/Email/foo@bar.com"));
Assert.Null(DocumentStore.DatabaseCommands.Get("users/1"));
}
}

Expand All @@ -37,13 +37,13 @@ public void Does_not_delete_base_document_when_constraint_is_deleted()
session.SaveChanges();

// Ensures constraint was created
Assert.NotNull(session.Advanced.DatabaseCommands.Get("UniqueConstraints/Users/Email/foo@bar.com"));
Assert.NotNull(session.Advanced.DatabaseCommands.Get("users/1"));
Assert.NotNull(DocumentStore.DatabaseCommands.Get("UniqueConstraints/Users/Email/foo@bar.com"));
Assert.NotNull(DocumentStore.DatabaseCommands.Get("users/1"));

session.Advanced.DatabaseCommands.Delete("UniqueConstraints/Users/Email/foo@bar.com", null);
DocumentStore.DatabaseCommands.Delete("UniqueConstraints/Users/Email/foo@bar.com", null);

// Base doc still intact
Assert.NotNull(session.Advanced.DatabaseCommands.Get("users/1"));
Assert.NotNull(DocumentStore.DatabaseCommands.Get("users/1"));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Bundles/Raven.Bundles.Tests/UniqueConstraints/UpdateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public void Updating_constraint_field_on_document_propagates_to_constraint_docum
session.SaveChanges();

// Ensures constraint was created
Assert.NotNull(session.Advanced.DatabaseCommands.Get("UniqueConstraints/Users/Email/foo@bar.com"));
Assert.NotNull(session.Advanced.DatabaseCommands.Get("users/1"));
Assert.NotNull(DocumentStore.DatabaseCommands.Get("UniqueConstraints/Users/Email/foo@bar.com"));
Assert.NotNull(DocumentStore.DatabaseCommands.Get("users/1"));

user.Email = "bar@foo.com";
session.SaveChanges();

// Both docs should be deleted
Assert.Null(session.Advanced.DatabaseCommands.Get("UniqueConstraints/Users/Email/foo@bar.com"));
Assert.NotNull(session.Advanced.DatabaseCommands.Get("UniqueConstraints/Users/Email/bar@foo.com"));
Assert.Null(DocumentStore.DatabaseCommands.Get("UniqueConstraints/Users/Email/foo@bar.com"));
Assert.NotNull(DocumentStore.DatabaseCommands.Get("UniqueConstraints/Users/Email/bar@foo.com"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Text;
using Raven.Abstractions.Extensions;
using Raven.Client.Document;
using Raven.Imports.Newtonsoft.Json;
using Raven.Bundles.Authorization;
using System.Linq;
Expand All @@ -27,7 +28,7 @@ public static OperationAllowedResult IsOperationAllowedOnDocument(this ISyncAdva

public static OperationAllowedResult[] IsOperationAllowedOnDocument(this ISyncAdvancedSessionOperation session, string userId, string operation, params string[] documentIds)
{
var serverClient = session.DatabaseCommands as ServerClient;
var serverClient = ((DocumentSession)session).DatabaseCommands as ServerClient;
if (serverClient == null)
throw new InvalidOperationException("Cannot get whatever operation is allowed on document in embedded mode.");

Expand Down Expand Up @@ -107,8 +108,9 @@ private static bool OperationMatches(string op1, string op2)

public static void SecureFor(this IDocumentSession session, string userId, string operation)
{
session.Advanced.DatabaseCommands.OperationsHeaders[Constants.RavenAuthorizationUser] = userId;
session.Advanced.DatabaseCommands.OperationsHeaders[Constants.RavenAuthorizationOperation] = operation;
var databaseCommands = ((DocumentSession)session).DatabaseCommands;
databaseCommands.OperationsHeaders[Constants.RavenAuthorizationUser] = userId;
databaseCommands.OperationsHeaders[Constants.RavenAuthorizationOperation] = operation;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static T[] MoreLikeThis<T>(this ISyncAdvancedSessionOperation advancedSes

public static T[] MoreLikeThis<T>(this ISyncAdvancedSessionOperation advancedSession, string index, MoreLikeThisQueryParameters parameters)
{
var cmd = advancedSession.DatabaseCommands as ServerClient;
var cmd = advancedSession.DocumentStore.DatabaseCommands as ServerClient;
if (cmd == null)
throw new NotImplementedException("Embedded client isn't supported by the MoreLikeThis bundle");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class VersioningClientExtensions
public static T[] GetRevisionsFor<T>(this ISyncAdvancedSessionOperation session, string id, int start, int pageSize)
{
var inMemoryDocumentSessionOperations = ((InMemoryDocumentSessionOperations)session);
var jsonDocuments = session.DatabaseCommands.StartsWith(id + "/revisions/", start, pageSize);
var jsonDocuments = session.DocumentStore.DatabaseCommands.StartsWith(id + "/revisions/", start, pageSize);
return jsonDocuments
.Select(inMemoryDocumentSessionOperations.TrackEntity<T>)
.ToArray();
Expand Down
2 changes: 1 addition & 1 deletion Raven.Client.Lightweight/Connection/ReplicationInformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ public void RefreshReplicationInformation(ServerClient commands)

lastReplicationUpdate = SystemTime.UtcNow;
}
#endif

private void UpdateReplicationInformationFromDocument(JsonDocument document)
{
Expand All @@ -383,7 +384,6 @@ private void UpdateReplicationInformationFromDocument(JsonDocument document)
failureCounts[replicationDestination] = new IntHolder();
}
}
#endif

private IsolatedStorageFile GetIsolatedStorageFileForReplicationInformation()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,15 @@ public IRavenQueryable<T> Query<T>(string indexName)
#if !SILVERLIGHT
null,
#endif
Advanced.AsyncDatabaseCommands),
AsyncDatabaseCommands),
ravenQueryStatistics,
indexName,
null,
this,
#if !SILVERLIGHT
null,
#endif
Advanced.AsyncDatabaseCommands);
AsyncDatabaseCommands);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Raven.Client.Lightweight/Document/DocumentSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ public T[] LoadInternal<T>(string[] ids)
public IRavenQueryable<T> Query<T>(string indexName)
{
var ravenQueryStatistics = new RavenQueryStatistics();
return new RavenQueryInspector<T>(new RavenQueryProvider<T>(this, indexName, ravenQueryStatistics, Advanced.DatabaseCommands
return new RavenQueryInspector<T>(new RavenQueryProvider<T>(this, indexName, ravenQueryStatistics, DatabaseCommands
#if !NET35
, AsyncDatabaseCommands
#endif
), ravenQueryStatistics, indexName, null, this, Advanced.DatabaseCommands
), ravenQueryStatistics, indexName, null, this, DatabaseCommands
#if !NET35
, AsyncDatabaseCommands
#endif
Expand Down
6 changes: 0 additions & 6 deletions Raven.Client.Lightweight/IAsyncAdvancedSessionOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ namespace Raven.Client
/// </summary>
public interface IAsyncAdvancedSessionOperations : IAdvancedDocumentSessionOperations
{
/// <summary>
/// Gets the async database commands.
/// </summary>
/// <value>The async database commands.</value>
IAsyncDatabaseCommands AsyncDatabaseCommands { get; }

/// <summary>
/// Load documents with the specified key prefix
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Raven.Client.Lightweight/IDocumentSessionImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// </copyright>
//-----------------------------------------------------------------------
using System;
using Raven.Client.Connection;
using Raven.Client.Document;
#if !NET35
using Raven.Client.Document.Batches;
Expand All @@ -20,6 +21,7 @@ internal interface IDocumentSessionImpl : IDocumentSession
#endif
{
DocumentConvention Conventions { get; }

T[] LoadInternal<T>(string[] ids);
T[] LoadInternal<T>(string[] ids, string[] includes);

Expand Down
12 changes: 0 additions & 12 deletions Raven.Client.Lightweight/ISyncAdvancedSessionOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,12 @@ public interface ISyncAdvancedSessionOperation : IAdvancedDocumentSessionOperati
/// <param name="entity">The entity.</param>
void Refresh<T>(T entity);

/// <summary>
/// Gets the database commands.
/// </summary>
/// <value>The database commands.</value>
IDatabaseCommands DatabaseCommands { get; }

/// <summary>
/// Load documents with the specified key prefix
/// </summary>
IEnumerable<T> LoadStartingWith<T>(string keyPrefix, int start = 0, int pageSize = 25);

#if !NET35
/// <summary>
/// Gets the async database commands.
/// </summary>
/// <value>The async database commands.</value>
IAsyncDatabaseCommands AsyncDatabaseCommands { get; }

/// <summary>
/// Access the lazy operations
/// </summary>
Expand Down
9 changes: 0 additions & 9 deletions Raven.Client.Lightweight/Shard/AsyncShardedDocumentSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,6 @@ public IAsyncDocumentQuery<T> AsyncLuceneQuery<T>()

#endregion

#region DatabaseCommands (not supported)

Raven.Client.Connection.Async.IAsyncDatabaseCommands IAsyncAdvancedSessionOperations.AsyncDatabaseCommands
{
get { throw new NotSupportedException("Not supported in a sharded session"); }
}

#endregion

/// <summary>
/// Saves all the changes to the Raven server.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public T[] Apply<T>(IList<IDatabaseCommands> commands, ShardRequestData request,

// if ALL nodes failed, we still throw
if (errors.Count == commands.Count)
#if !NET_3_5
#if !NET35
throw new AggregateException(errors);
#else
throw new InvalidOperationException("Got an error from all servers", errors.First())
Expand Down
5 changes: 0 additions & 5 deletions Raven.Client.Lightweight/Shard/ShardedDocumentSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,6 @@ public IDocumentQuery<T> LuceneQuery<T>()

#region DatabaseCommands (not supported)

Raven.Client.Connection.IDatabaseCommands ISyncAdvancedSessionOperation.DatabaseCommands
{
get { throw new NotSupportedException("Not supported in a sharded session"); }
}

public ILoaderWithInclude<T> Include<T, TInclude>(Expression<Func<T, object>> path)
{
return new MultiLoaderWithInclude<T>(this).Include<TInclude>(path);
Expand Down
4 changes: 2 additions & 2 deletions Raven.Tests.Silverlight/AsyncDatabaseCommandsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public IEnumerable<Task> CanGetDeleteADcoumentById()
session.Store(entity);
yield return session.SaveChangesAsync();

yield return session.Advanced.AsyncDatabaseCommands
yield return documentStore.AsyncDatabaseCommands
.DeleteDocumentAsync(entity.Id);
}

Expand Down Expand Up @@ -154,7 +154,7 @@ public IEnumerable<Task> TheResponseForGettingDocumentsShouldNotBeCached()

using (var session = documentStore.OpenAsyncSession(dbname))
{
yield return session.Advanced.AsyncDatabaseCommands
yield return documentStore.AsyncDatabaseCommands
.DeleteDocumentAsync(task.Result[0].Key);

var second = cmd.ForDatabase(dbname).GetDocumentsAsync(0, 25);
Expand Down
2 changes: 1 addition & 1 deletion Raven.Tests/Bugs/Caching/CachingOfDocumentInclude.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void New_query_returns_correct_value_when_cache_is_enabled_and_data_chang
using (var s = store.OpenSession())
{
s.Store(new User { Name = "Ayende", Email="same.email@example.com"});
s.Advanced.DatabaseCommands.PutIndex("index",
store.DatabaseCommands.PutIndex("index",
new IndexDefinition()
{
Map =
Expand Down
2 changes: 1 addition & 1 deletion Raven.Tests/Bugs/Indexing/WiseShrek.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void UsingKeywordAnalyzing()
using(var store = NewDocumentStore())
using (var session = store.OpenSession())
{
session.Advanced.DatabaseCommands.PutIndex("test", new IndexDefinition
store.DatabaseCommands.PutIndex("test", new IndexDefinition
{
Map =
@"from s in docs.Softs select new { s.f_platform, s.f_name, s.f_alias,s.f_License,s.f_totaldownload}",
Expand Down
2 changes: 1 addition & 1 deletion Raven.Tests/Bugs/Issue199.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void CanQueryStartingInH()
{
using (var session = store.OpenSession())
{
session.Advanced.DatabaseCommands.PutIndex("test", new IndexDefinition
store.DatabaseCommands.PutIndex("test", new IndexDefinition
{
Map = @"from s in docs.Softs
select new { s.f_platform, s.f_name, s.f_alias,s.f_License,s.f_totaldownload}",
Expand Down
4 changes: 2 additions & 2 deletions Raven.Tests/Bugs/OperationHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void CanPassOperationHeadersUsingEmbedded()
RecordOperationHeaders.Hello = null;
using(var session = documentStore.OpenSession())
{
session.Advanced.DatabaseCommands.OperationsHeaders["Hello"] = "World";
documentStore.DatabaseCommands.OperationsHeaders["Hello"] = "World";
session.Store(new { Bar = "foo"});
session.SaveChanges();

Expand Down Expand Up @@ -87,7 +87,7 @@ public void CanPassOperationHeadersUsingServer()
RecordOperationHeaders.Hello = null;
using (var session = documentStore.OpenSession())
{
session.Advanced.DatabaseCommands.OperationsHeaders["Hello"] = "World";
documentStore.DatabaseCommands.OperationsHeaders["Hello"] = "World";
session.Store(new { Bar = "foo" });
session.SaveChanges();

Expand Down
Loading

0 comments on commit b914ba0

Please sign in to comment.