Apply 'instanceof pattern matching' in spring-jdbc
This commit is contained in:
		
							parent
							
								
									73a18046c3
								
							
						
					
					
						commit
						114d6a9256
					
				|  | @ -1,5 +1,5 @@ | ||||||
| /* | /* | ||||||
|  * Copyright 2002-2021 the original author or authors. |  * Copyright 2002-2022 the original author or authors. | ||||||
|  * |  * | ||||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); |  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  * you may not use this file except in compliance with the License. |  * you may not use this file except in compliance with the License. | ||||||
|  | @ -655,8 +655,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { | ||||||
| 		catch (SQLException ex) { | 		catch (SQLException ex) { | ||||||
| 			// Release Connection early, to avoid potential connection pool deadlock | 			// Release Connection early, to avoid potential connection pool deadlock | ||||||
| 			// in the case when the exception translator hasn't been initialized yet. | 			// in the case when the exception translator hasn't been initialized yet. | ||||||
| 			if (psc instanceof ParameterDisposer) { | 			if (psc instanceof ParameterDisposer parameterDisposer) { | ||||||
| 				((ParameterDisposer) psc).cleanupParameters(); | 				parameterDisposer.cleanupParameters(); | ||||||
| 			} | 			} | ||||||
| 			String sql = getSql(psc); | 			String sql = getSql(psc); | ||||||
| 			psc = null; | 			psc = null; | ||||||
|  | @ -668,8 +668,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { | ||||||
| 		} | 		} | ||||||
| 		finally { | 		finally { | ||||||
| 			if (closeResources) { | 			if (closeResources) { | ||||||
| 				if (psc instanceof ParameterDisposer) { | 				if (psc instanceof ParameterDisposer parameterDisposer) { | ||||||
| 					((ParameterDisposer) psc).cleanupParameters(); | 					parameterDisposer.cleanupParameters(); | ||||||
| 				} | 				} | ||||||
| 				JdbcUtils.closeStatement(ps); | 				JdbcUtils.closeStatement(ps); | ||||||
| 				DataSourceUtils.releaseConnection(con, getDataSource()); | 				DataSourceUtils.releaseConnection(con, getDataSource()); | ||||||
|  | @ -724,8 +724,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { | ||||||
| 				} | 				} | ||||||
| 				finally { | 				finally { | ||||||
| 					JdbcUtils.closeResultSet(rs); | 					JdbcUtils.closeResultSet(rs); | ||||||
| 					if (pss instanceof ParameterDisposer) { | 					if (pss instanceof ParameterDisposer parameterDisposer) { | ||||||
| 						((ParameterDisposer) pss).cleanupParameters(); | 						parameterDisposer.cleanupParameters(); | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  | @ -839,8 +839,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { | ||||||
| 			Connection con = ps.getConnection(); | 			Connection con = ps.getConnection(); | ||||||
| 			return new ResultSetSpliterator<>(rs, rowMapper).stream().onClose(() -> { | 			return new ResultSetSpliterator<>(rs, rowMapper).stream().onClose(() -> { | ||||||
| 				JdbcUtils.closeResultSet(rs); | 				JdbcUtils.closeResultSet(rs); | ||||||
| 				if (pss instanceof ParameterDisposer) { | 				if (pss instanceof ParameterDisposer parameterDisposer) { | ||||||
| 					((ParameterDisposer) pss).cleanupParameters(); | 					parameterDisposer.cleanupParameters(); | ||||||
| 				} | 				} | ||||||
| 				JdbcUtils.closeStatement(ps); | 				JdbcUtils.closeStatement(ps); | ||||||
| 				DataSourceUtils.releaseConnection(con, getDataSource()); | 				DataSourceUtils.releaseConnection(con, getDataSource()); | ||||||
|  | @ -969,8 +969,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { | ||||||
| 				return rows; | 				return rows; | ||||||
| 			} | 			} | ||||||
| 			finally { | 			finally { | ||||||
| 				if (pss instanceof ParameterDisposer) { | 				if (pss instanceof ParameterDisposer parameterDisposer) { | ||||||
| 					((ParameterDisposer) pss).cleanupParameters(); | 					parameterDisposer.cleanupParameters(); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		}, true)); | 		}, true)); | ||||||
|  | @ -1035,8 +1035,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { | ||||||
| 			try { | 			try { | ||||||
| 				int batchSize = pss.getBatchSize(); | 				int batchSize = pss.getBatchSize(); | ||||||
| 				InterruptibleBatchPreparedStatementSetter ipss = | 				InterruptibleBatchPreparedStatementSetter ipss = | ||||||
| 						(pss instanceof InterruptibleBatchPreparedStatementSetter ? | 						(pss instanceof InterruptibleBatchPreparedStatementSetter ibpss ? ibpss : null); | ||||||
| 						(InterruptibleBatchPreparedStatementSetter) pss : null); |  | ||||||
| 				if (JdbcUtils.supportsBatchUpdates(ps.getConnection())) { | 				if (JdbcUtils.supportsBatchUpdates(ps.getConnection())) { | ||||||
| 					for (int i = 0; i < batchSize; i++) { | 					for (int i = 0; i < batchSize; i++) { | ||||||
| 						pss.setValues(ps, i); | 						pss.setValues(ps, i); | ||||||
|  | @ -1064,8 +1063,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 			finally { | 			finally { | ||||||
| 				if (pss instanceof ParameterDisposer) { | 				if (pss instanceof ParameterDisposer parameterDisposer) { | ||||||
| 					((ParameterDisposer) pss).cleanupParameters(); | 					parameterDisposer.cleanupParameters(); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
|  | @ -1154,8 +1153,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { | ||||||
| 				return result1; | 				return result1; | ||||||
| 			} | 			} | ||||||
| 			finally { | 			finally { | ||||||
| 				if (pss instanceof ParameterDisposer) { | 				if (pss instanceof ParameterDisposer parameterDisposer) { | ||||||
| 					((ParameterDisposer) pss).cleanupParameters(); | 					parameterDisposer.cleanupParameters(); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
|  | @ -1193,8 +1192,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { | ||||||
| 		catch (SQLException ex) { | 		catch (SQLException ex) { | ||||||
| 			// Release Connection early, to avoid potential connection pool deadlock | 			// Release Connection early, to avoid potential connection pool deadlock | ||||||
| 			// in the case when the exception translator hasn't been initialized yet. | 			// in the case when the exception translator hasn't been initialized yet. | ||||||
| 			if (csc instanceof ParameterDisposer) { | 			if (csc instanceof ParameterDisposer parameterDisposer) { | ||||||
| 				((ParameterDisposer) csc).cleanupParameters(); | 				parameterDisposer.cleanupParameters(); | ||||||
| 			} | 			} | ||||||
| 			String sql = getSql(csc); | 			String sql = getSql(csc); | ||||||
| 			csc = null; | 			csc = null; | ||||||
|  | @ -1205,8 +1204,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { | ||||||
| 			throw translateException("CallableStatementCallback", sql, ex); | 			throw translateException("CallableStatementCallback", sql, ex); | ||||||
| 		} | 		} | ||||||
| 		finally { | 		finally { | ||||||
| 			if (csc instanceof ParameterDisposer) { | 			if (csc instanceof ParameterDisposer parameterDisposer) { | ||||||
| 				((ParameterDisposer) csc).cleanupParameters(); | 				parameterDisposer.cleanupParameters(); | ||||||
| 			} | 			} | ||||||
| 			JdbcUtils.closeStatement(cs); | 			JdbcUtils.closeStatement(cs); | ||||||
| 			DataSourceUtils.releaseConnection(con, getDataSource()); | 			DataSourceUtils.releaseConnection(con, getDataSource()); | ||||||
|  | @ -1345,14 +1344,14 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { | ||||||
| 				} | 				} | ||||||
| 				else { | 				else { | ||||||
| 					Object out = cs.getObject(sqlColIndex); | 					Object out = cs.getObject(sqlColIndex); | ||||||
| 					if (out instanceof ResultSet) { | 					if (out instanceof ResultSet resultSet) { | ||||||
| 						if (outParam.isResultSetSupported()) { | 						if (outParam.isResultSetSupported()) { | ||||||
| 							results.putAll(processResultSet((ResultSet) out, outParam)); | 							results.putAll(processResultSet(resultSet, outParam)); | ||||||
| 						} | 						} | ||||||
| 						else { | 						else { | ||||||
| 							String rsName = outParam.getName(); | 							String rsName = outParam.getName(); | ||||||
| 							SqlReturnResultSet rsParam = new SqlReturnResultSet(rsName, getColumnMapRowMapper()); | 							SqlReturnResultSet rsParam = new SqlReturnResultSet(rsName, getColumnMapRowMapper()); | ||||||
| 							results.putAll(processResultSet((ResultSet) out, rsParam)); | 							results.putAll(processResultSet(resultSet, rsParam)); | ||||||
| 							if (logger.isTraceEnabled()) { | 							if (logger.isTraceEnabled()) { | ||||||
| 								logger.trace("Added default SqlReturnResultSet parameter named '" + rsName + "'"); | 								logger.trace("Added default SqlReturnResultSet parameter named '" + rsName + "'"); | ||||||
| 							} | 							} | ||||||
|  | @ -1543,18 +1542,13 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { | ||||||
| 
 | 
 | ||||||
| 	/** | 	/** | ||||||
| 	 * Determine SQL from potential provider object. | 	 * Determine SQL from potential provider object. | ||||||
| 	 * @param sqlProvider object which is potentially an SqlProvider | 	 * @param obj object which is potentially an SqlProvider | ||||||
| 	 * @return the SQL string, or {@code null} if not known | 	 * @return the SQL string, or {@code null} if not known | ||||||
| 	 * @see SqlProvider | 	 * @see SqlProvider | ||||||
| 	 */ | 	 */ | ||||||
| 	@Nullable | 	@Nullable | ||||||
| 	private static String getSql(Object sqlProvider) { | 	private static String getSql(Object obj) { | ||||||
| 		if (sqlProvider instanceof SqlProvider) { | 		return (obj instanceof SqlProvider sqlProvider ? sqlProvider.getSql() : null); | ||||||
| 			return ((SqlProvider) sqlProvider).getSql(); |  | ||||||
| 		} |  | ||||||
| 		else { |  | ||||||
| 			return null; |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private static <T> T result(@Nullable T result) { | 	private static <T> T result(@Nullable T result) { | ||||||
|  | @ -1613,8 +1607,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { | ||||||
| 
 | 
 | ||||||
| 				// If return value is a JDBC Statement, apply statement settings | 				// If return value is a JDBC Statement, apply statement settings | ||||||
| 				// (fetch size, max rows, transaction timeout). | 				// (fetch size, max rows, transaction timeout). | ||||||
| 				if (retVal instanceof Statement) { | 				if (retVal instanceof Statement statement) { | ||||||
| 					applyStatementSettings(((Statement) retVal)); | 					applyStatementSettings(statement); | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				return retVal; | 				return retVal; | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| /* | /* | ||||||
|  * Copyright 2002-2021 the original author or authors. |  * Copyright 2002-2022 the original author or authors. | ||||||
|  * |  * | ||||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); |  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  * you may not use this file except in compliance with the License. |  * you may not use this file except in compliance with the License. | ||||||
|  | @ -206,8 +206,8 @@ public class PreparedStatementCreatorFactory { | ||||||
| 				Set<String> names = new HashSet<>(); | 				Set<String> names = new HashSet<>(); | ||||||
| 				for (int i = 0; i < parameters.size(); i++) { | 				for (int i = 0; i < parameters.size(); i++) { | ||||||
| 					Object param = parameters.get(i); | 					Object param = parameters.get(i); | ||||||
| 					if (param instanceof SqlParameterValue) { | 					if (param instanceof SqlParameterValue sqlParameterValue) { | ||||||
| 						names.add(((SqlParameterValue) param).getName()); | 						names.add(sqlParameterValue.getName()); | ||||||
| 					} | 					} | ||||||
| 					else { | 					else { | ||||||
| 						names.add("Parameter #" + i); | 						names.add("Parameter #" + i); | ||||||
|  | @ -252,9 +252,9 @@ public class PreparedStatementCreatorFactory { | ||||||
| 				SqlParameter declaredParameter; | 				SqlParameter declaredParameter; | ||||||
| 				// SqlParameterValue overrides declared parameter meta-data, in particular for | 				// SqlParameterValue overrides declared parameter meta-data, in particular for | ||||||
| 				// independence from the declared parameter position in case of named parameters. | 				// independence from the declared parameter position in case of named parameters. | ||||||
| 				if (in instanceof SqlParameterValue paramValue) { | 				if (in instanceof SqlParameterValue sqlParameterValue) { | ||||||
| 					in = paramValue.getValue(); | 					in = sqlParameterValue.getValue(); | ||||||
| 					declaredParameter = paramValue; | 					declaredParameter = sqlParameterValue; | ||||||
| 				} | 				} | ||||||
| 				else { | 				else { | ||||||
| 					if (declaredParameters.size() <= i) { | 					if (declaredParameters.size() <= i) { | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| /* | /* | ||||||
|  * Copyright 2002-2020 the original author or authors. |  * Copyright 2002-2022 the original author or authors. | ||||||
|  * |  * | ||||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); |  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  * you may not use this file except in compliance with the License. |  * you may not use this file except in compliance with the License. | ||||||
|  | @ -193,9 +193,9 @@ public class SingleColumnRowMapper<T> implements RowMapper<T> { | ||||||
| 			return value.toString(); | 			return value.toString(); | ||||||
| 		} | 		} | ||||||
| 		else if (Number.class.isAssignableFrom(requiredType)) { | 		else if (Number.class.isAssignableFrom(requiredType)) { | ||||||
| 			if (value instanceof Number) { | 			if (value instanceof Number number) { | ||||||
| 				// Convert original Number to target Number class. | 				// Convert original Number to target Number class. | ||||||
| 				return NumberUtils.convertNumberToTargetClass(((Number) value), (Class<Number>) requiredType); | 				return NumberUtils.convertNumberToTargetClass(number, (Class<Number>) requiredType); | ||||||
| 			} | 			} | ||||||
| 			else { | 			else { | ||||||
| 				// Convert stringified value to target Number class. | 				// Convert stringified value to target Number class. | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| /* | /* | ||||||
|  * Copyright 2002-2021 the original author or authors. |  * Copyright 2002-2022 the original author or authors. | ||||||
|  * |  * | ||||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); |  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  * you may not use this file except in compliance with the License. |  * you may not use this file except in compliance with the License. | ||||||
|  | @ -569,8 +569,8 @@ public class CallMetaDataContext { | ||||||
| 			if (callParameterName == null) { | 			if (callParameterName == null) { | ||||||
| 				if (logger.isDebugEnabled()) { | 				if (logger.isDebugEnabled()) { | ||||||
| 					Object value = parameterValue; | 					Object value = parameterValue; | ||||||
| 					if (value instanceof SqlParameterValue) { | 					if (value instanceof SqlParameterValue sqlParameterValue) { | ||||||
| 						value = ((SqlParameterValue) value).getValue(); | 						value = sqlParameterValue.getValue(); | ||||||
| 					} | 					} | ||||||
| 					if (value != null) { | 					if (value != null) { | ||||||
| 						logger.debug("Unable to locate the corresponding IN or IN-OUT parameter for \"" + | 						logger.debug("Unable to locate the corresponding IN or IN-OUT parameter for \"" + | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| /* | /* | ||||||
|  * Copyright 2002-2019 the original author or authors. |  * Copyright 2002-2022 the original author or authors. | ||||||
|  * |  * | ||||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); |  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  * you may not use this file except in compliance with the License. |  * you may not use this file except in compliance with the License. | ||||||
|  | @ -105,8 +105,8 @@ public abstract class AbstractSqlParameterSource implements SqlParameterSource { | ||||||
| 			StringJoiner result = new StringJoiner(", ", getClass().getSimpleName() + " {", "}"); | 			StringJoiner result = new StringJoiner(", ", getClass().getSimpleName() + " {", "}"); | ||||||
| 			for (String parameterName : parameterNames) { | 			for (String parameterName : parameterNames) { | ||||||
| 				Object value = getValue(parameterName); | 				Object value = getValue(parameterName); | ||||||
| 				if (value instanceof SqlParameterValue) { | 				if (value instanceof SqlParameterValue sqlParameterValue) { | ||||||
| 					value = ((SqlParameterValue) value).getValue(); | 					value = sqlParameterValue.getValue(); | ||||||
| 				} | 				} | ||||||
| 				String typeName = getTypeName(parameterName); | 				String typeName = getTypeName(parameterName); | ||||||
| 				if (typeName == null) { | 				if (typeName == null) { | ||||||
|  |  | ||||||
|  | @ -291,11 +291,11 @@ public abstract class NamedParameterUtils { | ||||||
| 			actualSql.append(originalSql, lastIndex, startIndex); | 			actualSql.append(originalSql, lastIndex, startIndex); | ||||||
| 			if (paramSource != null && paramSource.hasValue(paramName)) { | 			if (paramSource != null && paramSource.hasValue(paramName)) { | ||||||
| 				Object value = paramSource.getValue(paramName); | 				Object value = paramSource.getValue(paramName); | ||||||
| 				if (value instanceof SqlParameterValue) { | 				if (value instanceof SqlParameterValue sqlParameterValue) { | ||||||
| 					value = ((SqlParameterValue) value).getValue(); | 					value = sqlParameterValue.getValue(); | ||||||
| 				} | 				} | ||||||
| 				if (value instanceof Iterable) { | 				if (value instanceof Iterable<?> iterable) { | ||||||
| 					Iterator<?> entryIter = ((Iterable<?>) value).iterator(); | 					Iterator<?> entryIter = iterable.iterator(); | ||||||
| 					int k = 0; | 					int k = 0; | ||||||
| 					while (entryIter.hasNext()) { | 					while (entryIter.hasNext()) { | ||||||
| 						if (k > 0) { | 						if (k > 0) { | ||||||
|  |  | ||||||
|  | @ -177,11 +177,11 @@ public class SqlLobValue implements DisposableSqlTypeValue { | ||||||
| 			if (this.content instanceof byte[] || this.content == null) { | 			if (this.content instanceof byte[] || this.content == null) { | ||||||
| 				this.lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) this.content); | 				this.lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) this.content); | ||||||
| 			} | 			} | ||||||
| 			else if (this.content instanceof String) { | 			else if (this.content instanceof String string) { | ||||||
| 				this.lobCreator.setBlobAsBytes(ps, paramIndex, ((String) this.content).getBytes()); | 				this.lobCreator.setBlobAsBytes(ps, paramIndex, string.getBytes()); | ||||||
| 			} | 			} | ||||||
| 			else if (this.content instanceof InputStream) { | 			else if (this.content instanceof InputStream inputStream) { | ||||||
| 				this.lobCreator.setBlobAsBinaryStream(ps, paramIndex, (InputStream) this.content, this.length); | 				this.lobCreator.setBlobAsBinaryStream(ps, paramIndex, inputStream, this.length); | ||||||
| 			} | 			} | ||||||
| 			else { | 			else { | ||||||
| 				throw new IllegalArgumentException( | 				throw new IllegalArgumentException( | ||||||
|  | @ -192,11 +192,11 @@ public class SqlLobValue implements DisposableSqlTypeValue { | ||||||
| 			if (this.content instanceof String || this.content == null) { | 			if (this.content instanceof String || this.content == null) { | ||||||
| 				this.lobCreator.setClobAsString(ps, paramIndex, (String) this.content); | 				this.lobCreator.setClobAsString(ps, paramIndex, (String) this.content); | ||||||
| 			} | 			} | ||||||
| 			else if (this.content instanceof InputStream) { | 			else if (this.content instanceof InputStream inputStream) { | ||||||
| 				this.lobCreator.setClobAsAsciiStream(ps, paramIndex, (InputStream) this.content, this.length); | 				this.lobCreator.setClobAsAsciiStream(ps, paramIndex, inputStream, this.length); | ||||||
| 			} | 			} | ||||||
| 			else if (this.content instanceof Reader) { | 			else if (this.content instanceof Reader reader) { | ||||||
| 				this.lobCreator.setClobAsCharacterStream(ps, paramIndex, (Reader) this.content, this.length); | 				this.lobCreator.setClobAsCharacterStream(ps, paramIndex, reader, this.length); | ||||||
| 			} | 			} | ||||||
| 			else { | 			else { | ||||||
| 				throw new IllegalArgumentException( | 				throw new IllegalArgumentException( | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| /* | /* | ||||||
|  * Copyright 2002-2020 the original author or authors. |  * Copyright 2002-2022 the original author or authors. | ||||||
|  * |  * | ||||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); |  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  * you may not use this file except in compliance with the License. |  * you may not use this file except in compliance with the License. | ||||||
|  | @ -162,11 +162,11 @@ public class DataSourceTransactionManager extends AbstractPlatformTransactionMan | ||||||
| 	 * @see org.springframework.transaction.jta.JtaTransactionManager | 	 * @see org.springframework.transaction.jta.JtaTransactionManager | ||||||
| 	 */ | 	 */ | ||||||
| 	public void setDataSource(@Nullable DataSource dataSource) { | 	public void setDataSource(@Nullable DataSource dataSource) { | ||||||
| 		if (dataSource instanceof TransactionAwareDataSourceProxy) { | 		if (dataSource instanceof TransactionAwareDataSourceProxy tadsp) { | ||||||
| 			// If we got a TransactionAwareDataSourceProxy, we need to perform transactions | 			// If we got a TransactionAwareDataSourceProxy, we need to perform transactions | ||||||
| 			// for its underlying target DataSource, else data access code won't see | 			// for its underlying target DataSource, else data access code won't see | ||||||
| 			// properly exposed transactions (i.e. transactions for the target DataSource). | 			// properly exposed transactions (i.e. transactions for the target DataSource). | ||||||
| 			this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource(); | 			this.dataSource = tadsp.getTargetDataSource(); | ||||||
| 		} | 		} | ||||||
| 		else { | 		else { | ||||||
| 			this.dataSource = dataSource; | 			this.dataSource = dataSource; | ||||||
|  |  | ||||||
|  | @ -438,8 +438,8 @@ public abstract class DataSourceUtils { | ||||||
| 	 */ | 	 */ | ||||||
| 	public static Connection getTargetConnection(Connection con) { | 	public static Connection getTargetConnection(Connection con) { | ||||||
| 		Connection conToUse = con; | 		Connection conToUse = con; | ||||||
| 		while (conToUse instanceof ConnectionProxy) { | 		while (conToUse instanceof ConnectionProxy connectionProxy) { | ||||||
| 			conToUse = ((ConnectionProxy) conToUse).getTargetConnection(); | 			conToUse = connectionProxy.getTargetConnection(); | ||||||
| 		} | 		} | ||||||
| 		return conToUse; | 		return conToUse; | ||||||
| 	} | 	} | ||||||
|  | @ -455,9 +455,9 @@ public abstract class DataSourceUtils { | ||||||
| 	private static int getConnectionSynchronizationOrder(DataSource dataSource) { | 	private static int getConnectionSynchronizationOrder(DataSource dataSource) { | ||||||
| 		int order = CONNECTION_SYNCHRONIZATION_ORDER; | 		int order = CONNECTION_SYNCHRONIZATION_ORDER; | ||||||
| 		DataSource currDs = dataSource; | 		DataSource currDs = dataSource; | ||||||
| 		while (currDs instanceof DelegatingDataSource) { | 		while (currDs instanceof DelegatingDataSource delegatingDataSource) { | ||||||
| 			order--; | 			order--; | ||||||
| 			currDs = ((DelegatingDataSource) currDs).getTargetDataSource(); | 			currDs = delegatingDataSource.getTargetDataSource(); | ||||||
| 		} | 		} | ||||||
| 		return order; | 		return order; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| /* | /* | ||||||
|  * Copyright 2002-2021 the original author or authors. |  * Copyright 2002-2022 the original author or authors. | ||||||
|  * |  * | ||||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); |  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  * you may not use this file except in compliance with the License. |  * you may not use this file except in compliance with the License. | ||||||
|  | @ -239,8 +239,8 @@ public class TransactionAwareDataSourceProxy extends DelegatingDataSource { | ||||||
| 
 | 
 | ||||||
| 				// If return value is a Statement, apply transaction timeout. | 				// If return value is a Statement, apply transaction timeout. | ||||||
| 				// Applies to createStatement, prepareStatement, prepareCall. | 				// Applies to createStatement, prepareStatement, prepareCall. | ||||||
| 				if (retVal instanceof Statement) { | 				if (retVal instanceof Statement statement) { | ||||||
| 					DataSourceUtils.applyTransactionTimeout((Statement) retVal, this.targetDataSource); | 					DataSourceUtils.applyTransactionTimeout(statement, this.targetDataSource); | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				return retVal; | 				return retVal; | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| /* | /* | ||||||
|  * Copyright 2002-2021 the original author or authors. |  * Copyright 2002-2022 the original author or authors. | ||||||
|  * |  * | ||||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); |  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  * you may not use this file except in compliance with the License. |  * you may not use this file except in compliance with the License. | ||||||
|  | @ -216,9 +216,9 @@ public class EmbeddedDatabaseFactory { | ||||||
| 	protected void shutdownDatabase() { | 	protected void shutdownDatabase() { | ||||||
| 		if (this.dataSource != null) { | 		if (this.dataSource != null) { | ||||||
| 			if (logger.isInfoEnabled()) { | 			if (logger.isInfoEnabled()) { | ||||||
| 				if (this.dataSource instanceof SimpleDriverDataSource) { | 				if (this.dataSource instanceof SimpleDriverDataSource simpleDriverDataSource) { | ||||||
| 					logger.info(String.format("Shutting down embedded database: url='%s'", | 					logger.info(String.format("Shutting down embedded database: url='%s'", | ||||||
| 						((SimpleDriverDataSource) this.dataSource).getUrl())); | 							simpleDriverDataSource.getUrl())); | ||||||
| 				} | 				} | ||||||
| 				else { | 				else { | ||||||
| 					logger.info(String.format("Shutting down embedded database '%s'", this.databaseName)); | 					logger.info(String.format("Shutting down embedded database '%s'", this.databaseName)); | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| /* | /* | ||||||
|  * Copyright 2002-2021 the original author or authors. |  * Copyright 2002-2022 the original author or authors. | ||||||
|  * |  * | ||||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); |  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  * you may not use this file except in compliance with the License. |  * you may not use this file except in compliance with the License. | ||||||
|  | @ -299,8 +299,8 @@ public abstract class ScriptUtils { | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		catch (Exception ex) { | 		catch (Exception ex) { | ||||||
| 			if (ex instanceof ScriptException) { | 			if (ex instanceof ScriptException scriptException) { | ||||||
| 				throw (ScriptException) ex; | 				throw scriptException; | ||||||
| 			} | 			} | ||||||
| 			throw new UncategorizedScriptException( | 			throw new UncategorizedScriptException( | ||||||
| 				"Failed to execute database script from resource [" + resource + "]", ex); | 				"Failed to execute database script from resource [" + resource + "]", ex); | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| /* | /* | ||||||
|  * Copyright 2002-2019 the original author or authors. |  * Copyright 2002-2022 the original author or authors. | ||||||
|  * |  * | ||||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); |  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  * you may not use this file except in compliance with the License. |  * you may not use this file except in compliance with the License. | ||||||
|  | @ -161,10 +161,10 @@ public class SqlFunction<T> extends MappingSqlQuery<T> { | ||||||
| 	 */ | 	 */ | ||||||
| 	public int run(Object... parameters) { | 	public int run(Object... parameters) { | ||||||
| 		Object obj = super.findObject(parameters); | 		Object obj = super.findObject(parameters); | ||||||
| 		if (!(obj instanceof Number)) { | 		if (!(obj instanceof Number number)) { | ||||||
| 			throw new TypeMismatchDataAccessException("Could not convert result object [" + obj + "] to int"); | 			throw new TypeMismatchDataAccessException("Could not convert result object [" + obj + "] to int"); | ||||||
| 		} | 		} | ||||||
| 		return ((Number) obj).intValue(); | 		return number.intValue(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	/** | 	/** | ||||||
|  |  | ||||||
|  | @ -213,10 +213,10 @@ public abstract class JdbcUtils { | ||||||
| 			if (obj instanceof String) { | 			if (obj instanceof String) { | ||||||
| 				return obj; | 				return obj; | ||||||
| 			} | 			} | ||||||
| 			else if (obj instanceof Number) { | 			else if (obj instanceof Number number) { | ||||||
| 				// Defensively convert any Number to an Integer (as needed by our | 				// Defensively convert any Number to an Integer (as needed by our | ||||||
| 				// ConversionService's IntegerToEnumConverterFactory) for use as index | 				// ConversionService's IntegerToEnumConverterFactory) for use as index | ||||||
| 				return NumberUtils.convertNumberToTargetClass((Number) obj, Integer.class); | 				return NumberUtils.convertNumberToTargetClass(number, Integer.class); | ||||||
| 			} | 			} | ||||||
| 			else { | 			else { | ||||||
| 				// e.g. on Postgres: getObject returns a PGObject but we need a String | 				// e.g. on Postgres: getObject returns a PGObject but we need a String | ||||||
|  | @ -405,8 +405,8 @@ public abstract class JdbcUtils { | ||||||
| 								"Could not access DatabaseMetaData method '" + metaDataMethodName + "'", ex); | 								"Could not access DatabaseMetaData method '" + metaDataMethodName + "'", ex); | ||||||
| 					} | 					} | ||||||
| 					catch (InvocationTargetException ex) { | 					catch (InvocationTargetException ex) { | ||||||
| 						if (ex.getTargetException() instanceof SQLException) { | 						if (ex.getTargetException() instanceof SQLException sqlException) { | ||||||
| 							throw (SQLException) ex.getTargetException(); | 							throw sqlException; | ||||||
| 						} | 						} | ||||||
| 						throw new MetaDataAccessException( | 						throw new MetaDataAccessException( | ||||||
| 								"Invocation of DatabaseMetaData method '" + metaDataMethodName + "' failed", ex); | 								"Invocation of DatabaseMetaData method '" + metaDataMethodName + "' failed", ex); | ||||||
|  |  | ||||||
|  | @ -216,8 +216,8 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep | ||||||
| 				// Try to find SQLException with actual error code, looping through the causes. | 				// Try to find SQLException with actual error code, looping through the causes. | ||||||
| 				// E.g. applicable to java.sql.DataTruncation as of JDK 1.6. | 				// E.g. applicable to java.sql.DataTruncation as of JDK 1.6. | ||||||
| 				SQLException current = sqlEx; | 				SQLException current = sqlEx; | ||||||
| 				while (current.getErrorCode() == 0 && current.getCause() instanceof SQLException) { | 				while (current.getErrorCode() == 0 && current.getCause() instanceof SQLException sqlException) { | ||||||
| 					current = (SQLException) current.getCause(); | 					current = sqlException; | ||||||
| 				} | 				} | ||||||
| 				errorCode = Integer.toString(current.getErrorCode()); | 				errorCode = Integer.toString(current.getErrorCode()); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue