if ( isDebugEnabled() )
{
System.out.println( "Connection to the server established.\n" + "Importing data ... " );
}
LdifReader ldifReader = new LdifReader( ldifFile );
if ( ldifReader.containsEntries() )
{
// Parse the file and inject every entry
long t0 = System.currentTimeMillis();
int nbAdd = 0;
for ( LdifEntry entry:ldifReader )
{
// Check if we have had some error, has next() does not throw any exception
if ( ldifReader.hasError() )
{
System.err
.println( "Found an error while persing an entry : " + ldifReader.getError().getLocalizedMessage() );
if ( ignoreErrors == false )
{
unbind( messageId );
System.err.println( I18n.err( I18n.ERR_208 ) );
System.exit( 1 );
}
}
if ( ( addEntry( entry, messageId++ ) == IMPORT_ERROR ) && ( ignoreErrors == false ) )
{
unbind( messageId );
System.err.println( I18n.err( I18n.ERR_208 ) );
System.exit( 1 );
}
nbAdd++;
if ( nbAdd % 10 == 0 )
{
System.out.print( '.' );
}
if ( nbAdd % 500 == 0 )
{
System.out.println( nbAdd );
}
}
long t1 = System.currentTimeMillis();
System.out.println( "Done!" );
System.out.println( nbAdd + " entries added in " + ( ( t1 - t0 ) / 1000 ) + " seconds" );
}
else
{
// Parse the file and inject every modification
long t0 = System.currentTimeMillis();
int nbMod = 0;
for ( LdifEntry entry:ldifReader )
{
// Check if we have had some error, has next() does not throw any exception
if ( ldifReader.hasError() )
{
System.err
.println( "Found an error while persing an entry : " + ldifReader.getError().getLocalizedMessage() );
if ( ignoreErrors == false )
{
unbind( messageId );
System.err.println( I18n.err( I18n.ERR_208 ) );
System.exit( 1 );
}
}
if ( ( changeEntry( entry, messageId++ ) == IMPORT_ERROR ) && ( ignoreErrors == false ) )
{
unbind( messageId );
System.err.println( I18n.err( I18n.ERR_208 ) );
System.exit( 1 );
}
nbMod++;
if ( nbMod % 10 == 0 )
{
System.out.print( '.' );
}
if ( nbMod % 500 == 0 )
{
System.out.println( nbMod );
}
}
long t1 = System.currentTimeMillis();
System.out.println( "Done!" );
System.out.println( nbMod + " entries changed in " + ( ( t1 - t0 ) / 1000 ) + " seconds" );
}
ldifReader.close();
// Logout to the server
unbind( messageId++ );
}