From 8d707eb5304e42babe3d680c5cd3880869cfabe2 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 16 Feb 2017 15:37:31 +0100 Subject: [PATCH] Polishing --- .../xml/BeanDefinitionParserDelegate.java | 2 +- .../jboss/JBossLoadTimeWeaver.java | 2 +- .../simple/SimpleJdbcInsertOperations.java | 5 +- .../jdbc/core/JdbcTemplateTests.java | 73 +++++++++++-------- 4 files changed, 48 insertions(+), 34 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java index d28f155c208..b13b292d387 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/jboss/JBossLoadTimeWeaver.java b/spring-context/src/main/java/org/springframework/instrument/classloading/jboss/JBossLoadTimeWeaver.java index 11add17d75d..16b0d0b3351 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/jboss/JBossLoadTimeWeaver.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/jboss/JBossLoadTimeWeaver.java @@ -85,7 +85,7 @@ public class JBossLoadTimeWeaver implements LoadTimeWeaver { if (this.addTransformer == null) { throw new IllegalArgumentException( "Could not find 'addTransformer' method on JBoss DelegatingClassFileTransformer: " + - this.delegatingTransformer.getClass().getName()); + this.delegatingTransformer.getClass().getName()); } this.addTransformer.setAccessible(true); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertOperations.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertOperations.java index 9af301d63ad..b260dc825b1 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertOperations.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertOperations.java @@ -74,9 +74,8 @@ public interface SimpleJdbcInsertOperations { /** * Include synonyms for the column meta data lookups via JDBC. - * Note: this is only necessary to include for Oracle since other - * databases supporting synonyms seems to include the synonyms - * automatically. + *

Note: This is only necessary to include for Oracle since other databases + * supporting synonyms seems to include the synonyms automatically. * @return the instance of this SimpleJdbcInsert */ SimpleJdbcInsertOperations includeSynonymsForTableColumnMetaData(); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java index 3d1220fcabb..03506699d91 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java @@ -45,6 +45,7 @@ import org.springframework.jdbc.CannotGetJdbcConnectionException; import org.springframework.jdbc.SQLWarningException; import org.springframework.jdbc.UncategorizedSQLException; import org.springframework.jdbc.core.support.AbstractInterruptibleBatchPreparedStatementSetter; +import org.springframework.jdbc.datasource.ConnectionProxy; import org.springframework.jdbc.datasource.SingleConnectionDataSource; import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator; @@ -65,17 +66,24 @@ import static org.springframework.tests.Matchers.*; */ public class JdbcTemplateTests { - @Rule - public ExpectedException thrown = ExpectedException.none(); - private Connection connection; + private DataSource dataSource; + private PreparedStatement preparedStatement; + private Statement statement; + private ResultSet resultSet; + private JdbcTemplate template; + private CallableStatement callableStatement; + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before public void setup() throws Exception { this.connection = mock(Connection.class); @@ -96,6 +104,7 @@ public class JdbcTemplateTests { given(this.callableStatement.getResultSet()).willReturn(this.resultSet); } + @Test public void testBeanProperties() throws Exception { assertTrue("datasource ok", this.template.getDataSource() == this.dataSource); @@ -141,10 +150,9 @@ public class JdbcTemplateTests { @Test public void testStringsWithStaticSql() throws Exception { - doTestStrings(false, null, null, null, null, new JdbcTemplateCallback() { + doTestStrings(null, null, null, null, new JdbcTemplateCallback() { @Override - public void doInJdbcTemplate(JdbcTemplate template, String sql, - RowCallbackHandler rch) { + public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) { template.query(sql, rch); } }); @@ -152,10 +160,9 @@ public class JdbcTemplateTests { @Test public void testStringsWithStaticSqlAndFetchSizeAndMaxRows() throws Exception { - doTestStrings(false, 10, 20, 30, null, new JdbcTemplateCallback() { + doTestStrings(10, 20, 30, null, new JdbcTemplateCallback() { @Override - public void doInJdbcTemplate(JdbcTemplate template, String sql, - RowCallbackHandler rch) { + public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) { template.query(sql, rch); } }); @@ -163,10 +170,9 @@ public class JdbcTemplateTests { @Test public void testStringsWithEmptyPreparedStatementSetter() throws Exception { - doTestStrings(true, null, null, null, null, new JdbcTemplateCallback() { + doTestStrings(null, null, null, null, new JdbcTemplateCallback() { @Override - public void doInJdbcTemplate(JdbcTemplate template, String sql, - RowCallbackHandler rch) { + public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) { template.query(sql, (PreparedStatementSetter) null, rch); } }); @@ -175,10 +181,9 @@ public class JdbcTemplateTests { @Test public void testStringsWithPreparedStatementSetter() throws Exception { final Integer argument = 99; - doTestStrings(true, null, null, null, argument, new JdbcTemplateCallback() { + doTestStrings(null, null, null, argument, new JdbcTemplateCallback() { @Override - public void doInJdbcTemplate(JdbcTemplate template, String sql, - RowCallbackHandler rch) { + public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) { template.query(sql, new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { @@ -191,10 +196,9 @@ public class JdbcTemplateTests { @Test public void testStringsWithEmptyPreparedStatementArgs() throws Exception { - doTestStrings(true, null, null, null, null, new JdbcTemplateCallback() { + doTestStrings(null, null, null, null, new JdbcTemplateCallback() { @Override - public void doInJdbcTemplate(JdbcTemplate template, String sql, - RowCallbackHandler rch) { + public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) { template.query(sql, (Object[]) null, rch); } }); @@ -203,20 +207,16 @@ public class JdbcTemplateTests { @Test public void testStringsWithPreparedStatementArgs() throws Exception { final Integer argument = 99; - doTestStrings(true, null, null, null, argument, new JdbcTemplateCallback() { + doTestStrings(null, null, null, argument, new JdbcTemplateCallback() { @Override - public void doInJdbcTemplate(JdbcTemplate template, String sql, - RowCallbackHandler rch) { + public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) { template.query(sql, new Object[] { argument }, rch); } }); } - private void doTestStrings( - boolean usePreparedStatement, - Integer fetchSize, Integer maxRows, Integer queryTimeout, Object argument, - JdbcTemplateCallback jdbcTemplateCallback) - throws Exception { + private void doTestStrings(Integer fetchSize, Integer maxRows, Integer queryTimeout, + Object argument, JdbcTemplateCallback jdbcTemplateCallback) throws Exception { String sql = "SELECT FORENAME FROM CUSTMR"; String[] results = { "rod", "gary", " portia" }; @@ -293,6 +293,19 @@ public class JdbcTemplateTests { verify(this.preparedStatement).close(); } + @Test + public void testConnectionCallback() throws Exception { + String result = this.template.execute(new ConnectionCallback() { + @Override + public String doInConnection(Connection con) { + assertTrue(con instanceof ConnectionProxy); + assertSame(JdbcTemplateTests.this.connection, ((ConnectionProxy) con).getTargetConnection()); + return "test"; + } + }); + assertEquals("test", result); + } + @Test public void testConnectionCallbackWithStatementSettings() throws Exception { String result = this.template.execute(new ConnectionCallback() { @@ -724,7 +737,6 @@ public class JdbcTemplateTests { @Test public void testBatchUpdateWithListOfObjectArrays() throws Exception { - final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final List ids = new ArrayList<>(); ids.add(new Object[] {100}); @@ -835,13 +847,15 @@ public class JdbcTemplateTests { @Test public void testCouldntGetConnectionInOperationWithExceptionTranslatorInitializedViaBeanProperty() - throws Exception { + throws SQLException { + doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(true); } @Test public void testCouldntGetConnectionInOperationWithExceptionTranslatorInitializedInAfterPropertiesSet() - throws Exception { + throws SQLException { + doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(false); } @@ -851,6 +865,7 @@ public class JdbcTemplateTests { */ private void doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(boolean beanProperty) throws SQLException { + SQLException sqlException = new SQLException("foo", "07xxx"); this.dataSource = mock(DataSource.class); given(this.dataSource.getConnection()).willThrow(sqlException);