Example #1
0
        private TreeInt ToTreeInt(IIndexedNode result)
        {
            ByRef treeInts = ByRef.NewInstance();

            result.Traverse(new _IIntVisitor_65(treeInts));
            return((TreeInt)treeInts.value);
        }
Example #2
0
        private AbstractQueryResult ReadQueryResult(Transaction trans)
        {
            ByRef result = ByRef.NewInstance();

            WithEnvironment(new _IRunnable_670(this, trans, result));
            return((AbstractQueryResult)result.value);
        }
Example #3
0
        public virtual void TestLifeCycle()
        {
            ByRef tearDownCalled = ByRef.NewInstance(false);

            RunsLifeCycle._tearDownCalled.With(tearDownCalled, new _IRunnable_11());
            Assert.IsTrue((((bool)tearDownCalled.value)));
        }
		public virtual void TestObjectInfoIsNotAvailableOnCreatingHandler()
		{
			ByRef executed = ByRef.NewInstance(false);
			EventRegistry().Creating += new System.EventHandler<Db4objects.Db4o.Events.CancellableObjectEventArgs>
				(new _IEventListener4_15(executed).OnEvent);
			Store(new EventsTestCaseBase.Item());
			Assert.IsTrue((((bool)executed.value)));
		}
Example #5
0
		public virtual IList Merged()
		{
			IList mergedSlots = new ArrayList();
			ByRef mergedSlot = ByRef.NewInstance(new Slot(0, 0));
			Tree.Traverse(_slots, new _IVisitor4_32(mergedSlot, mergedSlots));
			mergedSlots.Add(((Slot)mergedSlot.value));
			return mergedSlots;
		}
Example #6
0
        public virtual ISet Overlaps()
        {
            ISet overlaps = new HashSet();
            var  prevSlot = ByRef.NewInstance();

            Tree.Traverse(_slots, new _IVisitor4_29(this, prevSlot, overlaps));
            return(overlaps);
        }
Example #7
0
        public virtual Sharpen.Util.ISet Overlaps()
        {
            Sharpen.Util.ISet overlaps = new HashSet();
            ByRef             prevSlot = ByRef.NewInstance();

            TreeIntObject.Traverse(_slots, new _IVisitor4_29(this, prevSlot, overlaps));
            return(overlaps);
        }
Example #8
0
        public virtual void TestObjectInfoIsNotAvailableOnCreatingHandler()
        {
            var executed = ByRef.NewInstance(false);

            EventRegistry().Creating += new _IEventListener4_15(executed).OnEvent;
            Store(new Item());
            Assert.IsTrue((((bool)executed.value)));
        }
Example #9
0
        /// <exception cref="System.Exception"></exception>
        public virtual void TestDaemon()
        {
            ByRef isDaemon = ByRef.NewInstance();

            _subject.StartLowPriority("Deamon checker", new _IRunnable_60(isDaemon));
            _subject.Join(1000);
            Assert.IsTrue((((bool)isDaemon.value)));
        }
Example #10
0
        private bool CreateChildForDescendable(QCandidates parentCandidates, ITypeHandler4
                                               handler, QueryingReadContext queryingReadContext, ITypeHandler4 arrayElementHandler
                                               )
        {
            int  offset   = queryingReadContext.Offset();
            bool outerRes = true;
            // The following construct is worse than not ideal. For each constraint it completely reads the
            // underlying structure again. The structure could be kept fairly easy. TODO: Optimize!
            IEnumerator i = parentCandidates.IterateConstraints();

            while (i.MoveNext())
            {
                QCon   qcon = (QCon)i.Current;
                QField qf   = qcon.GetField();
                if (qf != null && !qf.Name().Equals(_fieldMetadata.GetName()))
                {
                    continue;
                }
                QCon tempParent = qcon.Parent();
                qcon.SetParent(null);
                QCandidates candidates = new QCandidates(parentCandidates.i_trans, null, qf, false
                                                         );
                candidates.AddConstraint(qcon);
                qcon.SetCandidates(candidates);
                ReadArrayCandidates(handler, queryingReadContext.Buffer(), arrayElementHandler, candidates
                                    );
                queryingReadContext.Seek(offset);
                bool isNot = qcon.IsNot();
                if (isNot)
                {
                    qcon.RemoveNot();
                }
                candidates.Evaluate();
                ByRef        pending  = ByRef.NewInstance();
                BooleanByRef innerRes = new BooleanByRef(isNot);
                candidates.Traverse(new QCandidate.CreateDescendChildTraversingVisitor(pending, innerRes
                                                                                       , isNot));
                if (isNot)
                {
                    qcon.Not();
                }
                // In case we had pending subresults, we need to communicate them up to our root.
                if (((Tree)pending.value) != null)
                {
                    ((Tree)pending.value).Traverse(new _IVisitor4_168(this));
                }
                if (!innerRes.value)
                {
                    // Again this could be double triggering.
                    //
                    // We want to clean up the "No route" at some stage.
                    qcon.Visit(GetRoot(), qcon.Evaluator().Not(false));
                    outerRes = false;
                }
                qcon.SetParent(tempParent);
            }
            return(outerRes);
        }
Example #11
0
        public virtual void TestRunWith()
        {
            EnvironmentsTestCase.IWhatever whatever = new _IWhatever_22();
            IEnvironment environment = new _IEnvironment_23(whatever);
            ByRef        ran         = ByRef.NewInstance();

            Environments.RunWith(environment, new _IRunnable_29(ran, whatever));
            Assert.IsTrue((((bool)ran.value)));
        }
Example #12
0
        private IList CollectOverlaps()
        {
            IBlockConverter blockConverter = _db.BlockConverter();
            IList           overlaps       = new ArrayList();
            ByRef           prevSlot       = ByRef.NewInstance();

            mappings.Traverse(new _IVisitor4_192(prevSlot, blockConverter, overlaps));
            return(overlaps);
        }
Example #13
0
        /// <exception cref="System.Exception"></exception>
        public virtual void TestFailureEvent()
        {
            var executed  = ByRef.NewInstance(false);
            var exception = new Exception();

            _subject.UncaughtException += new _IEventListener4_20(exception, executed).OnEvent;
            _subject.Start(ReflectPlatform.SimpleName(GetType()) + " throwing exception thread"
                           , new _IRunnable_27(exception));
            _subject.Join(1000);
            Assert.IsTrue((((bool)executed.value)));
        }
        private void Read(ByteArrayBuffer reader)
        {
            FreeSlotNode.sizeLimit = DiscardLimit();
            _freeBySize            = new TreeReader(reader, new FreeSlotNode(0), true).Read();
            ByRef addressTree = ByRef.NewInstance();

            if (_freeBySize != null)
            {
                _freeBySize.Traverse(new _IVisitor4_176(addressTree));
            }
            _freeByAddress = ((Tree)addressTree.value);
        }
Example #15
0
        private long[] GetIDsForClass(Transaction trans, ClassMetadata clazz, bool triggerQueryEvents
                                      )
        {
            MsgD msg = Msg.GetInternalIds.GetWriterForInts(trans, new int[] { clazz.GetID(),
                                                                              PrefetchDepth(), PrefetchCount(), triggerQueryEvents ? 1 : 0 });

            Write(msg);
            ByRef result = ByRef.NewInstance();

            WithEnvironment(new _IRunnable_901(this, trans, result));
            return((long[])result.value);
        }
Example #16
0
        /// <summary>Retrieves the value of a transaction local variables.</summary>
        /// <remarks>
        /// Retrieves the value of a transaction local variables.
        /// If this is the first time the variable is accessed
        /// <see cref="TransactionLocal.InitialValueFor(Transaction)">TransactionLocal.InitialValueFor(Transaction)
        ///     </see>
        /// will provide the initial value.
        /// </remarks>
        public virtual ByRef Get(TransactionLocal local)
        {
            ByRef existing = (ByRef)_locals[local];

            if (null != existing)
            {
                return(existing);
            }
            ByRef initialValue = ByRef.NewInstance(local.InitialValueFor(this));

            _locals[local] = initialValue;
            return(initialValue);
        }
Example #17
0
        private void AssertExpectedIDs(int[] expectedIds, IQuery query)
        {
            FieldIndexProcessorResult result = ExecuteProcessor(query);

            if (expectedIds.Length == 0)
            {
                Assert.AreSame(FieldIndexProcessorResult.FoundIndexButNoMatch, result);
                return;
            }
            ByRef treeInts = ByRef.NewInstance();

            result.Traverse(new _IIntVisitor_303(treeInts));
            AssertTreeInt(expectedIds, ((TreeInt)treeInts.value));
        }
Example #18
0
 internal virtual bool CreateChild(QCandidates a_candidates)
 {
     if (!_include)
     {
         return(false);
     }
     if (_fieldMetadata != null)
     {
         ITypeHandler4 handler = _fieldMetadata.GetHandler();
         if (handler != null)
         {
             QueryingReadContext queryingReadContext = new QueryingReadContext(Transaction(),
                                                                               MarshallerFamily().HandlerVersion(), _bytes, _key);
             ITypeHandler4 arrayElementHandler = Handlers4.ArrayElementHandler(handler, queryingReadContext
                                                                               );
             if (arrayElementHandler != null)
             {
                 int  offset   = queryingReadContext.Offset();
                 bool outerRes = true;
                 // The following construct is worse than not ideal.
                 // For each constraint it completely reads the
                 // underlying structure again. The structure could b
                 // kept fairly easy. TODO: Optimize!
                 IEnumerator i = a_candidates.IterateConstraints();
                 while (i.MoveNext())
                 {
                     QCon   qcon = (QCon)i.Current;
                     QField qf   = qcon.GetField();
                     if (qf == null || qf.Name().Equals(_fieldMetadata.GetName()))
                     {
                         QCon tempParent = qcon.Parent();
                         qcon.SetParent(null);
                         QCandidates candidates = new QCandidates(a_candidates.i_trans, null, qf);
                         candidates.AddConstraint(qcon);
                         qcon.SetCandidates(candidates);
                         ReadArrayCandidates(handler, queryingReadContext.Buffer(), arrayElementHandler, candidates
                                             );
                         queryingReadContext.Seek(offset);
                         bool isNot = qcon.IsNot();
                         if (isNot)
                         {
                             qcon.RemoveNot();
                         }
                         candidates.Evaluate();
                         ByRef  pending  = ByRef.NewInstance();
                         bool[] innerRes = new bool[] { isNot };
                         candidates.Traverse(new _IVisitor4_160(innerRes, isNot, pending));
                         // Collect all pending subresults.
                         // We need to change
                         // the
                         // constraint here, so
                         // our
                         // pending collector
                         // uses
                         // the right
                         // comparator.
                         // We only keep one
                         // pending result
                         // for
                         // all array
                         // elements.
                         // and memorize,
                         // whether we had a
                         // true or a false
                         // result.
                         // or both.
                         if (isNot)
                         {
                             qcon.Not();
                         }
                         // In case we had pending subresults, we
                         // need to communicate
                         // them up to our root.
                         if (((Tree)pending.value) != null)
                         {
                             ((Tree)pending.value).Traverse(new _IVisitor4_229(this));
                         }
                         if (!innerRes[0])
                         {
                             // Again this could be double triggering.
                             //
                             // We want to clean up the "No route"
                             // at some stage.
                             qcon.Visit(GetRoot(), qcon.Evaluator().Not(false));
                             outerRes = false;
                         }
                         qcon.SetParent(tempParent);
                     }
                 }
                 return(outerRes);
             }
             // We may get simple types here too, if the YapField was null
             // in the higher level simple evaluation. Evaluate these
             // immediately.
             if (Handlers4.IsQueryLeaf(handler))
             {
                 a_candidates.i_currentConstraint.Visit(this);
                 return(true);
             }
         }
     }
     if (_fieldMetadata == null)
     {
         return(false);
     }
     if (_fieldMetadata is NullFieldMetadata)
     {
         return(false);
     }
     _classMetadata.SeekToField(Transaction(), _bytes, _fieldMetadata);
     Db4objects.Db4o.Internal.Query.Processor.QCandidate candidate = ReadSubCandidate(
         a_candidates);
     if (candidate == null)
     {
         return(false);
     }
     // fast early check for ClassMetadata
     if (a_candidates.i_classMetadata != null && a_candidates.i_classMetadata.IsStronglyTyped
             ())
     {
         ITypeHandler4 handler = _fieldMetadata.GetHandler();
         if (Handlers4.IsUntyped(handler))
         {
             handler = TypeHandlerFor(candidate);
         }
         if (handler == null)
         {
             return(false);
         }
     }
     AddDependant(a_candidates.Add(candidate));
     return(true);
 }
 private void ExcludeClasses(ICommonConfiguration commonConfiguration, Type[] classes
                             )
 {
     commonConfiguration.ReflectWith(new ExcludingReflector(ByRef.NewInstance(typeof(MissingClassDiagnosticsTestCase.Pilot
                                                                                     )), classes));
 }
Example #20
0
 private void ExcludeClasses(ICommonConfiguration commonConfiguration, Type[] classes
                             )
 {
     commonConfiguration.ReflectWith(new ExcludingReflector(ByRef.NewInstance(typeof(Pilot
                                                                                     )), classes));
 }
Example #21
0
        private void PrintStats(IObjectContainer con, string filename)
        {
            Tree unavailable   = new TreeString(Remove);
            Tree noConstructor = new TreeString(Remove);

            // one element too many, substract one in the end
            IStoredClass[] internalClasses = con.Ext().StoredClasses();
            for (int i = 0; i < internalClasses.Length; i++)
            {
                string internalClassName = internalClasses[i].GetName();
                Type   clazz             = ReflectPlatform.ForName(internalClassName);
                if (clazz == null)
                {
                    unavailable = unavailable.Add(new TreeString(internalClassName));
                }
                else
                {
                    if (!CanCallConstructor(internalClassName))
                    {
                        noConstructor = noConstructor.Add(new TreeString(internalClassName));
                    }
                }
            }
            unavailable   = unavailable.RemoveLike(new TreeString(Remove));
            noConstructor = noConstructor.RemoveLike(new TreeString(Remove));
            if (unavailable != null)
            {
                PrintHeader("UNAVAILABLE");
                unavailable.Traverse(new _IVisitor4_80());
            }
            if (noConstructor != null)
            {
                PrintHeader("NO PUBLIC CONSTRUCTOR");
                noConstructor.Traverse(new _IVisitor4_88());
            }
            PrintHeader("CLASSES");
            Sharpen.Runtime.Out.WriteLine("Number of objects per class:");
            ByRef ids = ByRef.NewInstance(new TreeInt(0));

            if (internalClasses.Length > 0)
            {
                Tree all = new TreeStringObject(internalClasses[0].GetName(), internalClasses[0]);
                for (int i = 1; i < internalClasses.Length; i++)
                {
                    all = all.Add(new TreeStringObject(internalClasses[i].GetName(), internalClasses[
                                                           i]));
                }
                all.Traverse(new _IVisitor4_107(ids));
            }
            PrintHeader("SUMMARY");
            Sharpen.Runtime.Out.WriteLine("File: " + filename);
            Sharpen.Runtime.Out.WriteLine("Stored classes: " + internalClasses.Length);
            if (unavailable != null)
            {
                Sharpen.Runtime.Out.WriteLine("Unavailable classes: " + unavailable.Size());
            }
            if (noConstructor != null)
            {
                Sharpen.Runtime.Out.WriteLine("Classes without public constructors: " + noConstructor
                                              .Size());
            }
            Sharpen.Runtime.Out.WriteLine("Total number of objects: " + (((Tree)ids.value).Size
                                                                             () - 1));
        }