Sync with 3.1.x
* 3.1.x: (61 commits) Compensate for changes in JDK 7 Introspector Avoid 'type mismatch' errors in ExtendedBeanInfo Polish ExtendedBeanInfo and tests Infer AnnotationAttributes method return types Minor fix in MVC reference doc chapter Hibernate 4.1 etc TypeDescriptor equals implementation accepts annotations in any order "setBasenames" uses varargs now (for programmatic setup; SPR-9106) @ActiveProfiles mechanism works with @ImportResource as well (SPR-8992 polishing clarified Resource's "getFilename" method to consistently return null substituteNamedParameters detects and unwraps SqlParameterValue object Replace spaces with tabs Consider security in ClassUtils#getMostSpecificMethod Adding null check for username being null. Improvements for registering custom SQL exception translators in app c SPR-7680 Adding QueryTimeoutException to the DataAccessException hiera Minor polish in WebMvcConfigurationSupport Detect overridden boolean getters in ExtendedBeanInfo Polish ExtendedBeanInfoTests ...
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -268,4 +268,30 @@ public class NamedParameterUtilsTests {
|
||||
assertEquals(expectedSql, newSql);
|
||||
}
|
||||
|
||||
/*
|
||||
* SPR-8280
|
||||
*/
|
||||
@Test
|
||||
public void parseSqlStatementWithQuotedSingleQuote() {
|
||||
String sql = "SELECT ':foo'':doo', :xxx FROM DUAL";
|
||||
ParsedSql psql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
assertEquals(1, psql.getTotalParameterCount());
|
||||
assertEquals("xxx", psql.getParameterNames().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSqlStatementWithQuotesAndCommentBefore() {
|
||||
String sql = "SELECT /*:doo*/':foo', :xxx FROM DUAL";
|
||||
ParsedSql psql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
assertEquals(1, psql.getTotalParameterCount());
|
||||
assertEquals("xxx", psql.getParameterNames().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSqlStatementWithQuotesAndCommentAfter() {
|
||||
String sql2 = "SELECT ':foo'/*:doo*/, :xxx FROM DUAL";
|
||||
ParsedSql psql2 = NamedParameterUtils.parseSqlStatement(sql2);
|
||||
assertEquals(1, psql2.getTotalParameterCount());
|
||||
assertEquals("xxx", psql2.getParameterNames().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.ClassRelativeResourceLoader;
|
||||
@@ -49,7 +47,7 @@ public class DatabasePopulatorTests {
|
||||
assertEquals(name, jdbcTemplate.queryForObject("select NAME from T_TEST", String.class));
|
||||
}
|
||||
|
||||
private void assertUsersDatabaseCreated(DataSource db) {
|
||||
private void assertUsersDatabaseCreated() {
|
||||
assertEquals("Sam", jdbcTemplate.queryForObject("select first_name from users where last_name = 'Brannen'",
|
||||
String.class));
|
||||
}
|
||||
@@ -191,7 +189,22 @@ public class DatabasePopulatorTests {
|
||||
connection.close();
|
||||
}
|
||||
|
||||
assertUsersDatabaseCreated(db);
|
||||
assertUsersDatabaseCreated();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildWithSelectStatements() throws Exception {
|
||||
databasePopulator.addScript(resourceLoader.getResource("db-schema.sql"));
|
||||
databasePopulator.addScript(resourceLoader.getResource("db-test-data-select.sql"));
|
||||
Connection connection = db.getConnection();
|
||||
try {
|
||||
databasePopulator.populate(connection);
|
||||
} finally {
|
||||
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'"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.jdbc.support;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.TransientDataAccessResourceException;
|
||||
import org.springframework.jdbc.BadSqlGrammarException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests for custom translator.
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
*/
|
||||
public class CustomSQLExceptionTranslatorRegistrarTests {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
new ClassPathXmlApplicationContext("test-custom-translators-context.xml",
|
||||
CustomSQLExceptionTranslatorRegistrarTests.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomErrorCodeTranslation() {
|
||||
|
||||
SQLErrorCodes codes = SQLErrorCodesFactory.getInstance().getErrorCodes("H2");
|
||||
SQLErrorCodeSQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator();
|
||||
sext.setSqlErrorCodes(codes);
|
||||
|
||||
DataAccessException exFor4200 = sext.doTranslate("", "", new SQLException("Ouch", "42000", 42000));
|
||||
assertNotNull("Should have been translated", exFor4200);
|
||||
assertTrue("Should have been instance of BadSqlGrammarException",
|
||||
BadSqlGrammarException.class.isAssignableFrom(exFor4200.getClass()));
|
||||
|
||||
DataAccessException exFor2 = sext.doTranslate("", "", new SQLException("Ouch", "42000", 2));
|
||||
assertNotNull("Should have been translated", exFor2);
|
||||
assertTrue("Should have been instance of TransientDataAccessResourceException",
|
||||
TransientDataAccessResourceException.class.isAssignableFrom(exFor2.getClass()));
|
||||
|
||||
DataAccessException exFor3 = sext.doTranslate("", "", new SQLException("Ouch", "42000", 3));
|
||||
assertNull("Should not have been translated", exFor3);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user