Compare commits

..
Author SHA1 Message Date
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
11 changed files with 90 additions and 208 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
+7 -7
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.1</version>
</parent>
<groupId>io.ebean</groupId>
<artifactId>ebean-spring-txn</artifactId>
<version>11.5.1</version>
<version>12.2.1</version>
<name>ebean-spring-txn</name>
<packaging>jar</packaging>
@@ -25,7 +25,7 @@
<scm>
<developerConnection>scm:git:git@github.com:ebean-orm/ebean-spring-txn.git</developerConnection>
<tag>ebean-spring-txn-11.5.1</tag>
<tag>ebean-spring-txn-12.2.1</tag>
</scm>
<dependencies>
@@ -39,7 +39,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean</artifactId>
<version>11.5.1</version>
<version>12.2.1</version>
<scope>provided</scope>
</dependency>
@@ -120,11 +120,11 @@
<plugin>
<groupId>io.repaint.maven</groupId>
<artifactId>tiles-maven-plugin</artifactId>
<version>2.8</version>
<version>2.16</version>
<extensions>true</extensions>
<configuration>
<tiles>
<tile>io.ebean.tile:enhancement:5.2</tile>
<tile>io.ebean.tile:enhancement:12.2.1</tile>
</tiles>
</configuration>
</plugin>
@@ -1,33 +1,9 @@
/**
* 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.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;
@@ -62,8 +38,6 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
*/
private TransactionManager transactionManager;
private TransactionScopeManager scope;
/**
* Instantiates a new spring aware transaction scope manager.
*/
@@ -80,7 +54,6 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
// the public API and hence the Object type and casting here
this.transactionManager = (TransactionManager) txnMgr;
this.dataSource = transactionManager.getDataSource();
this.scope = new DefaultTransactionScopeManager(transactionManager);
}
/**
@@ -97,13 +70,12 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
if (holder == null || !holder.isSynchronizedWithTransaction()) {
// no current Spring transaction
SpiTransaction currentEbeanTransaction = scope.get();
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();
@@ -119,10 +91,7 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
springTxnLister = createSpringTxnListener(newTrans);
TransactionSynchronizationManager.registerSynchronization(springTxnLister);
ScopedTransaction scopedTxn = new ScopedTransaction(scope);
scopedTxn.push(new ScopeTrans(true, false, newTrans, TxScope.required()));
scope.set(scopedTxn);
return scopedTxn;
return transactionManager.externalBeginTransaction(newTrans, TxScope.required());
}
}
@@ -176,12 +145,9 @@ 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();
}
/**
@@ -222,7 +188,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,22 +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 org.springframework.beans.factory.FactoryBean;
@@ -1,30 +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 java.util.logging.Logger;
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.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -38,7 +23,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 +36,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() {
@@ -83,6 +89,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();
}
+8 -20
View File
@@ -1,23 +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 io.ebean.Transaction;
@@ -52,6 +32,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() {
+1 -1
View File
@@ -8,7 +8,7 @@
</encoder>
</appender>
<root level="WARN">
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>