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); }
public override void Close() { if (isClosed) { throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.OdbIsClosed .AddParameter(baseIdentification.GetIdentification())); } // When not local (client server) session can be null NeoDatis.Odb.Core.Transaction.ISession lsession = GetSession(isLocal); if (baseIdentification.CanWrite()) { objectWriter.WriteLastODBCloseStatus(true, false); } objectWriter.Flush(); if (isLocal && lsession.TransactionIsPending()) { throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.TransactionIsPending .AddParameter(lsession.GetId())); } isClosed = true; objectReader.Close(); objectWriter.Close(); // Logically release this file (only for this virtual machine) NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.FileMutex.GetInstance().ReleaseFile(GetStorageDeviceName ()); if (lsession != null) { lsession.Close(); } if (objectIntrospector != null) { objectIntrospector.Clear(); objectIntrospector = null; } // remove trigger manager provider.RemoveLocalTriggerManager(this); }
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); }