|
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.
|
|
37 | 37 | import org.apache.commons.logging.Log;
|
38 | 38 | import org.apache.commons.logging.LogFactory;
|
39 | 39 |
|
| 40 | +import org.springframework.core.SpringProperties; |
40 | 41 | import org.springframework.jdbc.support.SqlValue;
|
41 | 42 |
|
42 | 43 | /**
|
|
61 | 62 | */
|
62 | 63 | public abstract class StatementCreatorUtils {
|
63 | 64 |
|
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); |
65 | 79 |
|
66 | 80 | static final Set<String> driversWithNoSupportForGetParameterType =
|
67 | 81 | Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>(1));
|
68 | 82 |
|
| 83 | + private static final Log logger = LogFactory.getLog(StatementCreatorUtils.class); |
| 84 | + |
69 | 85 | private static final Map<Class<?>, Integer> javaTypeToSqlTypeMap = new HashMap<Class<?>, Integer>(32);
|
70 | 86 |
|
71 | 87 | static {
|
@@ -228,8 +244,8 @@ private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, S
|
228 | 244 | Integer sqlTypeToUse = null;
|
229 | 245 | DatabaseMetaData dbmd = null;
|
230 | 246 | String jdbcDriverName = null;
|
231 |
| - boolean checkGetParameterType = true; |
232 |
| - if (!driversWithNoSupportForGetParameterType.isEmpty()) { |
| 247 | + boolean checkGetParameterType = !shouldIgnoreGetParameterType; |
| 248 | + if (checkGetParameterType && !driversWithNoSupportForGetParameterType.isEmpty()) { |
233 | 249 | try {
|
234 | 250 | dbmd = ps.getConnection().getMetaData();
|
235 | 251 | jdbcDriverName = dbmd.getDriverName();
|
|
0 commit comments