mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
Adjustment on #1711, fix clearing of inactive transactions from thread local
Handles implicit transactions for update and delete queries plus delete by id
This commit is contained in:
1 parent
1042fdb280
commit
9326c9c79e
4 files changed
+17
-3
No files matched your search
@@ -2235,6 +2235,8 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
} catch (RuntimeException e) {
|
||||
wrap.endIfCreated();
|
||||
throw e;
|
||||
} finally {
|
||||
wrap.clearIfCreated();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,4 +41,7 @@ class ObtainedTransaction {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public void clearIfCreated() {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package io.ebeaninternal.server.core;
|
||||
|
||||
import io.ebean.EbeanServer;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.api.SpiTransaction;
|
||||
|
||||
/**
|
||||
@@ -11,12 +11,12 @@ import io.ebeaninternal.api.SpiTransaction;
|
||||
*/
|
||||
final class ObtainedTransactionImplicit extends ObtainedTransaction {
|
||||
|
||||
private final EbeanServer server;
|
||||
private final SpiEbeanServer server;
|
||||
|
||||
/**
|
||||
* Wrap the transaction indicating if it was just created.
|
||||
*/
|
||||
ObtainedTransactionImplicit(SpiTransaction t, EbeanServer server) {
|
||||
ObtainedTransactionImplicit(SpiTransaction t, SpiEbeanServer server) {
|
||||
super(t);
|
||||
this.server = server;
|
||||
}
|
||||
@@ -31,4 +31,9 @@ final class ObtainedTransactionImplicit extends ObtainedTransaction {
|
||||
server.endTransaction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearIfCreated() {
|
||||
server.clearServerTransaction();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -350,6 +350,10 @@ public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQuery
|
||||
public void endTransIfRequired() {
|
||||
if (createdTransaction && transaction.isActive()) {
|
||||
transaction.commit();
|
||||
if (query.getType().isUpdate()) {
|
||||
// for implicit update/delete queries clear the thread local
|
||||
ebeanServer.clearServerTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user