Exemplo n.º 1
0
 static void ActivateList(IObjectContainer db, IList list)
 {
     foreach (var obj in list)
     {
         db.Activate(obj, int.MaxValue);
     }
 }
Exemplo n.º 2
0
		static void ActivateList(IObjectContainer db, IList list)
		{
			foreach (var obj in list)
			{
				db.Activate(obj, int.MaxValue);
			}
		}
Exemplo n.º 3
0
        internal void AddFolderToDatabase(FavouriteFolder favFolder)
        {
            try
            {
                container = Db4oClient.RecentConn;
                if (m_lstFavfolder != null)
                {
                    FavouriteList favList = FetchAllFavouritesForAConnection();

                    if (favList == null)
                    {
                        favList = new FavouriteList(m_connParam);
                        List <FavouriteFolder> lstFavfolder = new List <FavouriteFolder>();
                        favList.m_TimeOfCreation = Sharpen.Runtime.CurrentTimeMillis();
                        lstFavfolder.Add(favFolder);
                        container.Store(favList);
                        container.Commit();
                        return;
                    }
                    container.Activate(favList, 5);
                    List <FavouriteFolder> lstFavFolder = favList.lstFavFolder;

                    bool            check = false;
                    FavouriteFolder temp  = null;
                    foreach (FavouriteFolder str in lstFavFolder)
                    {
                        if (str != null)
                        {
                            if (str.FolderName.Equals(favFolder.FolderName))
                            {
                                temp  = str;
                                check = true;
                                break;
                            }
                        }
                    }
                    if (check == false)
                    {
                        lstFavFolder.Add(favFolder);
                    }
                    else
                    {
                        lstFavFolder.Remove(temp);
                        lstFavFolder.Add(favFolder);
                        container.Delete(temp);
                    }


                    favList.lstFavFolder = lstFavFolder;
                    container.Ext().Store(favList, 5);
                    container.Commit();
                }
            }
            catch (Exception oEx)
            {
                LoggingHelper.HandleException(oEx);
            }
        }
Exemplo n.º 4
0
        public static void RetrieveSnapshotsSequentiallyImproved(IObjectContainer db)
        {
            IObjectSet    result  = db.QueryByExample(typeof(Car));
            Car           car     = (Car)result.Next();
            SensorReadout readout = car.GetHistory();

            while (readout != null)
            {
                db.Activate(readout, 1);
                Console.WriteLine(readout);
                readout = readout.Next;
            }
        }
Exemplo n.º 5
0
        public IList <GenericType> PerformQuery(IObjectContainer db)
        {
            IList <GenericType> resultObjects = new List <GenericType>();

            IList <GenericType> queryResults = db.Query <GenericType>(matchPredicate);

            foreach (GenericType currentObject in queryResults)
            {
                db.Activate(currentObject, queryDepth);
                resultObjects.Add(currentObject);
            }

            return(resultObjects);
        }
Exemplo n.º 6
0
        private static void FixItWithExplicitlyActivating()
        {
            using (IObjectContainer container = Db4oEmbedded.OpenFile("database.db4o"))
            {
                Person jodie = QueryForJodie(container);

                // #example: Fix with explicit activation
                Person julia = jodie.Mother.Mother.Mother.Mother.Mother;
                container.Activate(julia, 5);

                Console.WriteLine(julia.Name);
                string joannaName = julia.Mother.Name;
                Console.WriteLine(joannaName);
                // #end example
            }
        }
Exemplo n.º 7
0
        public IList <GenericType> PerformQuery(IObjectContainer db)
        {
            IList <GenericType> resultObjects = new List <GenericType>();

            IObjectSet objectSet = db.QueryByExample(queryObject);

            while (objectSet.HasNext() == true)
            {
                object currentObject = objectSet.Next();
                db.Activate(currentObject, queryDepth);

                resultObjects.Add((GenericType)currentObject);
            }

            return(resultObjects);
        }
Exemplo n.º 8
0
        private static void Deactivate()
        {
            using (IObjectContainer container = Db4oEmbedded.OpenFile("database.db4o"))
            {
                var jodie = QueryForJodie(container);

                container.Activate(jodie, 5);

                // #example: Deactivate an object
                Console.WriteLine(jodie.Name);
                // Now all fields will be null or 0
                // The same applies for all references objects up to a depth of 5
                container.Deactivate(jodie, 5);
                Console.WriteLine(jodie.Name);
                // #end example
            }
        }
Exemplo n.º 9
0
        private static void DealWithActivation()
        {
            using (IObjectContainer container = Db4oEmbedded.OpenFile(DatabaseFile))
            {
                Person joelle = QueryForJoelle(container);
                Person julia  = joelle.Mother.Mother.Mother.Mother.Mother;

                // #example: Check if an instance is activated
                bool isActivated = container.Ext().IsActive(julia);
                // #end example
                Console.WriteLine("Is activated? {0}", isActivated);
                // #example: Activate instance to a depth of five
                container.Activate(julia, 5);
                // #end example
                Console.WriteLine("Is activated? {0}", container.Ext().IsActive(julia));
            }
        }
Exemplo n.º 10
0
        internal static IList <T> ToInternalPagedList <T>(this IObjectSet objectSet, IObjectContainer container, int?activateDepth, int maximumRows, int startRowIndex, out int totalCount)
        {
            totalCount = 0;

            if (objectSet == null)
            {
                throw new ArgumentNullException("objectSet", "The objectSet instance cannot be null");
            }


            var applyPaging  = (maximumRows > 0 && startRowIndex > -1) ? true : false;
            var objectSetExt = objectSet.Ext();
            var itemIndexes  = objectSetExt.GetIDs().Select((id, index) => index);

            totalCount = itemIndexes.Count();

            if (applyPaging)
            {
                itemIndexes = itemIndexes.Skip(startRowIndex).Take(maximumRows);
            }

            var applyCustomDepth = false;

            if (activateDepth.HasValue)
            {
                if (container == null)
                {
                    throw new ArgumentNullException("container", "The container instance cannot be null when activateDepth.HasValue is true");
                }

                applyCustomDepth = true;
            }

            return(itemIndexes.Select(delegate(int index)
            {
                var item = (T)objectSetExt.Get(index);

                if (applyCustomDepth && !container.Ext().IsActive(item))
                {
                    container.Activate(item, activateDepth.Value);
                }

                return item;
            }).ToList());
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gets the activated.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="GlobalID">The global ID.</param>
        /// <param name="container">The container.</param>
        /// <param name="activationDepth">The activation depth.</param>
        /// <returns></returns>
        public static T GetActivated <T>(this string GlobalID, IObjectContainer container, int activationDepth)
        {
            if (String.IsNullOrEmpty(GlobalID))
            {
                return(default(T));
            }

            var item = container.Ext().GetByUUID(GlobalID.RecoverUUID());

            if (item == null)
            {
                return(default(T));
            }

            container.Activate(item, activationDepth);

            return((T)item);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Gets the activated.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="UUID">The UUID.</param>
        /// <param name="container">The container.</param>
        /// <param name="activationDepth">The activation depth.</param>
        /// <returns></returns>
        public static T GetActivated <T>(this Db4oUUID UUID, IObjectContainer container, int activationDepth)
        {
            if (UUID == null)
            {
                return(default(T));
            }

            var item = container.Ext().GetByUUID(UUID);

            if (item == null)
            {
                return(default(T));
            }

            container.Activate(item, activationDepth);

            return((T)item);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Gets the activated.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="localID">The local ID.</param>
        /// <param name="container">The container.</param>
        /// <param name="activationDepth">The activation depth.</param>
        /// <returns></returns>
        public static T GetActivated <T>(this long localID, IObjectContainer container, int activationDepth)
        {
            if (localID <= 0)
            {
                return(default(T));
            }

            var item = container.Ext().GetByID(localID);

            if (item == null)
            {
                return(default(T));
            }

            container.Activate(item, activationDepth);

            return((T)item);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Activates the specified UUID.
        /// </summary>
        /// <param name="UUID">The UUID.</param>
        /// <param name="container">The container.</param>
        /// <param name="activationDepth">The activation depth.</param>
        public static void Activate(this Db4oUUID UUID, IObjectContainer container, int activationDepth)
        {
            if (UUID == null)
            {
                return;
            }

            var item = container.Ext().GetByUUID(UUID);

            if (item == null)
            {
                return;
            }

            container.Activate(item, activationDepth);

            return;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Activates the specified local ID.
        /// </summary>
        /// <param name="localID">The local ID.</param>
        /// <param name="container">The container.</param>
        /// <param name="activationDepth">The activation depth.</param>
        public static void Activate(this long localID, IObjectContainer container, int activationDepth)
        {
            if (localID <= 0)
            {
                return;
            }

            var item = container.Ext().GetByID(localID);

            if (item == null)
            {
                return;
            }

            container.Activate(item, activationDepth);

            return;
        }
            public void OnEvent(object sender, Db4objects.Db4o.Events.CancellableObjectEventArgs
                                args)
            {
                object obj = ((CancellableObjectEventArgs)args).Object;

                if (!(obj is UpdateInCallbackThrowsTestCase.Item))
                {
                    return;
                }
                Transaction transaction = (Transaction)((CancellableObjectEventArgs)args).Transaction
                                              ();
                IObjectContainer container = transaction.ObjectContainer();

                UpdateInCallbackThrowsTestCase.Item foo   = (UpdateInCallbackThrowsTestCase.Item)obj;
                UpdateInCallbackThrowsTestCase.Item child = foo._child;
                if (isNetworking)
                {
                    container.Activate(child, 1);
                }
                child._name += "*";
                container.Store(child);
            }
Exemplo n.º 17
0
 public void PerformUpdate(IObjectContainer db)
 {
     db.Activate(objectToActivate, activateDepth);
 }
Exemplo n.º 18
0
        internal void AddFolderToDatabase(FavouriteFolder favFolder)
        {
            try
            {
                container = Db4oClient.RecentConn;
                if (m_lstFavfolder != null)
                {
                    FavouriteList favList = FetchAllFavouritesForAConnection();
                   
                    if (favList == null)
                    {
                        favList = new FavouriteList(m_connParam);
                        List<FavouriteFolder> lstFavfolder = new List<FavouriteFolder>();
                        favList.m_TimeOfCreation = Sharpen.Runtime.CurrentTimeMillis();   
                        lstFavfolder.Add(favFolder);
                        container.Store(favList);
                        container.Commit();
                        return;
                    }
                    container.Activate(favList, 5);
                    List<FavouriteFolder> lstFavFolder = favList.lstFavFolder;
                   
                    bool check = false;
                    FavouriteFolder temp = null;
                    foreach (FavouriteFolder str in lstFavFolder)
                    {
                        if (str != null)
                        {
                            if (str.FolderName.Equals(favFolder.FolderName))
                            {
                                temp = str;
                                check = true;
                                break;
                            }
                        }
                    }
                    if (check == false)
                    {

                        lstFavFolder.Add(favFolder);
                    }
                    else
                    {
                        lstFavFolder.Remove(temp);
                        lstFavFolder.Add(favFolder);
                        container.Delete(temp);
                    }


                    favList.lstFavFolder = lstFavFolder;
                    container.Ext().Store(favList, 5);
                    container.Commit();


                }
            }
            catch (Exception oEx)
            {
                LoggingHelper.HandleException(oEx);  
            }
        }
Exemplo n.º 19
0
 /// <summary>
 /// Activates the specified obj.
 /// </summary>
 /// <param name="obj">The obj.</param>
 /// <param name="depth">The depth.</param>
 public void Activate(object obj, int depth)
 {
     container.Activate(obj, depth);
 }
Exemplo n.º 20
0
 public static void RetrieveSnapshotsSequentiallyImproved(IObjectContainer db)
 {
     IObjectSet result = db.QueryByExample(typeof(Car));
     Car car = (Car)result.Next();
     SensorReadout readout = car.GetHistory();
     while (readout != null)
     {
         db.Activate(readout, 1);
         Console.WriteLine(readout);
         readout = readout.Next;
     }
 }
Exemplo n.º 21
0
        public static void UpdateAddress()
        {
            IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();

            config.Common.ObjectClass(typeof(Person)).CascadeOnUpdate(true);
            using (IObjectContainer db = Db4oEmbedded.OpenFile(config, @"C:\DBO\ODB.yap"))
            {
                string userSurename;

                Console.WriteLine("\nInsert person surename who address You want modificate: \n");

                userSurename = Console.ReadLine();

                string TempAddressCity;
                string TempAddressStreet;

                Console.WriteLine("\nSelect address witch You want modificate by city and street: \n");

                Console.WriteLine("Street: \n");
                TempAddressStreet = Console.ReadLine();
                Console.WriteLine("City: \n");
                TempAddressCity = Console.ReadLine();

                string forStoreStreet = "";
                string forStoreCity   = "";

                IObjectSet result = db.QueryByExample(new Person(null, userSurename, new Address(null, null, null), new Phone(null, null, null)));
                Person     found;

                if (result.HasNext())
                {
                    found = (Person)result.Next();

                    foreach (Address address in found.PersonAddresses.Where((x => x.City == TempAddressCity)).Where((x => x.Street == TempAddressStreet)))
                    {
                        Console.Write("Person address - Street: ");
                        address.Street = Console.ReadLine().ToString();
                        forStoreStreet = address.Street;

                        Console.Write("Person address - City: ");
                        address.City = Console.ReadLine().ToString();
                        forStoreCity = address.City;

                        Console.Write("Person address - Postal code: ");
                        address.PostalCode = Console.ReadLine().ToString();
                    }

                    foreach (var item in found.PersonAddresses)
                    {
                        Console.WriteLine(item.City);
                    }



                    db.Activate(found, 100);



                    db.Store(found.PersonAddresses.Find(x => (x.City == forStoreCity) && (x.Street == forStoreStreet)));
                }
                else
                {
                    Console.WriteLine("\nThis peron don't exist in database");
                }
            }
        }
Exemplo n.º 22
0
        public static void UpdatePhone()
        {
            IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();

            config.Common.ObjectClass(typeof(Person)).CascadeOnUpdate(true);
            using (IObjectContainer db = Db4oEmbedded.OpenFile(config, @"C:\DBO\ODB.yap"))
            {
                string userSurename;

                Console.WriteLine("\nInsert person surename who phone You want modificate: \n");

                userSurename = Console.ReadLine();

                string TempPhoneNumber;

                Console.WriteLine("\nSelect phone witch You want modificate by number: \n");

                Console.WriteLine("Number: \n");
                TempPhoneNumber = Console.ReadLine();

                string forStoreNumber = "";


                IObjectSet result = db.QueryByExample(new Person(null, userSurename, new Address(null, null, null), new Phone(null, null, null)));
                Person     found;

                if (result.HasNext())
                {
                    found = (Person)result.Next();

                    foreach (Phone phones in found.PersonPhones.Where(x => x.Number == TempPhoneNumber))
                    {
                        Console.Write("Person phone - Number: ");
                        phones.Number  = Console.ReadLine().ToString();
                        forStoreNumber = phones.Number;

                        Console.Write("Person phone - Operator: ");
                        phones.Operator = Console.ReadLine().ToString();

                        Console.Write("Person phone - Phone type: ");
                        phones.PhoneType = Console.ReadLine().ToString();
                    }

                    foreach (var item in found.PersonPhones)
                    {
                        Console.WriteLine(item.Number);
                    }



                    db.Activate(found, 100);



                    db.Store(found.PersonPhones.Find(x => x.Number == forStoreNumber));
                }
                else
                {
                    Console.WriteLine("\nThis peron don't exist in database");
                }
            }
        }
Exemplo n.º 23
0
 public void Activate(object obj, int depth)
 {
     session.Activate(obj, depth);
 }
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        #region Utitlities
        private static void ActivateSbItem(ISbItem item)
        {
            container.Activate(item, 5);
        }