示例#1
0
 public virtual FileUsageStats CollectStats()
 {
     _stats = new FileUsageStats(_db.FileLength(), FileHeaderUsage(), IdSystemUsage(),
                                 Freespace(), ClassMetadataUsage(), FreespaceUsage(), UuidUsage(), _slots, CommitTimestampUsage
                                     ());
     Sharpen.Util.ISet classRoots = ClassNode.BuildHierarchy(_db.ClassCollection());
     for (IEnumerator classRootIter = classRoots.GetEnumerator(); classRootIter.MoveNext
              ();)
     {
         ClassNode classRoot = ((ClassNode)classRootIter.Current);
         CollectClassSlots(classRoot.ClassMetadata());
         CollectClassStats(_stats, classRoot);
     }
     return(_stats);
 }
示例#2
0
        public override void Convert(ConversionStage.SystemUpStage stage)
        {
            LocalObjectContainer container = stage.File();

            if (!container.Config().GenerateCommitTimestamps().DefiniteYes())
            {
                return;
            }
            container.ClassCollection().WriteAllClasses();
            BuildCommitTimestampIndex(container);
            container.SystemTransaction().Commit();
        }
示例#3
0
        public virtual void ReplaceClassMetadataRepository()
        {
            Db4objects.Db4o.Internal.Transaction systemTransaction = _targetDb.SystemTransaction
                                                                         ();
            // Can't use strictMappedID because the repository ID can
            // be lower than HandlerRegisrtry _highestBuiltinTypeID and
            // the ClassRepository ID would be treated as a system handler
            // and the unmapped ID would be returned.
            int newRepositoryId   = _mapping.MappedId(SourceClassCollectionID());
            int sourceIdentityID  = DatabaseIdentityID(DefragmentServicesImpl.Sourcedb);
            int targetIdentityID  = _mapping.MappedId(sourceIdentityID);
            int targetUuidIndexID = _mapping.MappedId(SourceUuidIndexID());
            int oldIdentityId     = _targetDb.SystemData().Identity().GetID(systemTransaction);
            int oldRepositoryId   = _targetDb.ClassCollection().GetID();
            ClassMetadataRepository oldRepository = _targetDb.ClassCollection();
            ClassMetadataRepository newRepository = new ClassMetadataRepository(systemTransaction
                                                                                );

            newRepository.SetID(newRepositoryId);
            newRepository.Read(systemTransaction);
            newRepository.InitOnUp(systemTransaction);
            _targetDb.SystemData().ClassCollectionID(newRepositoryId);
            _targetDb.ReplaceClassMetadataRepository(newRepository);
            _targetDb.SystemData().UuidIndexId(targetUuidIndexID);
            Db4oDatabase identity = (Db4oDatabase)_targetDb.GetByID(systemTransaction, targetIdentityID
                                                                    );

            _targetDb.SetIdentity(identity);
            ClassMetadataIterator iterator = oldRepository.Iterator();

            while (iterator.MoveNext())
            {
                ClassMetadata           classMetadata = iterator.CurrentClass();
                BTreeClassIndexStrategy index         = (BTreeClassIndexStrategy)classMetadata.Index();
                index.Btree().Free(_targetDb.LocalSystemTransaction());
                FreeById(classMetadata.GetID());
            }
            FreeById(oldIdentityId);
            FreeById(oldRepositoryId);
        }
        public static IDictionary TypesFor(LocalObjectContainer db, Sharpen.Util.ISet ids
                                           )
        {
            IDictionary           id2clazzes = new Hashtable();
            ClassMetadataIterator iter       = db.ClassCollection().Iterator();

            while (iter.MoveNext())
            {
                for (IEnumerator idIter = ids.GetEnumerator(); idIter.MoveNext();)
                {
                    int           id    = ((int)idIter.Current);
                    ClassMetadata clazz = iter.CurrentClass();
                    BTree         btree = BTreeClassIndexStrategy.Btree(clazz);
                    if (btree.Search(db.SystemTransaction(), id) != null)
                    {
                        Sharpen.Util.ISet clazzes = ((Sharpen.Util.ISet)id2clazzes[id]);
                        if (clazzes == null)
                        {
                            clazzes        = new HashSet();
                            id2clazzes[id] = clazzes;
                        }
                        clazzes.Add(clazz);
                    }
                }
            }
            IDictionary id2clazz = new Hashtable();

            for (IEnumerator idIter = id2clazzes.Keys.GetEnumerator(); idIter.MoveNext();)
            {
                int id = ((int)idIter.Current);
                Sharpen.Util.ISet clazzes      = ((Sharpen.Util.ISet)id2clazzes[id]);
                ClassMetadata     mostSpecific = null;
                for (IEnumerator curClazzIter = clazzes.GetEnumerator(); curClazzIter.MoveNext();)
                {
                    ClassMetadata curClazz = ((ClassMetadata)curClazzIter.Current);
                    for (IEnumerator cmpClazzIter = clazzes.GetEnumerator(); cmpClazzIter.MoveNext();)
                    {
                        ClassMetadata cmpClazz = ((ClassMetadata)cmpClazzIter.Current);
                        if (curClazz.Equals(cmpClazz._ancestor))
                        {
                            goto OUTER_continue;
                        }
                    }
                    mostSpecific = curClazz;
                    break;
                    OUTER_continue :;
                }
                OUTER_break :;
                id2clazz[id] = mostSpecific;
            }
            return(id2clazz);
        }
示例#5
0
 private void RebuildUUIDIndex(LocalObjectContainer file)
 {
     var uuid = file.UUIDIndex();
     var i = file.ClassCollection().Iterator();
     while (i.MoveNext())
     {
         var clazz = i.CurrentClass();
         if (clazz.GenerateUUIDs())
         {
             uuid.RebuildIndexForClass(file, clazz);
         }
     }
 }
 private void BuildCommitTimestampIndex(LocalObjectContainer container)
 {
     versionFieldMetadata = container.Handlers.Indexes()._version;
     var i = container.ClassCollection().Iterator();
     while (i.MoveNext())
     {
         var clazz = i.CurrentClass();
         if (clazz.HasVersionField() && !clazz.IsStruct())
         {
             RebuildIndexForClass(container, clazz);
         }
     }
 }
        private void RebuildUUIDIndex(LocalObjectContainer file)
        {
            UUIDFieldMetadata     uuid = file.UUIDIndex();
            ClassMetadataIterator i    = file.ClassCollection().Iterator();

            while (i.MoveNext())
            {
                ClassMetadata clazz = i.CurrentClass();
                if (clazz.GenerateUUIDs())
                {
                    uuid.RebuildIndexForClass(file, clazz);
                }
            }
        }
示例#8
0
        private void BuildCommitTimestampIndex(LocalObjectContainer container)
        {
            versionFieldMetadata = container.Handlers.Indexes()._version;
            var i = container.ClassCollection().Iterator();

            while (i.MoveNext())
            {
                var clazz = i.CurrentClass();
                if (clazz.HasVersionField() && !clazz.IsStruct())
                {
                    RebuildIndexForClass(container, clazz);
                }
            }
        }
        public override void Convert(ConversionStage.SystemUpStage stage)
        {
            LocalObjectContainer  file = stage.File();
            ClassMetadataIterator i    = file.ClassCollection().Iterator();

            while (i.MoveNext())
            {
                ClassMetadata classmetadata = i.CurrentClass();
                if (Accept(classmetadata))
                {
                    classmetadata.DropClassIndex();
                }
            }
        }
示例#10
0
        private IList CheckClassIndices()
        {
            IList     invalidIds = new ArrayList();
            IIdSystem idSystem   = _db.IdSystem();

            if (!(idSystem is BTreeIdSystem))
            {
                return(invalidIds);
            }
            ClassMetadataIterator clazzIter = _db.ClassCollection().Iterator();

            while (clazzIter.MoveNext())
            {
                ClassMetadata clazz = clazzIter.CurrentClass();
                if (!clazz.HasClassIndex())
                {
                    continue;
                }
                BTreeClassIndexStrategy index = (BTreeClassIndexStrategy)clazz.Index();
                index.TraverseIds(_db.SystemTransaction(), new _IVisitor4_64(this, invalidIds, clazz
                                                                             ));
            }
            return(invalidIds);
        }
示例#11
0
        public virtual IStoredClass[] StoredClasses(DefragmentServicesImpl.DbSelector selector
                                                    )
        {
            LocalObjectContainer db = selector.Db(this);

            db.ShowInternalClasses(true);
            try
            {
                return(db.ClassCollection().StoredClasses());
            }
            finally
            {
                db.ShowInternalClasses(false);
            }
        }
        private ObjectServerImpl(LocalObjectContainer container, ServerConfigurationImpl
                                 serverConfig, int port, bool isEmbeddedServer)
        {
            _isEmbeddedServer = isEmbeddedServer;
            _container        = container;
            _serverConfig     = serverConfig;
            _socketFactory    = serverConfig.Networking.SocketFactory;
            _transactionPool  = new ClientTransactionPool(container);
            _port             = port;
            _name             = "db4o ServerSocket FILE: " + container.ToString() + "  PORT:" + _port;
            _container.SetServer(true);
            ConfigureObjectServer();
            _classInfoHelper = new Db4objects.Db4o.CS.Internal.ClassInfoHelper(Db4oClientServerLegacyConfigurationBridge
                                                                               .AsLegacy(serverConfig));
            _container.ClassCollection().CheckAllClassChanges();
            bool ok = false;

            try
            {
                EnsureLoadStaticClass();
                StartCommittedCallbackThread(_committedInfosQueue);
                StartServer();
                if (_serverConfig != null)
                {
                    _serverConfig.ApplyConfigurationItems(this);
                }
                ok = true;
            }
            finally
            {
                if (!ok)
                {
                    Close();
                }
            }
        }
示例#13
0
 public virtual int SourceClassCollectionID()
 {
     return(_sourceDb.ClassCollection().GetID());
 }