Esempio n. 1
0
        public override void Close()
        {
            Commit();

            var lsession = GetSession();

            _objectWriter.FileSystemProcessor.WriteLastOdbCloseStatus(true, false);

            _objectWriter.FileSystemProcessor.Flush();
            if (lsession.TransactionIsPending())
            {
                throw new OdbRuntimeException(NDatabaseError.TransactionIsPending.AddParameter(lsession.GetId()));
            }

            IsDbClosed = true;
            ObjectReader.Close();
            _objectWriter.Close();

            lsession.Close();

            if (_objectIntrospector != null)
            {
                _objectIntrospector.Clear();
                _objectIntrospector = null;
            }

            // remove trigger manager
            RemoveLocalTriggerManager();
        }
Esempio n. 2
0
        /// <summary>
        ///   The database file name
        /// </summary>
        public StorageEngine(IDbIdentification parameters)
        {
            _reflectionService = DependencyContainer.Resolve <IReflectionService>();

            try
            {
                var metaModelCompabilityChecker = DependencyContainer.Resolve <IMetaModelCompabilityChecker>();

                DbIdentification = parameters;
                IsDbClosed       = false;

                var isNewDatabase = DbIdentification.IsNew();

                _session = DependencyContainer.Resolve <ISession>(this);

                // Object Writer must be created before object Reader
                _objectWriter = DependencyContainer.Resolve <IObjectWriter>(this);
                ObjectReader  = DependencyContainer.Resolve <IObjectReader>(this);

                // Associate current session to the fsi -> all transaction writes
                // will be applied to this FileSystemInterface
                _session.SetFileSystemInterfaceToApplyTransaction(_objectWriter.FileSystemProcessor.FileSystemInterface);

                _objectIntrospectionDataProvider = new SessionDataProvider(_session);

                if (isNewDatabase)
                {
                    _objectWriter.CreateEmptyDatabaseHeader(OdbTime.GetCurrentTimeInTicks());
                }
                else
                {
                    GetObjectReader().ReadDatabaseHeader();
                }
                _objectWriter.AfterInit();
                _objectIntrospector = new ObjectIntrospector(GetClassInfoProvider());
                _triggerManager     = GetLocalTriggerManager();
                // This forces the initialization of the meta model
                var metaModel = GetMetaModel();

                var shouldUpdate = metaModelCompabilityChecker.Check(ClassIntrospector.Instrospect(metaModel.GetAllClasses()), GetMetaModel());

                if (shouldUpdate)
                {
                    UpdateMetaModel();
                }

                _objectWriter.SetTriggerManager(_triggerManager);
                _introspectionCallbackForInsert = new InstrumentationCallbackForStore(_triggerManager, false);
                _introspectionCallbackForUpdate = new InstrumentationCallbackForStore(_triggerManager, true);
            }
            catch
            {
                if (parameters is FileIdentification)
                {
                    Monitor.Exit(string.Intern(Path.GetFullPath(parameters.FileName)));
                }
                throw;
            }
        }