code: void doCloseConnection(DirContext context, ContextSource contextSource)
              throws javax.naming.NamingException {
          DirContextHolder transactionContextHolder = (DirContextHolder) TransactionSynchronizationManager
                  .getResource(contextSource);
          if (transactionContextHolder == null
                  || transactionContextHolder.getCtx() != context) {
              log.debug("Closing context");
              // This is not the transactional context or the transaction is
              // no longer active - we should close it.
              context.close();
          } else {
              log.debug("Leaving transactional context open");
          }
      }
docs: Close the supplied context, but only if it is not associated with the
  current transaction.
  
  @param context
  the DirContext to close.
  @param contextSource
  the ContextSource bound to the transaction.
  @throws NamingException