mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-04 06:33:10 +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) {
|
||||
RequestEvent.Type type = event.getType();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -34,16 +34,18 @@ public class JdbiTransactionManager {
|
||||
public void begin(boolean autoCommit) {
|
||||
try {
|
||||
Handle handle = handleManager.get();
|
||||
handle.getConnection().setAutoCommit(autoCommit);
|
||||
handle.getConfig(Handles.class).setForceEndTransactions(false);
|
||||
handle.begin();
|
||||
IN_TRANSACTION_HANDLES.add(handle.hashCode());
|
||||
LOG.debug(
|
||||
"Begin Transaction Thread Id [{}] has handle id [{}] Transaction {} Level {}",
|
||||
Thread.currentThread().getId(),
|
||||
handle.hashCode(),
|
||||
handle.isInTransaction(),
|
||||
handle.getTransactionIsolationLevel());
|
||||
if (autoCommit) {
|
||||
handle.getConnection().setAutoCommit(autoCommit);
|
||||
handle.getConfig(Handles.class).setForceEndTransactions(false);
|
||||
handle.begin();
|
||||
IN_TRANSACTION_HANDLES.add(handle.hashCode());
|
||||
LOG.debug(
|
||||
"Begin Transaction Thread Id [{}] has handle id [{}] Transaction {} Level {}",
|
||||
Thread.currentThread().getId(),
|
||||
handle.hashCode(),
|
||||
handle.isInTransaction(),
|
||||
handle.getTransactionIsolationLevel());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
terminateHandle();
|
||||
}
|
||||
@ -71,7 +73,7 @@ public class JdbiTransactionManager {
|
||||
}
|
||||
|
||||
public void rollback() {
|
||||
if (IN_TRANSACTION_HANDLES.contains(handleManager.get().hashCode())) {
|
||||
if (handleManager.handleExists()) {
|
||||
Handle handle = handleManager.get();
|
||||
if (handle == null) {
|
||||
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());
|
||||
} else {
|
||||
Object dao;
|
||||
Object result;
|
||||
if (JdbiUnitOfWorkProvider.getInstance().getHandleManager().handleExists()) {
|
||||
Handle handle = JdbiUnitOfWorkProvider.getInstance().getHandle();
|
||||
LOG.debug(
|
||||
@ -53,16 +54,24 @@ public class ManagedHandleInvocationHandler<T> implements InvocationHandler {
|
||||
handle.hashCode());
|
||||
|
||||
dao = handle.attach(underlying);
|
||||
result = invokeMethod(method, dao, args);
|
||||
} else {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return method.invoke(dao, args);
|
||||
} catch (Exception ex) {
|
||||
throw ex.getCause();
|
||||
}
|
||||
private Object invokeMethod(Method method, Object dao, Object[] args) throws Throwable {
|
||||
try {
|
||||
return method.invoke(dao, args);
|
||||
} catch (Exception ex) {
|
||||
throw ex.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user