Ejemplo n.º 1
0
        public async Task SelectNonExistingType()
        {
            Siaqodb nop = new Siaqodb(); await nop.OpenAsync(dbFolder);

            await nop.DropTypeAsync <Something>();

            await nop.DropTypeAsync <Customer>();

            List <Customer> listInitial = new List <Customer>();

            for (int i = 0; i < 10; i++)
            {
                Customer c = new Customer();
                c.ID = i;
                if (i % 2 == 0)
                {
                    c.Name = i.ToString() + "TEST";
                }
                else
                {
                    c.Name = "ADH" + i.ToString();
                }
                listInitial.Add(c);
                await nop.StoreObjectAsync(c);
            }
            await nop.FlushAsync();

            var query = await(from Something c in nop
                              select new SomethingAnony {
                One = c.one, Two = c.two
            }).ToListAsync();


            Assert.AreEqual(0, query.ToList().Count);
        }
Ejemplo n.º 2
0
        public async Task SkipTake()
        {
            Siaqodb nop = new Siaqodb(); await nop.OpenAsync(dbFolder);

            await nop.DropTypeAsync <Customer>();

            List <Customer> listInitial = new List <Customer>();

            for (int i = 0; i < 10; i++)
            {
                Customer c = new Customer();
                c.ID = i;
                if (i % 2 == 0)
                {
                    c.Name = i.ToString() + "TEST";
                }
                else
                {
                    c.Name = "ADH" + i.ToString();
                }
                listInitial.Add(c);
                await nop.StoreObjectAsync(c);
            }
            await nop.FlushAsync();

            var query = await(await(await(from Customer c in nop
                                          where c.ID >= 5
                                          select c).SkipAsync(2)).TakeAsync(2)).ToListAsync();


            Assert.AreEqual(query.Count, 2);
            Assert.AreEqual(query[0].ID, 7);
            Assert.AreEqual(query[1].ID, 8);
        }
Ejemplo n.º 3
0
        public async Task TestSelfMethod()
        {
            Siaqodb nop = new Siaqodb(); await nop.OpenAsync(dbFolder);

            await nop.DropTypeAsync <Customer>();

            List <Customer> listInitial = new List <Customer>();

            for (int i = 0; i < 10; i++)
            {
                Customer c = new Customer();
                c.ID = i;
                if (i % 2 == 0)
                {
                    c.Name = i.ToString() + "TEST";
                }
                else
                {
                    c.Name = "ADH" + i.ToString();
                }
                listInitial.Add(c);
                await nop.StoreObjectAsync(c);
            }
            await nop.FlushAsync();

            var query = await(from Customer c in nop
                              where c.IsTrue(c.Name) == true
                              select c).ToListAsync();

            Assert.AreEqual(query.Count, 1);
        }
Ejemplo n.º 4
0
        public void SelectWhereUnaryOperator()
        {
            Siaqodb nop = new Siaqodb(objPath);

            nop.DropType <CustomerLite>();
            List <CustomerLite> listInitial = new List <CustomerLite>();

            for (int i = 0; i < 10; i++)
            {
                CustomerLite c = new CustomerLite();
                c.Age = i;
                if (i % 2 == 0)
                {
                    c.Name = i.ToString() + "TEST";
                }
                else
                {
                    c.Name = "Siaqo" + i.ToString();
                }
                c.Active = false;
                listInitial.Add(c);
                nop.StoreObject(c);
            }
            nop.Flush();

            //run unoptimized
            var query = (from CustomerLite c in nop
                         where c.Age > 5 && !c.Active
                         select c).ToList();
            int k = 0;

            Assert.AreEqual(4, query.Count);
        }
Ejemplo n.º 5
0
        public void TestSelectWithAnonymous()
        {
            Siaqodb nop = new Siaqodb(objPath);

            nop.DropType <CustomerLite>();
            List <CustomerLite> listInitial = new List <CustomerLite>();

            for (int i = 0; i < 10; i++)
            {
                CustomerLite c = new CustomerLite();
                c.Name = i.ToString();
                c.Age  = i;
                if (i % 3 == 0)
                {
                    c.TEnum = TestEnum.Doi;
                }
                else
                {
                    c.TEnum = TestEnum.Trei;
                }
                listInitial.Add(c);
                nop.StoreObject(c);
            }
            nop.Flush();
            var query = from CustomerLite c in nop
                        where c.Age < 3
                        select new { c.Age, c.Name };

            int k = 0;

            foreach (var s in query)
            {
            }
        }
Ejemplo n.º 6
0
        public void WhereLocalVariable()
        {
            Siaqodb nop = new Siaqodb(objPath);

            nop.DropType <Customer>();
            List <Customer> listInitial = new List <Customer>();

            for (int i = 0; i < 10; i++)
            {
                Customer c = new Customer();
                c.ID = i;
                if (i % 2 == 0)
                {
                    c.Name = i.ToString() + "TEST";
                }
                else
                {
                    c.Name = "ADH" + i.ToString();
                }
                listInitial.Add(c);
                nop.StoreObject(c);
            }
            nop.Flush();
            var query = from Customer c in nop
                        where c.ID == this.id
                        select c;

            Assert.AreEqual(query.ToList <Customer>().Count, 1);
            Assert.AreEqual(3, query.ToList <Customer>()[0].ID);
        }
Ejemplo n.º 7
0
        public void SelectNonExistingType()
        {
            Siaqodb nop = new Siaqodb(objPath);

            nop.DropType <Something>();
            nop.DropType <Customer>();
            List <Customer> listInitial = new List <Customer>();

            for (int i = 0; i < 10; i++)
            {
                Customer c = new Customer();
                c.ID = i;
                if (i % 2 == 0)
                {
                    c.Name = i.ToString() + "TEST";
                }
                else
                {
                    c.Name = "ADH" + i.ToString();
                }
                listInitial.Add(c);
                nop.StoreObject(c);
            }
            nop.Flush();
            var query = from Something c in nop
                        select new SomethingAnony {
                One = c.one, Two = c.two
            };


            Assert.AreEqual(0, query.ToList().Count);
        }
Ejemplo n.º 8
0
        public void Run()
        {
            Siaqodb siaqodb = SiaqodbFactoryExample.GetInstance();

            siaqodb.DropType <ClassWithIndex>();//all objects of this Type will be deleted from database

            for (int i = 0; i < 10000; i++)
            {
                ClassWithIndex myobj = new ClassWithIndex()
                {
                    MyID = i % 10, Name = "MyTest" + i.ToString()
                };

                siaqodb.StoreObject(myobj);
            }
            DateTime start = DateTime.Now;
            var      q     = from ClassWithIndex myobj in siaqodb
                             where myobj.MyID == 8//index will be used so very fast retrieve from DB
                             select myobj;
            int k = 0;

            foreach (ClassWithIndex obj in q)
            {
                //do something with object
                k++;
            }
            string timeElapsed = (DateTime.Now - start).ToString();

            Log("Time elapsed to load:" + k.ToString() + " objects from 10.000 stored objects filtered by index:" + timeElapsed);
        }
        public static void Main()
         {
 	   		int counter = 0;
             Siaqodb siaqodb = new Siaqodb(@"d:\Siaqodb\database\TEST\");
 
            List<Canciones> musicList = (from m in XDocument.Load(@"C:\Users\ivan_000\Desktop\MusicList.xml")
                                            .Descendants("Music")
                                            select new Canciones{
                                            Album = m.Element("Album").Value,
                                            AlbumArtist = m.Element("AlbumArtist").Value,
                                            AlbumCover = m.Element("AlbumCover").Value,
                                            Artist = m.Element("Artist").Value,
                                            ArtistCover = m.Element("ArtistCover").Value,
                                            Genre = m.Element("Genre").Value,
                                            GenreCover = m.Element("GenreCover").Value,
                                            Path = m.Element("Path").Value,
                                            Title = m.Element("Title").Value,
                                            OID = musicList.Count()                                          
 
                                            }).ToList();
 										   
 						foreach(Cancion cancion in musicList)
 						{
 							counter++;
 							if (counter <= 100)
 									siaqodb.StoreObject(cancion);	
 							else
 								break;					
 						}
 
         }
Ejemplo n.º 10
0
        public void SelectWhereMinus()
        {
            Siaqodb nop = new Siaqodb(objPath);

            nop.DropType <CustomerLite>();
            List <CustomerLite> listInitial = new List <CustomerLite>();

            for (int i = 0; i < 10; i++)
            {
                CustomerLite c = new CustomerLite();
                c.Age = i;
                if (i % 2 == 0)
                {
                    c.Name = i.ToString() + "TEST";
                }
                else
                {
                    c.Name = "Siaqo" + i.ToString();
                }
                c.Active = false;
                listInitial.Add(c);
                nop.StoreObject(c);
            }
            nop.Flush();


            var query = (from CustomerLite c in nop
                         where c.Age + 2 > 0
                         select new { c.Name, c.Age }).ToList();
            int k = 0;

            Assert.AreEqual(3, query.Count);
        }
Ejemplo n.º 11
0
        public async Task SelectWhereUnaryOperator()
        {
            Siaqodb nop = new Siaqodb(); await nop.OpenAsync(dbFolder);

            await nop.DropTypeAsync <CustomerLite>();

            List <CustomerLite> listInitial = new List <CustomerLite>();

            for (int i = 0; i < 10; i++)
            {
                CustomerLite c = new CustomerLite();
                c.Age = i;
                if (i % 2 == 0)
                {
                    c.Name = i.ToString() + "TEST";
                }
                else
                {
                    c.Name = "Siaqo" + i.ToString();
                }
                c.Active = false;
                listInitial.Add(c);
                await nop.StoreObjectAsync(c);
            }
            await nop.FlushAsync();

            //run unoptimized
            var query = await(from CustomerLite c in nop
                              where c.Age > 5 && !c.Active
                              select new { c.Name, c.Age }).ToListAsync();
            int k = 0;

            Assert.AreEqual(4, query.Count);
        }
Ejemplo n.º 12
0
        public void TestStorePartialNull()
        {
            Siaqodb s_db = new Siaqodb(objPath);

            s_db.DropType <A>();
            s_db.DropType <B>();
            s_db.DropType <C>();
            for (int i = 0; i < 10; i++)
            {
                A a = new A();
                a.aId               = i;
                a.BVar              = new B();
                a.BVar.bId          = 11;
                a.BVar.Ci           = new C();
                a.BVar.Ci.ACircular = a;
                a.BVar.Ci.cId       = i;
                s_db.StoreObject(a);
            }
            IList <A> lsA = s_db.LoadAll <A>();

            lsA[0].BVar.Ci = null;
            s_db.StoreObjectPartially(lsA[0].BVar, "Ci");
            IList <A> lsA1 = s_db.LoadAll <A>();

            Assert.IsNull(lsA1[0].BVar.Ci);
        }
Ejemplo n.º 13
0
        public static Siaqodb GetInstance()
        {
            if (instance == null)
            {
                //put here your License Key
                SiaqodbConfigurator.SetLicense(@"QB89ZFVPOc4vXeNEBR5mLxnR0NlnEZfmLDNj3a+Wa6A=");

                //if ANDROID:
                if (Application.platform == RuntimePlatform.Android)
                {
                    siaoqodbPath = Application.persistentDataPath;
                }

                //if Windows or MAC
                else if (Application.platform == RuntimePlatform.OSXEditor ||
                         Application.platform == RuntimePlatform.WindowsEditor)
                {
                    siaoqodbPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + @"database";
                }

                //if iOS (iPhone /iPad)
                else if (Application.platform == RuntimePlatform.OSXPlayer ||
                         Application.platform == RuntimePlatform.IPhonePlayer)
                {
                    siaoqodbPath = Application.dataPath;
                }

                if (!Directory.Exists(siaoqodbPath))
                {
                    Directory.CreateDirectory(siaoqodbPath);
                }
                instance = new Siaqodb(siaoqodbPath);
            }
            return(instance);
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            Sqo.SiaqodbConfigurator.SetLicense(@"your license key");
            SiaqodbConfigurator.SetDocumentSerializer(new MyJsonSerializer());
            string siaoqodbPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + @"siaqodb";

            if (!Directory.Exists(siaoqodbPath))
            {
                Directory.CreateDirectory(siaoqodbPath);
            }

            using (Siaqodb siaqodb = new Siaqodb(siaoqodbPath))
            {
                CRUD_Document(siaqodb);
                Console.WriteLine("CRUD with Documents operations executed.");

                CRUD_POCO(siaqodb);
                Console.WriteLine("CRUD with POCO operations executed.");

                SimpleQuery(siaqodb);
                Console.WriteLine("SimpleQuery executed.");

                ComplexQuery(siaqodb);
                Console.WriteLine("ComplexQuery executed.");
            }
            Console.ReadLine();
        }
Ejemplo n.º 15
0
        public static void Delete()
        {
            using (Siaqodb siaqodb = new Siaqodb())
            {
                siaqodb.Open(siaqodbPath, 100 * OneMB, 20);
                Console.WriteLine("DeleteSiaqodb...");
                var all = siaqodb.LoadAll<MyEntity>();
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                foreach(MyEntity en in all)
                {
                    siaqodb.Delete(en);
                }

                stopwatch.Stop();
                Console.WriteLine("DeleteSiaqodb took:" + stopwatch.Elapsed);

            }

            using (var dbsql = new SQLite.SQLiteConnection(sqLitePath))
            {
                Console.WriteLine("DeleteSQLite...");
                var all = dbsql.Query<MyEntity>("select * from MyEntity");

                var stopwatch = new Stopwatch();
                stopwatch.Start();
                foreach (MyEntity en in all)
                {
                    dbsql.Delete(en);
                }
                stopwatch.Stop();
                Console.WriteLine("DeleteSQLite took:" + stopwatch.Elapsed);
            }
        }
Ejemplo n.º 16
0
        public void Run()
        {
            Siaqodb      siaqodb     = SiaqodbFactoryExample.GetInstance();
            ITransaction transaction = siaqodb.BeginTransaction();

            Log("Start transactional operation");
            try
            {
                Invoice inv = new Invoice {
                    Number = 1, CustomerId = 10, ID = Guid.NewGuid()
                };
                siaqodb.StoreObject(inv, transaction);
                for (int i = 1; i < 10; i++)
                {
                    InvoiceDetail detail = new InvoiceDetail {
                        InvoiceID = inv.ID, UnitPrice = i, Quantity = i % 3
                    };
                    siaqodb.StoreObject(detail, transaction);
                }

                transaction.Commit();
                Log("Transaction Commit() successfully!");
            }
            catch (Exception ex)
            {
                Log("There was a problem during transaction, Rollback all changes...");
                transaction.Rollback();
            }
        }
Ejemplo n.º 17
0
        public IndexManager(Siaqodb siaqodb)
        {
            this.siaqodb = siaqodb;
#if UNITY3D
            dummy = new DummyBtree(siaqodb);
#endif
        }
Ejemplo n.º 18
0
        public async Task TestStorePartialNull()
        {
            Siaqodb s_db = new Siaqodb(); await s_db.OpenAsync(dbFolder);

            await s_db.DropTypeAsync <A>();

            await s_db.DropTypeAsync <B>();

            await s_db.DropTypeAsync <C>();

            for (int i = 0; i < 10; i++)
            {
                A a = new A();
                a.aId               = i;
                a.BVar              = new B();
                a.BVar.bId          = 11;
                a.BVar.Ci           = new C();
                a.BVar.Ci.ACircular = a;
                a.BVar.Ci.cId       = i;
                await s_db.StoreObjectAsync(a);
            }
            await s_db.FlushAsync();

            IList <A> lsA = await s_db.LoadAllAsync <A>();

            lsA[0].BVar.Ci = null;
            await s_db.StoreObjectPartiallyAsync(lsA[0].BVar, "Ci");

            await s_db.FlushAsync();

            IList <A> lsA1 = await s_db.LoadAllAsync <A>();

            Assert.IsNull(lsA1[0].BVar.Ci);
        }
        public void Where_UnoptimizedUsingUnaryOperator()
        {
            Siaqodb siaqodb = SiaqodbFactoryExample.GetInstance();

            for (int i = 0; i < 10; i++)
            {
                BoolAndIntExample e = new BoolAndIntExample()
                {
                    SomeBool = i % 2 == 0, SomeInt = i
                };
                siaqodb.StoreObject(e);
            }

            //this query run Unoptimized, problem is !(Not) operator
            var query = from BoolAndIntExample e in siaqodb
                        where e.SomeInt > 5 && !e.SomeBool
                        select e;

            //now all Employee objects are loaded from database and query fall in LINQ to objects
            foreach (BoolAndIntExample e in query)
            {
                //do something with e
            }

            //to optimize query above, just use Equal operator:
            var queryOptimized = from BoolAndIntExample e in siaqodb
                                 where e.SomeInt > 5 && e.SomeBool == false
                                 select e;

            foreach (BoolAndIntExample e in query)
            {
                //do something with e
            }
        }
Ejemplo n.º 20
0
        public async Task TestWhereComplexObjectCompare()
        {
            Siaqodb s_db = new Siaqodb(); await s_db.OpenAsync(dbFolder);

            await s_db.DropTypeAsync <TapRecord>();

            await s_db.DropTypeAsync <D>();

            for (int i = 0; i < 10; i++)
            {
                D d = new D();
                d.tap  = new TapRecord();
                d.tap2 = new TapRecord()
                {
                    userName = "******"
                };
                d.TapList = new List <TapRecord>();
                d.TapList.Add(d.tap);
                d.TapList.Add(new TapRecord());
                d.TapList2.Add(new TapRecord()
                {
                    userName = "******"
                });
                await s_db.StoreObjectAsync(d);
            }
            await s_db.FlushAsync();

            var q = await(from D d in s_db
                          where d.tap2 == new TapRecord {
                userName = "******"
            }
                          select d).ToListAsync();

            Assert.AreEqual(10, q.Count);
        }
Ejemplo n.º 21
0
        public void TestLicenseStarterEdition()
        {
            Siaqodb s_db = new Siaqodb(objPath);

            s_db.DropType <A>();
            s_db.DropType <B>();
            s_db.DropType <C>();
            for (int i = 0; i < 102; i++)
            {
                A a = new A();
                a.aId               = i;
                a.BVar              = new B();
                a.BVar.bId          = 11;
                a.BVar.Ci           = new C();
                a.BVar.Ci.ACircular = a;
                a.BVar.Ci.cId       = i % 2;
                s_db.StoreObject(a);
            }
            IList <A> lsA = s_db.LoadAll <A>();

            Assert.AreEqual(102, lsA.Count);
            s_db.Close();
            bool ok = false;

            try
            {
                s_db.Open(objPath);
            }
            catch (Sqo.Exceptions.InvalidLicenseException e)
            {
                ok = true;
            }
            Assert.IsTrue(ok);
        }
Ejemplo n.º 22
0
        public void TestStorePartialOnIndexed()
        {
            SiaqodbConfigurator.AddIndex("cId", typeof(C));
            Siaqodb s_db = new Siaqodb(objPath);

            s_db.DropType <A>();
            s_db.DropType <B>();
            s_db.DropType <C>();
            for (int i = 0; i < 10; i++)
            {
                A a = new A();
                a.aId               = i;
                a.BVar              = new B();
                a.BVar.bId          = 11;
                a.BVar.Ci           = new C();
                a.BVar.Ci.ACircular = a;
                a.BVar.Ci.cId       = i % 2;
                s_db.StoreObject(a);
            }
            IList <A> lsA = s_db.LoadAll <A>();

            lsA[0].BVar.Ci.cId = 3;
            s_db.StoreObjectPartially(lsA[0].BVar, "Ci");
            var q = (from C c in s_db
                     where c.cId == 3
                     select c).ToList();

            Assert.AreEqual(1, q.Count);
        }
Ejemplo n.º 23
0
        public void Run()
        {
            Siaqodb siaqodb = SiaqodbFactoryExample.GetInstance();
            // example:dynamic filter depending what user choose in the UI
            // once it is needed to filter by FirstName and another time by FirstName AND Age
            //we will pick random cases
            int val = DateTime.Now.Second % 2;

            //declare predicate
            Expression <Func <Employee, bool> > predicate = null;

            if (val == 1)
            {
                //build a predicate to filter only by FirstName
                predicate = employee => employee.FirstName.Contains("Emp");

                Log("Predicate with only FirstName is activated");
            }
            else if (val == 0)
            {
                //build a predicate to filter by FirstName and Age
                predicate = employee => employee.FirstName.Contains("Emp") && employee.Age > 20;

                Log("Predicate with FirstName and Age is activated");
            }

            var q = siaqodb.Query <Employee>().Where(predicate).Select(e => e);

            foreach (Employee emp in q)
            {
                //do something with employee
            }
        }
Ejemplo n.º 24
0
        public void TestShrinkWithoutComplex()
        {
            Siaqodb s_db = new Siaqodb(objPath);

            s_db.DropType <AEmpty>();
            List <AEmpty> objs = new List <AEmpty>();

            for (int i = 0; i < 10; i++)
            {
                AEmpty ae = new AEmpty()
                {
                    MyInt = i
                };
                ae.SomeStrings = new List <string>();
                ae.SomeStrings.Add("aaa" + i.ToString());
                s_db.StoreObject(ae);
                objs.Add(ae);
            }
            for (int i = 0; i < 5; i++)
            {
                s_db.Delete(objs[i]);
            }

            s_db.Close();
            SiaqodbUtil.Shrink(objPath, ShrinkType.Total);
            s_db = new Siaqodb(objPath);

            IList <AEmpty> all = s_db.LoadAll <AEmpty>();

            for (int i = 0; i < 5; i++)
            {
                Assert.AreEqual(i + 1, s_db.GetOID(all[i]));
            }
        }
Ejemplo n.º 25
0
        public void LoadAllOrders()
        {
            Siaqodb siaqodb = SiaqodbFactoryExample.GetInstance();

            IList <Order> orders = siaqodb.LoadAll <Order>();

            foreach (Order order in orders)
            {
                Log("Order with nr:" + order.OrderNumber + " is of Customer:" + order.OrderCustomer.Name +
                    @" and it has:" + order.Details.Count + " details as:");
                foreach (OrderDetail det in order.Details)
                {
                    Log("Product:" + det.DetailProduct.Name + ", Price:" + det.Price + ", Quantity:" + det.Quantity);
                }
            }
            Customer customer = new Customer()
            {
                Name = "CustomerX", Address = new Address()
                {
                    City = "Berlin"
                }
            };

            var q = from Order o in siaqodb
                    where o.OrderCustomer == customer
                    select o;

            foreach (var city in q)
            {
            }
        }
Ejemplo n.º 26
0
        public void TestWhereComplexObjectCompare()
        {
            Siaqodb s_db = new Siaqodb(objPath);

            s_db.DropType <TapRecord>();
            s_db.DropType <D>();

            for (int i = 0; i < 10; i++)
            {
                D d = new D();
                d.tap  = new TapRecord();
                d.tap2 = new TapRecord()
                {
                    userName = "******"
                };
                d.TapList = new List <TapRecord>();
                d.TapList.Add(d.tap);
                d.TapList.Add(new TapRecord());
                d.TapList2.Add(new TapRecord()
                {
                    userName = "******"
                });
                s_db.StoreObject(d);
            }

            var q = (from D d in s_db
                     where d.tap2 == new TapRecord {
                userName = "******"
            }
                     select d).ToList();

            Assert.AreEqual(10, q.Count);
        }
Ejemplo n.º 27
0
        public void Run()
        {
            Siaqodb siaqodb = SiaqodbFactoryExample.GetInstance();

            siaqodb.DropType <MyClassWithLists>();
            for (int i = 0; i < 10; i++)
            {
                MyClassWithLists ps = new MyClassWithLists();
                ps.ID     = i;
                ps.myList = new List <int>();
                if (i % 2 == 0)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        ps.myList.Add(j * i);
                    }
                }
                ps.blob = new byte[] { 1, 2, 3 };

                siaqodb.StoreObject(ps);
            }

            //this query will run optimazed, only instances that satify condition are created by engine
            var q = from MyClassWithLists myListObj in siaqodb
                    where myListObj.myList.Contains(2)
                    select myListObj;

            Log("Following objects contains in myList prop element = 2:");

            foreach (MyClassWithLists mcl in q)
            {
                //do somthing with obj
            }
        }
        public void Where_UnoptimizedUsingStringMethods()
        {
            Siaqodb siaqodb = SiaqodbFactoryExample.GetInstance();

            //this query run Unoptimized, problem is Length property of String
            //siaqodb can only handle optimized following String methods:StartsWith,EndsWith and Contains
            //all other String methods/properties for object members result in a unoptimized query
            var query = from Company c in siaqodb
                        where c.Phone.Length == 3
                        select c;

            //now all Company objects are loaded from database and query fall in LINQ to objects
            foreach (Company c in query)
            {
                //do something with c
            }
            // !!! Important: if those String methods are used for a local variable and NOT to a member of a stored object
            //query run optimized so:
            string d = "test";
            var    queryOptimized = from Company c in siaqodb
                                    where c.Name == d.Substring(2)
                                    select c;

            //the above query run optimized
            foreach (Company c in queryOptimized)
            {
                //do something with c
            }
        }
Ejemplo n.º 29
0
        private void CreateDatabase1()
        {
            try
            {
                siaqodb = new Siaqodb(@"c:\Siaqodb\");

                //Siaqodb siaqodb = new Siaqodb(@"c:\Siaqodb\");
                //	Siaqodb siaqodb = new Siaqodb();
                //siaqodb.GetDBPath
                //siaqodb.


                //		siaqodb.Open(@"c:\Siaqodb\");

                Siaqodb.Stat mike = siaqodb.DbInfo;

                Company company = new Company();
                company.Name = "MyCompany";
                siaqodb.StoreObject(company);
                Employee employee1 = new Employee();
                employee1.Employer  = company;
                employee1.FirstName = "John";
                employee1.LastName  = "Walter";
                siaqodb.StoreObject(employee1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        public void Where_UnoptimizedUsingLocalMethod()
        {
            Siaqodb siaqodb = SiaqodbFactoryExample.GetInstance();

            //this query run Unoptimized, problem is TestMet method that get a member of a storable object
            //as argument
            var query = from Employee e in siaqodb
                        where TestMet(e.Age) == 30
                        select e;

            //now all Employee objects are loaded from database and query fall in LINQ to objects
            foreach (Employee e in query)
            {
                //do something with e
            }
            //!!! Important: queries that use Methods that are called with arguments that ARE NOT members of stored objects run Optmized
            //next query run optimized
            var queryOptimized = from Employee e in siaqodb
                                 where e.Age == TestMet(30)
                                 select e;

            foreach (Employee e in queryOptimized)
            {
                //do something with e
            }
        }
Ejemplo n.º 31
0
        public async Task TestListOfLists()
        {
            Siaqodb s_db = new Siaqodb(); await s_db.OpenAsync(dbFolder);

            await s_db.DropTypeAsync <MyList <int> >();

            for (int i = 0; i < 10; i++)
            {
                MyList <int> myList = new MyList <int>();
                myList.TheList = new List <ListContainer <int> >();
                ListContainer <int> innerList = new ListContainer <int>();
                innerList.List = new List <int>();
                innerList.List.Add(i);
                innerList.List.Add(i + 1);
                myList.TheList.Add(innerList);
                await s_db.StoreObjectAsync(myList);
            }
            await s_db.FlushAsync();

            s_db.Close();
            s_db = new Siaqodb(); await s_db.OpenAsync(dbFolder);

            IList <MyList <int> > list = await s_db.LoadAllAsync <MyList <int> >();

            Assert.AreEqual(10, list.Count);
            Assert.AreEqual(2, list[1].TheList[0].List.Count);
        }
Ejemplo n.º 32
0
 public static void CloseDatabase()
 {
     if (instance != null)
     {
         instance.Close();
         instance = null;
     }
 }
Ejemplo n.º 33
0
        private void Insert(Siaqodb siaqodb)
        {
            Company company = CreateCompany("FirstCompany");
            siaqodb.StoreObject(company);

            Company company2 = CreateCompany("SecondCompany");
            siaqodb.StoreObject(company2);
        }
Ejemplo n.º 34
0
 public static Siaqodb GetInstance()
 {
     if (instance == null)
     {
         instance = new Siaqodb(siaoqodbPath);
     }
     return instance;
 }
Ejemplo n.º 35
0
        private void Delete(Siaqodb siaqodb)
        {
            IObjectList<Company> allCompanies = siaqodb.LoadAll<Company>();

            //delete object in database( in memory will still be available until GC will take it)
            siaqodb.Delete(allCompanies[0]);

            int  count = siaqodb.Count<Company>();
            Log("actual number of companies after delete:"+count.ToString());
        }
Ejemplo n.º 36
0
        private void Load(Siaqodb siaqodb)
        {
            //load all employees that develop in C#
            var query = from Developer dev in siaqodb
                        where dev.DevelopIn == ProgrammingLanguage.CSharp
                        select dev;

            Log("Following developers work in CSharp:");
            foreach (Developer d in query)
            {
                Log(d.FirstName + " " + d.LastName);
            }
        }
Ejemplo n.º 37
0
		public static void DeleteDataBase () {
			instance = GetInstance ();
			Debug.Log ("Deleted");
			if (Directory.Exists(siaoqodbPath)) {
				DirectoryInfo directory = new DirectoryInfo (siaoqodbPath);
                CloseDatabase();
				foreach(System.IO.FileInfo file in directory.GetFiles()) 
					file.Delete();
				foreach(System.IO.DirectoryInfo subDirectory in directory.GetDirectories()) 
					subDirectory.Delete(true);
			}
			CloseDatabase ();
		}
Ejemplo n.º 38
0
        private void Insert(Siaqodb siaqodb)
        {
            Company company = CreateCompany();

            siaqodb.StoreObject(company);

            //Save into DB some objects with random data
            for (int i = 0; i < 10; i++)
            {
                Developer developer = CreateDeveloper(i, company.OID);

                siaqodb.StoreObject(developer);
            }
        }
Ejemplo n.º 39
0
        public static Siaqodb GetInstance()
        {
            if (instance == null)
            {
                SiaqodbConfigurator.SetLicense(@"nHLBqLU8pCLZdjsBgZWgh0Djd42MIr3Pytfrlpa+yQR8oIHfvRoNldrnxtoxsvz7");
                siaqodbPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + @"siaqodb";

                if (!Directory.Exists(siaqodbPath))
                {
                    Directory.CreateDirectory(siaqodbPath);
                }
                instance = new Siaqodb(siaqodbPath);
            }
            return instance;
        }
Ejemplo n.º 40
0
        private void Load(Siaqodb siaqodb)
        {
            //load all employees of company with name CompanyX
            // ! will not be created any Company objects also not any Employee objects and only needed values will be loaded from DB
            var query = from Company comp in siaqodb
                        where comp.Name=="CompanyX"
                        join Employee emp in siaqodb
                        on comp.OID equals emp.CompanyOID
                        select new {emp.FirstName ,emp.LastName };

            Log("Following employees works at CompanyX:");
            foreach (var e in query)
            {
                Log(e.FirstName + " " + e.LastName);
            }
        }
Ejemplo n.º 41
0
        public void EncryptSimple()
        {
            //now database files will be encrypted with default AES encryption algorithm and with built-in password
            string siaqodbPathNew=SiaqodbFactoryExample.siaoqodbPath+Path.DirectorySeparatorChar + @"siaqodb";
            if (!Directory.Exists(siaqodbPathNew))
            {
                Directory.CreateDirectory(siaqodbPathNew);
            }
            Siaqodb siaqodb = new Siaqodb(siaqodbPathNew);

            Company comp = CreateCompany("MyCompany");

            Log("Store object encrypted...");
            //data of this object will be encrypted in DB
            siaqodb.StoreObject(comp);

            siaqodb.Close();
        }
Ejemplo n.º 42
0
        private void LoadAndUpdate(Siaqodb siaqodb)
        {
            var query = from Company comp in siaqodb
                        where comp.Name.StartsWith("First")
                        select comp;

            Log("Following companies has name that starts with 'First' string");
            foreach (var e in query)
            {
                e.Address = "Address changed";
                siaqodb.StoreObject(e);//update will occur
            }
            siaqodb.Flush();

            //load all objects of type Company from DB
            IObjectList<Company> allCompanies = siaqodb.LoadAll<Company>();
            foreach (Company comp in allCompanies)
            {
                //see address of FirstCompany is updated
            }
        }
Ejemplo n.º 43
0
        public void EncryptUsingXTEA_And_CustomPassword()
        {
            SiaqodbConfigurator.SetEncryptor(BuildInAlgorithm.XTEA);
            SiaqodbConfigurator.SetEncryptionPassword("secret_pwd");

            //now database files will be encrypted with  XTEA encryption algorithm and can be opened only with the paswword set
            //because previously, in method EncryptSimple, we used database from path SiaqodbFactoryExample.siaoqodbPath with another Encryption algorithm,
            //we cannot open now same database with another encryption settings(algorithm+pwd) so open another new DB
            string siaoqodbPathForEncrypt = SiaqodbFactoryExample.siaoqodbPath  +Path.DirectorySeparatorChar + @"siaqodbEncrypted";
            if (!Directory.Exists(siaoqodbPathForEncrypt))
            {
                Directory.CreateDirectory(siaoqodbPathForEncrypt);
            }
            Siaqodb siaqodb = new Siaqodb(siaoqodbPathForEncrypt);

            Company comp = CreateCompany("MyCompany");
            //data of this object will be encrypted in DB
            siaqodb.StoreObject(comp);

            siaqodb.Close();
        }
Ejemplo n.º 44
0
        public static Siaqodb GetInstance()
        {
            if (instance == null)
            {

                //if ANDROID:
                //siaoqodbPath=Application.persistentDataPath;
                //if Windows or MAC
                siaoqodbPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + @"database";

                //if iOS (iPhone /iPad)
                //siaoqodbPath =Application.dataPath;

                if (!Directory.Exists(siaoqodbPath))
                {
                    Directory.CreateDirectory(siaoqodbPath);
                }
                instance = new Siaqodb(siaoqodbPath);
            }
            return instance;
        }
Ejemplo n.º 45
0
        public async void storeData()
        { 
            StorageFolder folder = ApplicationData.Current.LocalFolder;
            StorageFolder newFolder = await folder.CreateFolderAsync("Siaqodb", CreationCollisionOption.OpenIfExists);

            String folderName = newFolder.Path;
            System.Diagnostics.Debug.WriteLine("Folder Name: " + folderName);

            Siaqodb siaqodb = new Siaqodb(newFolder.Path + "\\Siaqodb");
            //Company company = new Company();
            //company.Name = "MyCompany";


            //siaqodb.StoreObject(company);

            //Employee employee1 = new Employee();
            //employee1.Employer = company;
            //employee1.FirstName = "John";
            //employee1.LastName = "Walter";

            //siaqodb.StoreObject(employee1);
        }
Ejemplo n.º 46
0
        private void Insert(Siaqodb siaqodb)
        {
            Company company = CreateCompany();

            siaqodb.StoreObject(company);

            //Save into DB some objects with random data
            for (int i = 0; i < 10; i++)
            {
                Employee employee;
                if (i % 2 == 0)
                {
                     employee = CreateEmployee(i, company.OID);
                }
                else
                {
                    employee = CreateEmployee(i);
                }
                siaqodb.StoreObject(employee);

            }
        }
        public void Run()
        {
            //siaqodb store one file on disk for each Type and names of db files are composed by AssmeblyName+fullNameSpace of Type to be sure about uniqueness
            //but sometimes name of file can be too long, so would be better if you can customize it, Siaqodb allow that by:
            SiaqodbConfigurator.SetDatabaseFileName<DummyType>("mydummy");
            //1.you have to call it before open any database that has stored/will store objects of DummyType type
            //2.as you see is not necessary to add extension to fileName, engine put by default .sqo extension
            //3.only one call to the method above is required(static stored)

            //open another DB since SiaqodbFactoryExample.GetInstance() return an opened DB

            string siaoqodbPathNew = SiaqodbFactoryExample.siaoqodbPath+ Path.DirectorySeparatorChar + @"siaqodbWithCustomFileNames";
            if (!Directory.Exists(siaoqodbPathNew))
            {
                Directory.CreateDirectory(siaoqodbPathNew);
            }
            Siaqodb siaqodb = new Siaqodb(siaoqodbPathNew);

            siaqodb.StoreObject(new DummyType());

            Log("In database:"+siaoqodbPathNew+", fileName for DummyType is mydummy.sqo");
            siaqodb.Close();
        }
Ejemplo n.º 48
0
        public static Siaqodb GetInstance()
        {
            if (instance == null)
            {
               //put here your License Key
				SiaqodbConfigurator.SetLicense(@"awRH8HJyTnRgus6I4sKUprqfuUta9E3e7BLTEavVnNJR8x/bg3EHrPeShTN0KxH1H4WY0TrY3bPhYq+AwJ98SQ==");

				//if ANDROID:
				if (Application.platform == RuntimePlatform.Android) {
					siaoqodbPath = Application.persistentDataPath + Path.DirectorySeparatorChar + @"database";
					Debug.Log ("Android Path " + siaoqodbPath);
				}
				//if Windows or MAC
				else if (Application.platform == RuntimePlatform.OSXEditor || 
				         Application.platform == RuntimePlatform.WindowsEditor) {
					siaoqodbPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + @"database";
					Debug.Log ("Editor Path " + siaoqodbPath);
				}
				
				//if iOS (iPhone /iPad)
				else if (Application.platform == RuntimePlatform.OSXPlayer ||
				         Application.platform == RuntimePlatform.IPhonePlayer) {
					siaoqodbPath = Application.persistentDataPath + Path.DirectorySeparatorChar + @"database";
					//siaoqodbPath = Application.dataPath.Replace("Data", "Documents");
					Debug.Log ("IPad Path " + siaoqodbPath);
				}

				if (!Directory.Exists(siaoqodbPath))
                {
                    Directory.CreateDirectory(siaoqodbPath);
                }
                instance = new Siaqodb(siaoqodbPath);
            }

            return instance;
        }
Ejemplo n.º 49
0
		public static void OpenDatabase () {
			if (instance == null) {
				instance = GetInstance ();
			}
			instance.Open (siaoqodbPath);
		}
Ejemplo n.º 50
0
        public static void Insert()
        {
            GenerateEntities();

            using (Siaqodb siaqodb = new Siaqodb())
            {
                siaqodb.Open(siaqodbPath, 300 * OneMB, 200);

                Console.WriteLine("Siaqodb INSERT...");
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var trans = siaqodb.BeginTransaction();
                for (int i = 0; i < ENTITY_COUNT; i++)
                {
                    Document doc = new Document();
                    doc.Key = entities[i].Id;
                    //set document content
                    doc.SetContent<MyEntity>(entities[i]);
                    //set tags(indexes)
                    doc.SetTag("myint", entities[i].IntValue);

                    //store the doc within the Bucket called 'myentities'
                    siaqodb.Documents["myentities"].Store(doc, trans);
                }
                trans.Commit();
                stopwatch.Stop();
                Console.WriteLine("Siaqodb INSERT took:" + stopwatch.Elapsed);

            }
            using (EmbeddableDocumentStore store = new EmbeddableDocumentStore
            {
                DataDirectory = ravenDBPath

            })
            {
                store.Configuration.DefaultStorageTypeName = "voron";
                store.Initialize(); // initializes document store, by connecting to server and downloading various configurations

                store.DatabaseCommands.PutIndex("MyEntity/IntValue",
                      new IndexDefinitionBuilder<MyEntity>()
                      {
                          Map = myints => from mi in myints
                                          select new { IntValue = mi.IntValue }
                      }, true);

                using (BulkInsertOperation bulkInsert = store.BulkInsert())
                {
                    Console.WriteLine("RavenDB INSERT...");
                    var stopwatch = new Stopwatch();
                    stopwatch.Start();

                    for (int i = 0; i < ENTITY_COUNT; i++)
                    {
                        bulkInsert.Store(entities[i], entities[i].Id);

                    }

                    stopwatch.Stop();
                    Console.WriteLine("RavenDB INSERT took:" + stopwatch.Elapsed);

                }
                using (IDocumentSession session = store.OpenSession()) // opens a session that will work in context of 'DefaultDatabase'
                {
                    //waiting for index to finish write operations
                    int temp = entities[0].IntValue;
                    var qq = (from myentity in session.Query<MyEntity>("MyEntity/IntValue").Customize(a => a.WaitForNonStaleResults())
                              where myentity.IntValue == temp
                              select myentity).ToList();
                }

            }
        }
Ejemplo n.º 51
0
        public static void Insert()
        {
            var entities = GetEntities().ToArray();
            using (Siaqodb siaqodb = new Siaqodb())
            {
                siaqodb.Open(siaqodbPath, 100 * OneMB, 20);

                Console.WriteLine("InsertSiaqodb...");
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                for (int i = 0; i < ENTITY_COUNT; i++)
                {
                    siaqodb.StoreObject(entities[i]);
                }

                stopwatch.Stop();
                Console.WriteLine("InsertSiaqodb took:" + stopwatch.Elapsed);

            }

            using (var dbsql = new SQLite.SQLiteConnection(sqLitePath))
            {
                dbsql.CreateTable<MyEntity>();
                Console.WriteLine("InsertSQLite...");
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                for (int i = 0; i < ENTITY_COUNT; i++)
                {
                    dbsql.Insert(entities[i]);
                }

                stopwatch.Stop();
                Console.WriteLine("InsertSQLite took:" + stopwatch.Elapsed);
            }
        }
Ejemplo n.º 52
0
        public static void ReadAll()
        {
            using (Siaqodb siaqodb = new Siaqodb())
            {
                siaqodb.Open(siaqodbPath, 200 * OneMB, 20);
                Console.WriteLine("Siaqodb READ ALL...");
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                int start = 0;
                List<Document> docs = new List<Document>();
                while (true)
                {
                    var current = siaqodb.Documents["myentities"].LoadAll(start, 1024);
                    if (current.Count == 0)
                        break;

                    start += current.Count;
                    docs.AddRange(current);

                }
                foreach (Document d in docs)
                {
                    var entity = d.GetContent<MyEntity>();
                }

                stopwatch.Stop();
                Console.WriteLine("Siaqodb READ ALL (" + docs.Count + " items) took:" + stopwatch.Elapsed);

            }
            using (EmbeddableDocumentStore store = new EmbeddableDocumentStore
            {
                DataDirectory = ravenDBPath

            })
            {
                store.Configuration.DefaultStorageTypeName = "voron";
                store.Initialize(); // initializes document store, by connecting to server and downloading various configurations

                Console.WriteLine("RavenDB READ ALL...");
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                int start = 0;
                List<MyEntity> docs = new List<MyEntity>();
                while (true)
                {

                    using (IDocumentSession session = store.OpenSession()) // opens a session that will work in context of 'DefaultDatabase'
                    {
                        bool finished = false;
                        for (int i = 0; i < 30; i++)//raven allows max 30 ops per session
                        {
                            var current = session.Query<MyEntity>().Take(1024).Skip(start).ToList();
                            if (current.Count == 0)
                            {
                                finished = true;
                                break;
                            }

                            start += current.Count;
                            docs.AddRange(current);
                        }
                        if (finished)
                            break;
                    }

                }

                stopwatch.Stop();
                Console.WriteLine("RavenDB READ ALL(" + docs.Count + " items) took:" + stopwatch.Elapsed);

            }
        }
Ejemplo n.º 53
0
        public static void ReadByPrimaryIndex()
        {
            using (Siaqodb siaqodb = new Siaqodb())
            {
                siaqodb.Open(siaqodbPath, 100 * OneMB, 20);
                Console.WriteLine("Siaqodb READ_BY_PK...");
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                List<MyEntity> loadedENs = new List<MyEntity>(ENTITY_COUNT);
                for (int i = 0; i < ENTITY_COUNT; i++)
                {
                    var en = siaqodb.Documents["myentities"].Load<MyEntity>(entities[i].Id);
                    loadedENs.Add(en);
                }

                stopwatch.Stop();
                Console.WriteLine("Siaqodb READ_BY_PK took:" + stopwatch.Elapsed);

            }
            using (EmbeddableDocumentStore store = new EmbeddableDocumentStore
            {
                DataDirectory = ravenDBPath

            })
            {
                store.Configuration.DefaultStorageTypeName = "voron";
                store.Initialize(); // initializes document store, by connecting to server and downloading various configurations
                Console.WriteLine("RavenDB READ_BY_PK...");
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                List<MyEntity> loadedENs = new List<MyEntity>(ENTITY_COUNT);
                for (int i = 0; i < ENTITY_COUNT; i++)
                {
                    var jsonDocument = store.DatabaseCommands.Get(entities[i].Id);
                    var en = jsonDocument.DataAsJson.Deserialize<MyEntity>(store.Conventions);
                    loadedENs.Add(en);
                }

                stopwatch.Stop();
                Console.WriteLine("RavenDB READ_BY_PK took:" + stopwatch.Elapsed);

            }
        }
Ejemplo n.º 54
0
        public static void Delete()
        {
            using (Siaqodb siaqodb = new Siaqodb())
            {
                siaqodb.Open(siaqodbPath, 300 * OneMB, 200);

                Console.WriteLine("Siaqodb DELETE...");
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var trans = siaqodb.BeginTransaction();
                for (int i = 0; i < ENTITY_COUNT; i++)
                {
                    var doc= siaqodb.Documents["myentities"].Load(entities[i].Id);
                    siaqodb.Documents["myentities"].Delete(doc,trans);
                }
                trans.Commit();

                stopwatch.Stop();
                Console.WriteLine("Siaqodb DELETE took:" + stopwatch.Elapsed);

            }
            using (EmbeddableDocumentStore store = new EmbeddableDocumentStore
            {
                DataDirectory = ravenDBPath

            })
            {
                store.Configuration.DefaultStorageTypeName = "voron";
                store.Initialize(); // initializes document store, by connecting to server and downloading various configurations

                Console.WriteLine("RavenDB DELETE...");
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                for (int i = 0; i < ENTITY_COUNT - 30; i += 30)
                {
                    using (IDocumentSession session = store.OpenSession())
                    {
                        for (int j = 0; j < 30; j++)
                        {
                            session.Delete(entities[i].Id);
                        }
                        session.SaveChanges();
                    }
                }

                stopwatch.Stop();
                Console.WriteLine("RavenDB DELETE took:" + stopwatch.Elapsed);

            }
        }
Ejemplo n.º 55
0
        public static void Update()
        {
            using (Siaqodb siaqodb = new Siaqodb())
            {
                siaqodb.Open(siaqodbPath, 300 * OneMB, 200);

                Console.WriteLine("Siaqodb UPDATE...");
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var trans = siaqodb.BeginTransaction();
                for (int i = 0; i < ENTITY_COUNT; i++)
                {
                    Document doc = new Document();
                    doc.Key = entities[i].Id;
                    entities[i].StringValue += i.ToString();
                    entities[i].IntValue++;
                    //set document content
                    doc.SetContent<MyEntity>(entities[i]);
                   //update the index too
                    doc.SetTag("myint", entities[i].IntValue);

                    //store the doc within the Bucket called 'myentities'
                    siaqodb.Documents["myentities"].Store(doc, trans);
                }
                trans.Commit();

                stopwatch.Stop();
                Console.WriteLine("Siaqodb UPDATE took:" + stopwatch.Elapsed);

            }
            using (EmbeddableDocumentStore store = new EmbeddableDocumentStore
            {
                DataDirectory = ravenDBPath

            })
            {
                store.Configuration.DefaultStorageTypeName = "voron";
                store.Initialize(); // initializes document store, by connecting to server and downloading various configurations
                Raven.Abstractions.Data.BulkInsertOptions opt = new Raven.Abstractions.Data.BulkInsertOptions()
                { OverwriteExisting = true };
                using (BulkInsertOperation bulkInsert = store.BulkInsert(null,opt ))
                {
                    Console.WriteLine("RavenDB UPDATE...");
                    var stopwatch = new Stopwatch();
                    stopwatch.Start();

                    for (int i = 0; i < ENTITY_COUNT; i++)
                    {
                        entities[i].StringValue += i.ToString();
                        entities[i].IntValue++;
                        bulkInsert.Store(entities[i], entities[i].Id);
                    }

                    stopwatch.Stop();
                    Console.WriteLine("RavenDB UPDATE took:" + stopwatch.Elapsed);

                }
            }
        }
Ejemplo n.º 56
0
        public static void ReadBySecondaryIndex()
        {
            using (Siaqodb siaqodb = new Siaqodb())
            {
                siaqodb.Open(siaqodbPath, 100 * OneMB, 20);
                Console.WriteLine("Siaqodb READ_BY_SECONDARY_INDEX...");
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                for (int i = 0; i < ENTITY_COUNT; i++)
                {
                    var docs = (from Document doc in siaqodb.Documents["myentities"]
                                where doc.GetTag<int>("myint") == entities[i].IntValue
                                select doc).ToObjects<MyEntity>();

                }

                stopwatch.Stop();
                Console.WriteLine("Siaqodb READ_BY_SECONDARY_INDEX took:" + stopwatch.Elapsed);

            }
            using (EmbeddableDocumentStore store = new EmbeddableDocumentStore
            {
                DataDirectory = ravenDBPath

            })
            {
                store.Configuration.DefaultStorageTypeName = "voron";
                store.Initialize(); // initializes document store, by connecting to server and downloading various configurations
                Console.WriteLine("RavenDB READ_BY_SECONDARY_INDEX...");
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                for (int i = 0; i < ENTITY_COUNT - 30; i += 30)
                {
                    using (IDocumentSession session = store.OpenSession())
                    {
                        for (int j = 0; j < 30; j++)
                        {

                            var temp = entities[i+j].IntValue;
                            var qq = (from myentity in session.Query<MyEntity>("MyEntity/IntValue")
                                      where myentity.IntValue == temp
                                      select myentity).ToList();

                        }
                    }

                }
                stopwatch.Stop();
                Console.WriteLine("RavenDB READ_BY_SECONDARY_INDEX took:" + stopwatch.Elapsed);

            }
        }