Preface

Java 命名和目录接口 (JNDI) 对于 LDAP 编程来说,就相当于 Java 数据库连接 (JDBC) 对于 SQL 编程。JDBC 和 JNDI/LDAP (Java LDAP) 之间有几个相似之处。它们虽然是具有不同优缺点的完全不同的两个 API,但它们共享许多不那么令人满意的特性:

The Java Naming and Directory Interface (JNDI) is to LDAP programming what Java Database Connectivity (JDBC) is to SQL programming. There are several similarities between JDBC and JNDI/LDAP (Java LDAP). Despite being two completely different APIs with different pros and cons, they share a number of less flattering characteristics:

  • They require extensive plumbing code, even to perform the simplest of tasks.

  • All resources need to be correctly closed, no matter what happens.

  • Exception handling is difficult.

这些要点通常会导致 API 的常见用例中出现大量代码重复。众所周知,代码重复是最糟糕的“代码异味”之一。总而言之,归结为以下几点:Java 中的 JDBC 和 LDAP 编程都极其枯燥且重复。

These points often lead to massive code duplication in common use cases of the APIs. As we all know, code duplication is one of the worst “code smells”. All in all, it boils down to this: JDBC and LDAP programming in Java are both incredibly dull and repetitive.

Spring Framework 的核心组件 Spring JDBC 提供了用于简化 SQL 编程的出色实用程序。我们需要一个用于 Java LDAP 编程的类似框架。

Spring JDBC, a core component of Spring Framework, provides excellent utilities for simplifying SQL programming. We need a similar framework for Java LDAP programming.