/
dbDataSource.xml
85 lines (75 loc) · 3.63 KB
/
dbDataSource.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?xml version="1.0" encoding="UTF-8"?>
<!-- Definitions of our JMX related beans -->
<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-2.0.xsd">
<!-- This is a Spring xml file demonstrating the various beans needed to configure the database stuff -->
<!-- We aren't using this because we didn't want to have a direct dependency on Apache DBCP -->
<!-- URL used for the database, most likely this would be in a properties file -->
<bean id="databaseUrl" class="java.lang.String">
<!-- we are using the in-memory H2 database in this example -->
<constructor-arg index="0" value="jdbc:h2:mem:springexample" />
</bean>
<bean id="databaseDriverClassName" class="java.lang.String">
<!-- we are using the in-memory H2 database in this example -->
<constructor-arg index="0" value="org.h2.Driver" />
</bean>
<!-- connection-source that delegates to a data-source -->
<bean id="connectionSource" class="com.j256.ormlite.jdbc.DataSourceConnectionSource" init-method="initialize">
<property name="url" ref="databaseUrl" />
<property name="dataSource" ref="dataSource" />
</bean>
<!-- our data-source that controlls connections to the datbase -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" ref="databaseDriverClassName" />
<property name="url" ref="databaseUrl" />
<property name="username" value="foo" />
<property name="password" value="bar" />
</bean>
<!-- transaction manager -->
<bean id="transactionManager" class="com.j256.ormlite.misc.TransactionManager">
<property name="connectionSource" ref="connectionSource" />
</bean>
<!-- spring wired field information -->
<bean id="deliveryTableConfig" class="com.j256.ormlite.table.DatabaseTableConfig">
<property name="dataClass" value="com.j256.ormlite.examples.spring.Delivery" />
<property name="tableName" value="deliveryTable" />
<property name="fieldConfigs">
<list>
<bean class="com.j256.ormlite.field.DatabaseFieldConfig">
<property name="fieldName" value="id" />
<property name="generatedId" value="true" />
</bean>
<bean class="com.j256.ormlite.field.DatabaseFieldConfig">
<property name="fieldName" value="when" />
<property name="canBeNull" value="false" />
</bean>
<bean class="com.j256.ormlite.field.DatabaseFieldConfig">
<property name="fieldName" value="signedBy" />
</bean>
<bean class="com.j256.ormlite.field.DatabaseFieldConfig">
<property name="fieldName" value="account" />
<property name="foreign" value="true" />
</bean>
</list>
</property>
</bean>
<!-- our daos that are created by using the DaoFactory -->
<bean id="accountDao" class="com.j256.ormlite.spring.DaoFactory" factory-method="createDao">
<constructor-arg index="0" ref="connectionSource" />
<constructor-arg index="1" value="com.j256.ormlite.examples.spring.Account" />
</bean>
<bean id="deliveryDao" class="com.j256.ormlite.spring.DaoFactory" factory-method="createDao">
<constructor-arg index="0" ref="connectionSource" />
<constructor-arg index="1" ref="deliveryTableConfig" />
</bean>
<!-- auto-creates tables as necessary, probably only useful for testing -->
<bean id="tableCreator" class="com.j256.ormlite.spring.TableCreator" init-method="initialize">
<property name="connectionSource" ref="connectionSource" />
<property name="configuredDaos">
<list>
<ref bean="accountDao" />
<ref bean="deliveryDao" />
</list>
</property>
</bean>
</beans>