Compare commits

..
Author SHA1 Message Date
rob bygrave 7133c81fc5 [maven-release-plugin] prepare release ebean-spring-txn-12.4.2 2020-12-18 10:00:52 +13:00
rob bygrave c6b4de39e8 Merge branch 'master' of github.com:ebean-orm/ebean-spring-txn 2020-12-18 09:58:30 +13:00
rob bygrave 94f367af70 #22 - Spring @Transactional with batch mode not invoking ebean batch flush 2020-12-18 09:58:16 +13:00
Rob BygraveandGitHub dc6c393300 Merge pull request #21 from ebean-orm/dependabot/maven/junit-junit-4.13.1
Bump junit from 4.12 to 4.13.1
2020-10-13 22:55:00 +13:00
dependabot[bot]andGitHub 239f3a0a54 Bump junit from 4.12 to 4.13.1
Bumps [junit](https://github.com/junit-team/junit4) from 4.12 to 4.13.1.
- [Release notes](https://github.com/junit-team/junit4/releases)
- [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.12.md)
- [Commits](https://github.com/junit-team/junit4/compare/r4.12...r4.13.1)

Signed-off-by: dependabot[bot] <support@github.com>
2020-10-13 07:51:29 +00:00
rob bygrave d3e78ab54e [maven-release-plugin] prepare for next development iteration 2020-09-18 01:15:35 +12:00
rob bygrave c6483535bd [maven-release-plugin] prepare release ebean-spring-txn-12.4.1 2020-09-18 01:15:24 +12:00
rob bygrave 95bb2a5d56 Bump to 12.4.1 2020-09-18 01:14:52 +12:00
rob bygrave 23649ed840 [maven-release-plugin] prepare for next development iteration 2020-03-13 17:12:25 +13:00
rob bygrave 3ee4034a76 [maven-release-plugin] prepare release ebean-spring-txn-12.2.1 2020-03-13 17:12:15 +13:00
rob bygrave 21d377546e Bump to 12.2.1 2020-03-13 17:10:21 +13:00
rob bygrave 8c9dccc6a3 [maven-release-plugin] prepare for next development iteration 2019-10-14 14:53:28 +13:00
rob bygrave 6fdf681993 [maven-release-plugin] prepare release ebean-spring-txn-12.1.1 2019-10-14 14:53:19 +13:00
rob bygrave 7e8f413578 No effective change - sync to Ebean 12.1.1 2019-10-14 14:52:46 +13:00
rob bygrave 6705e5a962 Bump Ebean provided dependency to 11.42.1 2019-08-08 22:14:44 +12:00
Rob Bygrave d9126a936d [maven-release-plugin] prepare for next development iteration 2018-03-12 21:45:57 +13:00
Rob Bygrave 4ee024b1ce [maven-release-plugin] prepare release ebean-spring-txn-11.10.4 2018-03-12 21:45:45 +13:00
Rob Bygrave 19491d5ae6 #19 - java.lang.IllegalStateException: Transaction is Inactive ... when using Ebean transactions with Ebean's Spring transaction manager 2018-03-12 21:45:14 +13:00
Rob Bygrave db816594c5 No effective change - tidy tests 2018-02-23 10:50:51 +13:00
Rob Bygrave fa73b7791f [maven-release-plugin] prepare for next development iteration 2018-02-09 23:49:03 +13:00
Rob Bygrave c61da5b0e5 [maven-release-plugin] prepare release ebean-spring-txn-11.10.3 2018-02-09 23:48:50 +13:00
Rob Bygrave 49d724ad65 Bump pom version to align with Ebean version 2018-02-09 23:48:01 +13:00
Rob Bygrave 3ee2410a79 #18 - SpringJdbcTransactionManager inifinite recursion (Ebean #1254)
Update pom ebean version
2018-02-09 23:46:38 +13:00
Rob Bygrave c2ddc70565 #18 - SpringJdbcTransactionManager inifinite recursion (Ebean #1254) 2018-02-09 23:05:27 +13:00
Rob Bygrave 2f66e07c25 Add test for https://github.com/ebean-orm/ebean/issues/1254 2018-02-09 22:20:57 +13:00
Rob Bygrave 0807569ee2 Update readme 2018-02-03 00:14:00 +13:00
Rob Bygrave 206dec1bf8 [maven-release-plugin] prepare for next development iteration 2018-02-03 00:05:12 +13:00
Rob Bygrave 0e852f5bb5 [maven-release-plugin] prepare release ebean-spring-txn-11.10.1 2018-02-03 00:04:59 +13:00
Rob Bygrave a272fb4e02 #17 - Refactor to use the better internals in Ebean 11.10.1 2018-02-03 00:04:22 +13:00
Rob Bygrave cbdc6e09aa [maven-release-plugin] prepare for next development iteration 2018-01-30 23:53:23 +13:00
Rob Bygrave 211087f636 [maven-release-plugin] prepare release ebean-spring-txn-11.5.1 2018-01-30 23:53:10 +13:00
Rob Bygrave dca824b431 #16 - Bump to support Ebean 11.5.1+ 2018-01-30 23:52:40 +13:00
Rob Bygrave 6bcc8eb0f2 Update Readme 2016-12-21 21:11:00 +13:00
Rob Bygrave 844df4d5c9 Update scm due to rename to ebean-spring-txn 2016-12-21 21:04:47 +13:00
Rob Bygrave 6360d5fe1c [maven-release-plugin] prepare for next development iteration 2016-12-21 20:59:11 +13:00
11 changed files with 178 additions and 237 deletions
+27 -2
View File
@@ -1,4 +1,29 @@
avaje-ebeanorm-spring
ebean-spring-txn
=====================
Spring integration with EbeanORM
Integration with Spring managed transactions.
This project provides an Ebean `ExternalTransactionManager` specifically
to integrate with Springs JDBC Transaction manager.
## To use
```java
ServerConfig serverConfig = new ServerConfig();
// set SpringJdbcTransactionManager ... as the external transaction manager
serverConfig.setExternalTransactionManager(new SpringJdbcTransactionManager());
...
EbeanServer server = EbeanServerFactory.create(serverConfig);
```
## Notes
You can use Ebean in Spring/Spring Boot *without* this and that case Ebean
manages the Transactions itself. With Ebean managing the transactions there
are some benefits with more control over JDBC batch, getGeneratedKeys
and a simpler abstraction (as Spring transactions is designed to manage
multiple resources such as JDBC Transactions and JPA EntityManager and Ebean
only needs to manage JDBC Transactions).
+33 -13
View File
@@ -4,13 +4,13 @@
<parent>
<groupId>org.avaje</groupId>
<artifactId>java8-parent</artifactId>
<version>1.3</version>
<artifactId>java8-oss</artifactId>
<version>2.2</version>
</parent>
<groupId>io.ebean</groupId>
<artifactId>ebean-spring-txn</artifactId>
<version>10.1.1</version>
<version>12.4.2</version>
<name>ebean-spring-txn</name>
<packaging>jar</packaging>
@@ -24,22 +24,22 @@
<url>http://ebean-orm.github.io/</url>
<scm>
<developerConnection>scm:git:git@github.com:ebean-orm/ebean-spring.git</developerConnection>
<tag>ebean-spring-txn-10.1.1</tag>
<developerConnection>scm:git:git@github.com:ebean-orm/ebean-spring-txn.git</developerConnection>
<tag>ebean-spring-txn-12.4.2</tag>
</scm>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
<version>1.7.25</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean</artifactId>
<version>[10,)</version>
<version>12.4.1</version>
<scope>provided</scope>
</dependency>
@@ -79,10 +79,30 @@
</dependency>
<dependency>
<groupId>org.avaje.composite</groupId>
<artifactId>avaje-composite-testing-ebean</artifactId>
<version>4.1</version>
<type>pom</type>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
@@ -100,11 +120,11 @@
<plugin>
<groupId>io.repaint.maven</groupId>
<artifactId>tiles-maven-plugin</artifactId>
<version>2.8</version>
<version>2.17</version>
<extensions>true</extensions>
<configuration>
<tiles>
<tile>io.ebean.tile:enhancement:2.1</tile>
<tile>io.ebean.tile:enhancement:12.4.1</tile>
</tiles>
</configuration>
</plugin>
@@ -1,27 +1,8 @@
/**
* Copyright (C) 2009 the original author or authors
* <p>
* This file is part of Ebean.
* <p>
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
* <p>
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package io.ebean.spring.txn;
import io.ebean.TxScope;
import io.ebean.config.ExternalTransactionManager;
import io.ebeaninternal.api.SpiTransaction;
import io.ebeaninternal.server.transaction.DefaultTransactionThreadLocal;
import io.ebeaninternal.server.transaction.TransactionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -57,11 +38,6 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
*/
private TransactionManager transactionManager;
/**
* The EbeanServer name.
*/
private String serverName;
/**
* Instantiates a new spring aware transaction scope manager.
*/
@@ -73,13 +49,10 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
*/
@Override
public void setTransactionManager(Object txnMgr) {
// 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();
}
/**
@@ -90,19 +63,16 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
*/
@Override
public Object getCurrentTransaction() {
// Get the current Spring ConnectionHolder associated to the current spring managed transaction
ConnectionHolder holder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
if (holder == null || !holder.isSynchronizedWithTransaction()) {
// no current Spring transaction
SpiTransaction currentEbeanTransaction = DefaultTransactionThreadLocal.get(serverName);
if (currentEbeanTransaction != null) { // this is unexpected
log.warn("No current Spring transaction BUT using current Ebean one {}", currentEbeanTransaction.getId());
SpiTransaction currentEbeanTransaction = transactionManager.getInScope();
if (currentEbeanTransaction == null || !currentEbeanTransaction.isActive()) {
return null;
} else {
log.trace("No current Spring transaction");
return currentEbeanTransaction;
}
return currentEbeanTransaction;
}
SpringTxnListener springTxnLister = getSpringTxnListener();
@@ -117,10 +87,7 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
// Create and register a Spring TransactionSynchronization for this transaction
springTxnLister = createSpringTxnListener(newTrans);
TransactionSynchronizationManager.registerSynchronization(springTxnLister);
// also put in Ebean ThreadLocal
DefaultTransactionThreadLocal.set(serverName, newTrans);
return newTrans;
return transactionManager.externalBeginTransaction(newTrans, TxScope.required());
}
}
@@ -131,7 +98,6 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
* </p>
*/
private SpringTxnListener getSpringTxnListener() {
if (TransactionSynchronizationManager.isSynchronizationActive()) {
List<TransactionSynchronization> synchronizations = TransactionSynchronizationManager.getSynchronizations();
if (synchronizations != null) {
@@ -143,7 +109,6 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
}
}
}
return null;
}
@@ -174,18 +139,15 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
private final SpringJdbcTransaction transaction;
private final String serverName;
private SpringTxnListener(TransactionManager transactionManager, SpringJdbcTransaction t) {
this.transactionManager = transactionManager;
this.transaction = t;
this.serverName = transactionManager.getServerName();
}
/**
* Return the associated Ebean wrapped transaction.
*/
public SpringJdbcTransaction getTransaction() {
SpringJdbcTransaction getTransaction() {
return transaction;
}
@@ -196,13 +158,13 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
@Override
public void beforeCommit(boolean readOnly) {
// Future note: for JPA2 locking we will
// have beforeCommit events to fire
if (!readOnly) {
transaction.flushBatch();
}
}
@Override
public void afterCompletion(int status) {
switch (status) {
case STATUS_COMMITTED:
log.debug("Spring Txn [{}] committed", transaction.getId());
@@ -220,7 +182,7 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
}
// Remove this transaction object as it is completed
DefaultTransactionThreadLocal.replace(serverName, null);
transactionManager.externalRemoveTransaction();
}
}
}
-26
View File
@@ -1,41 +1,15 @@
/**
* Copyright (C) 2009 the original author or authors
* <p>
* This file is part of Ebean.
* <p>
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
* <p>
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.example;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
/**
* The Class Account.
* @since 18.05.2009
* @author E Mc Greal
*/
@Entity
public class Account {
/** The id. */
@Id
private Long id;
/** The user. */
@OneToOne
private User user;
@@ -1,24 +1,6 @@
/**
* Copyright (C) 2009 the original author or authors
* <p>
* This file is part of Ebean.
* <p>
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
* <p>
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.example;
import io.ebean.annotation.PersistBatch;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
@@ -50,6 +32,7 @@ public class EbeanServerFactoryBean implements InitializingBean, FactoryBean<Ebe
throw new Exception("No ServerConig set. You must define a ServerConfig bean");
}
serverConfig.setPersistBatch(PersistBatch.ALL);
// Create the new EbeanServer using the configuration
this.ebeanServer = EbeanServerFactory.create(serverConfig);
}
@@ -1,30 +1,17 @@
/**
* Copyright (C) 2009 the original author or authors
* <p>
* This file is part of Ebean.
* <p>
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
* <p>
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.example;
import java.util.logging.Logger;
import io.ebean.DB;
import io.ebean.Ebean;
import io.ebean.Transaction;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -38,7 +25,7 @@ import static org.junit.Assert.assertTrue;
public class EbeanSpringModuleTest {
/** The Constant logger. */
private final static Logger logger = Logger.getLogger(EbeanSpringModuleTest.class.getName());
private final static Logger logger = LoggerFactory.getLogger(EbeanSpringModuleTest.class);
/** The user service. */
@Autowired
@@ -51,6 +38,27 @@ public class EbeanSpringModuleTest {
super();
}
/**
* Test app.
*/
@Test
public void testInactiveTransaction() {
Transaction transaction = Ebean.beginTransaction();
long id;
try {
User user = new User();
user.setName("save with txn 1");
Ebean.save(user);
transaction.commit();
id = user.getOid();
} finally {
// don't end the transaction ...
//transaction.end();
}
Ebean.delete(User.class, id);
}
@Test
public void testBatchInsert() {
@@ -68,6 +76,10 @@ public class EbeanSpringModuleTest {
user.setName("ebean");
userService.save(user);
logger.info("Saved new User");
assertThat(user.getOid()).isGreaterThan(0);
final User found = DB.find(User.class, user.getOid());
assertThat(found).isNotNull();
}
/**
@@ -83,6 +95,20 @@ public class EbeanSpringModuleTest {
logger.info("Found User with OID = 1");
}
@Test
public void testNonTransactional() {
userService.nonTransactional();
logger.info("nonTransactional done");
}
@Test
public void testFindNonTransactional() {
logger.info("Finding User with OID = 1 ...");
User user = userService.find(1);
User user2 = userService.findNoCurrentTransaction(2);
logger.info("nonTransactional find user1:{} user2:{}", user, user2);
}
/**
* Return the user service.
*/
-25
View File
@@ -1,23 +1,3 @@
/**
* Copyright (C) 2009 the original author or authors
* <p>
* This file is part of Ebean.
* <p>
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
* <p>
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.example;
import java.util.Set;
@@ -25,11 +5,6 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
/**
* The Class Role.
* @since 18.05.2009
* @author E Mc Greal
*/
@Entity
public class Role {
+6 -25
View File
@@ -1,22 +1,3 @@
/**
* Copyright (C) 2009 the original author or authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.example;
import javax.persistence.Entity;
@@ -25,13 +6,9 @@ import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import java.util.Set;
/**
* The Class User.
* @since 18.05.2009
* @author E Mc Greal
*/
@Entity
public class User {
@Id
long oid;
@@ -40,9 +17,13 @@ public class User {
@ManyToMany
private Set<Role> roles;
@OneToOne(mappedBy="user")
@OneToOne(mappedBy = "user")
private Account account;
public String toString() {
return "{user:" + oid + " name:" + name + "}";
}
public long getOid() {
return oid;
}
+6 -24
View File
@@ -1,35 +1,17 @@
/**
* Copyright (C) 2009 the original author or authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.example;
/**
* The Interface UserService.
* @since 18.05.2009
* @author E Mc Greal
*/
public interface UserService {
void save(User user);
void save(User user);
User find(long id);
void batchInsert();
User findNoCurrentTransaction(long id);
void nonTransactional();
void batchInsert();
}
+14 -33
View File
@@ -1,27 +1,6 @@
/**
* Copyright (C) 2009 the original author or authors
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
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 +22,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 +32,19 @@ public class UserServiceImpl implements UserService {
return ebeanServer.find(User.class, id);
}
public void nonTransactional() {
ebeanServer.currentTransaction();
}
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void batchInsert(){
public User findNoCurrentTransaction(long id) {
return ebeanServer.find(User.class, id);
}
List<User> users = new ArrayList<User>();
for(int i=0 ;i<5;i++){
@Transactional(propagation = Propagation.REQUIRED)
public void batchInsert() {
List<User> users = new ArrayList<>();
for(int i=0 ;i<25;i++){
User user = new User();
user.setName("user"+i);
users.add(user);
@@ -69,11 +52,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-------");
}
+32
View File
@@ -0,0 +1,32 @@
<configuration scan="true" scanPeriod="10 seconds">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>TRACE</level>
</filter>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
<logger name="io.ebean" level="INFO"/>
<!-- sql and transaction logging -->
<logger name="io.ebean.SQL" level="TRACE"/>
<logger name="io.ebean.TXN" level="TRACE"/>
<logger name="io.ebean.SUM" level="TRACE"/>
<logger name="io.ebean.DDL" level="TRACE"/>
<!-- l2 cache logging -->
<logger name="io.ebean.cache.QUERY" level="TRACE"/>
<logger name="io.ebean.cache.BEAN" level="TRACE"/>
<logger name="io.ebean.cache.COLL" level="TRACE"/>
<logger name="io.ebean.cache.NATKEY" level="TRACE"/>
<!-- elasticSearch query logging -->
<!--<logger name="io.ebean.ELA" level="TRACE"/>-->
</configuration>