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 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); }
internal ClassMetadata ClassMetadataForId(int id) { ClassMetadata classMetadata = (ClassMetadata)_classMetadataByID.Get(id); if (null == classMetadata) { return(null); } return(ReadClassMetadata(classMetadata, null)); }
private void AddToCache(Thing t) { var o = _countCache.Get(t.name); if (o == null) { o = 0; } _countCache.Put(t.name, ((int)o) + 1); }
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); }
/// <summary>returns the content bytes for a database with the given name.</summary> /// <remarks>returns the content bytes for a database with the given name.</remarks> /// <param name="name">the name to be use for #openFile() or #openServer() calls</param> /// <returns>the content bytes</returns> public virtual byte[] Get(string name) { var mia = (MemoryIoAdapter)_memoryFiles .Get(name); if (mia == null) { return(null); } return(mia._bytes); }
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 int ClassMetadataIdForName(string name) { ClassMetadata classMetadata = (ClassMetadata)_classMetadataByBytes.Get(GetNameBytes (name)); if (classMetadata == null) { classMetadata = FindInitializedClassByName(name); } if (classMetadata != null) { return(classMetadata.GetID()); } return(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); }
public virtual object Get(object key) { lock (this) { return(_delegate.Get(key)); } }
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); }
internal ClassMetadata ClassMetadataForReflectClass(IReflectClass reflectClazz) { ClassMetadata cached = (ClassMetadata)_classMetadataByClass.Get(reflectClazz); if (cached != null) { return(cached); } ClassMetadata byName = (ClassMetadata)_classMetadataByName.Get(reflectClazz.GetName ()); if (byName != null) { return(byName); } return(ReadClassMetadata(reflectClazz)); }
private IReflectClass PrimitiveClass(IReflectClass baseClass) { Type primitive = (Type)Primitives.Get(baseClass.GetName()); if (primitive != null) { return(baseClass.Reflector().ForClass(primitive)); } return(baseClass); }
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)); }
protected virtual int MappedClassID(int origID) { object obj = _classIDs.Get(origID); if (obj == null) { return(0); } return((int)obj); }
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 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); }
/// <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()); }
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); }
internal virtual Config4Field ConfigField(string fieldName) { Hashtable4 exceptionalFields = ExceptionalFieldsOrNull(); if (exceptionalFields == null) { return(null); } Config4Field config4Field = (Config4Field)exceptionalFields.Get(fieldName); if (config4Field == null) { return(null); } config4Field.Used(true); return(config4Field); }
public static Db4objects.Db4o.Internal.Marshall.SlotFormat ForHandlerVersion(int handlerVersion) { if (handlerVersion == HandlerRegistry.HandlerVersion) { return(CurrentSlotFormat); } if (handlerVersion < 0 || handlerVersion > CurrentSlotFormat.HandlerVersion()) { throw new ArgumentException(); } Db4objects.Db4o.Internal.Marshall.SlotFormat slotFormat = (Db4objects.Db4o.Internal.Marshall.SlotFormat )_versions.Get(handlerVersion); if (slotFormat != null) { return(slotFormat); } return(ForHandlerVersion(handlerVersion + 1)); }
public static SlotFormat ForHandlerVersion(int handlerVersion) { if (handlerVersion == HandlerRegistry.HandlerVersion) { return(CurrentSlotFormat); } if (handlerVersion < 0 || handlerVersion > CurrentSlotFormat.HandlerVersion()) { throw new ArgumentException(); } var slotFormat = (SlotFormat )_versions.Get(handlerVersion); if (slotFormat != null) { return(slotFormat); } return(ForHandlerVersion(handlerVersion + 1)); }
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); }
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); } } }
public virtual CustomClass ForName(string className) { return((CustomClass)_classes.Get(className)); }
private ClassInfo LookupClassMeta(string className) { return((ClassInfo)_classMetaTable.Get(className)); }
public virtual IReflectClass LookupByName(string name) { return((IReflectClass)_classByName.Get(name)); }
internal ClassMetadata GetActiveClassMetadata(IReflectClass reflectClazz) { return((ClassMetadata)_classMetadataByClass.Get(reflectClazz)); }
private GenericClass LookupGenericClass(string className) { return((GenericClass)_genericClassTable.Get(className)); }
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); }