|
Spring provides a unique data access abstraction,including a simple and productive JDBC framework.
Spring data access architecture also integrates with TopLink,Hibernate,JDO,and other O/R mapping solutions
 
In the figure,data accessing in an application is included in a separate layer called DAO
Spring DAO Support classes provide ability to acquire DAO implementations. They also include the DAO classes extended from DAOSupport to integrate to other database broker system. Each DAO class is used as a bridge to integrate to a special database broker system,as in the figure below:
 
DataSources In order to execute any JDBC operation on a database,you need a Connection. In Spring DAO,Connection objects are obtained through a DataSource.
DataSource contains database accessing information and is assigned to Spring DAO Support classes before using these DAO classes to operate database
DataSourse is declared as a bean in Spring descriptor XML file,for example:
JNDIObjectFactoryBean as DataSource to access via JNDI:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>java:comp/env/jdbc/myDatasource</value> </property> </bean>
DriverManagerDataSource as DataSource to access via JDBC:
<bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"> <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value> </property>
<property name="url"> <value>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Hibernate_books</value> </property>
<property name="username"><value>sa</value></property> <property name="password"><value>sa</value></property> </bean>
Using DataSource DataSource is assigned to DAO Support classes through different ways,base on kind of database broker system
Content of the Spring XML descriptor bean files show the way of how a DataSource is assigned to DAO Support. Following is an example for Hibernate:

With Hibernate,LocalSessionFactoryBean is to store DataSource. The LocalSessionFactoryBean then is passed into Hibernate DAO Integration in sessionFactory property. In this case,BookService class is a direct subclass of Hibernate DAO Integration.
|