Java Reference
In-Depth Information
layer. The service layer should always interact with the DAO interface and be free of
any DAO implementations. This case is no different, as you can see here:
public interface ProductDao {
PaginatedList getProductListByCategory(
String categoryId);
}
We have a ProductDao interface that will be used by the CatalogService class.
Since CatalogService interacts with the ProductDao interface, it doesn't care
about the actual implementation. On our ProductDao , we need to define a get-
ProductListByCategory method that CatalogService is able to take advantage of.
The return type is PaginatedList and the method signature consists of a catego-
ryId of type String:
public class ProductSqlMapDao
extends BaseSqlMapDao
implements ProductDao {
public ProductSqlMapDao(DaoManager daoManager) {
super(daoManager);
}
public PaginatedList getProductListByCategory(
String categoryId
) {
return queryForPaginatedList(
"Product.getProductListByCategory",
categoryId, PAGE_SIZE);
}
}
The implementation of the ProductDao will be the ProductSqlMapDao , which is
located in the org.apache.ibatis.jgamestore.persistence.sqlmapdao package. Prod-
uctSqlMapDao extends BaseSqlMapDao , and in turn BaseSqlMapDao extends SqlMap-
DaoTemplate . SqlMapDaoTemplate is a base i BATIS SQLMap class; this class contains
methods that are used to call the SQL that is defined in the SQLMap XML files. We
will use the queryForPaginatedList method in the body of the getProductListBy-
Category method implementation on the ProductSqlMapDao class. When we call
queryForPaginatedList we pass in the namespace and the statement name we
want to call (i.e., Product.getProductListByCategory ), the categoryId that we are
querying against, and the page size that we want the returned list to represent.
Search WWH ::




Custom Search