@Configuration
@ComponentScan(basePackages="com.apress.prospring3.ch8.dao.jdbc.annotation")
public class AppConfig {
@Bean
public DataSource dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.H2).
addScript("schema.sql").
addScript("test-data.sql").build();
return db;
}
}
In the previous listing, we use EmbeddedDatabaseBuilder to construct the embedded H2 database;
the effect is the same as using the <jdbc:embedded-database> tag in XML configuration. You can also use
the @Profile feature to specify that the configuration is the target only for a specific environment (for
example, dev).
Spring Data Project: JDBC Extensions
As mentioned at the beginning of this chapter, in recent years database technology has evolved so
quickly with the rise of so many purpose-specific databases, nowadays RDBMS is not the only choice as
an application's backend database management system. To respond to this database technology
evolution and the developer community's need, Spring created the Spring Data project
(www.springsource.org/spring-data). The major objective of the project is to provide useful extensions
on top of Spring's core data access functionality to address the needs of Spring developers who are
interacting with database backends other than RDBMSs. Advanced features to data access standards
(e.g., JDBC, JPA) are also provided.
The Spring Data project comes with a lot of extensions. One extension that we would like to
mention here is the JDBC Extensions (www.springsource.org/spring-data/jdbc-extensions). As its name
implies, the extension provides some advanced features to facilitate the development of JDBC
applications using Spring.
At the time of writing, the first release (version 1.0.0) is still in its milestone stage. The main features
that the extension provides are listed here:
QueryDSL support: QueryDSL (www.querydsl.com) is a domain-specific
language that provides a framework for developing type-safe queries. Spring
Data's JDBC Extensions provides QueryDslJdbcTemplate to facilitate the
development of JDBC applications using QueryDSL instead of SQL statements.
Advanced support for Oracle Database: The extension provides a lot of advanced
features for Oracle Database users. On the database connection side, it
supports Oracle-specific session settings, as well as Fast Connection Failover
technology when working with Oracle RAC. Also, classes that integrate with
Oracle Advanced Queueing are provided. On the data-type side, native support
for Oracle's XML types, STRUCT and ARRAY, and so on, are provided.
If you are developing JDBC applications using Spring with Oracle Database, the JDBC Extensions is
really worth a look.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home