Skip to content

Commit 4fb4c95

Browse files
committed
Merge branch '6.0.x'
2 parents b8b88e6 + 6cc084d commit 4fb4c95

File tree

9 files changed

+304
-145
lines changed

9 files changed

+304
-145
lines changed

spring-core/src/main/java/org/springframework/aot/AotDetector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public abstract class AotDetector {
3939
*/
4040
public static final String AOT_ENABLED = "spring.aot.enabled";
4141

42-
private static final boolean inNativeImage = NativeDetector.inNativeImage(Context.RUNTIME, Context.BUILD_TIME);
42+
private static final boolean inNativeImage = NativeDetector.inNativeImage(Context.RUN, Context.BUILD);
43+
4344

4445
/**
4546
* Determine whether AOT optimizations must be considered at runtime. This

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public abstract class NativeDetector {
3232

3333
private static final boolean inNativeImage = (imageCode != null);
3434

35+
3536
/**
3637
* Returns {@code true} if running in a native image context (for example
3738
* {@code buildtime}, {@code runtime}, or {@code agent}) expressed by setting the
@@ -55,23 +56,23 @@ public static boolean inNativeImage(Context... contexts) {
5556
return false;
5657
}
5758

59+
5860
/**
5961
* Native image context as defined in GraalVM's
6062
* <a href="https://github.com/oracle/graal/blob/master/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/ImageInfo.java">ImageInfo</a>.
61-
*
6263
* @since 6.0.10
6364
*/
6465
public enum Context {
6566

6667
/**
6768
* The code is executing in the context of image building.
6869
*/
69-
BUILD_TIME("buildtime"),
70+
BUILD("buildtime"),
7071

7172
/**
7273
* The code is executing at image runtime.
7374
*/
74-
RUNTIME("runtime");
75+
RUN("runtime");
7576

7677
private final String key;
7778

@@ -83,7 +84,6 @@ public enum Context {
8384
public String toString() {
8485
return this.key;
8586
}
86-
8787
}
8888

8989
}

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceTransactionManager.java

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -35,49 +35,52 @@
3535
import org.springframework.util.Assert;
3636

3737
/**
38-
* {@link org.springframework.transaction.PlatformTransactionManager}
39-
* implementation for a single JDBC {@link javax.sql.DataSource}. This class is
40-
* capable of working in any environment with any JDBC driver, as long as the setup
41-
* uses a {@code javax.sql.DataSource} as its {@code Connection} factory mechanism.
42-
* Binds a JDBC Connection from the specified DataSource to the current thread,
43-
* potentially allowing for one thread-bound Connection per DataSource.
38+
* {@link org.springframework.transaction.PlatformTransactionManager} implementation
39+
* for a single JDBC {@link javax.sql.DataSource}. This class is capable of working
40+
* in any environment with any JDBC driver, as long as the setup uses a
41+
* {@code javax.sql.DataSource} as its {@code Connection} factory mechanism.
42+
* Binds a JDBC {@code Connection} from the specified {@code DataSource} to the
43+
* current thread, potentially allowing for one thread-bound {@code Connection}
44+
* per {@code DataSource}.
4445
*
45-
* <p><b>Note: The DataSource that this transaction manager operates on needs
46-
* to return independent Connections.</b> The Connections may come from a pool
47-
* (the typical case), but the DataSource must not return thread-scoped /
48-
* request-scoped Connections or the like. This transaction manager will
49-
* associate Connections with thread-bound transactions itself, according
50-
* to the specified propagation behavior. It assumes that a separate,
51-
* independent Connection can be obtained even during an ongoing transaction.
46+
* <p><b>Note: The {@code DataSource} that this transaction manager operates on
47+
* needs to return independent {@code Connection}s.</b> The {@code Connection}s
48+
* typically come from a connection pool but the {@code DataSource} must not return
49+
* specifically scoped or constrained {@code Connection}s. This transaction manager
50+
* will associate {@code Connection}s with thread-bound transactions, according
51+
* to the specified propagation behavior. It assumes that a separate, independent
52+
* {@code Connection} can be obtained even during an ongoing transaction.
5253
*
53-
* <p>Application code is required to retrieve the JDBC Connection via
54+
* <p>Application code is required to retrieve the JDBC {@code Connection} via
5455
* {@link DataSourceUtils#getConnection(DataSource)} instead of a standard
55-
* Jakarta EE-style {@link DataSource#getConnection()} call. Spring classes such as
56+
* EE-style {@link DataSource#getConnection()} call. Spring classes such as
5657
* {@link org.springframework.jdbc.core.JdbcTemplate} use this strategy implicitly.
5758
* If not used in combination with this transaction manager, the
5859
* {@link DataSourceUtils} lookup strategy behaves exactly like the native
59-
* DataSource lookup; it can thus be used in a portable fashion.
60+
* {@code DataSource} lookup; it can thus be used in a portable fashion.
6061
*
6162
* <p>Alternatively, you can allow application code to work with the standard
62-
* Jakarta EE-style lookup pattern {@link DataSource#getConnection()}, for example for
63-
* legacy code that is not aware of Spring at all. In that case, define a
64-
* {@link TransactionAwareDataSourceProxy} for your target DataSource, and pass
65-
* that proxy DataSource to your DAOs, which will automatically participate in
66-
* Spring-managed transactions when accessing it.
63+
* EE-style lookup pattern {@link DataSource#getConnection()}, for example
64+
* for legacy code that is not aware of Spring at all. In that case, define a
65+
* {@link TransactionAwareDataSourceProxy} for your target {@code DataSource},
66+
* and pass that proxy {@code DataSource} to your DAOs which will automatically
67+
* participate in Spring-managed transactions when accessing it.
6768
*
6869
* <p>Supports custom isolation levels, and timeouts which get applied as
6970
* appropriate JDBC statement timeouts. To support the latter, application code
7071
* must either use {@link org.springframework.jdbc.core.JdbcTemplate}, call
71-
* {@link DataSourceUtils#applyTransactionTimeout} for each created JDBC Statement,
72-
* or go through a {@link TransactionAwareDataSourceProxy} which will create
73-
* timeout-aware JDBC Connections and Statements automatically.
72+
* {@link DataSourceUtils#applyTransactionTimeout} for each created JDBC
73+
* {@code Statement}, or go through a {@link TransactionAwareDataSourceProxy}
74+
* which will create timeout-aware JDBC {@code Connection}s and {@code Statement}s
75+
* automatically.
7476
*
7577
* <p>Consider defining a {@link LazyConnectionDataSourceProxy} for your target
76-
* DataSource, pointing both this transaction manager and your DAOs to it.
78+
* {@code DataSource}, pointing both this transaction manager and your DAOs to it.
7779
* This will lead to optimized handling of "empty" transactions, i.e. of transactions
78-
* without any JDBC statements executed. A LazyConnectionDataSourceProxy will not fetch
79-
* an actual JDBC Connection from the target DataSource until a Statement gets executed,
80-
* lazily applying the specified transaction settings to the target Connection.
80+
* without any JDBC statements executed. A {@code LazyConnectionDataSourceProxy} will
81+
* not fetch an actual JDBC {@code Connection} from the target {@code DataSource}
82+
* until a {@code Statement} gets executed, lazily applying the specified transaction
83+
* settings to the target {@code Connection}.
8184
*
8285
* <p>This transaction manager supports nested transactions via the JDBC 3.0
8386
* {@link java.sql.Savepoint} mechanism. The
@@ -88,9 +91,9 @@
8891
* <p>This transaction manager can be used as a replacement for the
8992
* {@link org.springframework.transaction.jta.JtaTransactionManager} in the single
9093
* resource case, as it does not require a container that supports JTA, typically
91-
* in combination with a locally defined JDBC DataSource (e.g. an Apache Commons
92-
* DBCP connection pool). Switching between this local strategy and a JTA
93-
* environment is just a matter of configuration!
94+
* in combination with a locally defined JDBC {@code DataSource} (e.g. a Hikari
95+
* connection pool). Switching between this local strategy and a JTA environment
96+
* is just a matter of configuration!
9497
*
9598
* <p>As of 4.3.4, this transaction manager triggers flush callbacks on registered
9699
* transaction synchronizations (if synchronization is generally active), assuming
@@ -112,6 +115,7 @@
112115
* @see TransactionAwareDataSourceProxy
113116
* @see LazyConnectionDataSourceProxy
114117
* @see org.springframework.jdbc.core.JdbcTemplate
118+
* @see org.springframework.jdbc.support.JdbcTransactionManager
115119
*/
116120
@SuppressWarnings("serial")
117121
public class DataSourceTransactionManager extends AbstractPlatformTransactionManager
@@ -124,16 +128,16 @@ public class DataSourceTransactionManager extends AbstractPlatformTransactionMan
124128

125129

126130
/**
127-
* Create a new DataSourceTransactionManager instance.
128-
* A DataSource has to be set to be able to use it.
131+
* Create a new {@code DataSourceTransactionManager} instance.
132+
* A {@code DataSource} has to be set to be able to use it.
129133
* @see #setDataSource
130134
*/
131135
public DataSourceTransactionManager() {
132136
setNestedTransactionAllowed(true);
133137
}
134138

135139
/**
136-
* Create a new DataSourceTransactionManager instance.
140+
* Create a new {@code DataSourceTransactionManager} instance.
137141
* @param dataSource the JDBC DataSource to manage transactions for
138142
*/
139143
public DataSourceTransactionManager(DataSource dataSource) {
@@ -144,22 +148,22 @@ public DataSourceTransactionManager(DataSource dataSource) {
144148

145149

146150
/**
147-
* Set the JDBC DataSource that this instance should manage transactions for.
148-
* <p>This will typically be a locally defined DataSource, for example an
149-
* Apache Commons DBCP connection pool. Alternatively, you can also drive
150-
* transactions for a non-XA J2EE DataSource fetched from JNDI. For an XA
151-
* DataSource, use JtaTransactionManager.
152-
* <p>The DataSource specified here should be the target DataSource to manage
153-
* transactions for, not a TransactionAwareDataSourceProxy. Only data access
154-
* code may work with TransactionAwareDataSourceProxy, while the transaction
155-
* manager needs to work on the underlying target DataSource. If there's
156-
* nevertheless a TransactionAwareDataSourceProxy passed in, it will be
157-
* unwrapped to extract its target DataSource.
158-
* <p><b>The DataSource passed in here needs to return independent Connections.</b>
159-
* The Connections may come from a pool (the typical case), but the DataSource
160-
* must not return thread-scoped / request-scoped Connections or the like.
161-
* @see TransactionAwareDataSourceProxy
162-
* @see org.springframework.transaction.jta.JtaTransactionManager
151+
* Set the JDBC {@code DataSource} that this instance should manage transactions for.
152+
* <p>This will typically be a locally defined {@code DataSource}, for example a
153+
* Hikari connection pool. Alternatively, you can also manage transactions for a
154+
* non-XA {@code DataSource} fetched from JNDI. For an XA {@code DataSource},
155+
* use {@link org.springframework.transaction.jta.JtaTransactionManager} instead.
156+
* <p>The {@code DataSource} specified here should be the target {@code DataSource}
157+
* to manage transactions for, not a {@link TransactionAwareDataSourceProxy}.
158+
* Only data access code may work with {@code TransactionAwareDataSourceProxy} while
159+
* the transaction manager needs to work on the underlying target {@code DataSource}.
160+
* If there is nevertheless a {@code TransactionAwareDataSourceProxy} passed in,
161+
* it will be unwrapped to extract its target {@code DataSource}.
162+
* <p><b>The {@code DataSource} passed in here needs to return independent
163+
* {@code Connection}s.</b> The {@code Connection}s typically come from a
164+
* connection pool but the {@code DataSource} must not return specifically
165+
* scoped or constrained {@code Connection}s, just possibly lazily fetched.
166+
* @see LazyConnectionDataSourceProxy
163167
*/
164168
public void setDataSource(@Nullable DataSource dataSource) {
165169
if (dataSource instanceof TransactionAwareDataSourceProxy tadsp) {
@@ -174,15 +178,15 @@ public void setDataSource(@Nullable DataSource dataSource) {
174178
}
175179

176180
/**
177-
* Return the JDBC DataSource that this instance manages transactions for.
181+
* Return the JDBC {@code DataSource} that this instance manages transactions for.
178182
*/
179183
@Nullable
180184
public DataSource getDataSource() {
181185
return this.dataSource;
182186
}
183187

184188
/**
185-
* Obtain the DataSource for actual use.
189+
* Obtain the {@code DataSource} for actual use.
186190
* @return the DataSource (never {@code null})
187191
* @throws IllegalStateException in case of no DataSource set
188192
* @since 5.0

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -33,9 +33,9 @@
3333
import org.springframework.util.Assert;
3434

3535
/**
36-
* Helper class that provides static methods for obtaining JDBC Connections from
37-
* a {@link javax.sql.DataSource}. Includes special support for Spring-managed
38-
* transactional Connections, e.g. managed by {@link DataSourceTransactionManager}
36+
* Helper class that provides static methods for obtaining JDBC {@code Connection}s
37+
* from a {@link javax.sql.DataSource}. Includes special support for Spring-managed
38+
* transactional {@code Connection}s, e.g. managed by {@link DataSourceTransactionManager}
3939
* or {@link org.springframework.transaction.jta.JtaTransactionManager}.
4040
*
4141
* <p>Used internally by Spring's {@link org.springframework.jdbc.core.JdbcTemplate},
@@ -46,7 +46,8 @@
4646
* @author Juergen Hoeller
4747
* @see #getConnection
4848
* @see #releaseConnection
49-
* @see DataSourceTransactionManager
49+
* @see org.springframework.jdbc.core.JdbcTemplate
50+
* @see org.springframework.jdbc.support.JdbcTransactionManager
5051
* @see org.springframework.transaction.jta.JtaTransactionManager
5152
* @see org.springframework.transaction.support.TransactionSynchronizationManager
5253
*/
@@ -310,8 +311,7 @@ public static boolean isConnectionTransactional(Connection con, @Nullable DataSo
310311
}
311312

312313
/**
313-
* Apply the current transaction timeout, if any,
314-
* to the given JDBC Statement object.
314+
* Apply the current transaction timeout, if any, to the given JDBC Statement object.
315315
* @param stmt the JDBC Statement object
316316
* @param dataSource the DataSource that the Connection was obtained from
317317
* @throws SQLException if thrown by JDBC methods

spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
* @see DataSourceUtils#getConnection
106106
* @see DataSourceUtils#releaseConnection
107107
* @see org.springframework.jdbc.core.JdbcTemplate
108-
* @see org.springframework.jdbc.datasource.DataSourceTransactionManager
108+
* @see org.springframework.jdbc.support.JdbcTransactionManager
109109
* @see org.springframework.transaction.jta.JtaTransactionManager
110110
*/
111111
@SuppressWarnings("serial")

spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
* @see org.springframework.jdbc.datasource.DataSourceUtils#getConnection
111111
* @see org.springframework.jdbc.datasource.DataSourceUtils#releaseConnection
112112
* @see org.springframework.jdbc.core.JdbcTemplate
113-
* @see org.springframework.jdbc.datasource.DataSourceTransactionManager
113+
* @see org.springframework.jdbc.support.JdbcTransactionManager
114114
* @see org.springframework.transaction.jta.JtaTransactionManager
115115
*/
116116
@SuppressWarnings("serial")

spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionHolder.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -41,11 +41,20 @@
4141
*/
4242
public class ConnectionHolder extends ResourceHolderSupport {
4343

44+
/**
45+
* Prefix for savepoint names.
46+
* @since 6.0.10
47+
*/
48+
static final String SAVEPOINT_NAME_PREFIX = "SAVEPOINT_";
49+
50+
4451
@Nullable
4552
private Connection currentConnection;
4653

4754
private boolean transactionActive;
4855

56+
private int savepointCounter = 0;
57+
4958

5059
/**
5160
* Create a new ConnectionHolder for the given R2DBC {@link Connection},
@@ -112,6 +121,17 @@ public Connection getConnection() {
112121
return this.currentConnection;
113122
}
114123

124+
/**
125+
* Create a new savepoint for the current {@link Connection},
126+
* using generated savepoint names that are unique for the Connection.
127+
* @return the name of the new savepoint
128+
* @since 6.0.10
129+
*/
130+
String nextSavepoint() {
131+
this.savepointCounter++;
132+
return SAVEPOINT_NAME_PREFIX + this.savepointCounter;
133+
}
134+
115135
/**
116136
* Releases the current {@link Connection}.
117137
*/

0 commit comments

Comments
 (0)