Example #1
0
 public override NeoDatis.Odb.OID GetObjectId(object @object, bool throwExceptionIfDoesNotExist
                                              )
 {
     NeoDatis.Odb.OID oid = null;
     if (@object != null)
     {
         oid = GetSession(true).GetCache().GetOid(@object, false);
         // If cross cache session is on, just check if current object has the OID on the cache
         if (oid == null && NeoDatis.Odb.OdbConfiguration.ReconnectObjectsToSession())
         {
             NeoDatis.Odb.Core.Transaction.ICrossSessionCache cache = NeoDatis.Odb.Impl.Core.Transaction.CacheFactory
                                                                      .GetCrossSessionCache(GetBaseIdentification().GetIdentification());
             oid = cache.GetOid(@object);
             if (oid != null)
             {
                 return(oid);
             }
         }
         oid = GetSession(true).GetCache().GetOid(@object, false);
         if (oid == null && throwExceptionIfDoesNotExist)
         {
             throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.UnknownObjectToGetOid
                                                        .AddParameter(@object.ToString()));
         }
         return(oid);
     }
     throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.OdbCanNotReturnOidOfNullObject
                                                );
 }
Example #2
0
 public static void ClearAll()
 {
     System.Collections.Generic.IEnumerator <string> names = instances.Keys.GetEnumerator
                                                                 ();
     while (names.MoveNext())
     {
         string name = names.Current;
         NeoDatis.Odb.Core.Transaction.ICrossSessionCache cache = instances[name];
         cache.Clear();
     }
     instances.Clear();
 }
Example #3
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 #4
0
 /// <summary>Reconnect an object to the current session.</summary>
 /// <remarks>
 /// Reconnect an object to the current session. It connects the object and
 /// all the dependent objects (Objects accessible from the object graph of the
 /// root object
 /// </remarks>
 public override void Reconnect(object @object)
 {
     if (@object == null)
     {
         throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.ReconnectCanReconnectNullObject
                                                    );
     }
     NeoDatis.Odb.Core.Transaction.ICrossSessionCache crossSessionCache = NeoDatis.Odb.Impl.Core.Transaction.CacheFactory
                                                                          .GetCrossSessionCache(GetBaseIdentification().GetIdentification());
     NeoDatis.Odb.OID oid = crossSessionCache.GetOid(@object);
     //in some situation the user can control the disconnect and reconnect
     //so before throws an exception test if in the current session
     //there is the object on the cache
     if (oid == null)
     {
         throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.CrossSessionCacheNullOidForObject
                                                    .AddParameter(@object));
     }
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader oih = objectReader.ReadObjectInfoHeaderFromOid
                                                                     (oid, false);
     GetSession(true).AddObjectToCache(oid, @object, oih);
     // Retrieve Dependent Objects
     NeoDatis.Odb.Impl.Core.Layers.Layer1.Introspector.GetDependentObjectIntrospectingCallback
         getObjectsCallback = new NeoDatis.Odb.Impl.Core.Layers.Layer1.Introspector.GetDependentObjectIntrospectingCallback
                                  ();
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = GetSession(true).GetMetaModel
                                                             ().GetClassInfoFromId(oih.GetClassInfoId());
     objectIntrospector.GetMetaRepresentation(@object, ci, true, null, getObjectsCallback
                                              );
     System.Collections.Generic.ICollection <object> dependentObjects = getObjectsCallback
                                                                        .GetObjects();
     System.Collections.Generic.IEnumerator <object> iterator = dependentObjects.GetEnumerator
                                                                    ();
     while (iterator.MoveNext())
     {
         object o = iterator.Current;
         if (o != null)
         {
             oid = crossSessionCache.GetOid(o);
             if (oid == null)
             {
                 throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.CrossSessionCacheNullOidForObject
                                                            .AddParameter(o));
             }
             oih = objectReader.ReadObjectInfoHeaderFromOid(oid, false);
             GetSession(true).AddObjectToCache(oid, o, oih);
         }
     }
 }