Skip to content

Commit

Permalink
Merge branch '6.0.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#	spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/R2dbcTransactionManager.java
#	spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/R2dbcTransactionManagerUnitTests.java
  • Loading branch information
jhoeller committed Sep 11, 2023
2 parents a199654 + db76542 commit 3099710
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,9 @@ protected void doClose() {
// Let subclasses do some final clean-up if they wish...
onClose();

// Reset common introspection caches to avoid class reference leaks.
resetCommonCaches();

// Reset local application listeners to pre-refresh state.
if (this.earlyApplicationListeners != null) {
this.applicationListeners.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,9 @@ public static boolean isSynthesizedAnnotation(@Nullable Annotation annotation) {
public static void clearCache() {
AnnotationTypeMappings.clearCache();
AnnotationsScanner.clearCache();
AttributeMethods.cache.clear();
RepeatableContainers.cache.clear();
OrderUtils.orderCache.clear();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ final class AttributeMethods {

static final AttributeMethods NONE = new AttributeMethods(null, new Method[0]);


private static final Map<Class<? extends Annotation>, AttributeMethods> cache =
new ConcurrentReferenceHashMap<>();
static final Map<Class<? extends Annotation>, AttributeMethods> cache = new ConcurrentReferenceHashMap<>();

private static final Comparator<Method> methodComparator = (m1, m2) -> {
if (m1 != null && m2 != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,7 +41,7 @@ public abstract class OrderUtils {
private static final String JAVAX_PRIORITY_ANNOTATION = "jakarta.annotation.Priority";

/** Cache for @Order value (or NOT_ANNOTATED marker) per Class. */
private static final Map<AnnotatedElement, Object> orderCache = new ConcurrentReferenceHashMap<>(64);
static final Map<AnnotatedElement, Object> orderCache = new ConcurrentReferenceHashMap<>(64);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
*/
public abstract class RepeatableContainers {

static final Map<Class<? extends Annotation>, Object> cache = new ConcurrentReferenceHashMap<>();

@Nullable
private final RepeatableContainers parent;

Expand Down Expand Up @@ -141,8 +143,6 @@ public static RepeatableContainers none() {
*/
private static class StandardRepeatableContainers extends RepeatableContainers {

private static final Map<Class<? extends Annotation>, Object> cache = new ConcurrentReferenceHashMap<>();

private static final Object NONE = new Object();

private static final StandardRepeatableContainers INSTANCE = new StandardRepeatableContainers();
Expand Down
40 changes: 24 additions & 16 deletions spring-jcl/src/main/java/org/apache/commons/logging/LogFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,25 @@ public static Log getLog(String name) {
*/
@Deprecated
public static LogFactory getFactory() {
return new LogFactory() {};
return new LogFactory() {
@Override
public Object getAttribute(String name) {
return null;
}
@Override
public String[] getAttributeNames() {
return new String[0];
}
@Override
public void removeAttribute(String name) {
}
@Override
public void setAttribute(String name, Object value) {
}
@Override
public void release() {
}
};
}

/**
Expand Down Expand Up @@ -106,29 +124,19 @@ public Log getInstance(String name) {
// Just in case some code happens to call uncommon Commons Logging methods...

@Deprecated
public Object getAttribute(String name) {
return null;
}
public abstract Object getAttribute(String name);

@Deprecated
public String[] getAttributeNames() {
return new String[0];
}
public abstract String[] getAttributeNames();

@Deprecated
public void removeAttribute(String name) {
// do nothing
}
public abstract void removeAttribute(String name);

@Deprecated
public void setAttribute(String name, Object value) {
// do nothing
}
public abstract void setAttribute(String name, Object value);

@Deprecated
public void release() {
// do nothing
}
public abstract void release();

@Deprecated
public static void release(ClassLoader classLoader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ public String[] getAttributeNames() {
return this.attributes.keySet().toArray(new String[0]);
}

@Override
public void release() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
*/
public class JdbcTemplateQueryTests {

private Connection connection = mock();

private DataSource dataSource = mock();

private Connection connection = mock();

private Statement statement = mock();

private PreparedStatement preparedStatement = mock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@
*/
public class JdbcTemplateTests {

private Connection connection = mock();

private DataSource dataSource = mock();

private Connection connection = mock();

private Statement statement = mock();

private PreparedStatement preparedStatement = mock();

private ResultSet resultSet = mock();

private CallableStatement callableStatement = mock();

private ResultSet resultSet = mock();

private JdbcTemplate template = new JdbcTemplate(this.dataSource);


Expand Down Expand Up @@ -136,9 +136,9 @@ public void testBogusUpdate() throws Exception {
given(this.preparedStatement.executeUpdate()).willThrow(sqlException);

Dispatcher d = new Dispatcher(idParam, sql);
assertThatExceptionOfType(UncategorizedSQLException.class).isThrownBy(() ->
this.template.update(d))
.withCause(sqlException);
assertThatExceptionOfType(UncategorizedSQLException.class)
.isThrownBy(() -> this.template.update(d))
.withCause(sqlException);
verify(this.preparedStatement).setInt(1, idParam);
verify(this.preparedStatement).close();
verify(this.connection, atLeastOnce()).close();
Expand Down Expand Up @@ -371,9 +371,9 @@ public void testSqlUpdateEncountersSqlException() throws Exception {
given(this.statement.executeUpdate(sql)).willThrow(sqlException);
given(this.connection.createStatement()).willReturn(this.statement);

assertThatExceptionOfType(DataAccessException.class).isThrownBy(() ->
this.template.update(sql))
.withCause(sqlException);
assertThatExceptionOfType(DataAccessException.class)
.isThrownBy(() -> this.template.update(sql))
.withCause(sqlException);
verify(this.statement).close();
verify(this.connection, atLeastOnce()).close();
}
Expand Down Expand Up @@ -700,9 +700,9 @@ public int getBatchSize() {
};

try {
assertThatExceptionOfType(DataAccessException.class).isThrownBy(() ->
this.template.batchUpdate(sql, setter))
.withCause(sqlException);
assertThatExceptionOfType(DataAccessException.class)
.isThrownBy(() -> this.template.batchUpdate(sql, setter))
.withCause(sqlException);
}
finally {
verify(this.preparedStatement, times(2)).addBatch();
Expand Down Expand Up @@ -804,9 +804,9 @@ public void testCouldNotGetConnectionForOperationOrExceptionTranslator() throws
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
RowCountCallbackHandler rcch = new RowCountCallbackHandler();

assertThatExceptionOfType(CannotGetJdbcConnectionException.class).isThrownBy(() ->
template.query("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3", rcch))
.withCause(sqlException);
assertThatExceptionOfType(CannotGetJdbcConnectionException.class)
.isThrownBy(() -> template.query("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3", rcch))
.withCause(sqlException);
}

@Test
Expand All @@ -818,9 +818,9 @@ public void testCouldNotGetConnectionForOperationWithLazyExceptionTranslator() t
this.template.afterPropertiesSet();
RowCountCallbackHandler rcch = new RowCountCallbackHandler();

assertThatExceptionOfType(CannotGetJdbcConnectionException.class).isThrownBy(() ->
this.template.query("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3", rcch))
.withCause(sqlException);
assertThatExceptionOfType(CannotGetJdbcConnectionException.class)
.isThrownBy(() -> this.template.query("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3", rcch))
.withCause(sqlException);
}

@Test
Expand Down Expand Up @@ -858,9 +858,9 @@ private void doTestCouldNotGetConnectionInOperationWithExceptionTranslatorInitia
this.template.afterPropertiesSet();
}
RowCountCallbackHandler rcch = new RowCountCallbackHandler();
assertThatExceptionOfType(CannotGetJdbcConnectionException.class).isThrownBy(() ->
this.template.query("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3", rcch))
.withCause(sqlException);
assertThatExceptionOfType(CannotGetJdbcConnectionException.class)
.isThrownBy(() -> this.template.query("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3", rcch))
.withCause(sqlException);
}

@Test
Expand All @@ -887,9 +887,9 @@ public void testPreparedStatementSetterFails() throws Exception {
given(this.preparedStatement.executeUpdate()).willThrow(sqlException);

PreparedStatementSetter pss = ps -> ps.setString(1, name);
assertThatExceptionOfType(DataAccessException.class).isThrownBy(() ->
new JdbcTemplate(this.dataSource).update(sql, pss))
.withCause(sqlException);
assertThatExceptionOfType(DataAccessException.class)
.isThrownBy(() -> new JdbcTemplate(this.dataSource).update(sql, pss))
.withCause(sqlException);
verify(this.preparedStatement).setString(1, name);
verify(this.preparedStatement).close();
verify(this.connection, atLeastOnce()).close();
Expand Down Expand Up @@ -925,9 +925,9 @@ public void testFatalWarning() throws Exception {
t.setIgnoreWarnings(false);

ResultSetExtractor<Byte> extractor = rs -> rs.getByte(1);
assertThatExceptionOfType(SQLWarningException.class).isThrownBy(() ->
t.query(sql, extractor))
.withCause(warnings);
assertThatExceptionOfType(SQLWarningException.class)
.isThrownBy(() -> t.query(sql, extractor))
.withCause(warnings);
verify(this.resultSet).close();
verify(this.preparedStatement).close();
verify(this.connection).close();
Expand Down Expand Up @@ -968,7 +968,7 @@ public void testSQLErrorCodeTranslation() throws Exception {
this.template.query(sql, (RowCallbackHandler) rs -> {
throw sqlException;
}))
.withCause(sqlException);
.withCause(sqlException);
verify(this.resultSet).close();
verify(this.preparedStatement).close();
verify(this.connection, atLeastOnce()).close();
Expand All @@ -988,7 +988,7 @@ public void testSQLErrorCodeTranslationWithSpecifiedDatabaseName() throws Except
this.template.query(sql, (RowCallbackHandler) rs -> {
throw sqlException;
}))
.withCause(sqlException);
.withCause(sqlException);
verify(this.resultSet).close();
verify(this.preparedStatement).close();
verify(this.connection).close();
Expand Down Expand Up @@ -1018,7 +1018,7 @@ public void testUseCustomExceptionTranslator() throws Exception {
template.query(sql, (RowCallbackHandler) rs -> {
throw sqlException;
}))
.withCause(sqlException);
.withCause(sqlException);
verify(this.resultSet).close();
verify(this.preparedStatement).close();
verify(this.connection).close();
Expand Down
Loading

0 comments on commit 3099710

Please sign in to comment.