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()); }
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)); }
/// <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); }
private IReflectClass InitializeClass(int classID, string className) { IReflectClass newClazz = EnsureClassInitialised(classID); _classByName.Put(className, newClazz); return(newClazz); }
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); }
/// <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); }
public virtual void TestToString() { Hashtable4 table = new Hashtable4(); table.Put("foo", "bar"); table.Put("bar", "baz"); Assert.AreEqual(Iterators.Join(table.Iterator(), "{", "}", ", "), table.ToString( )); }
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)); }
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); }
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); }
public virtual void Put(object key, object value) { lock (this) { _delegate.Put(key, value); } }
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")); }
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); }
private void AddToCache(Thing t) { var o = _countCache.Get(t.name); if (o == null) { o = 0; } _countCache.Put(t.name, ((int)o) + 1); }
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); }
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; }
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); }
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); }
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)); }
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); }
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); }
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); }
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); } } }
/// <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()); }
private void RegisterGenericClass(string className, GenericClass classMeta) { _genericClassTable.Put(className, classMeta); ((GenericReflector)classMeta.Reflector()).Register(classMeta); }