public virtual NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo BuildNnoi (object o, NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo classInfo, NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo [] values, long[] attributesIdentification, int[] attributeIds, System.Collections.Generic.IDictionary <object, NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo> alreadyReadObjects ) { NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo (o, classInfo, values, attributesIdentification, attributeIds); if (storageEngine != null) { // for unit test purpose NeoDatis.Odb.Core.Transaction.ICache cache = storageEngine.GetSession(true).GetCache (); // Check if object is in the cache, if so sets its oid NeoDatis.Odb.OID oid = cache.GetOid(o, false); if (oid != null) { nnoi.SetOid(oid); // Sets some values to the new header to keep track of the infos // when // executing NeoDatis without closing it, just committing. // Bug reported by Andy NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader oih = cache.GetObjectInfoHeaderFromOid (oid, true); nnoi.GetHeader().SetObjectVersion(oih.GetObjectVersion()); nnoi.GetHeader().SetUpdateDate(oih.GetUpdateDate()); nnoi.GetHeader().SetCreationDate(oih.GetCreationDate()); } } return(nnoi); }
/// <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); }
/// <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>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()); }
public virtual void SetLastObjectInfoHeader(ObjectInfoHeader lastObjectInfoHeader) { this.lastObjectInfoHeader = lastObjectInfoHeader; }
/// <summary>Only adds the Object info - used for non committed objects</summary> public virtual void AddObjectInfo(ObjectInfoHeader objectInfoHeader) { if (objectInfoHeader.GetOid() == null) { throw new ODBRuntimeException(NeoDatisError.CacheNullOid); } if (objectInfoHeader.GetClassInfoId() == null) { throw new ODBRuntimeException(NeoDatisError.CacheObjectInfoHeaderWithoutClassId.AddParameter(objectInfoHeader.GetOid())); } // TODO : Should remove first inserted object and not clear all cache if (objectInfoPointersCacheFromOid.Count > OdbConfiguration.GetMaxNumberOfObjectInCache()) { ManageFullCache(); } objectInfoPointersCacheFromOid[objectInfoHeader.GetOid()] = objectInfoHeader; // For monitoring purpose nbObjects = objects.Count; nbOids = oids.Count; nbOih = objectInfoPointersCacheFromOid.Count; }
public virtual void AddObject(OID oid, object o, ObjectInfoHeader objectInfoHeader) { if (oid == null) { throw new ODBRuntimeException(NeoDatisError.CacheNullOid); } if (CheckHeaderPosition() && objectInfoHeader.GetPosition() == -1) { throw new ODBRuntimeException(NeoDatisError.CacheNegativePosition .AddParameter("Adding OIH with position = -1")); } // TODO : Should remove first inserted object and not clear all cache if (objects.Count > OdbConfiguration.GetMaxNumberOfObjectInCache()) { // clear(); ManageFullCache(); } oids[oid] = o; try { objects[o] = oid; } catch (System.ArgumentNullException) { } // FIXME URL in HashMap What should we do? // In some case, the object can throw exception when added to the // cache // because Map.put, end up calling the equals method that can throw // exception // This is the case of URL that has a transient attribute handler // that is used in the URL.equals method objectInfoPointersCacheFromOid[oid] = objectInfoHeader; // For monitoring purpose nbObjects = objects.Count; nbOids = oids.Count; nbOih = objectInfoPointersCacheFromOid.Count; }