예제 #1
0
        private bool ForEachConstraintRecursively(IFunction4 block)
        {
            IQueue4     queue      = new NoDuplicatesQueue(new NonblockingQueue());
            IEnumerator constrIter = IterateConstraints();

            while (constrIter.MoveNext())
            {
                queue.Add(constrIter.Current);
            }
            while (queue.HasNext())
            {
                QCon constr = (QCon)queue.Next();
                bool cancel = (bool)block.Apply(constr);
                if (cancel)
                {
                    return(true);
                }
                IEnumerator childIter = constr.IterateChildren();
                while (childIter.MoveNext())
                {
                    queue.Add(childIter.Current);
                }
                IEnumerator joinIter = constr.IterateJoins();
                while (joinIter.MoveNext())
                {
                    queue.Add(joinIter.Current);
                }
            }
            return(false);
        }
예제 #2
0
		public virtual object Produce(object key, IFunction4 producer, IProcedure4 onDiscard
			)
		{
			_calls++;
			IFunction4 delegateProducer = new _IFunction4_26(this, producer);
			return _delegate.Produce(key, delegateProducer, onDiscard);
		}
        private void WithDatabase(string file, IFunction4 function)
        {
            Configure();
            IExtObjectContainer objectContainer = Db4oFactory.OpenFile(file).Ext();

            try
            {
                function.Apply(objectContainer);
            }
            finally
            {
                objectContainer.Close();
            }
            IObjectServer server = Db4oFactory.OpenServer(ClientServerFileName(file), -1);

            server.GrantAccess(Username, Password);
            objectContainer = Db4oFactory.OpenClient("localhost", server.Ext().Port(), Username
                                                     , Password).Ext();
            try
            {
                function.Apply(objectContainer);
            }
            finally
            {
                objectContainer.Close();
                server.Close();
            }
        }
예제 #4
0
 private object AsTopLevelCall(IFunction4 block, Transaction trans)
 {
     trans = CheckTransaction(trans);
     BeginTopLevelCall();
     try
     {
         return(block.Apply(trans));
     }
     catch (Db4oRecoverableException exc)
     {
         throw;
     }
     catch (SystemException exc)
     {
         throw;
     }
     catch (Exception exc)
     {
         FatalShutdown(exc);
     }
     finally
     {
         EndTopLevelCall();
     }
     // should never happen - just to make compiler happy
     throw new Db4oException();
 }
예제 #5
0
 public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer
                               )
 {
     if (key == null)
     {
         throw new ArgumentNullException();
     }
     if (_am.Remove(key))
     {
         _am.AddFirst(key);
         return(_slots[key]);
     }
     if (_a1out.Contains(key))
     {
         ReclaimFor(key, producer, finalizer);
         _am.AddFirst(key);
         return(_slots[key]);
     }
     if (_a1in.Contains(key))
     {
         return(_slots[key]);
     }
     ReclaimFor(key, producer, finalizer);
     _a1in.AddFirst(key);
     return(_slots[key]);
 }
예제 #6
0
 private CachingBin.Page GetPage(long startAddress, IFunction4 producer)
 {
     CachingBin.Page page = ((CachingBin.Page)_cache.Produce(PageAddressFor(startAddress
                                                                            ), producer, _onDiscardPage));
     page.EnsureEndAddress(_fileLength);
     return(page);
 }
예제 #7
0
		public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer
			)
		{
			if (key == null)
			{
				throw new ArgumentNullException();
			}
			if (_am.Remove(key))
			{
				_am.AddFirst(key);
				return _slots[key];
			}
			if (_a1out.Contains(key))
			{
				ReclaimFor(key, producer, finalizer);
				_am.AddFirst(key);
				return _slots[key];
			}
			if (_a1in.Contains(key))
			{
				return _slots[key];
			}
			ReclaimFor(key, producer, finalizer);
			_a1in.AddFirst(key);
			return _slots[key];
		}
예제 #8
0
        public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer
                                      )
        {
            if (key == null)
            {
                throw new ArgumentNullException();
            }
            if (_am.Remove(key))
            {
                _am.AddFirst(key);
                return(_slots[key]);
            }
            if (_a1.Remove(key))
            {
                _am.AddFirst(key);
                return(_slots[key]);
            }
            if (_slots.Count >= _maxSize)
            {
                DiscardPage(finalizer);
            }
            object value = producer.Apply(key);

            _slots[key] = value;
            _a1.AddFirst(key);
            return(value);
        }
예제 #9
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;
		}
예제 #10
0
파일: LRU2QCache.cs 프로젝트: erdincay/db4o
		public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer
			)
		{
			if (key == null)
			{
				throw new ArgumentNullException();
			}
			if (_am.Remove(key))
			{
				_am.AddFirst(key);
				return _slots[key];
			}
			if (_a1.Remove(key))
			{
				_am.AddFirst(key);
				return _slots[key];
			}
			if (_slots.Count >= _maxSize)
			{
				DiscardPage(finalizer);
			}
			object value = producer.Apply(key);
			_slots[key] = value;
			_a1.AddFirst(key);
			return value;
		}
예제 #11
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);
        }
 public SequentialIdGenerator(IFunction4 findFreeId, int initialValue, int minValidId
                              , int maxValidId)
 {
     _findFreeId = findFreeId;
     _minValidId = minValidId;
     _maxValidId = maxValidId;
     InitializeGenerator(initialValue);
 }
예제 #13
0
 public SequentialIdGenerator(IFunction4 findFreeId, int initialValue, int minValidId
     , int maxValidId)
 {
     _findFreeId = findFreeId;
     _minValidId = minValidId;
     _maxValidId = maxValidId;
     InitializeGenerator(initialValue);
 }
        public virtual object Produce(object key, IFunction4 producer, IProcedure4 onDiscard
                                      )
        {
            _calls++;
            IFunction4 delegateProducer = new _IFunction4_26(this, producer);

            return(_delegate.Produce(key, delegateProducer, onDiscard));
        }
예제 #15
0
 public FunctionApplicationIterator(IEnumerator iterator, IFunction4 function) : base
     (iterator)
 {
     if (null == function)
     {
         throw new ArgumentNullException();
     }
     _function = function;
 }
 public FunctionApplicationIterator(IEnumerator iterator, IFunction4 function) : base
         (iterator)
 {
     if (null == function)
     {
         throw new ArgumentNullException();
     }
     _function = function;
 }
예제 #17
0
파일: CachingBin.cs 프로젝트: masroore/db4o
 /// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
 public CachingBin(IBin bin, ICache4 cache, int pageCount, int pageSize) : base(bin
     )
 {
     _onDiscardPage = new _IProcedure4_22(this);
     _producerFromDisk = new _IFunction4_138(this);
     _producerFromPool = new _IFunction4_147(this);
     _pageSize = pageSize;
     _pagePool = new SimpleObjectPool(NewPagePool(pageCount));
     _cache = cache;
     _fileLength = _bin.Length();
 }
예제 #18
0
 /// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
 public CachingBin(IBin bin, ICache4 cache, int pageCount, int pageSize) : base(bin
                                                                                )
 {
     _onDiscardPage    = new _IProcedure4_22(this);
     _producerFromDisk = new _IFunction4_138(this);
     _producerFromPool = new _IFunction4_147(this);
     _pageSize         = pageSize;
     _pagePool         = new SimpleObjectPool(NewPagePool(pageCount));
     _cache            = cache;
     _fileLength       = _bin.Length();
 }
예제 #19
0
			private static object WithContainer(string filename, IFunction4 block)
			{
				IObjectContainer container = Db4oFactory.OpenFile(filename);
				try
				{
					return block.Apply(container);
				}
				finally
				{
					container.Close();
				}
			}
            private static object WithContainer(string filename, IFunction4 block)
            {
                IObjectContainer container = Db4oFactory.OpenFile(filename);

                try
                {
                    return(block.Apply(container));
                }
                finally
                {
                    container.Close();
                }
            }
예제 #21
0
		public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer
			)
		{
			if (_am.Remove((((long)key))))
			{
				_am.AddFirst((((long)key)));
				return _slots[((long)key)];
			}
			if (_a1.Remove((((long)key))))
			{
				_am.AddFirst((((long)key)));
				return _slots[((long)key)];
			}
			if (_slots.Count >= _maxSize)
			{
				DiscardPage(finalizer);
			}
			object value = producer.Apply(((long)key));
			_slots[((long)key)] = value;
			_a1.AddFirst((((long)key)));
			return value;
		}
예제 #22
0
        public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer
                                      )
        {
            if (_am.Remove((((long)key))))
            {
                _am.AddFirst((((long)key)));
                return(_slots[((long)key)]);
            }
            if (_a1.Remove((((long)key))))
            {
                _am.AddFirst((((long)key)));
                return(_slots[((long)key)]);
            }
            if (_slots.Count >= _maxSize)
            {
                DiscardPage(finalizer);
            }
            var value = producer.Apply(((long)key));

            _slots[((long)key)] = value;
            _a1.AddFirst((((long)key)));
            return(value);
        }
예제 #23
0
 private void ReclaimFor(object key, IFunction4 producer, IProcedure4 finalizer)
 {
     if (_slots.Count < _maxSize)
     {
         _slots[key] = producer.Apply(key);
         return;
     }
     if (_a1in.Size() > _inSize)
     {
         var lastKey = _a1in.RemoveLast();
         Discard(lastKey, finalizer);
         if (_a1out.IsFull())
         {
             _a1out.RemoveLast();
         }
         _a1out.AddFirst(lastKey);
     }
     else
     {
         var lastKey = _am.RemoveLast();
         Discard(lastKey, finalizer);
     }
     _slots[key] = producer.Apply(key);
 }
예제 #24
0
		private void ReclaimFor(object key, IFunction4 producer, IProcedure4 finalizer)
		{
			if (_slots.Count < _maxSize)
			{
				_slots[key] = producer.Apply(key);
				return;
			}
			if (_a1in.Size() > _inSize)
			{
				object lastKey = _a1in.RemoveLast();
				Discard(lastKey, finalizer);
				if (_a1out.IsFull())
				{
					_a1out.RemoveLast();
				}
				_a1out.AddFirst(lastKey);
			}
			else
			{
				object lastKey = _am.RemoveLast();
				Discard(lastKey, finalizer);
			}
			_slots[key] = producer.Apply(key);
		}
예제 #25
0
 private IEnumerator MapPersistentFields(object obj, IFunction4 function)
 {
     return(Iterators.Map(IteratePersistentFields(obj), function));
 }
예제 #26
0
		public ITest Transmogrify(IFunction4 fun) 
		{
			return (ITest) fun.Apply(this);
		}
예제 #27
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);
        }
예제 #28
0
 private void InitializeConstructor(ITypeHandler4 customTypeHandler)
 {
     if (IsTransient())
     {
         _container.LogMsg(23, GetName());
         SetStateDead();
         return;
     }
     if (IsInterface() || IsAbstract())
     {
         return;
     }
     var constructor = CreateConstructor(customTypeHandler);
     if (constructor != null)
     {
         _constructor = constructor;
         return;
     }
     NotStorable();
 }
예제 #29
0
 public TestPuppet()
 {
     producer = new _IFunction4_50(this);
 }
예제 #30
0
 public virtual object Produce(object key, IFunction4 producer, IProcedure4 onDiscard
                               )
 {
     return(producer.Apply(key));
 }
예제 #31
0
 /// <summary>
 /// Returns a new iterator which yields the result of applying the function
 /// to every element in the original iterator.
 /// </summary>
 /// <remarks>
 /// Returns a new iterator which yields the result of applying the function
 /// to every element in the original iterator.
 /// <see cref="Skip">Skip</see>
 /// can be returned from function to indicate the current
 /// element should be skipped.
 /// </remarks>
 /// <param name="iterator"></param>
 /// <param name="function"></param>
 /// <returns></returns>
 public static IEnumerator Map(IEnumerator iterator, IFunction4 function)
 {
     return(new FunctionApplicationIterator(iterator, function));
 }
예제 #32
0
		public static IEnumerable Map(IEnumerable iterable, IFunction4 function)
		{
			return new _IEnumerable_253(iterable, function);
		}
예제 #33
0
		public static IEnumerable Series(object seed, IFunction4 function)
		{
			return new _IEnumerable_356(seed, function);
		}
예제 #34
0
		private IEnumerator MapPersistentFields(object obj, IFunction4 function)
		{
			return Iterators.Map(IteratePersistentFields(obj), function);
		}
예제 #35
0
		/// <summary>
		/// Returns a new iterator which yields the result of applying the function
		/// to every element in the original iterator.
		/// </summary>
		/// <remarks>
		/// Returns a new iterator which yields the result of applying the function
		/// to every element in the original iterator.
		/// <see cref="Skip">Skip</see>
		/// can be returned from function to indicate the current
		/// element should be skipped.
		/// </remarks>
		/// <param name="iterator"></param>
		/// <param name="function"></param>
		/// <returns></returns>
		public static IEnumerator Map(IEnumerator iterator, IFunction4 function)
		{
			return new FunctionApplicationIterator(iterator, function);
		}
예제 #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);
		}
예제 #37
0
 public static IEnumerator Map(System.Array array, IFunction4 function)
 {
     return(Map(array.GetEnumerator(), function));
 }
예제 #38
0
 public static IEnumerator Map(object[] array, IFunction4 function)
 {
     return(Map(new ArrayIterator4(array), function));
 }
예제 #39
0
		private void WithDatabase(string file, IFunction4 function)
		{
			Configure();
			IExtObjectContainer objectContainer = Db4oFactory.OpenFile(file).Ext();
			try
			{
				function.Apply(objectContainer);
			}
			finally
			{
				objectContainer.Close();
			}
			IObjectServer server = Db4oFactory.OpenServer(ClientServerFileName(file), -1);
			server.GrantAccess(Username, Password);
			objectContainer = Db4oFactory.OpenClient("localhost", server.Ext().Port(), Username
				, Password).Ext();
			try
			{
				function.Apply(objectContainer);
			}
			finally
			{
				objectContainer.Close();
				server.Close();
			}
		}
예제 #40
0
				public _IEnumerator_358(object seed, IFunction4 function)
				{
					this.seed = seed;
					this.function = function;
					this._current = seed;
				}
예제 #41
0
 public object Produce(object key, IFunction4 producer, IProcedure4 onDiscard)
 {
     Record("Produce", key);
     return producer.Apply(key);
 }
예제 #42
0
			public _IFunction4_26(CacheStatistics _enclosing, IFunction4 producer)
			{
				this._enclosing = _enclosing;
				this.producer = producer;
			}
예제 #43
0
		public static IEnumerable ConcatMap(IEnumerable iterable, IFunction4 function)
		{
			return Concat(Map(iterable, function));
		}
예제 #44
0
 public static IEnumerable ConcatMap(IEnumerable iterable, IFunction4 function)
 {
     return(Concat(Map(iterable, function)));
 }
예제 #45
0
		public static IEnumerator Map(object[] array, IFunction4 function)
		{
			return Map(new ArrayIterator4(array), function);
		}
예제 #46
0
 public _IEnumerator_358(object seed, IFunction4 function)
 {
     this.seed     = seed;
     this.function = function;
     this._current = seed;
 }
예제 #47
0
			public _IEnumerable_253(IEnumerable iterable, IFunction4 function)
			{
				this.iterable = iterable;
				this.function = function;
			}
예제 #48
0
 public SequentialIdGenerator(IFunction4 findFreeId, int minValidId, int maxValidId
     ) : this(findFreeId, minValidId - 1, minValidId, maxValidId)
 {
 }
예제 #49
0
			public _IEnumerable_356(object seed, IFunction4 function)
			{
				this.seed = seed;
				this.function = function;
			}
예제 #50
0
		private object AsTopLevelStore(IFunction4 block, Transaction trans)
		{
			trans = CheckTransaction(trans);
			object result = AsTopLevelCall(block, trans);
			if (_stackDepth == 0)
			{
				trans.ProcessDeletes();
			}
			return result;
		}
예제 #51
0
		public virtual ITest Transmogrify(IFunction4 fun)
		{
			return ((ITest)fun.Apply(this));
		}
예제 #52
0
			public TestPuppet()
			{
				producer = new _IFunction4_50(this);
			}
예제 #53
0
 public static IEnumerable Map(IEnumerable iterable, IFunction4 function)
 {
     return(new _IEnumerable_253(iterable, function));
 }
 public _IFunction4_26(CacheStatistics _enclosing, IFunction4 producer)
 {
     this._enclosing = _enclosing;
     this.producer   = producer;
 }
예제 #55
0
		public SodaQueryComparatorTestCase()
		{
			oidByItemId = new _IFunction4_121(this);
		}
예제 #56
0
 public _IEnumerable_253(IEnumerable iterable, IFunction4 function)
 {
     this.iterable = iterable;
     this.function = function;
 }
예제 #57
0
 virtual protected object Cache4Produce(object key, IFunction4 producer)
 {
     return(_cache4.Produce(key, producer, null));
 }
예제 #58
0
 public static IEnumerable Series(object seed, IFunction4 function)
 {
     return(new _IEnumerable_356(seed, function));
 }
예제 #59
0
 public virtual ITest Transmogrify(IFunction4 fun)
 {
     return((ITest)fun.Apply(this));
 }
예제 #60
0
 public _IEnumerable_356(object seed, IFunction4 function)
 {
     this.seed     = seed;
     this.function = function;
 }