Skip to content

Commit 60c1905

Browse files
committed
Introduced "spring.jdbc.getParameterType.ignore" property
Issue: SPR-11386
1 parent 1a8629d commit 60c1905

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

spring-core/src/main/java/org/springframework/core/SpringProperties.java

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* @since 3.2.7
4242
* @see org.springframework.core.env.AbstractEnvironment#IGNORE_GETENV_PROPERTY_NAME
4343
* @see org.springframework.beans.CachedIntrospectionResults#IGNORE_BEANINFO_PROPERTY_NAME
44+
* @see org.springframework.jdbc.core.StatementCreatorUtils#IGNORE_GETPARAMETERTYPE_PROPERTY_NAME
4445
*/
4546
public abstract class SpringProperties {
4647

spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -37,6 +37,7 @@
3737
import org.apache.commons.logging.Log;
3838
import org.apache.commons.logging.LogFactory;
3939

40+
import org.springframework.core.SpringProperties;
4041
import org.springframework.jdbc.support.SqlValue;
4142

4243
/**
@@ -61,11 +62,26 @@
6162
*/
6263
public abstract class StatementCreatorUtils {
6364

64-
private static final Log logger = LogFactory.getLog(StatementCreatorUtils.class);
65+
/**
66+
* System property that instructs Spring to ignore {@link java.sql.ParameterMetaData#getParameterType}
67+
* completely, i.e. to never even attempt to retrieve {@link PreparedStatement#getParameterMetaData()}.
68+
* <p>The default is "false", trying {@code getParameterType} calls first and falling back to
69+
* {@link PreparedStatement#setNull} / {@link PreparedStatement#setObject} calls based on well-known
70+
* behavior of common databases. Spring records JDBC drivers with non-working {@code getParameterType}
71+
* implementations and won't attempt to call that method for that driver again, always falling back.
72+
* <p>Consider switching this flag to "true" if you experience misbehavior at runtime, e.g. with
73+
* a connection pool setting back the {@link PreparedStatement} instance in case of an exception
74+
* thrown from {@code getParameterType} (e.g. on JBoss AS 7).
75+
*/
76+
public static final String IGNORE_GETPARAMETERTYPE_PROPERTY_NAME = "spring.jdbc.getParameterType.ignore";
77+
78+
static final boolean shouldIgnoreGetParameterType = SpringProperties.getFlag(IGNORE_GETPARAMETERTYPE_PROPERTY_NAME);
6579

6680
static final Set<String> driversWithNoSupportForGetParameterType =
6781
Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>(1));
6882

83+
private static final Log logger = LogFactory.getLog(StatementCreatorUtils.class);
84+
6985
private static final Map<Class<?>, Integer> javaTypeToSqlTypeMap = new HashMap<Class<?>, Integer>(32);
7086

7187
static {
@@ -228,8 +244,8 @@ private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, S
228244
Integer sqlTypeToUse = null;
229245
DatabaseMetaData dbmd = null;
230246
String jdbcDriverName = null;
231-
boolean checkGetParameterType = true;
232-
if (!driversWithNoSupportForGetParameterType.isEmpty()) {
247+
boolean checkGetParameterType = !shouldIgnoreGetParameterType;
248+
if (checkGetParameterType && !driversWithNoSupportForGetParameterType.isEmpty()) {
233249
try {
234250
dbmd = ps.getConnection().getMetaData();
235251
jdbcDriverName = dbmd.getDriverName();

0 commit comments

Comments
 (0)