Not only does the persistence delegate support the basic database inserts, updates, and deletes, but it also supports the component modelâs searches. Writing logic to support arbitrary searches, however, can be very complex. You really do not want to have to repeat the complexity of search logic for every single component in your system if you can avoid it. Fortunately, you can avoid it by capturing search logic in a single place, the persistence delegate.
The final example in this chapter, Example 9.5, is
the full source code to the
class, an implementation of
class. It does not, on its own,
provide implementations of the persistence operations you discussed
so far in the chapter. Business components require subclasses of
JDBCSupport that specifically map a specific
business component to a data model. The base class does
have, however, a generalized search engine that accepts the
SearchCriteria object, translates it into SQL, and
finally returns the results.
ExampleÂ 9-5.Â The Abstract JDBCSupport Class with a Generic SQL Search Algorithm
package com.imaginary.lwp.jdbc; import com.imaginary.lwp.BaseFacade; import com.imaginary.lwp.FindException; import com.imaginary.lwp.PersistenceSupport; import com.imaginary.lwp.SearchBinding; import com.imaginary.lwp.SearchCriteria; import com.imaginary.lwp.Transaction; import com.imaginary.util.DistributedList; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; ...