Skip to content

Commit 75bd516

Browse files
committed
Refined TemporaryLobCreator null handling (from 4.3.x)
Issue: SPR-15656
1 parent 10139d4 commit 75bd516

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/PostgresCallMetaDataProvider.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -78,4 +78,5 @@ public SqlParameter createDefaultOutParameter(String parameterName, CallParamete
7878
public boolean byPassReturnParameter(String parameterName) {
7979
return RETURN_VALUE_NAME.equals(parameterName);
8080
}
81+
8182
}

spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,24 @@ public abstract class RdbmsOperation implements InitializingBean {
8989

9090

9191
/**
92-
* An alternative to the more commonly used setDataSource() when you want to
93-
* use the same JdbcTemplate in multiple RdbmsOperations. This is appropriate if the
94-
* JdbcTemplate has special configuration such as a SQLExceptionTranslator that should
95-
* apply to multiple RdbmsOperation objects.
92+
* An alternative to the more commonly used {@link #setDataSource} when you want to
93+
* use the same {@link JdbcTemplate} in multiple {@code RdbmsOperations}. This is
94+
* appropriate if the {@code JdbcTemplate} has special configuration such as a
95+
* {@link org.springframework.jdbc.support.SQLExceptionTranslator} to be reused.
9696
*/
9797
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
9898
this.jdbcTemplate = jdbcTemplate;
9999
}
100100

101101
/**
102-
* Return the JdbcTemplate object used by this object.
102+
* Return the {@link JdbcTemplate} used by this operation object.
103103
*/
104104
public JdbcTemplate getJdbcTemplate() {
105105
return this.jdbcTemplate;
106106
}
107107

108108
/**
109-
* Set the JDBC DataSource to obtain connections from.
109+
* Set the JDBC {@link DataSource} to obtain connections from.
110110
* @see org.springframework.jdbc.core.JdbcTemplate#setDataSource
111111
*/
112112
public void setDataSource(DataSource dataSource) {
@@ -409,7 +409,7 @@ protected void validateParameters(@Nullable Object[] parameters) throws InvalidD
409409
* Validate the named parameters passed to an execute method based on declared parameters.
410410
* Subclasses should invoke this method before every {@code executeQuery()} or
411411
* {@code update()} method.
412-
* @param parameters parameter Map supplied. May be {@code null}.
412+
* @param parameters parameter Map supplied (may be {@code null})
413413
* @throws InvalidDataAccessApiUsageException if the parameters are invalid
414414
*/
415415
protected void validateNamedParameters(@Nullable Map<String, ?> parameters) throws InvalidDataAccessApiUsageException {

spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/TemporaryLobCreator.java

+19-10
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ public class TemporaryLobCreator implements LobCreator {
6060
public void setBlobAsBytes(PreparedStatement ps, int paramIndex, @Nullable byte[] content)
6161
throws SQLException {
6262

63-
Blob blob = ps.getConnection().createBlob();
64-
blob.setBytes(1, content);
65-
66-
this.temporaryBlobs.add(blob);
67-
ps.setBlob(paramIndex, blob);
63+
if (content != null) {
64+
Blob blob = ps.getConnection().createBlob();
65+
blob.setBytes(1, content);
66+
this.temporaryBlobs.add(blob);
67+
ps.setBlob(paramIndex, blob);
68+
}
69+
else {
70+
ps.setBlob(paramIndex, (Blob) null);
71+
}
6872

6973
if (logger.isDebugEnabled()) {
7074
logger.debug(content != null ? "Copied bytes into temporary BLOB with length " + content.length :
@@ -103,11 +107,15 @@ public void setBlobAsBinaryStream(
103107
public void setClobAsString(PreparedStatement ps, int paramIndex, @Nullable String content)
104108
throws SQLException {
105109

106-
Clob clob = ps.getConnection().createClob();
107-
clob.setString(1, content);
108-
109-
this.temporaryClobs.add(clob);
110-
ps.setClob(paramIndex, clob);
110+
if (content != null) {
111+
Clob clob = ps.getConnection().createClob();
112+
clob.setString(1, content);
113+
this.temporaryClobs.add(clob);
114+
ps.setClob(paramIndex, clob);
115+
}
116+
else {
117+
ps.setClob(paramIndex, (Clob) null);
118+
}
111119

112120
if (logger.isDebugEnabled()) {
113121
logger.debug(content != null ? "Copied string into temporary CLOB with length " + content.length() :
@@ -183,4 +191,5 @@ public void close() {
183191
logger.error("Could not free LOB", ex);
184192
}
185193
}
194+
186195
}

spring-jms/src/main/java/org/springframework/jms/listener/adapter/AbstractAdaptableMessageListener.java

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public void setResponseQosSettings(@Nullable QosSettings responseQosSettings) {
189189
/**
190190
* Return the {@link QosSettings} to use when sending a response,
191191
* or {@code null} if the defaults should be used.
192+
* @since 5.0
192193
*/
193194
@Nullable
194195
protected QosSettings getResponseQosSettings() {

0 commit comments

Comments
 (0)