Esempio n. 1
0
        private bool CheckIfCollectionContainsItem(IEnumerable collection)
        {
            foreach (var item in collection)
            {
                if (item == null && TheObject == null && _oid == null)
                {
                    return(true);
                }

                if (Equals(item, TheObject))
                {
                    return(true);
                }

                if (_oid == null || item == null)
                {
                    continue;
                }

                if (!OdbType.IsNative(item.GetType()))
                {
                    continue;
                }

                if (Equals(item, _oid))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        ///   Store an object with the specific id
        /// </summary>
        /// <param name="oid"> </param>
        /// <param name="plainObject"> </param>
        private OID InternalStore <T>(OID oid, T plainObject) where T : class
        {
            if (GetSession().IsRollbacked())
            {
                throw new OdbRuntimeException(
                          NDatabaseError.OdbHasBeenRollbacked.AddParameter(GetBaseIdentification().ToString()));
            }

            if (plainObject == null)
            {
                throw new OdbRuntimeException(NDatabaseError.OdbCanNotStoreNullObject);
            }

            var type = typeof(T);

            if (OdbType.IsNative(type))
            {
                throw new OdbRuntimeException(
                          NDatabaseError.OdbCanNotStoreNativeObjectDirectly.AddParameter(type.FullName).AddParameter(
                              OdbType.GetFromClass(type).Name).AddParameter(type.FullName));
            }

            // first detects if we must perform an insert or an update
            // If object is in the cache, we must perform an update, else an insert
            var cache = GetSession().GetCache();

            var cacheOid = cache.IdOfInsertingObject(plainObject);

            if (cacheOid != null)
            {
                return(cacheOid);
            }

            // throw new ODBRuntimeException("Inserting meta representation of
            // an object without the object itself is not yet supported");
            var mustUpdate = cache.Contains(plainObject);

            // The introspection callback is used to execute some specific task (like calling trigger, for example) while introspecting the object
            var callback = _introspectionCallbackForInsert;

            if (mustUpdate)
            {
                callback = _introspectionCallbackForUpdate;
            }

            // Transform the object into an ObjectInfo
            var nnoi =
                (NonNativeObjectInfo)
                _objectIntrospector.GetMetaRepresentation(plainObject, true, null, callback);

            // During the introspection process, if object is to be updated, then the oid has been set
            mustUpdate = nnoi.GetOid() != null;

            return(mustUpdate
                       ? _objectWriter.UpdateNonNativeObjectInfo(nnoi, false)
                       : _objectWriter.InsertNonNativeObject(oid, nnoi, true));
        }
Esempio n. 3
0
 protected bool IsNative()
 {
     return(TheObject == null || OdbType.IsNative(TheObject.GetType()));
 }
Esempio n. 4
0
        public static bool TypesAreCompatible(OdbType type1, OdbType type2)
        {
            if (type1 == null || type2 == null)
                return false;

            if (type1.IsArray() && type2.IsArray())
                return TypesAreCompatible(type1.SubType, type2.SubType);

            if (type1.Name.Equals(type2.Name))
                return true;

            if (type1.IsEnum() && type2.IsEnum())
                return type1.GetNativeClass() == type2.GetNativeClass();

            if (type1.IsNative() && type2.IsNative())
                return type1.IsEquivalent(type2);

            if (type1.IsNonNative() && type2.IsNonNative())
                return (type1.GetNativeClass() == type2.GetNativeClass()) ||
                       (type1.GetNativeClass().IsAssignableFrom(type2.GetNativeClass()));

            return false;
        }