Ejemplo n.º 1
0
        public virtual void TestByteArrayKeys()
        {
            byte[] key1 = new byte[] { 1, 2, 3 };
            byte[] key2 = new byte[] { 3, 2, 1 };
            byte[] key3 = new byte[] { 3, 2, 1 };
            // same values as key2
            Hashtable4 table = new Hashtable4(2);

            table.Put(key1, "foo");
            table.Put(key2, "bar");
            Assert.AreEqual("foo", table.Get(key1));
            Assert.AreEqual("bar", table.Get(key2));
            Assert.AreEqual(2, CountKeys(table));
            Assert.AreEqual(2, table.Size());
            table.Put(key3, "baz");
            Assert.AreEqual("foo", table.Get(key1));
            Assert.AreEqual("baz", table.Get(key2));
            Assert.AreEqual(2, CountKeys(table));
            Assert.AreEqual(2, table.Size());
            Assert.AreEqual("baz", table.Remove(key2));
            Assert.AreEqual(1, CountKeys(table));
            Assert.AreEqual(1, table.Size());
            Assert.AreEqual("foo", table.Remove(key1));
            Assert.AreEqual(0, CountKeys(table));
            Assert.AreEqual(0, table.Size());
        }
Ejemplo n.º 2
0
 private static IntegerConverter IntegerConverterforClassName(IReflector
                                                              reflector, string className)
 {
     if (_integerConverters == null)
     {
         _integerConverters = new Hashtable4();
         IntegerConverter[] converters =
         {
             new
             _IntegerConverter_211(),
             new _IntegerConverter_215(),new _IntegerConverter_219(
                 ),
             new _IntegerConverter_223(),new _IntegerConverter_227(), new _IntegerConverter_231
                 (),
             new _IntegerConverter_235(),new _IntegerConverter_239()
         };
         for (var converterIndex = 0; converterIndex < converters.Length; ++converterIndex)
         {
             var converter = converters[converterIndex];
             _integerConverters.Put(converter.PrimitiveName(), converter);
             if (!converter.PrimitiveName().Equals(converter.WrapperName(reflector)))
             {
                 _integerConverters.Put(converter.WrapperName(reflector), converter);
             }
         }
     }
     return((IntegerConverter)_integerConverters.Get(className));
 }
Ejemplo n.º 3
0
        /// <summary>Returns a ReflectClass instance for the specified class</summary>
        /// <param name="clazz">class</param>
        /// <returns>a ReflectClass instance for the specified class</returns>
        /// <seealso cref="Db4objects.Db4o.Reflect.IReflectClass">Db4objects.Db4o.Reflect.IReflectClass
        ///     </seealso>
        public virtual IReflectClass ForClass(Type clazz)
        {
            if (clazz == null)
            {
                return(null);
            }
            IReflectClass claxx = (IReflectClass)_classByClass.Get(clazz);

            if (claxx != null)
            {
                return(claxx);
            }
            if (!clazz.IsArray && ReflectPlatform.IsNamedClass(clazz))
            {
                claxx = ForName(ReflectPlatform.FullyQualifiedName(clazz));
                if (claxx != null)
                {
                    _classByClass.Put(clazz, claxx);
                    return(claxx);
                }
            }
            claxx = _delegate.ForClass(clazz);
            if (claxx == null)
            {
                return(null);
            }
            claxx = EnsureDelegate(claxx);
            _classByClass.Put(clazz, claxx);
            return(claxx);
        }
Ejemplo n.º 4
0
        private IReflectClass InitializeClass(int classID, string className)
        {
            IReflectClass newClazz = EnsureClassInitialised(classID);

            _classByName.Put(className, newClazz);
            return(newClazz);
        }
Ejemplo n.º 5
0
        private IReflectClass EnsureClassAvailability(int id)
        {
            if (id == 0)
            {
                return(null);
            }
            IReflectClass ret = (IReflectClass)_classByID.Get(id);

            if (ret != null)
            {
                return(ret);
            }
            ByteArrayBuffer classreader = _stream.ReadStatefulBufferById(_trans, id);
            ClassMarshaller marshaller  = MarshallerFamily()._class;
            RawClassSpec    spec        = marshaller.ReadSpec(_trans, classreader);
            string          className   = spec.Name();

            ret = LookupByName(className);
            if (ret != null)
            {
                _classByID.Put(id, ret);
                _pendingClasses.Add(id);
                return(ret);
            }
            ReportMissingClass(className);
            ret = _builder.CreateClass(className, EnsureClassAvailability(spec.SuperClassID()
                                                                          ), spec.NumFields());
            // step 1 only add to _classByID, keep the class out of _classByName and _classes
            _classByID.Put(id, ret);
            _pendingClasses.Add(id);
            return(ret);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// creates an in-memory database with the passed content bytes and adds it
 /// to the adapter for the specified name.
 /// </summary>
 /// <remarks>
 /// creates an in-memory database with the passed content bytes and adds it
 /// to the adapter for the specified name.
 /// </remarks>
 /// <param name="name">the name to be use for #openFile() or #openServer() calls</param>
 /// <param name="bytes">the database content</param>
 public virtual void Put(string name, byte[] bytes)
 {
     if (bytes == null)
     {
         bytes = new byte[0];
     }
     _memoryFiles.Put(name, new Db4objects.Db4o.IO.MemoryIoAdapter(this, bytes));
 }
 private void RegisterClassMetadataById(ClassMetadata clazz)
 {
     if (clazz.GetID() == 0)
     {
         clazz.Write(_systemTransaction);
     }
     _classMetadataByID.Put(clazz.GetID(), clazz);
 }
Ejemplo n.º 8
0
        public virtual void TestToString()
        {
            Hashtable4 table = new Hashtable4();

            table.Put("foo", "bar");
            table.Put("bar", "baz");
            Assert.AreEqual(Iterators.Join(table.Iterator(), "{", "}", ", "), table.ToString(
                                ));
        }
Ejemplo n.º 9
0
        public virtual void TestSameKeyTwice()
        {
            int        key   = 1;
            Hashtable4 table = new Hashtable4();

            table.Put(key, "foo");
            table.Put(key, "bar");
            Assert.AreEqual("bar", table.Get(key));
            Assert.AreEqual(1, CountKeys(table));
        }
Ejemplo n.º 10
0
        internal virtual Db4oDatabase Produce(byte[] signature, long creationTime)
        {
            Db4oDatabase db = (Db4oDatabase)_identities.Get(signature);

            if (db != null)
            {
                return(db);
            }
            db = new Db4oDatabase(signature, creationTime);
            db.Bind(_stream.Transaction);
            _identities.Put(signature, db);
            return(db);
        }
 public void AddClassMetadata(ClassMetadata clazz)
 {
     Container().SetDirtyInSystemTransaction(this);
     _classes.Add(clazz);
     if (clazz.StateUnread())
     {
         _classMetadataByBytes.Put(clazz.i_nameBytes, clazz);
     }
     else
     {
         _classMetadataByClass.Put(clazz.ClassReflector(), clazz);
     }
     RegisterClassMetadataById(clazz);
 }
Ejemplo n.º 12
0
        public IObjectClass ObjectClass(object clazz)
        {
            string className = null;

            if (clazz is string)
            {
                className = (string)clazz;
            }
            else
            {
                IReflectClass claxx = ReflectorFor(clazz);
                if (claxx == null)
                {
                    return(null);
                }
                className = claxx.GetName();
            }
            if (ReflectPlatform.FullyQualifiedName(typeof(object)).Equals(className))
            {
                throw new ArgumentException("Configuration of the Object class is not supported."
                                            );
            }
            Hashtable4   xClasses = ExceptionalClasses();
            Config4Class c4c      = (Config4Class)xClasses.Get(className);

            if (c4c == null)
            {
                c4c = new Config4Class(this, className);
                xClasses.Put(className, c4c);
            }
            return(c4c);
        }
Ejemplo n.º 13
0
 public virtual void Put(object key, object value)
 {
     lock (this)
     {
         _delegate.Put(key, value);
     }
 }
Ejemplo n.º 14
0
        public virtual void TestContainsKey()
        {
            Hashtable4 table = new Hashtable4();

            Assert.IsFalse(table.ContainsKey(null));
            Assert.IsFalse(table.ContainsKey("foo"));
            table.Put("foo", null);
            Assert.IsTrue(table.ContainsKey("foo"));
            table.Put("bar", "baz");
            Assert.IsTrue(table.ContainsKey("bar"));
            Assert.IsFalse(table.ContainsKey("baz"));
            Assert.IsTrue(table.ContainsKey("foo"));
            table.Remove("foo");
            Assert.IsTrue(table.ContainsKey("bar"));
            Assert.IsFalse(table.ContainsKey("foo"));
        }
Ejemplo n.º 15
0
 public void MapQueryResultToID(LazyClientObjectSetStub stub, int queryResultID)
 {
     if (_queryResults == null)
     {
         _queryResults = new Hashtable4();
     }
     _queryResults.Put(queryResultID, stub);
 }
            private void AddToCache(ObjectTranslatorTestCase.Thing t)
            {
                object o = (object)_countCache.Get(t.name);

                if (o == null)
                {
                    o = 0;
                }
                _countCache.Put(t.name, ((int)o) + 1);
            }
Ejemplo n.º 17
0
            private void AddToCache(Thing t)
            {
                var o = _countCache.Get(t.name);

                if (o == null)
                {
                    o = 0;
                }
                _countCache.Put(t.name, ((int)o) + 1);
            }
Ejemplo n.º 18
0
        private Hashtable4 TableFromKeys(object[] keys)
        {
            Hashtable4 ht = new Hashtable4();

            for (int i = 0; i < keys.Length; i++)
            {
                ht.Put(keys[i], keys[i]);
            }
            return(ht);
        }
Ejemplo n.º 19
0
 public ClientTransactionPool(LocalObjectContainer mainContainer)
 {
     // Transaction -> ContainerCount
     // String -> ContainerCount
     ClientTransactionPool.ContainerCount mainEntry = new ClientTransactionPool.ContainerCount
                                                          (mainContainer, 1);
     _transaction2Container = new Hashtable4();
     _fileName2Container    = new Hashtable4();
     _fileName2Container.Put(mainContainer.FileName(), mainEntry);
     _mainContainer = mainContainer;
 }
Ejemplo n.º 20
0
        private IIndexedNodeWithRange NodeForConstraint(QCon con)
        {
            IIndexedNodeWithRange node = (IIndexedNodeWithRange)_nodeCache.Get(con);

            if (null != node || _nodeCache.ContainsKey(con))
            {
                return(node);
            }
            node = NewNodeForConstraint(con);
            _nodeCache.Put(con, node);
            return(node);
        }
Ejemplo n.º 21
0
        public virtual IObjectField ObjectField(string fieldName)
        {
            Hashtable4   exceptionalFieldsCollection = ExceptionalFields();
            Config4Field c4f = (Config4Field)exceptionalFieldsCollection.Get(fieldName);

            if (c4f == null)
            {
                c4f = new Config4Field(this, fieldName);
                exceptionalFieldsCollection.Put(fieldName, c4f);
            }
            return(c4f);
        }
        private ClassMetadata FindInitializedClassByName(string name)
        {
            ClassMetadata classMetadata = (ClassMetadata)_classMetadataByName.Get(name);

            if (classMetadata != null)
            {
                return(classMetadata);
            }
            ClassMetadataIterator i = Iterator();

            while (i.MoveNext())
            {
                classMetadata = (ClassMetadata)i.Current;
                if (name.Equals(classMetadata.GetName()))
                {
                    _classMetadataByName.Put(name, classMetadata);
                    return(classMetadata);
                }
            }
            return(null);
        }
Ejemplo n.º 23
0
        public virtual void TestDifferentKeysSameHashCode()
        {
            Hashtable4TestCase.Key key1  = new Hashtable4TestCase.Key(1);
            Hashtable4TestCase.Key key2  = new Hashtable4TestCase.Key(1);
            Hashtable4TestCase.Key key3  = new Hashtable4TestCase.Key(2);
            Hashtable4             table = new Hashtable4(2);

            table.Put(key1, "foo");
            table.Put(key2, "bar");
            Assert.AreEqual("foo", table.Get(key1));
            Assert.AreEqual("bar", table.Get(key2));
            Assert.AreEqual(2, CountKeys(table));
            table.Put(key2, "baz");
            Assert.AreEqual("foo", table.Get(key1));
            Assert.AreEqual("baz", table.Get(key2));
            Assert.AreEqual(2, CountKeys(table));
            table.Put(key1, "spam");
            Assert.AreEqual("spam", table.Get(key1));
            Assert.AreEqual("baz", table.Get(key2));
            Assert.AreEqual(2, CountKeys(table));
            table.Put(key3, "eggs");
            Assert.AreEqual("spam", table.Get(key1));
            Assert.AreEqual("baz", table.Get(key2));
            Assert.AreEqual("eggs", table.Get(key3));
            Assert.AreEqual(3, CountKeys(table));
            table.Put(key2, "mice");
            Assert.AreEqual("spam", table.Get(key1));
            Assert.AreEqual("mice", table.Get(key2));
            Assert.AreEqual("eggs", table.Get(key3));
            Assert.AreEqual(3, CountKeys(table));
        }
Ejemplo n.º 24
0
        private IClassIndexStrategy ClassIndex(ClassMetadata classMetadata)
        {
            IClassIndexStrategy classIndex = (IClassIndexStrategy)_classIndices.Get(classMetadata
                                                                                    );

            if (classIndex == null)
            {
                classIndex = new BTreeClassIndexStrategy(classMetadata);
                _classIndices.Put(classMetadata, classIndex);
                classIndex.Initialize(_targetDb);
            }
            return(classIndex);
        }
Ejemplo n.º 25
0
        public virtual void TestClear()
        {
            Hashtable4 table = new Hashtable4();

            for (int i = 0; i < 2; ++i)
            {
                table.Clear();
                Assert.AreEqual(0, table.Size());
                table.Put("foo", "bar");
                Assert.AreEqual(1, table.Size());
                AssertIterator(table, new object[] { "foo" });
            }
        }
        internal ClassMetadata ProduceClassMetadata(IReflectClass reflectClazz)
        {
            ClassMetadata classMetadata = ClassMetadataForReflectClass(reflectClazz);

            if (classMetadata != null)
            {
                return(classMetadata);
            }
            ClassMetadata classBeingCreated = (ClassMetadata)_creating.Get(reflectClazz);

            if (classBeingCreated != null)
            {
                return(classBeingCreated);
            }
            ClassMetadata newClassMetadata = new ClassMetadata(Container(), reflectClazz);

            _creating.Put(reflectClazz, newClassMetadata);
            try
            {
                if (!CreateClassMetadata(newClassMetadata, reflectClazz))
                {
                    return(null);
                }
                // ObjectContainerBase#createClassMetadata may add the ClassMetadata already,
                // so we have to check again
                if (!IsRegistered(reflectClazz))
                {
                    AddClassMetadata(newClassMetadata);
                    _classInits.Process(newClassMetadata);
                }
                else
                {
                    RegisterClassMetadataById(newClassMetadata);
                    if (newClassMetadata.AspectsAreNull())
                    {
                        _classInits.Process(newClassMetadata);
                    }
                }
                Container().SetDirtyInSystemTransaction(this);
            }
            finally
            {
                _creating.Remove(reflectClazz);
            }
            return(newClassMetadata);
        }
Ejemplo n.º 27
0
        public virtual void Test()
        {
            Hashtable4          ht        = new Hashtable4();
            ObjectContainerBase container = Container();

            container.ShowInternalClasses(true);
            IQuery q = Db().Query();

            q.Constrain(typeof(Db4oDatabase));
            IObjectSet objectSet = q.Execute();

            while (objectSet.HasNext())
            {
                Db4oDatabase identity = (Db4oDatabase)objectSet.Next();
                Assert.IsFalse(ht.ContainsKey(identity.i_signature));
                ht.Put(identity.i_signature, string.Empty);
            }
            container.ShowInternalClasses(false);
        }
Ejemplo n.º 28
0
        protected virtual void AssertItemsCanBeRetrievedByUUID(Hashtable4 uuidCache)
        {
            IQuery     q         = NewItemQuery();
            IObjectSet objectSet = q.Execute();

            while (objectSet.HasNext())
            {
                UUIDTestCase.Item item = (UUIDTestCase.Item)objectSet.Next();
                Db4oUUID          uuid = Uuid(item);
                Assert.IsNotNull(uuid);
                Assert.AreSame(item, Db().GetByUUID(uuid));
                Db4oUUID cached = (Db4oUUID)uuidCache.Get(item.name);
                if (cached != null)
                {
                    Assert.AreEqual(cached, uuid);
                }
                else
                {
                    uuidCache.Put(item.name, uuid);
                }
            }
        }
Ejemplo n.º 29
0
        /// <summary>returns a prototype object for a specific class.</summary>
        /// <remarks>returns a prototype object for a specific class.</remarks>
        public virtual object PrototypeForClass(Type clazz)
        {
            if (clazz == null)
            {
                throw new PrototypesException("Class can not be null");
            }
            IReflectClass claxx = _reflector.ForClass(clazz);

            if (claxx == null)
            {
                throw new PrototypesException("Not found in the reflector: " + clazz);
            }
            string className = claxx.GetName();

            Prototypes.Prototype prototype = (Prototypes.Prototype)_prototypes.Get(className);
            if (prototype != null)
            {
                return(prototype.Object());
            }
            prototype = new Prototypes.Prototype(this, claxx);
            _prototypes.Put(className, prototype);
            return(prototype.Object());
        }
Ejemplo n.º 30
0
 private void RegisterGenericClass(string className, GenericClass classMeta)
 {
     _genericClassTable.Put(className, classMeta);
     ((GenericReflector)classMeta.Reflector()).Register(classMeta);
 }