示例#1
0
        public override bool Equals(object obj)
        {
            KeyStruct other = (KeyStruct)obj;

            for (int i = 0; i < keys.Length; i++)
            {
                if (keys[i] != other.keys[i])
                {
                    return(false);
                }
            }

            return(true);
        }
        public override bool Equals(object obj)
        {
            KeyStruct other = (KeyStruct)obj;

            if (keys.Length != other.keys.Length)
            {
                return(false);
            }

            for (int i = 0; i < keys.Length; i++)
            {
                object thisKey = keys[i];
                object thatKey = other.keys[i];

                if (!(thisKey.Equals(thatKey)))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#3
0
        private object GetValue(object[] keys)
        {
            KeyStruct key = new KeyStruct(keys);

            return(baseLookup[key]);
        }
示例#4
0
        public void Add(object value, object[] keys)
        {
            KeyStruct key = new KeyStruct(keys);

            baseLookup[key] = value;
        }
        private void LoadObject(string identity, ref object obj, bool ignoreObjectNotFound, Type type, KeyStruct key)
        {
            IClassMap classMap = this.Context.DomainMap.MustGetClassMap(obj.GetType() );
            IObjectCache cache = GetObjectCache();

            if (classMap.IsReadOnly)
            {
                if (this.Context.ReadOnlyObjectCacheManager.LoadObject(obj))
                {
                    SetTransactionGuid(obj);
                    cache.LoadedObjects[key] = obj;
                    return;
                }
            }

            if (classMap.LoadSpan.Length > 0)
            {
                IList listToFill = new ArrayList();
                NPathQuery query = this.Context.GetLoadObjectNPathQuery(obj, classMap.LoadSpan);
                this.Context.PersistenceEngine.LoadObjects( query, listToFill );
                if (listToFill.Count < 1)
                {
                    if (ignoreObjectNotFound == false)
                    {
                        throw new ObjectNotFoundException("Object of type " + type.ToString() + " and with identity '" + identity + "' not found!"); // do not localize
                    }
                    obj = null;
                }
                else if (listToFill.Count > 1)
                {
                    //throw new WtfException("I thought you said your primary keys were unique, no??")
                    obj = null;
                }
                else
                {
                    obj = listToFill[0];
                    SetTransactionGuid(obj);
                    cache.LoadedObjects[key] = obj;
                }
            }
            else
            {
                SetTransactionGuid(obj);
                this.Context.PersistenceEngine.LoadObject(ref obj);
                if (obj == null)
                {
                    if (ignoreObjectNotFound == false)
                    {
                        throw new ObjectNotFoundException("Object of type " + type.ToString() + " and with identity '" + identity + "' not found!"); // do not localize
                    }
                }
                else
                {
                    cache.LoadedObjects[key] = obj;
                }
            }
        }
        protected virtual bool HasObject(string identity, Type type, KeyStruct key)
        {
            object obj;

            IObjectCache cache = GetObjectCache();

            obj = cache.LoadedObjects[key];
            if (obj != null)
            {
                return true;
            }
            else
            {
                obj = cache.UnloadedObjects[key];
                if (obj != null)
                {
                    return true;
                }
            }
            return false;
        }
        protected virtual KeyStruct GetKey(object obj)
        {
            if (obj == null)
            {
                throw new NullReferenceException("Can't create key for null object!"); // do not localize
            }

            IIdentityHelper identityHelper = obj as IIdentityHelper;
            if (identityHelper != null)
            {
                if (identityHelper.HasKeyStruct())
                    return identityHelper.GetKeyStruct();
            }

            Type type = AssemblyManager.GetBaseType(obj);
            KeyStruct key = new KeyStruct(GetKeyParts(type, this.Context.ObjectManager.GetObjectIdentityKeyParts(obj)));

            if (identityHelper != null)
            {
                //Only cache the keyStruct if the identity
                //has been stored (which means it is no longer
                //a temporary identity)
                if (identityHelper.HasIdentityKeyParts())
                    identityHelper.SetKeyStruct(key);
            }
            return key;
        }
 private object GetValue(object[] keys)
 {
     KeyStruct key = new KeyStruct(keys);
     return baseLookup[key];
 }
 public void Add(object value, object[] keys)
 {
     KeyStruct key = new KeyStruct(keys);
     baseLookup[key] = value;
 }
示例#10
0
 public void SetKeyStruct(KeyStruct keyStruct)
 {
     identityHelperMixin.SetKeyStruct(keyStruct);
 }
 public void SetKeyStruct(KeyStruct value)
 {
     this.keyStruct = value;
     this.hasKeyStruct = true;
 }
 public virtual void SetObjectIdentity(object obj, KeyStruct keyStruct)
 {
     try
     {
         IClassMap classMap = this.Context.DomainMap.MustGetClassMap(obj.GetType());
         long i = 1;
         Type refType;
         object refObj;
         object val;
         foreach (IPropertyMap propertyMap in classMap.GetIdentityPropertyMaps())
         {
             if (propertyMap.ReferenceType != ReferenceType.None)
             {
                 //Bad...only works for referenced objects with non-composite ids...
                 refType = obj.GetType().GetProperty(propertyMap.Name).PropertyType;
                 refObj = this.Context.GetObjectById(keyStruct.keys[i], refType, true);
                 SetPropertyValue(obj, propertyMap.Name, refObj);
                 SetOriginalPropertyValue(obj, propertyMap.Name, refObj);
                 SetNullValueStatus(obj, propertyMap.Name, false);
             }
             else
             {
                 val = keyStruct.keys[i];
                 SetPropertyValue(false, obj, propertyMap.Name, val);
                 SetOriginalPropertyValue(obj, propertyMap.Name, val);
                 SetNullValueStatus(obj, propertyMap.Name, false);
             }
             i += 1;
         }
     }
     catch (Exception ex)
     {
         throw new NPersistException(string.Format ("Could not set Identity '{0}' on object '{1}'",keyStruct.keys[1].ToString(),obj), ex);
     }
 }