Compare commits

...
Author SHA1 Message Date
Rob Bygrave a2c82263ee Bump to 12.12.0 2021-09-24 11:29:50 +12:00
rbygrave 30f3d542b3 Bump to 12.11.4 2021-09-09 13:10:13 +12:00
rbygrave 56cb2c69aa Bump to 12.11.1 2021-08-16 19:49:02 +12:00
rbygrave bd1dd43cbf Bump to 12.11.0 2021-08-16 19:43:28 +12:00
rob bygrave 5caae29df9 [maven-release-plugin] prepare for next development iteration 2020-12-23 20:46:33 +13:00
rob bygrave 9713b607b5 [maven-release-plugin] prepare release ebean-spring-txn-12.6.4 2020-12-23 20:46:10 +13:00
rob bygrave 0e46558cae Bump ebean to 12.6.4 for #22 2020-12-23 20:45:33 +13:00
Rob BygraveandGitHub 2386f1034b Merge pull request #24 from spinachomes/master
add fail situation for transaction Propagation.REQUIRES_NEW
2020-12-21 16:30:02 +13:00
李清波 ddf9f5c508 add fail situation for transaction Propagation.REQUIRES_NEW 2020-12-21 11:23:00 +08:00
rob bygrave 559867294f Add test for transaction Propagation.REQUIRES_NEW 2020-12-21 14:47:23 +13:00
rob bygrave bf0c8d8dab Add test for transaction Propagation.REQUIRES_NEW 2020-12-21 14:45:13 +13:00
rob bygrave 7077e92cb0 [maven-release-plugin] prepare for next development iteration 2020-12-18 15:29:36 +13:00
rob bygrave 035c5570c3 [maven-release-plugin] prepare release ebean-spring-txn-12.6.3 2020-12-18 15:29:25 +13:00
rob bygrave 0be0fd1e05 Bump to 12.6.3-SNAPSHOT 2020-12-18 15:28:31 +13:00
rob bygrave bdfd380687 #23 - Use updated PostCommit to send ChangeLog changes. Use PreCommit to flush last ChangeLog changes at PreCommit 2020-12-18 14:55:57 +13:00
rob bygrave d1a4c73cd6 [maven-release-plugin] prepare for next development iteration 2020-12-18 10:01:04 +13:00
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
11 changed files with 149 additions and 191 deletions
+15
View File
@@ -6,6 +6,21 @@ 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
+24 -10
View File
@@ -4,13 +4,13 @@
<parent>
<groupId>org.avaje</groupId>
<artifactId>java8-parent</artifactId>
<version>1.3</version>
<artifactId>java8-oss</artifactId>
<version>3.2</version>
</parent>
<groupId>io.ebean</groupId>
<artifactId>ebean-spring-txn</artifactId>
<version>11.10.1</version>
<version>12.12.0</version>
<name>ebean-spring-txn</name>
<packaging>jar</packaging>
@@ -25,24 +25,38 @@
<scm>
<developerConnection>scm:git:git@github.com:ebean-orm/ebean-spring-txn.git</developerConnection>
<tag>ebean-spring-txn-11.10.1</tag>
<tag>HEAD</tag>
</scm>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
<version>1.7.30</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean</artifactId>
<version>11.10.1</version>
<version>12.12.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-ddl-generator</artifactId>
<version>12.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.0</version>
<scope>test</scope>
</dependency>
<!-- Provided: Spring, Spring Boot -->
<dependency>
<groupId>org.springframework</groupId>
@@ -81,7 +95,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
@@ -95,7 +109,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
<version>1.4.199</version>
<scope>test</scope>
</dependency>
@@ -120,11 +134,11 @@
<plugin>
<groupId>io.repaint.maven</groupId>
<artifactId>tiles-maven-plugin</artifactId>
<version>2.8</version>
<version>2.24</version>
<extensions>true</extensions>
<configuration>
<tiles>
<tile>io.ebean.tile:enhancement:5.2</tile>
<tile>io.ebean.tile:enhancement:12.12.0</tile>
</tiles>
</configuration>
</plugin>
@@ -49,11 +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.dataSource = transactionManager.dataSource();
}
/**
@@ -64,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 = transactionManager.get();
if (currentEbeanTransaction != null) { // this is unexpected
log.warn("No current Spring transaction BUT using current Ebean one {}", currentEbeanTransaction.getId());
SpiTransaction currentEbeanTransaction = transactionManager.inScope();
if (currentEbeanTransaction == null || !currentEbeanTransaction.isActive()) {
return null;
} else {
log.trace("No current Spring transaction");
return currentEbeanTransaction;
}
return currentEbeanTransaction;
}
SpringTxnListener springTxnLister = getSpringTxnListener();
@@ -91,7 +87,6 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
// Create and register a Spring TransactionSynchronization for this transaction
springTxnLister = createSpringTxnListener(newTrans);
TransactionSynchronizationManager.registerSynchronization(springTxnLister);
return transactionManager.externalBeginTransaction(newTrans, TxScope.required());
}
}
@@ -103,7 +98,6 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
* </p>
*/
private SpringTxnListener getSpringTxnListener() {
if (TransactionSynchronizationManager.isSynchronizationActive()) {
List<TransactionSynchronization> synchronizations = TransactionSynchronizationManager.getSynchronizations();
if (synchronizations != null) {
@@ -115,7 +109,6 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
}
}
}
return null;
}
@@ -165,22 +158,22 @@ 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.preCommit();
}
}
@Override
public void afterCompletion(int status) {
switch (status) {
case STATUS_COMMITTED:
log.debug("Spring Txn [{}] committed", transaction.getId());
transactionManager.notifyOfCommit(transaction);
transaction.postCommit();
break;
case STATUS_ROLLED_BACK:
log.debug("Spring Txn [{}] rollback", transaction.getId());
transactionManager.notifyOfRollback(transaction, null);
transaction.postRollback(null);
break;
default:
-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,13 +38,38 @@ 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() {
userService.batchInsert();
}
@Test
public void testRequiresNew() {
userService.requiresNew();
}
/**
* Test app.
*/
@@ -68,6 +80,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 +99,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 {
+9 -26
View File
@@ -1,37 +1,16 @@
/**
* 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.Model;
import javax.persistence.Entity;
import javax.persistence.Id;
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 {
public class User extends Model {
@Id
long oid;
@@ -40,9 +19,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;
}
+8 -24
View File
@@ -1,35 +1,19 @@
/**
* 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();
void requiresNew();
}
+28 -21
View File
@@ -1,27 +1,10 @@
/**
* 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 org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@@ -36,7 +19,9 @@ import java.util.List;
* @since 18.05.2009
* @author E Mc Greal
*/
public class UserServiceImpl implements UserService {
public class UserServiceImpl implements UserService, ApplicationContextAware {
private ApplicationContext applicationContext;
/** The ebean server. */
@Autowired
@@ -52,6 +37,14 @@ public class UserServiceImpl implements UserService {
return ebeanServer.find(User.class, id);
}
public void nonTransactional() {
ebeanServer.currentTransaction();
}
public User findNoCurrentTransaction(long id) {
return ebeanServer.find(User.class, id);
}
@Transactional(propagation = Propagation.REQUIRED)
public void batchInsert() {
@@ -69,8 +62,18 @@ public class UserServiceImpl implements UserService {
ebeanServer.saveAll(users);
System.out.println("---------after batch-------");
applicationContext.getBean(UserService.class).requiresNew();
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void requiresNew() {
User user = new User();
user.setName("user_x0");
user.insert();
//ebeanServer.save(user);
}
/**
* Return the ebean server.
@@ -87,4 +90,8 @@ public class UserServiceImpl implements UserService {
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
+1 -1
View File
@@ -8,7 +8,7 @@
</encoder>
</appender>
<root level="WARN">
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>