ORM frameworks. JPA defines a common ORM pattern for object to relational mapping for Java
application to access RDBMS, while leaving the implementation (called the persistence provider) to the
open source communities and commercial vendors. Some popular JPA persistence providers include
Hibernate, Eclipselink, and OpenJPA. Chapter 9 discusses Spring's support for Hibernate, and Chapter
10 discusses Spring's support for JPA. These two chapters combined show how we use Spring and JPA 2,
using Hibernate as the persistence service provider, to build the implementation of our data access tier.
For Spring with JPA and Hibernate, we will also discuss how to use the Spring Data JPA to implement
logging for users who create blogs or comment and how to use Hibernate's Envers (Entity Versioning
System) to implement the audit log function.
Strictly speaking, MyBatis is not an ORM tool but a DataMapper framework that does not remove all
responsibility from the developer for creating the SQL statements needed to map Java objects to data in
the RDMBS. MyBatis introduces the concept of a SQL map, allowing you to specify a variety of SQL
queries and how these queries map to both input and output parameters. MyBatis is quite powerful in
some aspects of data access. Chapter 11 discusses MyBatis in detail and shows how we built the second
data access implementation.
In all cases, we use Spring's infrastructure classes for each data access tool. These classes integrate
with Spring's transaction architecture, which allows transactions to be managed in a platform- and
resource-provider-independent way in the service layer of the SpringBlog application.
Implementing the Service Layer
The SpringBlog application is fairly simple, and aside from the basic storage and retrieval of blog data,
there are very few business rules in the system. However, there are two particular business functions in
the SpringBlog application that exploit two of the most interesting Spring features: the AOP-based
obscenity filter and the audit log.
Using AOP for Obscenity Filtering
AOP is a hot topic in the Java world at the moment, and as a result, Java developers are fortunate to have
a wide range of AOP implementations available to them. Spring AOP support comes in two forms: the
Spring native AOP framework and integration with the AspectJ AOP framework. Chapters 6 and 7 discuss
both Spring AOP and AspectJ integration in detail.
For the SpringBlog application, we wanted to provide a practical example of AOP usage rather than
the traditional (and boring) logging example. One of the features that we were working on for the sample
application was an obscenity filter, and during design, it became apparent that AOP was the ideal
mechanism for implementing this filter. In Chapter 21, you will see how we built the obscenity filter and
how we used AOP to apply the filter selectively to the relevant methods.
Using Spring Transaction Support
As developers, one of the features of Spring that we found most impressive was the transaction support.
Spring's transaction support provides a simple mechanism to control transactions across one or more
resource providers, either programmatically or declaratively. Chapter 13 discusses the transaction
framework in detail, focusing specifically on database transactions using both local and distributed
transactions.
For the SpringBlog application, we defined a requirement that all operations in the blog be audited
and logged to the database. To ensure that an operation is rolled back if the audit process fails, we used
the Spring transaction framework to encapsulate each operation and its audit process in a single
transaction. We will discuss this in Chapter 13.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home