mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9575048b4 | ||
|
|
82fd6dc65f | ||
|
|
5b4ff2627c | ||
|
|
2aa92d63fd | ||
|
|
658b5b7e06 | ||
|
|
4e3cd83e36 | ||
|
|
e00e490e73 | ||
|
|
dd95081e63 |
@@ -1,3 +1,6 @@
|
||||
[](https://maven-badges.herokuapp.com/maven-central/io.ebean/ebean-spring-txn)
|
||||
[](https://github.com/ebean-orm/ebean-spring-txn/blob/master/LICENSE)
|
||||
|
||||
ebean-spring-txn
|
||||
=====================
|
||||
|
||||
@@ -9,21 +12,34 @@ to integrate with Springs JDBC Transaction manager.
|
||||
## To use
|
||||
|
||||
```java
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
|
||||
// set SpringJdbcTransactionManager ... as the external transaction manager
|
||||
serverConfig.setExternalTransactionManager(new SpringJdbcTransactionManager());
|
||||
config.setExternalTransactionManager(new SpringJdbcTransactionManager());
|
||||
|
||||
...
|
||||
EbeanServer server = EbeanServerFactory.create(serverConfig);
|
||||
Database database = DatabaseFactory.create(config);
|
||||
|
||||
```
|
||||
|
||||
## 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
|
||||
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).
|
||||
only needs to manage JDBC Transactions).
|
||||
|
||||
|
||||
## Java modules
|
||||
|
||||
Add `requires io.ebean.spring.txn` to module-info.
|
||||
|
||||
```java
|
||||
module foo {
|
||||
|
||||
requires io.ebean.spring.txn;
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
@@ -10,14 +10,14 @@
|
||||
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-spring-txn</artifactId>
|
||||
<version>13.9.1</version>
|
||||
<version>13.13.0</version>
|
||||
|
||||
<name>ebean-spring-txn</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Ebean support for Spring transactions</description>
|
||||
|
||||
<properties>
|
||||
<spring.framework.version>5.3.22</spring.framework.version>
|
||||
<spring.framework.version>5.3.25</spring.framework.version>
|
||||
<spring.boot.version>2.7.3</spring.boot.version>
|
||||
<surefire.useModulePath>false</surefire.useModulePath>
|
||||
</properties>
|
||||
@@ -32,28 +32,28 @@
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>1.7.32</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean</artifactId>
|
||||
<version>13.9.2</version>
|
||||
<version>13.13.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-ddl-generator</artifactId>
|
||||
<version>13.9.2</version>
|
||||
<version>13.13.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.13.3</version>
|
||||
<version>2.14.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ final class SpringJdbcTransaction extends ExternalJdbcTransaction {
|
||||
private final ConnectionHolder holder;
|
||||
|
||||
SpringJdbcTransaction(ConnectionHolder holder, TransactionManager manager) {
|
||||
super("s" + holder.hashCode(), true, holder.getConnection(), manager);
|
||||
super(true, holder.getConnection(), manager);
|
||||
this.holder = holder;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import io.ebeaninternal.api.SpiTransaction;
|
||||
import io.ebeaninternal.server.transaction.TransactionManager;
|
||||
import org.springframework.jdbc.datasource.ConnectionHolder;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
@@ -91,12 +90,10 @@ public final class SpringJdbcTransactionManager implements ExternalTransactionMa
|
||||
private SpringTxnListener listener() {
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
List<TransactionSynchronization> synchronizations = TransactionSynchronizationManager.getSynchronizations();
|
||||
if (synchronizations != null) {
|
||||
// search for our specific listener
|
||||
for (TransactionSynchronization synchronization : synchronizations) {
|
||||
if (synchronization instanceof SpringTxnListener) {
|
||||
return (SpringTxnListener) synchronization;
|
||||
}
|
||||
// search for our specific listener
|
||||
for (TransactionSynchronization synchronization : synchronizations) {
|
||||
if (synchronization instanceof SpringTxnListener) {
|
||||
return (SpringTxnListener) synchronization;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,7 +114,7 @@ public final class SpringJdbcTransactionManager implements ExternalTransactionMa
|
||||
* When Ebean is notified (of the commit/rollback) it can then manage its cache, notify
|
||||
* BeanPersistListeners etc.
|
||||
*/
|
||||
private static class SpringTxnListener extends TransactionSynchronizationAdapter {
|
||||
private static class SpringTxnListener implements TransactionSynchronization {
|
||||
|
||||
private final TransactionManager transactionManager;
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
<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>
|
||||
@@ -29,4 +26,4 @@
|
||||
<!-- elasticSearch query logging -->
|
||||
<!--<logger name="io.ebean.ELA" level="TRACE"/>-->
|
||||
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
||||
Reference in New Issue
Block a user