Java Reference
In-Depth Information
For the purchase() operation, you have to execute three SQL statements in total. The first is to query
the topic price. The second and third update the topic stock and account balance accordingly.
Then you can declare a book shop instance in the Spring IoC container to provide purchasing
services. For simplicity's sake, you can use DriverManagerDataSource , which opens a new connection
to the database for every request.
Note To access a database running on the Derby server, you have to include derbyclient.jar (located in
the lib directory of the Derby installation) in your classpath. Alternatively, if you're using Maven, you can add a
dependency element:
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.4.2.0</version>
</dependency>
<beans xmlns= " http://www.springframework.org/schema/beans "
xmlns:xsi= " http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation= " http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd " >
<bean id= " dataSource "
class= " org.springframework.jdbc.datasource.DriverManagerDataSource " >
<property name= " driverClassName "
value= " org.apache.derby.jdbc.ClientDriver " />
<property name= " url "
value= " jdbc: derby://localhost:1527/bookshop; create=true " />
<property name= " username " value= " app " />
<property name= " password " value= " app " />
</bean>
<bean id= " bookShop "
class= " com.apress.springenterpriserecipes.bookshop.spring.JdbcBookShop " >
<property name= " dataSource " ref= " dataSource " />
</bean>
</beans>
To demonstrate the problems that can arise without transaction management, suppose you have
the data shown in Tables 4-2, 4-3, and 4-4 entered in your bookshop database.
Search WWH ::




Custom Search