public static void executeInBulk(@NotNull Document document,final boolean executeInBulk,@NotNull Runnable task){
  if (!(document instanceof DocumentEx)) {
    task.run();
    return;
  }
  DocumentEx documentEx=(DocumentEx)document;
  if (executeInBulk == documentEx.isInBulkUpdate()) {
    task.run();
    return;
  }
  documentEx.setInBulkUpdate(executeInBulk);
  try {
    task.run();
  }
  finally {
    documentEx.setInBulkUpdate(!executeInBulk);
  }
}

public static void executeInBulk ( @ NotNull Document document , final boolean executeInBulk , @ NotNull Runnable task ) { if ( ! ( document instanceof DocumentEx ) ) { task . run ( ) ; return ; } DocumentEx documentEx = ( DocumentEx ) document ; if ( executeInBulk == documentEx . isInBulkUpdate ( ) ) { task . run ( ) ; return ; } documentEx . setInBulkUpdate ( executeInBulk ) ; try { task . run ( ) ; } finally { documentEx . setInBulkUpdate ( ! executeInBulk ) ; } }
ensures that given task is executed when given document is at the given ' in bulk ' mode .
