Skip to content

Commit 2874066

Browse files
committed
DataSourceTransactionManager triggers flush callbacks on registered transaction synchronizations
Issue: SPR-14847
1 parent e2b1dcb commit 2874066

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.transaction.support.DefaultTransactionStatus;
2929
import org.springframework.transaction.support.ResourceTransactionManager;
3030
import org.springframework.transaction.support.TransactionSynchronizationManager;
31+
import org.springframework.transaction.support.TransactionSynchronizationUtils;
3132

3233
/**
3334
* {@link org.springframework.transaction.PlatformTransactionManager}
@@ -87,6 +88,12 @@
8788
* DBCP connection pool). Switching between this local strategy and a JTA
8889
* environment is just a matter of configuration!
8990
*
91+
* <p>As of 4.3.4, this transaction manager triggers flush callbacks on registered
92+
* transaction synchronizations (if synchronization is generally active), assuming
93+
* resources operating on the underlying JDBC {@code Connection}. This allows for
94+
* setup analogous to {@code JtaTransactionManager}, in particular with respect to
95+
* lazily registered ORM resources (e.g. a Hibernate {@code Session}).
96+
*
9097
* @author Juergen Hoeller
9198
* @since 02.05.2003
9299
* @see #setNestedTransactionAllowed
@@ -368,6 +375,13 @@ public void setRollbackOnly() {
368375
public boolean isRollbackOnly() {
369376
return getConnectionHolder().isRollbackOnly();
370377
}
378+
379+
@Override
380+
public void flush() {
381+
if (TransactionSynchronizationManager.isSynchronizationActive()) {
382+
TransactionSynchronizationUtils.triggerFlush();
383+
}
384+
}
371385
}
372386

373387
}

spring-tx/src/main/java/org/springframework/transaction/TransactionStatus.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -80,6 +80,10 @@ public interface TransactionStatus extends SavepointManager, Flushable {
8080
/**
8181
* Flush the underlying session to the datastore, if applicable:
8282
* for example, all affected Hibernate/JPA sessions.
83+
* <p>This is effectively just a hint and may be a no-op if the underlying
84+
* transaction manager does not have a flush concept. A flush signal may
85+
* get applied to the primary resource or to transaction synchronizations,
86+
* depending on the underlying resource.
8387
*/
8488
@Override
8589
void flush();

0 commit comments

Comments
 (0)