private static async Task CanUseSingleAsync(DocumentStoreBase store) { using (var session = store.OpenAsyncSession()) { Profile profile = await session.Advanced.AsyncDocumentQuery <Profile>("ProfileByName") .WhereLucene("Name", "Google") .SingleAsync(); Assert.NotNull(profile); Assert.Throws <AggregateException>(() => { profile = session.Advanced.AsyncDocumentQuery <Profile>("ProfileByName") .SingleAsync().Result; }); profile = await session.Advanced.AsyncDocumentQuery <Profile>("ProfileByName") .WhereLucene("Name", "NoSuch") .SingleOrDefaultAsync(); Assert.Null(profile); profile = await session.Advanced.AsyncDocumentQuery <Profile>("ProfileByName") .WhereLucene("Name", "Google") .SingleOrDefaultAsync(); Assert.NotNull(profile); Assert.Throws <AggregateException>(() => { profile = session.Advanced.AsyncDocumentQuery <Profile>("ProfileByName") .SingleOrDefaultAsync().Result; }); } }
private void CanUseCountAndCountLazilySync(DocumentStoreBase store) { using (var session = store.OpenSession()) { Assert.Equal(0, session.Advanced.DocumentQuery <Profile>("ProfileByName") .WhereLucene("Name", "NoSuch") .Count()); Assert.Equal(1, session.Advanced.DocumentQuery <Profile>("ProfileByName") .WhereLucene("Name", "Google") .Count()); Assert.Equal(2, session.Advanced.DocumentQuery <Profile>("ProfileByName") .Count()); } using (var session = store.OpenSession()) { Assert.Equal(0, session.Advanced.DocumentQuery <Profile>("ProfileByName") .WhereLucene("Name", "NoSuch") .CountLazily().Value); Assert.Equal(1, session.Advanced.DocumentQuery <Profile>("ProfileByName") .WhereLucene("Name", "Google") .CountLazily().Value); Assert.Equal(2, session.Advanced.DocumentQuery <Profile>("ProfileByName") .CountLazily().Value); } }
internal TemporalDeleteListener(DocumentStoreBase documentStore) { documentStore.SessionCreatedInternal += session => { ThreadLocalSession.Value = (IDocumentSession) session; }; }
private static void CanUseFirstSync(DocumentStoreBase store) { using (var session = store.OpenSession()) { var profile = session.Advanced.DocumentQuery <Profile>("ProfileByName") .WhereLucene("Name", "Google") .First(); Assert.NotNull(profile); Assert.Throws <InvalidOperationException>(() => { profile = session.Advanced.DocumentQuery <Profile>("ProfileByName") .WhereLucene("Name", "NoSuch") .First(); }); profile = session.Advanced.DocumentQuery <Profile>("ProfileByName") .WhereLucene("Name", "Google") .FirstOrDefault(); Assert.NotNull(profile); profile = session.Advanced.DocumentQuery <Profile>("ProfileByName") .WhereLucene("Name", "NoSuch") .FirstOrDefault(); Assert.Null(profile); } }
public ServerOperationExecutor(DocumentStoreBase store) { _store = store; _requestExecutor = store.Conventions.DisableTopologyUpdates ? ClusterRequestExecutor.CreateForSingleNode(store.Urls[0], store.Certificate) : ClusterRequestExecutor.Create(store.Urls, store.Certificate); }
internal TemporalDeleteListener(DocumentStoreBase documentStore) { documentStore.SessionCreatedInternal += session => { ThreadLocalSession.Value = (IDocumentSession)session; }; }
public ServerOperationExecutor(DocumentStoreBase store) { _requestExecutor = store.Conventions.DisableTopologyUpdates ? ClusterRequestExecutor.CreateForSingleNode(store.Urls[0], store.Certificate, store.Conventions) : ClusterRequestExecutor.Create(store.Urls, store.Certificate, store.Conventions); store.AfterDispose += (sender, args) => _requestExecutor.Dispose(); }
public OperationExecutor(DocumentStoreBase store, string databaseName = null) { _store = store; _databaseName = databaseName ?? store.Database; if (_databaseName != null) { _requestExecutor = store.GetRequestExecutor(_databaseName); } }
/// <summary> /// Initializes a new instance of the <see cref="RavenClientEnlistment"/> class. /// </summary> public RavenClientEnlistment(DocumentStoreBase documentStore,ITransactionalDocumentSession session, Action onTxComplete) { transaction = Transaction.Current.TransactionInformation; this.documentStore = documentStore; this.session = session; this.onTxComplete = onTxComplete; TransactionRecoveryInformationFileName = Guid.NewGuid() + ".recovery-information"; ctx = documentStore.TransactionRecoveryStorage.Create(); }
/// <summary> /// Initializes a new instance of the <see cref="RavenClientEnlistment"/> class. /// </summary> public RavenClientEnlistment(DocumentStoreBase documentStore, ITransactionalDocumentSession session, Action onTxComplete) { transaction = Transaction.Current.TransactionInformation; this.documentStore = documentStore; this.session = session; this.onTxComplete = onTxComplete; TransactionRecoveryInformationFileName = Guid.NewGuid() + ".recovery-information"; ctx = documentStore.TransactionRecoveryStorage.Create(); }
/// <summary> /// Initializes a new instance of the <see cref="InMemoryDocumentSessionOperations"/> class. /// </summary> protected InMemoryDocumentSessionOperations( DocumentStoreBase documentStore, DocumentSessionListeners listeners, Guid id) { Id = id; this.documentStore = documentStore; this.listeners = listeners; ResourceManagerId = documentStore.ResourceManagerId; UseOptimisticConcurrency = false; AllowNonAuthoritativeInformation = true; NonAuthoritativeInformationTimeout = TimeSpan.FromSeconds(15); MaxNumberOfRequestsPerSession = documentStore.Conventions.MaxNumberOfRequestsPerSession; }
private async Task CanUseLazilyAsync(DocumentStoreBase store) { using (var session = store.OpenAsyncSession()) { Assert.Equal(0, (await session.Advanced.AsyncDocumentQuery <Profile>("ProfileByName") .WhereLucene("Name", "NoSuch") .LazilyAsync(null).Value).Count()); Assert.Equal(1, (await session.Advanced.AsyncDocumentQuery <Profile>("ProfileByName") .WhereLucene("Name", "Google") .LazilyAsync(null).Value).Count()); Assert.Equal(2, (await session.Advanced.AsyncDocumentQuery <Profile>("ProfileByName") .LazilyAsync(null).Value).Count()); } }
private async Task CanUseCountLazilyAsync(DocumentStoreBase store) { using (var session = store.OpenAsyncSession()) { Assert.Equal(0, await session.Advanced.AsyncDocumentQuery <Profile>("ProfileByName") .Where("Name:NoSuch") .CountLazilyAsync().Value); Assert.Equal(1, await session.Advanced.AsyncDocumentQuery <Profile>("ProfileByName") .Where("Name:Google") .CountLazilyAsync().Value); Assert.Equal(2, await session.Advanced.AsyncDocumentQuery <Profile>("ProfileByName") .CountLazilyAsync().Value); } }
private static void FillDatabase(DocumentStoreBase store) { store.ExecuteIndex(new ProfileByName()); var profile = new Profile { Name = "Google", Location = "Shard1" }; var profile2 = new Profile { Name = "HibernatingRhinos", Location = "Shard2" }; using (var documentSession = store.OpenSession()) { documentSession.Store(profile, profile.Id); documentSession.Store(profile2, profile2.Id); documentSession.SaveChanges(); } }
/// <summary> /// Initializes a new instance of the <see cref="InMemoryDocumentSessionOperations"/> class. /// </summary> protected InMemoryDocumentSessionOperations( string dbName, DocumentStoreBase documentStore, DocumentSessionListeners listeners, Guid id) { Id = id; this.dbName = dbName; this.documentStore = documentStore; this.listeners = listeners; ResourceManagerId = documentStore.ResourceManagerId; UseOptimisticConcurrency = false; AllowNonAuthoritativeInformation = true; NonAuthoritativeInformationTimeout = TimeSpan.FromSeconds(15); MaxNumberOfRequestsPerSession = documentStore.Conventions.MaxNumberOfRequestsPerSession; GenerateEntityIdOnTheClient = new GenerateEntityIdOnTheClient(documentStore, GenerateKey); EntityToJson = new EntityToJson(documentStore, listeners); }
private static UniqueConstraintsTypeDictionary InternalFindDictionary(DocumentStoreBase store) { if (store != null) { try { UniqueConstraintsStoreListener listener = store.RegisteredStoreListeners.OfType <UniqueConstraintsStoreListener>().SingleOrDefault(); if (listener != null) { return(listener.UniqueConstraintsTypeDictionary); } } catch (InvalidOperationException) { // Multiple dictionaries found; this should never happen. } } return(null); }
/// <summary> /// Parses connection string and assigns obtained settings to the instance of the RavenDB store. /// </summary> /// <param name="store">The RavenDB document store.</param> /// <param name="connectionString">The connection string.</param> /// <returns></returns> public static void ParseConnectionString(this DocumentStoreBase store, string connectionString) { var settings = connectionString.Trim(';').Split(';'); foreach (var item in settings) { var splitSetting = item.Split('='); switch (splitSetting[0].ToLower()) { case "database": store.Database = splitSetting[1].Trim(); break; case "urls": store.Urls = splitSetting[1].Split(','); break; default: break; } } }
private static UniqueConstraintsTypeDictionary InternalFindDictionary(DocumentStoreBase store) { if (store != null) { try { UniqueConstraintsStoreListener listener = store.RegisteredStoreListeners.OfType<UniqueConstraintsStoreListener>().SingleOrDefault(); if (listener != null) { return listener.UniqueConstraintsTypeDictionary; } } catch (InvalidOperationException) { // Multiple dictionaries found; this should never happen. } } return null; }
private void CanUseSingleSync(DocumentStoreBase store) { using (var session = store.OpenSession()) { Profile profile; profile = session.Advanced.DocumentQuery <Profile>("ProfileByName") .Where("Name:Google") .Single(); Assert.NotNull(profile); Assert.Throws <InvalidOperationException>(() => { profile = session.Advanced.DocumentQuery <Profile>("ProfileByName") .Single(); }); profile = session.Advanced.DocumentQuery <Profile>("ProfileByName") .Where("Name:NoSuch") .SingleOrDefault(); Assert.Null(profile); profile = session.Advanced.DocumentQuery <Profile>("ProfileByName") .Where("Name:Google") .SingleOrDefault(); Assert.NotNull(profile); Assert.Throws <InvalidOperationException>(() => { profile = session.Advanced.DocumentQuery <Profile>("ProfileByName") .SingleOrDefault(); }); } }
private ServerOperationExecutor(DocumentStoreBase store, ClusterRequestExecutor requestExecutor, ClusterRequestExecutor initialRequestExecutor, ConcurrentDictionary <string, ServerOperationExecutor> cache, string nodeTag) { if (store == null) { throw new ArgumentNullException(nameof(store)); } if (requestExecutor == null) { throw new ArgumentNullException(nameof(requestExecutor)); } _store = store; _requestExecutor = requestExecutor; _initialRequestExecutor = initialRequestExecutor; _nodeTag = nodeTag; _cache = cache; store.RegisterEvents(_requestExecutor); if (_nodeTag == null) { store.AfterDispose += (sender, args) => Dispose(); } }
public ServerOperationExecutor(DocumentStoreBase store) : this(store, CreateRequestExecutor(store), initialRequestExecutor : null, new ConcurrentDictionary <string, ServerOperationExecutor>(StringComparer.OrdinalIgnoreCase), nodeTag : null) { }
/// <summary> /// Registers a special IContractResolver which takes care of proper Json serialization of grains /// </summary> /// <param name="documentStore">The document store where the contract resolver should be registered</param> /// <returns>The original document store with modified contract resolver.</returns> public static DocumentStoreBase ConfigureContractResolver(this DocumentStoreBase documentStore) { documentStore.Conventions.JsonContractResolver = new GrainReferenceAwareContractResolver(); return(documentStore); }
public SessionOperationExecutor(DocumentStoreBase store, string databaseName = null) : base(store, databaseName) { }
internal SessionInfo(InMemoryDocumentSessionOperations session, SessionOptions options, DocumentStoreBase documentStore, bool asyncCommandRunning) { if (documentStore is null) { throw new ArgumentNullException(nameof(documentStore)); } _session = session ?? throw new ArgumentNullException(nameof(session)); _loadBalancerContextSeed = session.RequestExecutor.Conventions.LoadBalancerContextSeed; _canUseLoadBalanceBehavior = session.Conventions.LoadBalanceBehavior == LoadBalanceBehavior.UseSessionContext && session.Conventions.LoadBalancerPerSessionContextSelector != null; LastClusterTransactionIndex = documentStore.GetLastTransactionIndex(session.DatabaseName); AsyncCommandRunning = asyncCommandRunning; NoCaching = options.NoCaching; }
public OperationExecutor(DocumentStoreBase store, string databaseName = null) : this((IDocumentStore)store, databaseName) { }
public MaintenanceOperationExecutor(DocumentStoreBase store, string databaseName = null) { _store = store; _databaseName = databaseName ?? store.Database; }
private static ClusterRequestExecutor CreateRequestExecutor(DocumentStoreBase store) { return(store.Conventions.DisableTopologyUpdates ? ClusterRequestExecutor.CreateForSingleNode(store.Urls[0], store.Certificate, store.Conventions) : ClusterRequestExecutor.Create(store.Urls, store.Certificate, store.Conventions)); }