Here, we get the new id for the record to be inserted, set it on the bean that was
passed in, and then insert that bean into the database. The code is very simple to
follow, just a bit verbose when compared to either the i BATIS or Hibernate versions.
The other methods are equally straightforward, so we will not take up any
more space on them.
11.2 Using the DAO pattern with other data sources
The DAO pattern is very similar to the Gateway pattern, which makes it suitable
for many other data sources such as LDAP or web services.
If you are not familiar with the Gateway pattern, it is also sometimes referred to
as a Wrapper, because that is what it does. It “wraps” an API to make it look like a
simple object, as shown in figure 11.1, where the WebServiceGateway interface
hides the underlying implementation.
If you are thinking that sounds familiar, it should, because that is also the idea
behind the DAO pattern, which is just a specialized gateway that also helps you
manage transactions, pooling, and other database-specific issues.
Example: using a DAO with LDAP
LDAP is an awesome tool for storing hierarchical data, and is often used by net-
work administrators for tracking users, group memberships, and other similar
data. For example, both Novell Directory Services ( NDS ) and Microsoft's ActiveDi-
rectory are based on LDAP and expose LDAP API s.
Using the DAO pattern to access a directory using LDAP is a great way to keep
the nuances of JNDI programming out of your application code. By creating a
The DAO pattern is similar to the Gateway pattern.
Search WWH ::