Esempio n. 1
0
        public virtual void TraverseOwnSlots(IProcedure4 block)
        {
            _parentIdSystem.TraverseOwnSlots(block);
            block.Apply(OwnSlotInfo(_persistentState.GetID()));
            block.Apply(OwnSlotInfo(_bTree.GetID()));
            var nodeIds = _bTree.AllNodeIds(_container.SystemTransaction());

            while (nodeIds.MoveNext())
            {
                block.Apply(OwnSlotInfo((((int)nodeIds.Current))));
            }
        }
Esempio n. 2
0
		public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer
			)
		{
			object value = _slots[key];
			if (value == null)
			{
				object newValue = producer.Apply(key);
				if (newValue == null)
				{
					return null;
				}
				if (_slots.Count >= _maxSize)
				{
					object discarded = Sharpen.Collections.Remove(_slots, _lru.RemoveLast());
					if (null != finalizer)
					{
						finalizer.Apply(discarded);
					}
				}
				_slots[key] = newValue;
				_lru.AddFirst(key);
				return newValue;
			}
			_lru.Remove(key);
			// O(N) 
			_lru.AddFirst(key);
			return value;
		}
Esempio n. 3
0
 private void ForEachClassId(IProcedure4 procedure)
 {
     for (IEnumerator ids = _stream.ClassCollection().Ids(); ids.MoveNext();)
     {
         procedure.Apply((int)ids.Current);
     }
 }
Esempio n. 4
0
        public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer
                                      )
        {
            object value = _slots[key];

            if (value == null)
            {
                object newValue = producer.Apply(key);
                if (newValue == null)
                {
                    return(null);
                }
                if (_slots.Count >= _maxSize)
                {
                    object discarded = Sharpen.Collections.Remove(_slots, _lru.RemoveLast());
                    if (null != finalizer)
                    {
                        finalizer.Apply(discarded);
                    }
                }
                _slots[key] = newValue;
                _lru.AddFirst(key);
                return(newValue);
            }
            _lru.Remove(key);
            // O(N)
            _lru.AddFirst(key);
            return(value);
        }
Esempio n. 5
0
            public void Apply(object cache)
            {
                var slot = new ByteArrayBuffer(0);

                ((IClientSlotCache)cache).Add(_enclosing.Trans(), 42, slot);
                operation.Apply(_enclosing.Trans());
                Assert.IsNull(((IClientSlotCache)cache).Get(_enclosing.Trans(), 42));
            }
Esempio n. 6
0
		private void Discard(long key, IProcedure4 finalizer)
		{
			if (null != finalizer)
			{
				finalizer.Apply(_slots[key]);
			}
			Sharpen.Collections.Remove(_slots, key);
		}
		private void AssertEventThrows(string eventName, ICodeBlock codeBlock, IProcedure4
			 listenerSetter)
		{
			IEventRegistry eventRegistry = EventRegistryFactory.ForObjectContainer(Db());
			listenerSetter.Apply(eventRegistry);
			Assert.Expect(typeof(EventException), typeof(NotImplementedException), codeBlock, 
				eventName);
		}
 public virtual void SlotFreed(Slot slot)
 {
     if (_slotFreedCallback == null)
     {
         return;
     }
     _slotFreedCallback.Apply(slot);
 }
Esempio n. 9
0
 private void Discard(object key, IProcedure4 finalizer)
 {
     if (null != finalizer)
     {
         finalizer.Apply(_slots[key]);
     }
     Sharpen.Collections.Remove(_slots, key);
 }
        private void AssertEventThrows(string eventName, ICodeBlock codeBlock, IProcedure4
                                       listenerSetter)
        {
            IEventRegistry eventRegistry = EventRegistryFactory.ForObjectContainer(Db());

            listenerSetter.Apply(eventRegistry);
            Assert.Expect(typeof(EventException), typeof(NotImplementedException), codeBlock,
                          eventName);
        }
Esempio n. 11
0
        private void Discard(object key, IProcedure4 finalizer)
        {
            var removed = Sharpen.Collections.Remove(_slots, key);

            if (finalizer != null)
            {
                finalizer.Apply(removed);
            }
        }
 private void AssertInconsistencyDetected(IProcedure4 proc)
 {
     ConsistencyCheckerTestSuite.Item item = new ConsistencyCheckerTestSuite.Item();
     _db.Store(item);
     _db.Commit();
     Assert.IsTrue(new ConsistencyChecker(_db).CheckSlotConsistency().Consistent());
     proc.Apply(item);
     _db.Commit();
     Assert.IsFalse(new ConsistencyChecker(_db).CheckSlotConsistency().Consistent());
 }
Esempio n. 13
0
		public static void ForEachField(IReflectClass claxx, IProcedure4 procedure)
		{
			while (claxx != null)
			{
				IReflectField[] declaredFields = claxx.GetDeclaredFields();
				for (int reflectFieldIndex = 0; reflectFieldIndex < declaredFields.Length; ++reflectFieldIndex)
				{
					IReflectField reflectField = declaredFields[reflectFieldIndex];
					procedure.Apply(reflectField);
				}
				claxx = claxx.GetSuperclass();
			}
		}
Esempio n. 14
0
 public static void ForEachField(IReflectClass claxx, IProcedure4 procedure)
 {
     while (claxx != null)
     {
         var declaredFields = claxx.GetDeclaredFields();
         for (var reflectFieldIndex = 0; reflectFieldIndex < declaredFields.Length; ++reflectFieldIndex)
         {
             var reflectField = declaredFields[reflectFieldIndex];
             procedure.Apply(reflectField);
         }
         claxx = claxx.GetSuperclass();
     }
 }
Esempio n. 15
0
        private void ForEachConstraint(IProcedure4 proc)
        {
            IEnumerator i = IterateConstraints();

            while (i.MoveNext())
            {
                QCon constraint = (QCon)i.Current;
                if (!constraint.ProcessedByIndex())
                {
                    proc.Apply(constraint);
                }
            }
        }
Esempio n. 16
0
 private void RunTestAfterCommit(IProcedure4 setOperations)
 {
     BigSetTestCase.Holder <BigSetTestCase.Item> holder = NewHolderWithBigSet(new BigSetTestCase.Item
                                                                                  ("1"), new BigSetTestCase.Item("2"));
     StoreAndCommit(holder);
     Db4objects.Db4o.Collections.ISet <BigSetTestCase.Item> set = holder._set;
     Assert.AreEqual(2, set.Count);
     setOperations.Apply(set);
     PurgeAll(holder, holder._set);
     BigSetTestCase.Holder <BigSetTestCase.Item> resurrected = (BigSetTestCase.Holder <BigSetTestCase.Item
                                                                                       >)RetrieveOnlyInstance(holder.GetType());
     IteratorAssert.SameContent(set.GetEnumerator(), resurrected._set.GetEnumerator());
 }
Esempio n. 17
0
 private void ProcessEachNode(IProcedure4 action)
 {
     if (_nodes == null)
     {
         return;
     }
     ProcessAllNodes();
     while (_processing.HasNext())
     {
         action.Apply((BTreeNode)_processing.Next());
     }
     _processing = null;
 }
        private void WithCache(IProcedure4 procedure)
        {
            IClientSlotCache clientSlotCache = null;

            try
            {
                clientSlotCache = (IClientSlotCache)Reflection4.GetFieldValue(Container(), "_clientSlotCache"
                                                                              );
            }
            catch (ReflectException e)
            {
                Assert.Fail("Can't get field _clientSlotCache on  container. " + e.ToString());
            }
            procedure.Apply(clientSlotCache);
        }
Esempio n. 19
0
        private void RunTestAfterCommit(IProcedure4 setOperations)
        {
            var holder = NewHolderWithBigSet(new Item
                                                 ("1"), new Item("2"));

            StoreAndCommit(holder);
            var set = holder._set;

            Assert.AreEqual(2, set.Count);
            setOperations.Apply(set);
            PurgeAll(holder, holder._set);
            var resurrected = (Holder <Item
                                       >)RetrieveOnlyInstance(holder.GetType());

            IteratorAssert.SameContent(set.GetEnumerator(), resurrected._set.GetEnumerator());
        }
 private static void ApplyProcedure(PagingMemoryStorage storage, IProcedure4 procedure4
     )
 {
     IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();
     config.File.Storage = storage;
     IEmbeddedObjectContainer container = Db4oEmbedded.OpenFile(config, "benchmark.db4o"
         );
     try
     {
         procedure4.Apply(container);
     }
     finally
     {
         container.Close();
     }
 }
		private void AssertInconsistencyDetected(IProcedure4 proc)
		{
			IEmbeddedConfiguration config = NewConfiguration();
			LocalObjectContainer db = (LocalObjectContainer)Db4oEmbedded.OpenFile(config, TempFile
				());
			try
			{
				ConsistencyCheckerTestCase.Item item = new ConsistencyCheckerTestCase.Item();
				db.Store(item);
				db.Commit();
				Assert.IsTrue(new ConsistencyChecker(db).CheckSlotConsistency().Consistent());
				proc.Apply(new Pair(db, item));
				db.Commit();
				Assert.IsFalse(new ConsistencyChecker(db).CheckSlotConsistency().Consistent());
			}
			finally
			{
				db.Close();
			}
		}
        private void AssertInconsistencyDetected(IProcedure4 proc)
        {
            IEmbeddedConfiguration config = NewConfiguration();
            LocalObjectContainer   db     = (LocalObjectContainer)Db4oEmbedded.OpenFile(config, TempFile
                                                                                            ());

            try
            {
                ConsistencyCheckerTestCase.Item item = new ConsistencyCheckerTestCase.Item();
                db.Store(item);
                db.Commit();
                Assert.IsTrue(new ConsistencyChecker(db).CheckSlotConsistency().Consistent());
                proc.Apply(new Pair(db, item));
                db.Commit();
                Assert.IsFalse(new ConsistencyChecker(db).CheckSlotConsistency().Consistent());
            }
            finally
            {
                db.Close();
            }
        }
Esempio n. 23
0
		private void ProcessEachNode(IProcedure4 action)
		{
			if (_nodes == null)
			{
				return;
			}
			ProcessAllNodes();
			while (_processing.HasNext())
			{
				action.Apply((BTreeNode)_processing.Next());
			}
			_processing = null;
		}
Esempio n. 24
0
 public virtual void TraverseOwnSlots(IProcedure4 block)
 {
     _parentIdSystem.TraverseOwnSlots(block);
     block.Apply(OwnSlotInfo(_persistentState.GetID()));
     block.Apply(OwnSlotInfo(_bTree.GetID()));
     var nodeIds = _bTree.AllNodeIds(_container.SystemTransaction());
     while (nodeIds.MoveNext())
     {
         block.Apply(OwnSlotInfo((((int) nodeIds.Current))));
     }
 }
Esempio n. 25
0
 private void WithCache(IProcedure4 procedure)
 {
     IClientSlotCache clientSlotCache = null;
     try
     {
         clientSlotCache = (IClientSlotCache) Reflection4.GetFieldValue(Container(), "_clientSlotCache"
             );
     }
     catch (ReflectException e)
     {
         Assert.Fail("Can't get field _clientSlotCache on  container. " + e);
     }
     procedure.Apply(clientSlotCache);
 }
Esempio n. 26
0
		public virtual void TraverseOwnSlots(IProcedure4 block)
		{
			block.Apply(Pair.Of(0, _slot));
		}
Esempio n. 27
0
        public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer
                                      )
        {
            var intKey = (((int)key));

            if (_last == null)
            {
                var lastValue = producer.Apply(((int)key));
                if (lastValue == null)
                {
                    return(null);
                }
                _size = 1;
                var lastEntry = new Entry(intKey, lastValue);
                _slots.Put(intKey, lastEntry);
                _first = lastEntry;
                _last  = lastEntry;
                return(lastValue);
            }
            var entry = (Entry)_slots.Get(intKey);

            if (entry == null)
            {
                if (_size >= _maxSize)
                {
                    var oldEntry = (Entry)_slots.Remove(_last._key);
                    _last       = oldEntry._previous;
                    _last._next = null;
                    if (null != finalizer)
                    {
                        finalizer.Apply(oldEntry._value);
                    }
                    _size--;
                }
                var newValue = producer.Apply(((int)key));
                if (newValue == null)
                {
                    return(null);
                }
                _size++;
                var newEntry = new Entry(intKey, newValue);
                _slots.Put(intKey, newEntry);
                _first._previous = newEntry;
                newEntry._next   = _first;
                _first           = newEntry;
                return(newValue);
            }
            if (_first == entry)
            {
                return(entry._value);
            }
            var previous = entry._previous;

            entry._previous = null;
            if (_last == entry)
            {
                _last = previous;
            }
            previous._next = entry._next;
            if (previous._next != null)
            {
                previous._next._previous = previous;
            }
            _first._previous = entry;
            entry._next      = _first;
            _first           = entry;
            return(entry._value);
        }
Esempio n. 28
0
		public virtual void TraverseDeclaredFields(IProcedure4 procedure)
		{
			if (_aspects == null)
			{
				return;
			}
			for (int i = 0; i < _aspects.Length; i++)
			{
				if (_aspects[i] is FieldMetadata)
				{
					procedure.Apply(_aspects[i]);
				}
			}
		}
Esempio n. 29
0
		private void ForEachConstraint(IProcedure4 proc)
		{
			IEnumerator i = IterateConstraints();
			while (i.MoveNext())
			{
				QCon constraint = (QCon)i.Current;
				if (!constraint.ProcessedByIndex())
				{
					proc.Apply(constraint);
				}
			}
		}
Esempio n. 30
0
        public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer
                                      )
        {
            long longKey = (((long)key));

            if (_last == null)
            {
                object lastValue = producer.Apply(((long)key));
                if (lastValue == null)
                {
                    return(null);
                }
                _size = 1;
                LRULongCache.Entry lastEntry = new LRULongCache.Entry(longKey, lastValue);
                _slots.Put(longKey, lastEntry);
                _first = lastEntry;
                _last  = lastEntry;
                return(lastValue);
            }
            LRULongCache.Entry entry = (LRULongCache.Entry)_slots.Get(longKey);
            if (entry == null)
            {
                if (_size >= _maxSize)
                {
                    LRULongCache.Entry oldEntry = (LRULongCache.Entry)_slots.Remove(_last._key);
                    _last       = oldEntry._previous;
                    _last._next = null;
                    if (null != finalizer)
                    {
                        finalizer.Apply((object)oldEntry._value);
                    }
                    _size--;
                }
                object newValue = producer.Apply(((long)key));
                if (newValue == null)
                {
                    return(null);
                }
                _size++;
                LRULongCache.Entry newEntry = new LRULongCache.Entry(longKey, newValue);
                _slots.Put(longKey, newEntry);
                _first._previous = newEntry;
                newEntry._next   = _first;
                _first           = newEntry;
                return(newValue);
            }
            if (_first == entry)
            {
                return((object)entry._value);
            }
            LRULongCache.Entry previous = entry._previous;
            entry._previous = null;
            if (_last == entry)
            {
                _last = previous;
            }
            previous._next = entry._next;
            if (previous._next != null)
            {
                previous._next._previous = previous;
            }
            _first._previous = entry;
            entry._next      = _first;
            _first           = entry;
            return((object)entry._value);
        }
Esempio n. 31
0
 private void AssertInconsistencyDetected(IProcedure4 proc)
 {
     var item = new Item();
     _db.Store(item);
     _db.Commit();
     Assert.IsTrue(new ConsistencyChecker(_db).CheckSlotConsistency().Consistent());
     proc.Apply(item);
     _db.Commit();
     Assert.IsFalse(new ConsistencyChecker(_db).CheckSlotConsistency().Consistent());
 }
Esempio n. 32
0
 public virtual void TraverseOwnSlots(IProcedure4 block)
 {
     block.Apply(Pair.Of(0, _slot));
 }
		private static void ApplyProcedure(PagingMemoryStorage storage, IProcedure4 procedure4
			)
		{
			IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();
			config.File.Storage = storage;
			IEmbeddedObjectContainer container = Db4oEmbedded.OpenFile(config, "benchmark.db4o"
				);
			try
			{
				procedure4.Apply(container);
			}
			finally
			{
				container.Close();
			}
		}
Esempio n. 34
0
 public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer
     )
 {
     var intKey = (((int) key));
     if (_last == null)
     {
         var lastValue = producer.Apply(((int) key));
         if (lastValue == null)
         {
             return null;
         }
         _size = 1;
         var lastEntry = new Entry(intKey, lastValue);
         _slots.Put(intKey, lastEntry);
         _first = lastEntry;
         _last = lastEntry;
         return lastValue;
     }
     var entry = (Entry) _slots.Get(intKey);
     if (entry == null)
     {
         if (_size >= _maxSize)
         {
             var oldEntry = (Entry) _slots.Remove(_last._key);
             _last = oldEntry._previous;
             _last._next = null;
             if (null != finalizer)
             {
                 finalizer.Apply(oldEntry._value);
             }
             _size--;
         }
         var newValue = producer.Apply(((int) key));
         if (newValue == null)
         {
             return null;
         }
         _size++;
         var newEntry = new Entry(intKey, newValue);
         _slots.Put(intKey, newEntry);
         _first._previous = newEntry;
         newEntry._next = _first;
         _first = newEntry;
         return newValue;
     }
     if (_first == entry)
     {
         return entry._value;
     }
     var previous = entry._previous;
     entry._previous = null;
     if (_last == entry)
     {
         _last = previous;
     }
     previous._next = entry._next;
     if (previous._next != null)
     {
         previous._next._previous = previous;
     }
     _first._previous = entry;
     entry._next = _first;
     _first = entry;
     return entry._value;
 }
Esempio n. 35
0
 public virtual void TraverseDeclaredAspects(IProcedure4 procedure)
 {
     if (_aspects == null)
     {
         return;
     }
     for (var i = 0; i < _aspects.Length; i++)
     {
         procedure.Apply(_aspects[i]);
     }
 }
Esempio n. 36
0
		public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer
			)
		{
			long longKey = (((long)key));
			if (_last == null)
			{
				object lastValue = producer.Apply(((long)key));
				if (lastValue == null)
				{
					return null;
				}
				_size = 1;
				LRULongCache.Entry lastEntry = new LRULongCache.Entry(longKey, lastValue);
				_slots.Put(longKey, lastEntry);
				_first = lastEntry;
				_last = lastEntry;
				return lastValue;
			}
			LRULongCache.Entry entry = (LRULongCache.Entry)_slots.Get(longKey);
			if (entry == null)
			{
				if (_size >= _maxSize)
				{
					LRULongCache.Entry oldEntry = (LRULongCache.Entry)_slots.Remove(_last._key);
					_last = oldEntry._previous;
					_last._next = null;
					if (null != finalizer)
					{
						finalizer.Apply((object)oldEntry._value);
					}
					_size--;
				}
				object newValue = producer.Apply(((long)key));
				if (newValue == null)
				{
					return null;
				}
				_size++;
				LRULongCache.Entry newEntry = new LRULongCache.Entry(longKey, newValue);
				_slots.Put(longKey, newEntry);
				_first._previous = newEntry;
				newEntry._next = _first;
				_first = newEntry;
				return newValue;
			}
			if (_first == entry)
			{
				return ((object)entry._value);
			}
			LRULongCache.Entry previous = entry._previous;
			entry._previous = null;
			if (_last == entry)
			{
				_last = previous;
			}
			previous._next = entry._next;
			if (previous._next != null)
			{
				previous._next._previous = previous;
			}
			_first._previous = entry;
			entry._next = _first;
			_first = entry;
			return ((object)entry._value);
		}
Esempio n. 37
0
		private void Discard(object key, IProcedure4 finalizer)
		{
			object removed = Sharpen.Collections.Remove(_slots, key);
			if (finalizer != null)
			{
				finalizer.Apply(removed);
			}
		}
Esempio n. 38
0
		private void ForEachClassId(IProcedure4 procedure)
		{
			for (IEnumerator ids = _stream.ClassCollection().Ids(); ids.MoveNext(); )
			{
				procedure.Apply((int)ids.Current);
			}
		}
 public virtual void Activate(object obj)
 {
     _activationStrategy.Apply(obj);
 }