mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-08 16:38:04 +00:00
set autocommit to true for non transactional (#13184)
* set autocommit to true for non transactional * set autocommit to true for non transactional
This commit is contained in:
parent
4f20070e6d
commit
03fc4d8be5
@ -13,7 +13,9 @@ class HttpGetRequestJdbiUnitOfWorkEventListener implements RequestEventListener
|
|||||||
public void onEvent(RequestEvent event) {
|
public void onEvent(RequestEvent event) {
|
||||||
RequestEvent.Type type = event.getType();
|
RequestEvent.Type type = event.getType();
|
||||||
LOG.debug("Handling GET Request Event {} {}", type, Thread.currentThread().getId());
|
LOG.debug("Handling GET Request Event {} {}", type, Thread.currentThread().getId());
|
||||||
if (type == RequestEvent.Type.FINISHED) {
|
if (type == RequestEvent.Type.RESOURCE_METHOD_START) {
|
||||||
|
JdbiTransactionManager.getInstance().begin(true);
|
||||||
|
} else if (type == RequestEvent.Type.FINISHED) {
|
||||||
JdbiTransactionManager.getInstance().terminateHandle();
|
JdbiTransactionManager.getInstance().terminateHandle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ public class JdbiTransactionManager {
|
|||||||
public void begin(boolean autoCommit) {
|
public void begin(boolean autoCommit) {
|
||||||
try {
|
try {
|
||||||
Handle handle = handleManager.get();
|
Handle handle = handleManager.get();
|
||||||
|
if (autoCommit) {
|
||||||
handle.getConnection().setAutoCommit(autoCommit);
|
handle.getConnection().setAutoCommit(autoCommit);
|
||||||
handle.getConfig(Handles.class).setForceEndTransactions(false);
|
handle.getConfig(Handles.class).setForceEndTransactions(false);
|
||||||
handle.begin();
|
handle.begin();
|
||||||
@ -44,6 +45,7 @@ public class JdbiTransactionManager {
|
|||||||
handle.hashCode(),
|
handle.hashCode(),
|
||||||
handle.isInTransaction(),
|
handle.isInTransaction(),
|
||||||
handle.getTransactionIsolationLevel());
|
handle.getTransactionIsolationLevel());
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
terminateHandle();
|
terminateHandle();
|
||||||
}
|
}
|
||||||
@ -71,7 +73,7 @@ public class JdbiTransactionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void rollback() {
|
public void rollback() {
|
||||||
if (IN_TRANSACTION_HANDLES.contains(handleManager.get().hashCode())) {
|
if (handleManager.handleExists()) {
|
||||||
Handle handle = handleManager.get();
|
Handle handle = handleManager.get();
|
||||||
if (handle == null) {
|
if (handle == null) {
|
||||||
LOG.debug("Handle was found to be null during rollback for [{}]", Thread.currentThread().getId());
|
LOG.debug("Handle was found to be null during rollback for [{}]", Thread.currentThread().getId());
|
||||||
|
@ -42,6 +42,7 @@ public class ManagedHandleInvocationHandler<T> implements InvocationHandler {
|
|||||||
return getWrappedInstanceForDaoClass(method.getReturnType());
|
return getWrappedInstanceForDaoClass(method.getReturnType());
|
||||||
} else {
|
} else {
|
||||||
Object dao;
|
Object dao;
|
||||||
|
Object result;
|
||||||
if (JdbiUnitOfWorkProvider.getInstance().getHandleManager().handleExists()) {
|
if (JdbiUnitOfWorkProvider.getInstance().getHandleManager().handleExists()) {
|
||||||
Handle handle = JdbiUnitOfWorkProvider.getInstance().getHandle();
|
Handle handle = JdbiUnitOfWorkProvider.getInstance().getHandle();
|
||||||
LOG.debug(
|
LOG.debug(
|
||||||
@ -53,18 +54,26 @@ public class ManagedHandleInvocationHandler<T> implements InvocationHandler {
|
|||||||
handle.hashCode());
|
handle.hashCode());
|
||||||
|
|
||||||
dao = handle.attach(underlying);
|
dao = handle.attach(underlying);
|
||||||
|
result = invokeMethod(method, dao, args);
|
||||||
} else {
|
} else {
|
||||||
// This is non-transactional request
|
// This is non-transactional request
|
||||||
dao = JdbiUnitOfWorkProvider.getInstance().getHandleManager().getJdbi().onDemand(underlying);
|
Handle handle = JdbiUnitOfWorkProvider.getInstance().getHandleManager().getJdbi().open();
|
||||||
|
handle.getConnection().setAutoCommit(true);
|
||||||
|
dao = handle.attach(underlying);
|
||||||
|
result = invokeMethod(method, dao, args);
|
||||||
|
handle.close();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object invokeMethod(Method method, Object dao, Object[] args) throws Throwable {
|
||||||
try {
|
try {
|
||||||
return method.invoke(dao, args);
|
return method.invoke(dao, args);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw ex.getCause();
|
throw ex.getCause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user