/// <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); } } }
/// <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); } } }