|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2013 the original author or authors. |
| 2 | + * Copyright 2002-2014 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
35 | 35 | import org.apache.commons.logging.Log;
|
36 | 36 | import org.apache.commons.logging.LogFactory;
|
37 | 37 |
|
| 38 | +import org.springframework.core.SpringProperties; |
38 | 39 | import org.springframework.jdbc.support.SqlValue;
|
39 | 40 |
|
40 | 41 | /**
|
|
59 | 60 | */
|
60 | 61 | public abstract class StatementCreatorUtils {
|
61 | 62 |
|
62 |
| - private static final Log logger = LogFactory.getLog(StatementCreatorUtils.class); |
| 63 | + /** |
| 64 | + * System property that instructs Spring to ignore {@link java.sql.ParameterMetaData#getParameterType} |
| 65 | + * completely, i.e. to never even attempt to retrieve {@link PreparedStatement#getParameterMetaData()} |
| 66 | + * for {@link StatementCreatorUtils#setNull} calls. |
| 67 | + * <p>The default is "false", trying {@code getParameterType} calls first and falling back to |
| 68 | + * {@link PreparedStatement#setNull} / {@link PreparedStatement#setObject} calls based on well-known |
| 69 | + * behavior of common databases. Spring records JDBC drivers with non-working {@code getParameterType} |
| 70 | + * implementations and won't attempt to call that method for that driver again, always falling back. |
| 71 | + * <p>Consider switching this flag to "true" if you experience misbehavior at runtime, e.g. with |
| 72 | + * a connection pool setting back the {@link PreparedStatement} instance in case of an exception |
| 73 | + * thrown from {@code getParameterType} (as reported on JBoss AS 7). |
| 74 | + */ |
| 75 | + public static final String IGNORE_GETPARAMETERTYPE_PROPERTY_NAME = "spring.jdbc.getParameterType.ignore"; |
| 76 | + |
| 77 | + |
| 78 | + static final boolean shouldIgnoreGetParameterType = SpringProperties.getFlag(IGNORE_GETPARAMETERTYPE_PROPERTY_NAME); |
63 | 79 |
|
64 | 80 | // Using a ConcurrentHashMap as a Set (for Java 5 compatibility)
|
65 | 81 | static final Map<String, Boolean> driversWithNoSupportForGetParameterType =
|
66 | 82 | new ConcurrentHashMap<String, Boolean>(1);
|
67 | 83 |
|
| 84 | + private static final Log logger = LogFactory.getLog(StatementCreatorUtils.class); |
| 85 | + |
68 | 86 | private static final Map<Class<?>, Integer> javaTypeToSqlTypeMap = new HashMap<Class<?>, Integer>(32);
|
69 | 87 |
|
70 | 88 | static {
|
@@ -227,8 +245,8 @@ private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, S
|
227 | 245 | Integer sqlTypeToUse = null;
|
228 | 246 | DatabaseMetaData dbmd = null;
|
229 | 247 | String jdbcDriverName = null;
|
230 |
| - boolean checkGetParameterType = true; |
231 |
| - if (!driversWithNoSupportForGetParameterType.isEmpty()) { |
| 248 | + boolean checkGetParameterType = !shouldIgnoreGetParameterType; |
| 249 | + if (checkGetParameterType && !driversWithNoSupportForGetParameterType.isEmpty()) { |
232 | 250 | try {
|
233 | 251 | dbmd = ps.getConnection().getMetaData();
|
234 | 252 | jdbcDriverName = dbmd.getDriverName();
|
|
0 commit comments