Example #1
0
        public override object GetObjectFromOid(NeoDatis.Odb.OID oid)
        {
            if (oid == null)
            {
                throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.CanNotGetObjectFromNullOid
                                                           );
            }
            NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi = GetObjectReader()
                                                                            .ReadNonNativeObjectInfoFromOid(null, oid, true, true);
            if (nnoi.IsDeletedObject())
            {
                throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.ObjectIsMarkedAsDeletedForOid
                                                           .AddParameter(oid));
            }
            object o = nnoi.GetObject();

            if (o == null)
            {
                o = GetObjectReader().GetInstanceBuilder().BuildOneInstance(nnoi);
            }
            NeoDatis.Odb.Core.Transaction.ISession lsession = GetSession(true);
            // Here oid can be different from nnoi.getOid(). This is the case when
            // the oid is an external oid. That`s why we use
            // nnoi.getOid() to put in the cache
            lsession.GetCache().AddObject(nnoi.GetOid(), o, nnoi.GetHeader());
            lsession.GetTmpCache().ClearObjectInfos();
            return(o);
        }
Example #2
0
        /// <summary>Actually deletes an object database</summary>
        public override NeoDatis.Odb.OID Delete(object @object)
        {
            NeoDatis.Odb.Core.Transaction.ISession lsession = GetSession(true);
            if (lsession.IsRollbacked())
            {
                throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.OdbHasBeenRollbacked
                                                           .AddParameter(baseIdentification.ToString()));
            }
            if (@object == null)
            {
                throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.OdbCanNotDeleteNullObject
                                                           );
            }
            NeoDatis.Odb.Core.Transaction.ICache cache = lsession.GetCache();
            bool throwExceptionIfNotInCache            = false;

            // Get header of the object (position, previous object position, next
            // object position and class info position)
            // Header must come from cache because it may have been updated before.
            NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader header = cache.GetObjectInfoHeaderFromObject
                                                                               (@object, throwExceptionIfNotInCache);
            if (header == null)
            {
                NeoDatis.Odb.OID cachedOid = cache.GetOid(@object, false);
                //reconnect object is turn on tries to get object from cross session
                if (cachedOid == null && NeoDatis.Odb.OdbConfiguration.ReconnectObjectsToSession(
                        ))
                {
                    NeoDatis.Odb.Core.Transaction.ICrossSessionCache crossSessionCache = NeoDatis.Odb.Impl.Core.Transaction.CacheFactory
                                                                                         .GetCrossSessionCache(GetBaseIdentification().GetIdentification());
                    cachedOid = crossSessionCache.GetOid(@object);
                }
                if (cachedOid == null)
                {
                    throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.ObjectDoesNotExistInCacheForDelete
                                                               .AddParameter(@object.GetType().FullName).AddParameter(@object.ToString()));
                }
                header = objectReader.ReadObjectInfoHeaderFromOid(cachedOid, false);
            }
            triggerManager.ManageDeleteTriggerBefore(@object.GetType().FullName, @object, header
                                                     .GetOid());
            NeoDatis.Odb.OID oid = objectWriter.Delete(header);
            triggerManager.ManageDeleteTriggerAfter(@object.GetType().FullName, @object, oid);
            // removes the object from the cache
            cache.RemoveObjectWithOid(header.GetOid());
            if (NeoDatis.Odb.OdbConfiguration.ReconnectObjectsToSession())
            {
                NeoDatis.Odb.Impl.Core.Transaction.CacheFactory.GetCrossSessionCache(GetBaseIdentification
                                                                                         ().GetIdentification()).RemoveObject(@object);
            }
            return(oid);
        }
Example #3
0
        /// <summary>Warning,</summary>
        public override void DeleteObjectWithOid(NeoDatis.Odb.OID oid)
        {
            NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader oih = null;
            NeoDatis.Odb.Core.Transaction.ISession lsession           = GetSession(true);
            NeoDatis.Odb.Core.Transaction.ICache   cache = lsession.GetCache();
            // Check if oih is in the cache
            oih = cache.GetObjectInfoHeaderFromOid(oid, false);
            if (oih == null)
            {
                oih = objectReader.ReadObjectInfoHeaderFromOid(oid, true);
            }
            object @object = null;

            if (NeoDatis.Odb.OdbConfiguration.ReconnectObjectsToSession())
            {
                NeoDatis.Odb.Impl.Core.Transaction.CacheFactory.GetCrossSessionCache(GetBaseIdentification
                                                                                         ().GetIdentification()).RemoveOid(oid);
            }
            objectWriter.Delete(oih);
            // removes the object from the cache
            cache.RemoveObjectWithOid(oih.GetOid());
        }