public synchronized void manageSubBtree()

in mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java [1645:1712]


    public synchronized <K, V> void manageSubBtree( BTree<K, V> btree )
        throws BTreeAlreadyManagedException, IOException
    {
        LOG.debug( "Managing the sub-btree {}", btree.getName() );
        BTreeFactory.setRecordManager( btree, this );

        String name = btree.getName();

        if ( managedBtrees.containsKey( name ) )
        {
            // There is already a subB-tree with this name in the recordManager...
            LOG.error( "There is already a sub-B-tree named '{}' managed by this recordManager", name );
            throw new BTreeAlreadyManagedException( name );
        }

        // Now, write the subB-tree informations
        long btreeInfoOffset = writeBtreeInfo( btree );
        BTreeHeader<K, V> btreeHeader = ( ( AbstractBTree<K, V> ) btree ).getBtreeHeader();
        ( ( PersistedBTree<K, V> ) btree ).setBtreeInfoOffset( btreeInfoOffset );

        // Serialize the B-tree root page
        Page<K, V> rootPage = btreeHeader.getRootPage();

        PageIO[] rootPageIos = serializePage( btree, btreeHeader.getRevision(), rootPage );

        // Get the reference on the first page
        long rootPageOffset = rootPageIos[0].getOffset();

        // Store the rootPageOffset into the Btree header and into the rootPage
        btreeHeader.setRootPageOffset( rootPageOffset );

        ( ( AbstractPage<K, V> ) rootPage ).setOffset( rootPageOffset );

        LOG.debug( "Flushing the newly managed '{}' btree rootpage", btree.getName() );
        flushPages( rootPageIos );

        // And the B-tree header
        long btreeHeaderOffset = writeBtreeHeader( btree, btreeHeader );

        // Now, if this is a new B-tree, add it to the B-tree of B-trees
        // Add the btree into the map of managed B-trees
        if ( ( btree.getType() != BTreeTypeEnum.BTREE_OF_BTREES ) &&
            ( btree.getType() != BTreeTypeEnum.COPIED_PAGES_BTREE ) &&
            ( btree.getType() != BTreeTypeEnum.PERSISTED_SUB ) )
        {
            managedBtrees.put( name, ( BTree<Object, Object> ) btree );
        }

        // And in the Map of currentBtreeHeaders and newBtreeHeaders
        currentBTreeHeaders.put( name, btreeHeader );
        newBTreeHeaders.put( name, btreeHeader );

        // Create the new NameRevision
        NameRevision nameRevision = new NameRevision( name, 0L );

        // Inject it into the B-tree of B-tree
        if ( ( btree.getType() != BTreeTypeEnum.BTREE_OF_BTREES ) &&
            ( btree.getType() != BTreeTypeEnum.COPIED_PAGES_BTREE ) &&
            ( btree.getType() != BTreeTypeEnum.PERSISTED_SUB ) )
        {
            // We can safely increment the number of managed B-trees
            nbBtree++;

            btreeOfBtrees.insert( nameRevision, btreeHeaderOffset );
        }

        updateRecordManagerHeader();
    }