public virtual void Clear() { objectReader = null; objectWriter = null; session = null; lastIdPositions = null; lastIds = null; }
public DefaultServerIdManager(NeoDatis.Odb.Core.Layers.Layer3.IObjectWriter objectWriter , NeoDatis.Odb.Core.Layers.Layer3.IObjectReader objectReader, long currentBlockIdPosition , int currentBlockIdNumber, NeoDatis.Odb.OID currentMaxId) : base(objectWriter, objectReader, currentBlockIdPosition, currentBlockIdNumber, currentMaxId) { sessionManager = NeoDatis.Odb.OdbConfiguration.GetCoreProvider().GetClientServerSessionManager (); }
protected virtual void Init() { CheckRuntimeCompatibility(); isClosed = false; isLocal = baseIdentification.IsLocal(); // The check if it is a new Database must be executed before object // writer initialization. Because Object Writer Init // Creates the file so the check (which is based on the file existence // would always return false*/ bool isNewDatabase = IsNewDatabase(); commitListeners = new OdbArrayList <ICommitListener>(); classIntrospector = provider.GetClassIntrospector(); ISession session = BuildDefaultSession(); // Object Writer must be created before object Reader objectWriter = BuildObjectWriter(); // Object writer is a two Phase init object objectWriter.Init2(); objectReader = BuildObjectReader(); AddSession(session, false); // If the file does not exist, then a default header must be created if (isNewDatabase) { objectWriter.CreateEmptyDatabaseHeader(OdbTime.GetCurrentTimeInMs(), baseIdentification.GetUserName(), baseIdentification.GetPassword()); } else { try { GetObjectReader().ReadDatabaseHeader(baseIdentification.GetUserName(), baseIdentification.GetPassword()); } catch (ODBAuthenticationRuntimeException e) { Close(); throw; } } objectWriter.AfterInit(); objectIntrospector = BuildObjectIntrospector(); this.triggerManager = BuildTriggerManager(); // This forces the initialization of the meta model MetaModel metaModel = GetMetaModel(); if (OdbConfiguration.CheckModelCompatibility()) { CheckMetaModelCompatibility(classIntrospector.Instrospect(metaModel.GetAllClasses())); } // logically locks access to the file (only for this Virtual machine) FileMutex.GetInstance().OpenFile(GetStorageDeviceName()); // Updates the Transaction Id in the file objectWriter.WriteLastTransactionId(GetCurrentTransactionId()); this.objectWriter.SetTriggerManager(this.triggerManager); this.introspectionCallbackForInsert = new DefaultInstrumentationCallbackForStore(this, triggerManager, false); this.introspectionCallbackForUpdate = new DefaultInstrumentationCallbackForStore(this, triggerManager, true); }
/// <param name="objectWriter">The object writer</param> /// <param name="objectReader">The object reader</param> /// <param name="currentBlockIdPosition">The position of the current block</param> /// <param name="currentBlockIdNumber">The number of the current block</param> /// <param name="currentMaxId">Maximum Database id</param> public DefaultIdManager(NeoDatis.Odb.Core.Layers.Layer3.IObjectWriter objectWriter , NeoDatis.Odb.Core.Layers.Layer3.IObjectReader objectReader, long currentBlockIdPosition , int currentBlockIdNumber, NeoDatis.Odb.OID currentMaxId) { this.provider = NeoDatis.Odb.OdbConfiguration.GetCoreProvider(); this.objectWriter = objectWriter; this.objectReader = objectReader; this.session = objectWriter.GetSession(); this.currentBlockIdPosition = currentBlockIdPosition; this.currentBlockIdNumber = currentBlockIdNumber; this.maxId = provider.GetObjectOID((long)currentBlockIdNumber * NeoDatis.Odb.OdbConfiguration .GetNB_IDS_PER_BLOCK(), 0); this.nextId = provider.GetObjectOID(currentMaxId.GetObjectId() + 1, 0); lastIds = new NeoDatis.Odb.OID[IdBufferSize]; for (int i = 0; i < IdBufferSize; i++) { lastIds[i] = NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.StorageEngineConstant.NullObjectId; } lastIdPositions = new long[IdBufferSize]; lastIdIndex = 0; }
/// <param name="objectWriter">The object writer</param> /// <param name="objectReader">The object reader</param> /// <param name="currentBlockIdPosition">The position of the current block</param> /// <param name="currentBlockIdNumber">The number of the current block</param> /// <param name="currentMaxId">Maximum Database id</param> public DefaultIdManager(NeoDatis.Odb.Core.Layers.Layer3.IObjectWriter objectWriter , NeoDatis.Odb.Core.Layers.Layer3.IObjectReader objectReader, long currentBlockIdPosition , int currentBlockIdNumber, NeoDatis.Odb.OID currentMaxId) { this.provider = NeoDatis.Odb.OdbConfiguration.GetCoreProvider(); this.objectWriter = objectWriter; this.objectReader = objectReader; this.session = objectWriter.GetSession(); this.currentBlockIdPosition = currentBlockIdPosition; this.currentBlockIdNumber = currentBlockIdNumber; this.maxId = provider.GetObjectOID((long)currentBlockIdNumber * NeoDatis.Odb.OdbConfiguration .GetNB_IDS_PER_BLOCK(), 0); this.nextId = provider.GetObjectOID(currentMaxId.GetObjectId() + 1, 0); lastIds = new NeoDatis.Odb.OID[IdBufferSize]; for (int i = 0; i < IdBufferSize; i++) { lastIds[i] = NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.StorageEngineConstant.NullObjectId; } lastIdPositions = new long[IdBufferSize]; lastIdIndex = 0; }
/// <summary> /// Used to commit meta model : classes This is useful when running in client /// server mode TODO Check this /// </summary> protected virtual void CommitMetaModel() { NeoDatis.Odb.Core.Layers.Layer2.Meta.MetaModel sessionMetaModel = session.GetMetaModel (); // If meta model has not been modified, there is nothing to do if (!sessionMetaModel.HasChanged()) { return; } if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId)) { NeoDatis.Tool.DLogger.Debug("Start commitMetaModel"); } NeoDatis.Odb.Core.Layers.Layer2.Meta.MetaModel lastCommitedMetaModel = new NeoDatis.Odb.Core.Layers.Layer2.Meta.SessionMetaModel (); if (isLocal) { // In local mode, we must not reload the meta model as there is no // concurrent access lastCommitedMetaModel = sessionMetaModel; } else { // In ClientServer mode, re-read the meta-model from the database // base to get last update. lastCommitedMetaModel = session.GetStorageEngine().GetObjectReader().ReadMetaModel (lastCommitedMetaModel, false); } // Gets the classes that have changed (that have modified ,deleted or // inserted objects) System.Collections.Generic.IEnumerator <NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo > cis = sessionMetaModel.GetChangedClassInfo().GetEnumerator(); NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo newCi = null; NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo lastCommittedCI = null; NeoDatis.Odb.Core.Layers.Layer3.IObjectWriter writer = session.GetStorageEngine() .GetObjectWriter(); NeoDatis.Odb.OID lastCommittedObjectOIDOfThisTransaction = null; NeoDatis.Odb.OID lastCommittedObjectOIDOfPrevTransaction = null; // for all changes between old and new meta model while (cis.MoveNext()) { newCi = cis.Current; if (lastCommitedMetaModel.ExistClass(newCi.GetFullClassName())) { // The last CI represents the last committed meta model of the // database lastCommittedCI = lastCommitedMetaModel.GetClassInfoFromId(newCi.GetId()); // Just be careful to keep track of current CI committed zone // deleted objects lastCommittedCI.GetCommitedZoneInfo().SetNbDeletedObjects(newCi.GetCommitedZoneInfo ().GetNbDeletedObjects()); } else { lastCommittedCI = newCi; } lastCommittedObjectOIDOfThisTransaction = newCi.GetCommitedZoneInfo().last; lastCommittedObjectOIDOfPrevTransaction = lastCommittedCI.GetCommitedZoneInfo().last; NeoDatis.Odb.OID lastCommittedObjectOID = lastCommittedObjectOIDOfPrevTransaction; // If some object have been created then if (lastCommittedObjectOIDOfPrevTransaction != null) { // Checks if last object of committed meta model has not been // deleted if (session.GetCache().IsDeleted(lastCommittedObjectOIDOfPrevTransaction)) { // TODO This is wrong: if a committed transaction deleted a // committed object and creates x new // objects, then all these new objects will be lost: // if it has been deleted then use the last object of the // session class info lastCommittedObjectOID = lastCommittedObjectOIDOfThisTransaction; newCi.GetCommitedZoneInfo().last = lastCommittedObjectOID; } } // Connect Unconnected zone to connected zone // make next oid of last committed object point to first // uncommitted object // make previous oid of first uncommitted object point to // last committed object if (lastCommittedObjectOID != null && newCi.GetUncommittedZoneInfo().HasObjects()) { if (newCi.GetCommitedZoneInfo().HasObjects()) { // these 2 updates are executed directly without // transaction, because // We are in the commit process. writer.UpdateNextObjectFieldOfObjectInfo(lastCommittedObjectOID, newCi.GetUncommittedZoneInfo ().first, false); writer.UpdatePreviousObjectFieldOfObjectInfo(newCi.GetUncommittedZoneInfo().first , lastCommittedObjectOID, false); } else { // Committed zone has 0 object writer.UpdatePreviousObjectFieldOfObjectInfo(newCi.GetUncommittedZoneInfo().first , null, false); } } // The number of committed objects must be updated with the number // of the last committed CI because a transaction may have been // committed changing this number. // Notice that the setNbObjects receive the full CommittedCIZoneInfo // object // because it will set the number of objects and the number of // deleted objects newCi.GetCommitedZoneInfo().SetNbObjects(lastCommittedCI.GetCommitedZoneInfo()); // and don't forget to set the deleted objects // This sets the number of objects, the first object OID and the // last object OID newCi = BuildClassInfoForCommit(newCi); writer.UpdateInstanceFieldsOfClassInfo(newCi, false); if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId)) { NeoDatis.Tool.DLogger.Debug("Analysing class " + newCi.GetFullClassName()); NeoDatis.Tool.DLogger.Debug("\t-Commited CI = " + newCi); NeoDatis.Tool.DLogger.Debug("\t-connect last commited object with oid " + lastCommittedObjectOID + " to first uncommited object " + newCi.GetUncommittedZoneInfo().first); NeoDatis.Tool.DLogger.Debug("\t-Commiting new Number of objects = " + newCi.GetNumberOfObjects ()); } } sessionMetaModel.ResetChangedClasses(); // To guarantee integrity after commit, the meta model is set to null // If the user continues using odb instance after commit the meta model // will be lazy-reloaded. Only for Client Server mode if (!isLocal) { session.SetMetaModel(null); } }
public virtual void Clear() { objectReader = null; objectWriter = null; session = null; lastIdPositions = null; lastIds = null; }
protected virtual void Init() { CheckRuntimeCompatibility(); isClosed = false; isLocal = baseIdentification.IsLocal(); // The check if it is a new Database must be executed before object // writer initialization. Because Object Writer Init // Creates the file so the check (which is based on the file existence // would always return false*/ bool isNewDatabase = IsNewDatabase(); commitListeners = new OdbArrayList<ICommitListener>(); classIntrospector = provider.GetClassIntrospector(); ISession session = BuildDefaultSession(); // Object Writer must be created before object Reader objectWriter = BuildObjectWriter(); // Object writer is a two Phase init object objectWriter.Init2(); objectReader = BuildObjectReader(); AddSession(session, false); // If the file does not exist, then a default header must be created if (isNewDatabase) { objectWriter.CreateEmptyDatabaseHeader(OdbTime.GetCurrentTimeInMs(), baseIdentification.GetUserName(), baseIdentification.GetPassword()); } else { try { GetObjectReader().ReadDatabaseHeader(baseIdentification.GetUserName(), baseIdentification.GetPassword()); } catch (ODBAuthenticationRuntimeException e) { Close(); throw; } } objectWriter.AfterInit(); objectIntrospector = BuildObjectIntrospector(); this.triggerManager = BuildTriggerManager(); // This forces the initialization of the meta model MetaModel metaModel = GetMetaModel(); if (OdbConfiguration.CheckModelCompatibility()) { CheckMetaModelCompatibility(classIntrospector.Instrospect(metaModel.GetAllClasses())); } // logically locks access to the file (only for this Virtual machine) FileMutex.GetInstance().OpenFile(GetStorageDeviceName()); // Updates the Transaction Id in the file objectWriter.WriteLastTransactionId(GetCurrentTransactionId()); this.objectWriter.SetTriggerManager(this.triggerManager); this.introspectionCallbackForInsert = new DefaultInstrumentationCallbackForStore(this, triggerManager, false); this.introspectionCallbackForUpdate = new DefaultInstrumentationCallbackForStore(this, triggerManager, true); }