Searches

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 JDBCSupport class, an implementation of the PersistenceSupport 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.[34] 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; ...

Get Database Programming with JDBC & Java, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.