예제 #1
0
        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;
                });
            }
        }
예제 #2
0
        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;
         };
 }
예제 #4
0
        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);
            }
        }
예제 #5
0
 public ServerOperationExecutor(DocumentStoreBase store)
 {
     _store           = store;
     _requestExecutor = store.Conventions.DisableTopologyUpdates
         ? ClusterRequestExecutor.CreateForSingleNode(store.Urls[0], store.Certificate)
         : ClusterRequestExecutor.Create(store.Urls, store.Certificate);
 }
예제 #6
0
 internal TemporalDeleteListener(DocumentStoreBase documentStore)
 {
     documentStore.SessionCreatedInternal += session =>
     {
         ThreadLocalSession.Value = (IDocumentSession)session;
     };
 }
예제 #7
0
        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();
        }
예제 #8
0
 public OperationExecutor(DocumentStoreBase store, string databaseName = null)
 {
     _store        = store;
     _databaseName = databaseName ?? store.Database;
     if (_databaseName != null)
     {
         _requestExecutor = store.GetRequestExecutor(_databaseName);
     }
 }
예제 #9
0
		/// <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();
		}
예제 #10
0
        /// <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();
        }
예제 #11
0
 /// <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;
 }
예제 #12
0
        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());
            }
        }
예제 #13
0
        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);
            }
        }
예제 #14
0
        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();
            }
        }
예제 #15
0
 /// <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);
        }
예제 #17
0
        /// <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;
		}
예제 #19
0
        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();
                });
            }
        }
예제 #20
0
        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();
            }
        }
예제 #21
0
 public ServerOperationExecutor(DocumentStoreBase store)
     : this(store, CreateRequestExecutor(store), initialRequestExecutor : null, new ConcurrentDictionary <string, ServerOperationExecutor>(StringComparer.OrdinalIgnoreCase), nodeTag : null)
 {
 }
예제 #22
0
 /// <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);
 }
예제 #23
0
 public SessionOperationExecutor(DocumentStoreBase store, string databaseName = null)
     : base(store, databaseName)
 {
 }
예제 #24
0
        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;
        }
예제 #25
0
 public OperationExecutor(DocumentStoreBase store, string databaseName = null)
     : this((IDocumentStore)store, databaseName)
 {
 }
 public MaintenanceOperationExecutor(DocumentStoreBase store, string databaseName = null)
 {
     _store        = store;
     _databaseName = databaseName ?? store.Database;
 }
예제 #27
0
 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));
 }