Database Backend
For the database backend, the JDBC embedded database with H2 will be used. However, the scripts
(database creation script, initial data population script) will be designed to be compatible with MySQL
too. So, when desired, the application is able to use MySQL as the backend database.
For Spring's ApplicationContext configuration, we will simply use the <jdbc:embedded-database>
tag to declare an embedded database. Two SQL scripts will be developed. One is for database creation
(called schema.sql), and the other is for initial data (for example, initial users, categories and
subcategories, sample blog entries, and so on) population (called initial-data.sql).
Using MyBatis for Persistence Layer Implementation
As mentioned in Chapter 3, for the persistence layer, two different implementations will be provided.
One will use JPA, while the other will use MyBatis.
For the MyBatis implementation, we will use MyBatis 3. More specifically, the MyBatis mapper
interfaces and XML-style mapping configurations will be adopted. All the entity classes will be placed
under the package com.apress.prospring3.springblog.domain (actually the same set of domain objects
will be used by both JPA and MyBatis for mapping).
In addition, all the MyBatis mapper interfaces (for example, the EntryMapper interface for
supporting the Entry entity class) will be placed under the package
com.apress.prospring3.springblog.persistence. Moreover, to support browsing blog posting entries in
the web application frontend, pagination support will be implemented as well.
In terms of database operations, query is the most complicated part since in the frontend users can
choose to filter posting entries by posting dates, categories and subcategories, and so on. To fulfill this
requirement, we will use MyBatis's dynamic SQL feature.
Auditing and Entity Versioning
In the sample application, all blog posting entries and comments will have auditing features enabled.
For keeping track of basic audit information (created by, created date, last modified by, last
modified date) for blog posting and comments, as well as keeping versions of each record, we will utilize
MyBatis's plug-in mechanism to intercept the calls to the update operation and populate the basic audit
information (created by, created date, last modified by, last modified date) accordingly. On the other
hand, a copy of the preupdate record will be saved into the history table.
For details, please refer to the section "MyBatis Service Implementation" in Chapter 21.
Summary
In this chapter, we discussed how Spring integrates with MyBatis (formerly iBATIS) when developing
data access logic. Topics included the core concepts, configuration, and mapping definition, and so on.
Then, we discussed how to perform various database operations using MyBatis. We covered various
techniques in retrieving data with different associations and how to use dynamic SQL.
In this chapter, we covered only a small portion of the features available in MyBatis when
implementing most common database operations. For detailed information about MyBatis and its
documentation, please refer to the project web site (www.mybatis.org).
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home