提交 d9c44704 编写于 作者: P Phillip Webb

Upgrade to HSQLDB 2.3.1

Replace `hsqldb:hsqldb:1.8.0.10` with `org.hsqldb:hsqldb:2.3.1` and
fix breaking tests.

Issue: SPR-10947
上级 87e443b4
......@@ -15,7 +15,7 @@ configure(allprojects) { project ->
ext.aspectjVersion = "1.8.0.M1"
ext.groovyVersion = "1.8.9"
ext.hsqldbVersion = "1.8.0.10"
ext.hsqldbVersion = "2.3.1"
ext.junitVersion = "4.11"
ext.slf4jVersion = "1.6.1"
ext.jettyVersion = "9.1.0.v20131115"
......@@ -495,7 +495,7 @@ project("spring-jdbc") {
optional(project(":spring-context")) // for JndiDataSourceLookup
compile(project(":spring-tx"))
optional("c3p0:c3p0:0.9.1.2")
optional("hsqldb:hsqldb:${hsqldbVersion}")
optional("org.hsqldb:hsqldb:${hsqldbVersion}")
optional("com.h2database:h2:1.0.71")
optional("org.apache.derby:derby:10.5.3.0_1")
optional("org.apache.derby:derbyclient:10.5.3.0_1")
......@@ -528,7 +528,7 @@ project("spring-context-support") {
testCompile("org.apache.poi:poi:3.9")
testCompile("commons-beanutils:commons-beanutils:1.8.0") // for Velocity/JasperReports
testCompile("commons-digester:commons-digester:1.8.1") // for Velocity/JasperReports
testCompile("hsqldb:hsqldb:${hsqldbVersion}")
testCompile("org.hsqldb:hsqldb:${hsqldbVersion}")
}
// pick up **/*.types files in src/main
......@@ -622,7 +622,7 @@ project("spring-orm") {
provided("javax.servlet:javax.servlet-api:3.0.1")
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
testCompile("commons-dbcp:commons-dbcp:1.2.2")
testCompile("hsqldb:hsqldb:${hsqldbVersion}")
testCompile("org.hsqldb:hsqldb:${hsqldbVersion}")
compile(project(":spring-core"))
compile(project(":spring-beans"))
optional(project(":spring-aop"))
......@@ -790,7 +790,7 @@ project("spring-test") {
testCompile(project(":spring-webmvc-tiles3"))
testCompile("org.hibernate:hibernate-core:3.6.9.Final")
testCompile "org.slf4j:slf4j-jcl:${slf4jVersion}"
testCompile("hsqldb:hsqldb:${hsqldbVersion}")
testCompile("org.hsqldb:hsqldb:${hsqldbVersion}")
testCompile("org.hibernate:hibernate-validator:4.3.0.Final")
testCompile("org.codehaus.jackson:jackson-mapper-asl:1.9.12")
testCompile("com.fasterxml.jackson.core:jackson-databind:2.2.2")
......@@ -918,7 +918,7 @@ configure(rootProject) {
testCompile("javax.inject:javax.inject:1")
testCompile("javax.resource:connector-api:1.5")
testCompile("org.aspectj:aspectjweaver:${aspectjVersion}")
testCompile("hsqldb:hsqldb:${hsqldbVersion}")
testCompile("org.hsqldb:hsqldb:${hsqldbVersion}")
}
task api(type: Javadoc) {
......
......@@ -28,6 +28,8 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
......@@ -59,8 +61,9 @@ public class DatabasePopulatorTests {
private void assertUsersDatabaseCreated(String... lastNames) {
for (String lastName : lastNames) {
assertEquals("Did not find user with last name [" + lastName + "].", 1,
jdbcTemplate.queryForInt("select count(0) from users where last_name = ?", lastName));
assertThat("Did not find user with last name [" + lastName + "].",
jdbcTemplate.queryForObject("select count(0) from users where last_name = ?", Integer.class, lastName),
equalTo(1));
}
}
......@@ -131,8 +134,8 @@ public class DatabasePopulatorTests {
connection.close();
}
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Keith'"));
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Dave'"));
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class), equalTo(1));
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class), equalTo(1));
}
@Test
......@@ -148,8 +151,8 @@ public class DatabasePopulatorTests {
connection.close();
}
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Keith'"));
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Dave'"));
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class), equalTo(1));
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class), equalTo(1));
}
@Test
......@@ -165,8 +168,8 @@ public class DatabasePopulatorTests {
connection.close();
}
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Keith'"));
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Dave'"));
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class), equalTo(1));
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class), equalTo(1));
}
@Test
......@@ -181,8 +184,8 @@ public class DatabasePopulatorTests {
connection.close();
}
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Keith'"));
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Dave'"));
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class), equalTo(1));
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class), equalTo(1));
}
@Test
......@@ -198,8 +201,8 @@ public class DatabasePopulatorTests {
connection.close();
}
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Keith'"));
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Dave'"));
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class), equalTo(1));
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class), equalTo(1));
}
@Test
......@@ -244,8 +247,8 @@ public class DatabasePopulatorTests {
connection.close();
}
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Keith'"));
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Dave'"));
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class), equalTo(1));
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class), equalTo(1));
}
/**
......
DROP TABLE users IF EXISTS;
CREATE TABLE users (
id INTEGER NOT NULL IDENTITY PRIMARY KEY,
id INTEGER NOT NULL IDENTITY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL
);
......@@ -16,6 +16,9 @@
package org.springframework.orm.jpa;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.springframework.test.jpa.AbstractJpaTests;
import org.springframework.transaction.support.TransactionSynchronizationManager;
......@@ -81,6 +84,10 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests extends Abstr
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
}
protected int countRowsInTable(EntityManager em, String tableName) {
Query query = em.createNativeQuery("SELECT COUNT(0) FROM " + tableName);
return ((Number) query.getSingleResult()).intValue();
};
public enum Provider {
ECLIPSELINK, HIBERNATE, OPENJPA
......
......@@ -93,7 +93,7 @@ public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEnt
em.persist(p);
em.flush();
assertEquals("1 row must have been inserted", 1, countRowsInTable("person"));
assertEquals("1 row must have been inserted", 1, countRowsInTable(em, "person"));
}
public void testStateClean() {
......@@ -122,14 +122,14 @@ public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEnt
setComplete();
endTransaction(); // Should rollback
assertEquals("Tx must have committed back",
1, countRowsInTable("person"));
1, countRowsInTable(em, "person"));
// Now clean up the database
startNewTransaction();
em.joinTransaction();
deleteAllPeopleUsingEntityManager(em);
assertEquals("People have been killed",
0, countRowsInTable("person"));
0, countRowsInTable(em, "person"));
setComplete();
}
......@@ -143,7 +143,7 @@ public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEnt
doInstantiateAndSave(em);
endTransaction(); // Should rollback
assertEquals("Tx must have been rolled back",
0, countRowsInTable("person"));
0, countRowsInTable(em, "person"));
}
public void testCommitOccurs() {
......@@ -154,7 +154,7 @@ public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEnt
setComplete();
endTransaction(); // Should rollback
assertEquals("Tx must have committed back",
1, countRowsInTable("person"));
1, countRowsInTable(em, "person"));
// Now clean up the database
deleteFromTables(new String[] { "person" });
......
......@@ -105,7 +105,7 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit
public void doInstantiateAndSave(EntityManager em) {
assertEquals("Should be no people from previous transactions",
0, countRowsInTable("person"));
0, countRowsInTable(em, "person"));
Person p = new Person();
p.setFirstName("Tony");
......@@ -113,7 +113,7 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit
em.persist(p);
em.flush();
assertEquals("1 row must have been inserted", 1, countRowsInTable("person"));
assertEquals("1 row must have been inserted", 1, countRowsInTable(em, "person"));
}
public void testReuseInNewTransaction() {
......@@ -132,7 +132,7 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit
setComplete();
endTransaction(); // Should rollback
assertEquals("Tx must have committed back",
1, countRowsInTable("person"));
1, countRowsInTable(em, "person"));
// Now clean up the database
deleteFromTables(new String[] { "person" });
......@@ -143,7 +143,7 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit
doInstantiateAndSave(em);
endTransaction(); // Should rollback
assertEquals("Tx must have been rolled back",
0, countRowsInTable("person"));
0, countRowsInTable(em, "person"));
}
public void testCommitOccurs() {
......@@ -152,7 +152,7 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit
setComplete();
endTransaction(); // Should rollback
assertEquals("Tx must have committed back",
1, countRowsInTable("person"));
1, countRowsInTable(em, "person"));
// Now clean up the database
deleteFromTables(new String[] { "person" });
......
......@@ -134,7 +134,7 @@ public abstract class AbstractTransactionalDataSourceSpringContextTests
* @return the number of rows in the table
*/
protected int countRowsInTable(String tableName) {
return this.jdbcTemplate.queryForInt("SELECT COUNT(0) FROM " + tableName);
return this.jdbcTemplate.queryForObject("SELECT COUNT(0) FROM " + tableName, Integer.class);
}
......
......@@ -109,7 +109,7 @@ public class HibernateSessionFlushingTests extends AbstractTransactionalJUnit4Sp
// finally flushed (i.e., in production code)
}
@Test(expected = GenericJDBCException.class)
@Test(expected = ConstraintViolationException.class)
public void updateSamWithNullDriversLicenseWithSessionFlush() {
updateSamWithNullDriversLicense();
// Manual flush is required to avoid false positive in test
......
......@@ -2,7 +2,7 @@ DROP TABLE drivers_license IF EXISTS;
DROP TABLE person IF EXISTS;
CREATE TABLE person (
id INTEGER NOT NULL IDENTITY PRIMARY KEY,
id INTEGER NOT NULL IDENTITY,
name VARCHAR(50) NOT NULL,
drivers_license_id INTEGER NOT NULL
);
......@@ -10,7 +10,7 @@ CREATE UNIQUE INDEX person_name ON person(name);
CREATE UNIQUE INDEX person_drivers_license_id ON person(drivers_license_id);
CREATE TABLE drivers_license (
id INTEGER NOT NULL IDENTITY PRIMARY KEY,
id INTEGER NOT NULL IDENTITY,
license_number INTEGER NOT NULL
);
CREATE UNIQUE INDEX drivers_license_license_number ON drivers_license(license_number);
CREATE TABLE enigma (
id INTEGER NOT NULL IDENTITY PRIMARY KEY
id INTEGER NOT NULL IDENTITY
);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册