提交 7dcb3b58 编写于 作者: S Scott Andrews

fixing broken unit test related to SPR-5429

上级 300e4d72
......@@ -62,6 +62,8 @@ public class DbcpDataSourceFactory implements FactoryBean<DataSource>, Disposabl
private Resource dataLocation;
private Resource dropLocation;
/**
* The object created by this factory.
*/
......@@ -115,6 +117,14 @@ public class DbcpDataSourceFactory implements FactoryBean<DataSource>, Disposabl
this.dataLocation = testDataLocation;
}
/**
* Sets the location of the file containing the drop scripts for the database.
* @param testDataLocation the location of the data file
*/
public void setDropLocation(Resource testDropLocation) {
this.dropLocation = testDropLocation;
}
// implementing FactoryBean
// this method is called by Spring to expose the DataSource as a bean
......@@ -163,6 +173,14 @@ public class DbcpDataSourceFactory implements FactoryBean<DataSource>, Disposabl
private void populateDataSource() {
DatabasePopulator populator = new DatabasePopulator(dataSource);
if (dropLocation != null) {
try {
populator.populate(this.dropLocation);
}
catch (Exception e) {
// ignore
}
}
populator.populate(this.schemaLocation);
populator.populate(this.dataLocation);
}
......
DROP TABLE visits;
DROP TABLE pets;
DROP TABLE owners;
DROP TABLE types;
DROP TABLE vet_specialties;
DROP TABLE specialties;
DROP TABLE vets;
......@@ -25,6 +25,7 @@ jdbc.password=
jdbc.populate=true
jdbc.schemaLocation=classpath:/META-INF/hsqldb/initDB.txt
jdbc.dataLocation=classpath:/META-INF/hsqldb/populateDB.txt
jdbc.dropLocation=classpath:/META-INF/hsqldb/dropTables.txt
# Property that determines which Hibernate dialect to use
# (only applied with "applicationContext-hibernate.xml")
......@@ -49,6 +50,7 @@ jpa.database=HSQL
#jdbc.populate=false
#jdbc.schemaLocation=
#jdbc.dataLocation=
#jdbc.dropLocation=
# Property that determines which Hibernate dialect to use
# (only applied with "applicationContext-hibernate.xml")
......
......@@ -13,8 +13,10 @@
<tx:annotation-driven/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
p:username="${jdbc.username}" p:password="${jdbc.password}" />
<bean id="dataSource" class="org.springframework.samples.petclinic.config.DbcpDataSourceFactory"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
p:username="${jdbc.username}" p:password="${jdbc.password}" p:populate="${jdbc.populate}"
p:schemaLocation="${jdbc.schemaLocation}" p:dataLocation="${jdbc.dataLocation}"
p:dropLocation="${jdbc.dropLocation}"/>
</beans>
......@@ -11,10 +11,12 @@
<tx:annotation-driven />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<bean id="dataSource" class="org.springframework.samples.petclinic.config.DbcpDataSourceFactory"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
p:username="${jdbc.username}" p:password="${jdbc.password}" p:populate="${jdbc.populate}"
p:schemaLocation="${jdbc.schemaLocation}" p:dataLocation="${jdbc.dataLocation}"
p:dropLocation="${jdbc.dropLocation}"/>
<!-- Note: the specific "jpaAdapter" bean sits in adapter context file -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource" p:jpaVendorAdapter-ref="jpaAdapter">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册