diff --git a/pom.xml b/pom.xml
index d2208ebe3..85a2d7f39 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
io.ebean
ebean-spring-txn
- 10.1.2-SNAPSHOT
+ 11.5.1-SNAPSHOT
ebean-spring-txn
jar
@@ -32,14 +32,14 @@
org.slf4j
slf4j-api
- 1.7.21
+ 1.7.25
provided
io.ebean
ebean
- [10,)
+ 11.5.1
provided
@@ -79,10 +79,30 @@
- org.avaje.composite
- avaje-composite-testing-ebean
- 4.1
- pom
+ junit
+ junit
+ 4.12
+ test
+
+
+
+ org.assertj
+ assertj-core
+ 3.1.0
+ test
+
+
+
+ com.h2database
+ h2
+ 1.4.196
+ test
+
+
+
+ ch.qos.logback
+ logback-classic
+ 1.2.3
test
@@ -104,7 +124,7 @@
true
- io.ebean.tile:enhancement:2.1
+ io.ebean.tile:enhancement:5.2
diff --git a/src/main/java/io/ebean/spring/txn/SpringJdbcTransactionManager.java b/src/main/java/io/ebean/spring/txn/SpringJdbcTransactionManager.java
index f95336a64..9bf3ce707 100644
--- a/src/main/java/io/ebean/spring/txn/SpringJdbcTransactionManager.java
+++ b/src/main/java/io/ebean/spring/txn/SpringJdbcTransactionManager.java
@@ -19,10 +19,15 @@
*/
package io.ebean.spring.txn;
+import io.ebean.TxScope;
import io.ebean.config.ExternalTransactionManager;
+import io.ebeaninternal.api.ScopeTrans;
+import io.ebeaninternal.api.ScopedTransaction;
import io.ebeaninternal.api.SpiTransaction;
+import io.ebeaninternal.server.transaction.DefaultTransactionScopeManager;
import io.ebeaninternal.server.transaction.DefaultTransactionThreadLocal;
import io.ebeaninternal.server.transaction.TransactionManager;
+import io.ebeaninternal.server.transaction.TransactionScopeManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.ConnectionHolder;
@@ -57,10 +62,7 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
*/
private TransactionManager transactionManager;
- /**
- * The EbeanServer name.
- */
- private String serverName;
+ private TransactionScopeManager scope;
/**
* Instantiates a new spring aware transaction scope manager.
@@ -76,10 +78,9 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
// RB: At this stage not exposing TransactionManager to
// the public API and hence the Object type and casting here
-
this.transactionManager = (TransactionManager) txnMgr;
this.dataSource = transactionManager.getDataSource();
- this.serverName = transactionManager.getServerName();
+ this.scope = new DefaultTransactionScopeManager(transactionManager);
}
/**
@@ -96,7 +97,7 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
if (holder == null || !holder.isSynchronizedWithTransaction()) {
// no current Spring transaction
- SpiTransaction currentEbeanTransaction = DefaultTransactionThreadLocal.get(serverName);
+ SpiTransaction currentEbeanTransaction = scope.get();
if (currentEbeanTransaction != null) { // this is unexpected
log.warn("No current Spring transaction BUT using current Ebean one {}", currentEbeanTransaction.getId());
} else {
@@ -118,9 +119,10 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
springTxnLister = createSpringTxnListener(newTrans);
TransactionSynchronizationManager.registerSynchronization(springTxnLister);
- // also put in Ebean ThreadLocal
- DefaultTransactionThreadLocal.set(serverName, newTrans);
- return newTrans;
+ ScopedTransaction scopedTxn = new ScopedTransaction(scope);
+ scopedTxn.push(new ScopeTrans(true, false, newTrans, TxScope.required()));
+ scope.set(scopedTxn);
+ return scopedTxn;
}
}
@@ -185,7 +187,7 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
/**
* Return the associated Ebean wrapped transaction.
*/
- public SpringJdbcTransaction getTransaction() {
+ SpringJdbcTransaction getTransaction() {
return transaction;
}
diff --git a/src/test/java/org/example/UserServiceImpl.java b/src/test/java/org/example/UserServiceImpl.java
index b828010a6..43448b8ed 100644
--- a/src/test/java/org/example/UserServiceImpl.java
+++ b/src/test/java/org/example/UserServiceImpl.java
@@ -21,7 +21,6 @@
package org.example;
import io.ebean.Transaction;
-import io.ebean.PersistBatch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@@ -43,10 +42,7 @@ public class UserServiceImpl implements UserService {
@Autowired
private EbeanServer ebeanServer;
- /* (non-Javadoc)
- * @see org.spring.modules.ebean.UserService#save(org.spring.modules.ebean.User)
- */
- @Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor=Throwable.class)
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor=Throwable.class)
public void save(User user) {
ebeanServer.save(user);
}
@@ -56,12 +52,11 @@ public class UserServiceImpl implements UserService {
return ebeanServer.find(User.class, id);
}
+ @Transactional(propagation = Propagation.REQUIRED)
+ public void batchInsert() {
- @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
- public void batchInsert(){
-
- List users = new ArrayList();
- for(int i=0 ;i<5;i++){
+ List users = new ArrayList<>();
+ for(int i=0 ;i<25;i++){
User user = new User();
user.setName("user"+i);
users.add(user);
@@ -69,11 +64,9 @@ public class UserServiceImpl implements UserService {
System.out.println("---------before batch-------");
- Transaction tx = ebeanServer.beginTransaction();
- tx.setBatch(PersistBatch.NONE);
- tx.setBatchOnCascade(PersistBatch.ALL);
+ Transaction tx = ebeanServer.currentTransaction();
tx.setBatchSize(20);
- ebeanServer.saveAll(users);//
+ ebeanServer.saveAll(users);
System.out.println("---------after batch-------");
}
diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml
new file mode 100644
index 000000000..e096c77e4
--- /dev/null
+++ b/src/test/resources/logback-test.xml
@@ -0,0 +1,32 @@
+
+
+
+ TRACE
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file