From e8a0ef0206924c4e4a2227467fc419aaba955cb9 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 12 Nov 2015 00:48:14 +0100 Subject: [PATCH] Polishing --- .../jdbc/core/simple/SimpleJdbcCall.java | 21 ++++++++++--------- .../core/simple/CallMetaDataContextTests.java | 20 ++++++++++++++++++ .../jdbc/core/simple/SimpleJdbcCallTests.java | 13 ++++++++---- .../core/simple/SimpleJdbcInsertTests.java | 13 ++++++++---- .../simple/TableMetaDataContextTests.java | 9 ++++---- 5 files changed, 54 insertions(+), 22 deletions(-) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCall.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCall.java index cad54c599cb..e08be0acd66 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCall.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCall.java @@ -39,18 +39,19 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource; * the JDBC driver. Since we rely on the JDBC driver, this "auto-detection" * can only be used for databases that are known to provide accurate meta data. * These currently include Derby, MySQL, Microsoft SQL Server, Oracle, DB2, - * Sybase and PostgreSQL. For any other databases you are required to declare all - * parameters explicitly. You can of course declare all parameters explicitly even - * if the database provides the necessary meta data. In that case your declared - * parameters will take precedence. You can also turn off any meta data processing - * if you want to use parameter names that do not match what is declared during - * the stored procedure compilation. + * Sybase and PostgreSQL. For any other databases you are required to declare + * all parameters explicitly. You can of course declare all parameters + * explicitly even if the database provides the necessary meta data. In that + * case your declared parameters will take precedence. You can also turn off + * any metadata processing if you want to use parameter names that do not + * match what is declared during the stored procedure compilation. * *

The actual insert is being handled using Spring's * {@link org.springframework.jdbc.core.JdbcTemplate}. * - *

Many of the configuration methods return the current instance of the SimpleJdbcCall - * to provide the ability to chain multiple ones together in a "fluent" interface style. + *

Many of the configuration methods return the current instance of the + * SimpleJdbcCall in order to provide the ability to chain multiple ones + * together in a "fluent" interface style. * * @author Thomas Risberg * @author Stephane Nicoll @@ -61,8 +62,8 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource; public class SimpleJdbcCall extends AbstractJdbcCall implements SimpleJdbcCallOperations { /** - * Constructor that takes one parameter with the JDBC DataSource to use when creating the - * JdbcTemplate. + * Constructor that takes one parameter with the JDBC DataSource to use when + * creating the underlying JdbcTemplate. * @param dataSource the {@code DataSource} to use * @see org.springframework.jdbc.core.JdbcTemplate#setDataSource */ diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/CallMetaDataContextTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/CallMetaDataContextTests.java index c4a497a4863..64729db886d 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/CallMetaDataContextTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/CallMetaDataContextTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2002-2015 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.core.simple; import java.sql.Connection; @@ -29,11 +45,14 @@ import static org.mockito.BDDMockito.*; public class CallMetaDataContextTests { private DataSource dataSource; + private Connection connection; + private DatabaseMetaData databaseMetaData; private CallMetaDataContext context = new CallMetaDataContext(); + @Before public void setUp() throws Exception { connection = mock(Connection.class); @@ -48,6 +67,7 @@ public class CallMetaDataContextTests { verify(connection).close(); } + @Test public void testMatchParameterValuesAndSqlInOutParameters() throws Exception { final String TABLE = "customers"; diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcCallTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcCallTests.java index 692b87e02fa..0681b4b0e14 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcCallTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcCallTests.java @@ -49,13 +49,17 @@ import static org.springframework.tests.Matchers.*; */ public class SimpleJdbcCallTests { + private Connection connection; + + private DatabaseMetaData databaseMetaData; + + private DataSource dataSource; + + private CallableStatement callableStatement; + @Rule public ExpectedException thrown = ExpectedException.none(); - private Connection connection; - private DatabaseMetaData databaseMetaData; - private DataSource dataSource; - private CallableStatement callableStatement; @Before public void setUp() throws Exception { @@ -67,6 +71,7 @@ public class SimpleJdbcCallTests { given(dataSource.getConnection()).willReturn(connection); } + @Test public void testNoSuchStoredProcedure() throws Exception { final String NO_SUCH_PROC = "x"; diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertTests.java index 2bd32f1a9d8..aaa6a87e83c 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -39,12 +39,15 @@ import static org.mockito.BDDMockito.*; */ public class SimpleJdbcInsertTests { + private Connection connection; + + private DatabaseMetaData databaseMetaData; + + private DataSource dataSource; + @Rule public ExpectedException thrown = ExpectedException.none(); - private Connection connection; - private DatabaseMetaData databaseMetaData; - private DataSource dataSource; @Before public void setUp() throws Exception { @@ -60,6 +63,7 @@ public class SimpleJdbcInsertTests { verify(connection).close(); } + @Test public void testNoSuchTable() throws Exception { ResultSet resultSet = mock(ResultSet.class); @@ -81,4 +85,5 @@ public class SimpleJdbcInsertTests { verify(resultSet).close(); } } + } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/TableMetaDataContextTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/TableMetaDataContextTests.java index 16b43d685dc..d7bf27e37fb 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/TableMetaDataContextTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/TableMetaDataContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -43,11 +43,14 @@ import static org.mockito.BDDMockito.*; public class TableMetaDataContextTests { private Connection connection; + private DataSource dataSource; + private DatabaseMetaData databaseMetaData; private TableMetaDataContext context = new TableMetaDataContext(); + @Before public void setUp() throws Exception { connection = mock(Connection.class); @@ -57,9 +60,6 @@ public class TableMetaDataContextTests { given(dataSource.getConnection()).willReturn(connection); } - public void verifyClosed() throws Exception { - verify(connection).close(); - } @Test public void testMatchInParametersAndSqlTypeInfoWrapping() throws Exception { @@ -153,4 +153,5 @@ public class TableMetaDataContextTests { verify(metaDataResultSet).close(); verify(columnsResultSet).close(); } + }