private void loadEntries()

in ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java [559:661]


    private void loadEntries( File entryDir ) throws LdapException
    {
        LOG.debug( "Processing dir {}", entryDir.getName() );

        // First, load the entries
        File[] entries = entryDir.listFiles( entryFilter );

        if ( ( entries != null ) && ( entries.length != 0 ) )
        {
            LdifReader ldifReader = new LdifReader( schemaManager );

            for ( File entry : entries )
            {
                LOG.debug( "parsing ldif file {}", entry.getName() );
                List<LdifEntry> ldifEntries = ldifReader.parseLdifFile( entry.getAbsolutePath() );
                
                try
                {
                    ldifReader.close();
                }
                catch ( IOException ioe )
                {
                    throw new LdapOtherException( ioe.getMessage(), ioe );
                }

                if ( ( ldifEntries != null ) && !ldifEntries.isEmpty() )
                {
                    // this ldif will have only one entry
                    LdifEntry ldifEntry = ldifEntries.get( 0 );
                    LOG.debug( "Adding entry {}", ldifEntry );

                    Entry serverEntry = new DefaultEntry( schemaManager, ldifEntry.getEntry() );

                    if ( !serverEntry.containsAttribute( SchemaConstants.ENTRY_CSN_AT ) )
                    {
                        serverEntry.put( SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString() );
                    }

                    if ( !serverEntry.containsAttribute( SchemaConstants.ENTRY_UUID_AT ) )
                    {
                        serverEntry.put( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
                    }

                    // call add on the wrapped partition not on the self
                    AddOperationContext addContext = new AddOperationContext( null, serverEntry );
                    PartitionTxn partitionTxn = beginWriteTransaction();
                    
                    try
                    {
                        addContext.setTransaction( partitionTxn );
                        addContext.setPartition( this );
                    
                        super.add( addContext );
                        
                        partitionTxn.commit();
                    }
                    catch ( LdapException le )
                    {
                        try
                        {
                            partitionTxn.abort();
                        }
                        catch ( IOException ioe )
                        {
                            throw new LdapOtherException( ioe.getMessage(), ioe );
                        }
                        
                        throw le;
                    }
                    catch ( IOException ioe )
                    {
                        try
                        {
                            partitionTxn.abort();
                        }
                        catch ( IOException ioe2 )
                        {
                            throw new LdapOtherException( ioe2.getMessage(), ioe2 );
                        }
                        
                        throw new LdapOtherException( ioe.getMessage(), ioe );
                    }
                }
            }

        }
        else
        {
            // If we don't have ldif files, we won't have sub-directories
            return;
        }

        // Second, recurse on the sub directories
        File[] dirs = entryDir.listFiles( dirFilter );

        if ( ( dirs != null ) && ( dirs.length != 0 ) )
        {
            for ( File f : dirs )
            {
                loadEntries( f );
            }
        }
    }