Ejemplo n.º 1
0
        public void Can_create_index_using_linq_from_client()
        {
            using (var server = GetNewServer(port, path))
            {
                var documentStore = new DocumentStore { Url = "http://localhost:" + port };
                documentStore.Initialise();
                documentStore.DatabaseCommands.PutIndex("UsersByLocation", new IndexDefinition<LinqIndexesFromClient.User>
                {
                    Map = users => from user in users
                                   where user.Location == "Tel Aviv"
                                   select new { user.Name },
                });

                using (var session = documentStore.OpenSession())
                {
                    session.Store(new LinqIndexesFromClient.User
                    {
                        Location = "Tel Aviv",
                        Name = "Yael"
                    });

                    session.SaveChanges();

                    LinqIndexesFromClient.User single = session.Query<LinqIndexesFromClient.User>("UsersByLocation")
                        .Where("Name:Yael")
                        .WaitForNonStaleResults()
                        .Single();

                    Assert.Equal("Yael", single.Name);
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            using (var documentStore = new DocumentStore { Url = "http://localhost:8080" })
            {
                documentStore.Initialise();
                //documentStore.DatabaseCommands.PutIndex("regionIndex",
                //                                        new IndexDefinition
                //                                        {
                //                                            Map = "from company in docs.Companies select new{company.Region}"
                //                                        });
                using (var session = documentStore.OpenSession())
            {

                session.Store(new Company { Name = "Company 1", Region = "Asia" });
                session.Store(new Company { Name = "Company 2", Region = "Africa" });
                session.SaveChanges();

                var allCompanies = session
                    .Query<Company>("regionIndex")
                    .Where("Region:Africa")
                    .WaitForNonStaleResults()
                    .ToArray();

                foreach (var company in allCompanies)
                    Console.WriteLine(company.Name);
            }}
        }
Ejemplo n.º 3
0
        public ActionResult AddCountSoldtoAlbum()
        {
            using (var documentStore = new DocumentStore {  Url = "http://localhost:8080" })
            {
                documentStore.Initialise();
                using (var session = documentStore.OpenSession())
                {
                    int count = 0;
                    do
                    {
                        var albums = session.LuceneQuery<Album>()
                            .Skip(count)
                            .Take(128)
                            .ToArray();
                        if (albums.Length == 0)
                            break;

                        foreach (var album in albums)
                        {
                            var result = session.LuceneQuery<SoldAlbum>("SoldAlbums")
                                .Where("Album:" + album.Id)
                                .SingleOrDefault();

                            album.CountSold = result == null ? 0 : result.Quantity;
                        }

                        count += albums.Length;

                        session.SaveChanges();
                        session.Clear();
                    } while (true); 
                }
            }
            return Content("OK");
        }
Ejemplo n.º 4
0
 public Versioning()
 {
     path = Path.GetDirectoryName(Assembly.GetAssembly(typeof (Versioning)).CodeBase);
     path = Path.Combine(path, "TestDb").Substring(6);
     if (Directory.Exists(path))
         Directory.Delete(path, true);
     ravenDbServer = new RavenDbServer(
         new RavenConfiguration
         {
             Port = 58080,
             DataDirectory = path,
             RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
             Catalog =
             {
                 Catalogs =
             {
                 new AssemblyCatalog(typeof (VersioningPutTrigger).Assembly)
             }
             },
             Settings =
             {
                 {"Raven/Versioning/MaxRevisions", "5"},
                 {"Raven/Versioning/Exclude", "Users;Comments;"}
             }
         });
     documentStore = new DocumentStore
     {
         Url = "http://localhost:58080"
     };
     documentStore.Initialise();
 }
Ejemplo n.º 5
0
        protected void Application_Start()
        {
            _documentStore = new DocumentStore { Url = "http://localhost:8080/" };
            _documentStore.Initialise();

            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
        }
Ejemplo n.º 6
0
 private static DocumentStore ConnectToDocumentStore()
 {
     var documentStore = new DocumentStore
                             {
                                 Url = "http://localhost:8080"
                             };
     documentStore.Initialise();
     return documentStore;
 }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            if (Directory.Exists("ravendb")) Directory.Delete("ravendb", true);
            var documentStore = new DocumentStore
            {
                Configuration =
                {
                    DataDirectory = "ravendb"
                }
            };
            documentStore.Initialise();
            documentStore.DatabaseCommands.PutIndex("FooByName",
                new IndexDefinition<Foo>()
                {
                    Map = docs => from doc in docs select new { Name = doc.Name }
                });

            var numberOfFoos = 10000;

            // Insert Foos
            using (var session = documentStore.OpenSession())
            {
                for (var i = 0; i < numberOfFoos; i++)
                {
                    var newFoo = new Foo { Name = i.ToString() };
                    session.Store(newFoo);
                }
                session.SaveChanges();
            }

            // Query a single foo to wait for the index
            using (var session = documentStore.OpenSession())
            {
                var foo = session.Query<Foo>("FooByName").Where("Name:1").WaitForNonStaleResults(TimeSpan.FromMinutes(1)).First();
            }
            Console.WriteLine("starting querying");
            // Query all foos twice
            for (var queryRun = 0; queryRun < 15; queryRun++)
            {
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                for (var i = 0; i < numberOfFoos; i++)
                {
                    using (var session = documentStore.OpenSession())
                    {
                        var foo = session.Query<Foo>("FooByName").Where("Name:" + i.ToString()).First();
                    }
                }
                stopWatch.Stop();
                Console.WriteLine("{0}. run: Querying {1} Foos in {2} ({3}ms per query)", queryRun, numberOfFoos, stopWatch.Elapsed, stopWatch.ElapsedMilliseconds / numberOfFoos);
            }
        }
Ejemplo n.º 8
0
		private DocumentStore NewDocumentStore()
		{
			path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(DocumentStoreServerTests)).CodeBase);
			path = Path.Combine(path, "TestDb").Substring(6);
			var documentStore = new DocumentStore
			{
				Configuration =
				{
					DataDirectory = path
				}
			};
			documentStore.Initialise();
			return documentStore;
		}
        public void Can_specify_cutoff_using_server()
        {
            using (var server = GetNewServer(port, path))
            {
                var documentStore = new DocumentStore { Url = "http://localhost:" + port };
                documentStore.Initialise();

                documentStore.DatabaseCommands.Query("Raven/DocumentsByEntityName", new IndexQuery
                {
                    PageSize = 10,
                    Cutoff = DateTime.Now.AddHours(-1)
                });
            }
        }
		public void Should_insert_into_db_and_set_id()
		{
			using (var server = GetNewServer(port, path))
			{
				var documentStore = new DocumentStore { Url = "http://localhost:"+ port };
				documentStore.Initialise();

				var session = documentStore.OpenSession();
				var entity = new Company {Name = "Company"};
				session.Store(entity);
				session.SaveChanges();
				Assert.NotEqual(Guid.Empty.ToString(), entity.Id);
			}
		}
Ejemplo n.º 11
0
		private DocumentStore NewDocumentStore()
		{
			path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(DocumentStoreServerTests)).CodeBase);
			path = Path.Combine(path, "TestDb").Substring(6);
			var documentStore = new DocumentStore
			{
				Configuration =
					{
						RunInUnreliableYetFastModeThatIsNotSuitableForProduction =true,
						DataDirectory = path
					}
			};
			documentStore.Initialise();
			return documentStore;
		}
Ejemplo n.º 12
0
        public void TotalResultIsIncludedInQueryResult()
        {
            using (var server = GetNewServer(port, path))
            {
                using (var store = new DocumentStore { Url = "http://localhost:" + port })
                {
                    store.Initialise();

                    using (var session = store.OpenSession())
                    {
                        Company company1 = new Company()
                        {
                            Name = "Company1",
                            Address1 = "",
                            Address2 = "",
                            Address3 = "",
                            Contacts = new List<Contact>(),
                            Phone = 2
                        };
                        Company company2 = new Company()
                        {
                            Name = "Company2",
                            Address1 = "",
                            Address2 = "",
                            Address3 = "",
                            Contacts = new List<Contact>(),
                            Phone = 2
                        };

                        session.Store(company1);
                        session.Store(company2);
                        session.SaveChanges();
                    }

                    using (var session = store.OpenSession())
                    {
                        int resultCount = session.LuceneQuery<Company>().WaitForNonStaleResults().QueryResult.TotalResults;
                        Assert.Equal(2, resultCount);
                    }
                }
            }
              
           

        }
Ejemplo n.º 13
0
		private DocumentStore NewDocumentStore()
		{
			path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(DocumentStoreServerTests)).CodeBase);
			path = Path.Combine(path, "TestDb").Substring(6);
			var documentStore = new DocumentStore
			{
				Configuration =
					{
						RunInUnreliableYetFastModeThatIsNotSuitableForProduction =true,
						DataDirectory = path
					},
				Conventions =
					{
						FindTypeTagName = type => typeof(IServer).IsAssignableFrom(type) ? "Servers" : null
					}
			};
			documentStore.Initialise();
			return documentStore;
		}
Ejemplo n.º 14
0
        public void Can_get_two_documents_in_one_call()
        {
            using (var server = GetNewServer(port, path))
            {
                var documentStore = new DocumentStore("localhost", port);
                documentStore.Initialise();

                var session = documentStore.OpenSession();
                session.Store(new Company { Name = "Company A", Id = "1"});
                session.Store(new Company { Name = "Company B", Id = "2" });
                session.SaveChanges();

                var session2 = documentStore.OpenSession();

                var companies = session2.Load<Company>("1","2");
                Assert.Equal(2, companies.Length);
                Assert.Equal("Company A", companies[0].Name);
                Assert.Equal("Company B", companies[1].Name);
            }
        }
Ejemplo n.º 15
0
        public void Can_delete_document()
        {
            using (var server = GetNewServer(port, path))
            {
                var documentStore = new DocumentStore("localhost", port);
                documentStore.Initialise();

                var session = documentStore.OpenSession();
                var entity = new Company { Name = "Company" };
                session.Store(entity);
                session.SaveChanges();

                using(var session2 = documentStore.OpenSession())
                    Assert.NotNull(session2.Load<Company>(entity.Id));

                session.Delete(entity);
                session.SaveChanges();

                using (var session3 = documentStore.OpenSession())
                    Assert.Null(session3.Load<Company>(entity.Id));
            }
        }
        static void Main(string[] args)
        {
            DateTime start = DateTime.Now;

            using (var documentStore = new DocumentStore { Url = "http://localhost:8082" })
            {
                documentStore.Initialise();

                using (var dc = new CodePointOpenDataContext())
                {
                    var postcodes = from pc in dc.PostCodeGeoDatas
                                    select
                                        new PostCodes
                                            {
                                                PostCode = pc.PostCode,
                                                Location =
                                                    new Location { Latitude = pc.Latitude, Longitude = pc.Longitude }
                                            };

                    foreach (var postCodeEntry in postcodes)
                    {
                        using (var session = documentStore.OpenSession())
                        {
                            session.Store(postCodeEntry);
                            session.SaveChanges();
                        }
                    }
                }
            }

            DateTime end = DateTime.Now;

            TimeSpan result = end - start;
            Console.WriteLine(result.TotalMilliseconds);
            Console.WriteLine(result.TotalSeconds);
            Console.ReadKey();
        }
		public void Can_query_using_special_characters()
		{
			using (var server = GetNewServer(port, path))
			{
				var documentStore = new DocumentStore { Url = "http://localhost:" + port };
				documentStore.Initialise();

				
				documentStore.DatabaseCommands.PutIndex("my_index",
													new IndexDefinition
													{
														Map = "from doc in docs select new { doc.Language, doc.Type}",
														Stores = { { "Name", FieldStorage.Yes }, { "Phone", FieldStorage.Yes } }
													});

				using(var s = documentStore.OpenSession())
				{
					s.Store(new
					{
						Language = "Français",//Note the ç
						Type = "Feats"
					});
					s.SaveChanges();
				}

				using (var s = documentStore.OpenSession())
				{
					var query = s.LuceneQuery<object>("my_index")
						.Where("Type:Feats AND Language:Français")
						.WaitForNonStaleResults();
					query.ToArray();

					Assert.Equal(1, query.QueryResult.TotalResults);
				}
			}
		}
Ejemplo n.º 18
0
        public void Can_create_index_using_linq_from_client_using_map_reduce()
        {
            using (var server = GetNewServer(port, path))
            {
                var documentStore = new DocumentStore { Url = "http://localhost:" + port };
                documentStore.Initialise();
                documentStore.DatabaseCommands.PutIndex("UsersCountByLocation", new IndexDefinition<LinqIndexesFromClient.User, LinqIndexesFromClient.LocationCount>
                {
                    Map = users => from user in users
                                   where user.Location == "Tel Aviv"
                                   select new { user.Location, Count =1 },
                    Reduce = results => from loc in results
                                        group loc by loc.Location into g
                                        select new { Location = g.Key, Count =  g.Sum(x=>x.Count)},
                });

                using (var session = documentStore.OpenSession())
                {
                    session.Store(new LinqIndexesFromClient.User
                    {
                        Location = "Tel Aviv",
                        Name = "Yael"
                    });

                    session.SaveChanges();

                    LinqIndexesFromClient.LocationCount single = session.Query<LinqIndexesFromClient.LocationCount>("UsersCountByLocation")
                        .Where("Location:Tel Aviv")
                        .WaitForNonStaleResults()
                        .Single();

                    Assert.Equal("Tel Aviv", single.Location);
                    Assert.Equal(1, single.Count);
                }
            }
        }
		public void Should_retrieve_all_entities()
		{
			using (var server = GetNewServer(port, path))
			{
				var documentStore = new DocumentStore { Url = "http://localhost:" + port };
				documentStore.Initialise();

				var session1 = documentStore.OpenSession();
				session1.Store(new Company {Name = "Company 1"});
				session1.Store(new Company {Name = "Company 2"});

				session1.SaveChanges();

				var session2 = documentStore.OpenSession();
				var companyFound = session2.LuceneQuery<Company>()
					.WaitForNonStaleResults()
					.ToArray();

				Assert.Equal(2, companyFound.Length);
			}
		}
		public void Should_update_retrieved_entity()
		{
			using (var server = GetNewServer(port, path))
			{
				var documentStore = new DocumentStore { Url = "http://localhost:" + port };
				documentStore.Initialise();

				var session1 = documentStore.OpenSession();
				var company = new Company {Name = "Company 1"};
				session1.Store(company);
				session1.SaveChanges();

				var companyId = company.Id;

				var session2 = documentStore.OpenSession();
				var companyFound = session2.Load<Company>(companyId);
				companyFound.Name = "New Name";
				session2.SaveChanges();

				Assert.Equal("New Name", session2.Load<Company>(companyId).Name);
			}
		}
		public void Should_update_stored_entity()
		{
			using (var server = GetNewServer(port, path))
			{
				var documentStore = new DocumentStore { Url = "http://localhost:" + port };
				documentStore.Initialise();

				var session = documentStore.OpenSession();
				var company = new Company {Name = "Company 1"};
				session.Store(company);

				session.SaveChanges();

				var id = company.Id;
				company.Name = "Company 2";
				session.SaveChanges();
				var companyFound = session.Load<Company>(company.Id);
				Assert.Equal("Company 2", companyFound.Name);
				Assert.Equal(id, company.Id);
			}
		}
        public void Can_rollback_transaction_on_insert()
        {
            using (var server = GetNewServer(port, path))
            {
                string id;
                var documentStore = new DocumentStore { Url = "http://localhost:" + port };
                documentStore.Initialise();

                using (var session = documentStore.OpenSession())
                {
                    using (var tx = new TransactionScope())
                    {
                        var company = new Company { Name = "Company 1" };
                        session.Store(company);

                        session.SaveChanges();

                        id = company.Id;
                    }
                }
                using (var session2 = documentStore.OpenSession())
                {

                    Assert.Null(session2.Load<Company>(id));
                }
            }
        }
        public void Can_insert_with_transaction()
        {
            using (var server = GetNewServer(port, path))
            {
                const string id = "Company/id";
                var documentStore = new DocumentStore { Url = "http://localhost:" + port };
                documentStore.Initialise();

                using (var session = documentStore.OpenSession())
                {
                    Assert.Null(session.Load<Company>(id));
                    using (var tx = new TransactionScope())
                    {
                        var company = new Company { Id = id, Name = "Company 1" };
                        session.Store(company);

                        session.SaveChanges();

                        tx.Complete();
                    }
                    Assert.NotNull(session.Load<Company>(id));

                }
            }
        }
        public void Optimistic_concurrency()
        {
            using (var server = GetNewServer(port, path))
            {
				var documentStore = new DocumentStore { Url = "http://localhost:" + port };
				documentStore.Initialise();

                var session = documentStore.OpenSession();
                session.UseOptimisticConcurrency = true;
                var company = new Company { Name = "Company 1" };
                session.Store(company);
                session.SaveChanges();

                using (var session2 = documentStore.OpenSession())
                {
                    var company2 = session2.Load<Company>(company.Id);
                    company2.Name = "foo";
                    session2.SaveChanges();
                }

                company.Name = "Company 2";
                Assert.Throws<ConcurrencyException>(() => session.SaveChanges());
            }
        }
		public void Can_select_from_index_using_linq_method_chain_using_integer_and_greater_than_or_equal()
		{
			using (var server = GetNewServer(port, path))
			{
				var documentStore = new DocumentStore { Url = "http://localhost:" + port };
				documentStore.Initialise();
				var session = documentStore.OpenSession();
				var company = new Company { Name = "Company 1", Phone = 5 };
				session.Store(company);
				session.SaveChanges();

				documentStore.DatabaseCommands.PutIndex("company_by_name",
														new IndexDefinition
														{
															Map = "from doc in docs where doc.Name != null select new { doc.Name, doc.Phone}",
															Stores = { { "Name", FieldStorage.Yes }, { "Phone", FieldStorage.Yes } }
														});

				var q = session.Query<Company>("company_by_name")
					.Customize(query => query.WaitForNonStaleResults(TimeSpan.FromHours(1)))
					.Where(x => x.Phone > 1);
				var single = q.ToArray()[0];
				Assert.Equal("Company 1", single.Name);
				Assert.Equal(5, single.Phone);
			}
		}
		public void Can_sort_from_index()
		{
			using (var server = GetNewServer(port, path))
			{
				var documentStore = new DocumentStore { Url = "http://localhost:" + port };
				documentStore.Initialise();

				var session = documentStore.OpenSession();
				
				session.Store(new Company { Name = "Company 1", Phone = 5 });
				session.Store(new Company { Name = "Company 2", Phone = 3 });
				session.SaveChanges();

				documentStore.DatabaseCommands.PutIndex("company_by_name",
														new IndexDefinition
														{
                                                            Map = "from doc in docs where doc.Name != null select new { doc.Name, doc.Phone}",
															Indexes = { { "Phone", FieldIndexing.Analyzed } }
														});

				// Wait until the index is built
                session.LuceneQuery<Company>("company_by_name")
					.WaitForNonStaleResults()
					.ToArray();

                var companies = session.LuceneQuery<Company>("company_by_name")
					.OrderBy("Phone")
					.WaitForNonStaleResults()
					.ToArray();

				Assert.Equal("Company 2", companies[0].Name);
				Assert.Equal("Company 1", companies[1].Name);
			}
		}
		public void Can_get_correct_averages_from_map_reduce_index()
		{
			using (var server = GetNewServer(port, path))
			{
				var documentStore = new DocumentStore { Url = "http://localhost:" + port };
				documentStore.Initialise();
				documentStore.DatabaseCommands.PutIndex("AvgAgeByLocation", new IndexDefinition<LinqIndexesFromClient.User, LinqIndexesFromClient.LocationAge>
				{
					Map = users => from user in users
								   select new { user.Location, user.Age },
					Reduce = results => from loc in results
										group loc by loc.Location into g
										select new { Location = g.Key, Age = g.Average(x => x.Age) },
				});

				using (var session = documentStore.OpenSession())
				{
					session.Store(new LinqIndexesFromClient.User
					{
						Location = "Tel Aviv",
						Age = 29,
						Name = "Yael"
					});

					session.Store(new LinqIndexesFromClient.User
					{
						Location = "Tel Aviv",
						Age = 24,
						Name = "Einat"
					});

					session.SaveChanges();

                    LinqIndexesFromClient.LocationAge single = session.LuceneQuery<LinqIndexesFromClient.LocationAge>("AvgAgeByLocation")
						.Where("Location:Tel Aviv")
						.WaitForNonStaleResults()
						.Single();

					Assert.Equal("Tel Aviv", single.Location);
					Assert.Equal(26.5m, single.Age);
				}
			}
		}
        public void Can_project_from_index()
        {
            using (var server = GetNewServer(port, path))
            {
				var documentStore = new DocumentStore { Url = "http://localhost:" + port };
				documentStore.Initialise();
                var session = documentStore.OpenSession();
                var company = new Company { Name = "Company 1", Phone = 5 };
                session.Store(company);
                session.SaveChanges();

                documentStore.DatabaseCommands.PutIndex("company_by_name",
                                                        new IndexDefinition
                                                        {
                                                            Map = "from doc in docs where doc.Name != null select new { doc.Name, doc.Phone}",
															Stores = { { "Name", FieldStorage.Yes }, { "Phone", FieldStorage.Yes } }
                                                        });

            	var q = session
                    .LuceneQuery<Company>("company_by_name")
					.SelectFields<Company>("Name","Phone")
            		.WaitForNonStaleResults();
                var single = q.Single();
                Assert.Equal("Company 1", single.Name);
                Assert.Equal(5, single.Phone);
            }
        }
Ejemplo n.º 29
0
 public ActionResult PortToRaven()
 {
     using (var documentStore = new DocumentStore
     {
         Url = "http://localhost:8080",
         Conventions =
             {
                 FindTypeTagName = type =>
                 {
                     if (type.GetProperty("Genre") == null)
                         return "Genres";
                     return "Albums";
                 }
             }
     })
     {
         documentStore.Initialise();
         using (var session = documentStore.OpenSession())
         {
             session.OnEntityConverted += (entity, document, metadata) => metadata.Remove("Raven-Clr-Type");
             foreach (var album in new MusicStoreEntities().Albums.Include("Artist").Include("Genre"))
             {
                 session.Store(new
                 {
                     Id = "albums/" + album.AlbumId,
                     album.AlbumArtUrl,
                     Arist = new { album.Artist.Name, Id = "artists/" + album.Artist.ArtistId },
                     Genre = new { album.Genre.Name, Id = "genres/" + album.Genre.GenreId },
                     album.Price,
                     album.Title,
                 });
             }
             foreach (var genre in new MusicStoreEntities().Genres)
             {
                 session.Store(new
                 {
                     genre.Description,
                     genre.Name,
                     Id = "genres/" + genre.GenreId
                 });
             }
             session.SaveChanges();
         }
     }
     return Content("OK");
 }
		public void Can_store_using_batch()
		{
			using (var server = GetNewServer(port, path))
			{
				var documentStore = new DocumentStore { Url = "http://localhost:" + port };
				documentStore.Initialise();
				var batchResults = documentStore
					.DatabaseCommands
					.Batch(new ICommandData[]
					{
						new PutCommandData
						{
							Document = JObject.FromObject(new Company{Name = "Hibernating Rhinos"}),
							Etag = null,
							Key = "rhino1",
							Metadata = new JObject(),
						},
						new PutCommandData
						{
							Document = JObject.FromObject(new Company{Name = "Hibernating Rhinos"}),
							Etag = null,
							Key = "rhino2",
							Metadata = new JObject(),
						},
						new DeleteCommandData
						{
							Etag = null,
							Key = "rhino2"
						}
					});

				Assert.Equal("rhino1", batchResults[0].Key);
				Assert.Equal("rhino2", batchResults[1].Key);

				Assert.Null(documentStore.DatabaseCommands.Get("rhino2"));
				Assert.NotNull(documentStore.DatabaseCommands.Get("rhino1"));
			}
		}