0

I have an import method. First, a session record is created in the database. Then comes the import process, wrapped in a transaction.

   private void importTables(File sessionRootDirectory, UUID sessionId, ImportResult result) {
    asyncJdbi.useTransaction(handle -> {
        try {
            sessionService.updateSession(sessionId, EiSessionStatus.RUNNING);
            String rootPath = sessionRootDirectory.getPath();
            ImportContext importContext = new ImportContext(rootPath, handle, result, sessionId);
            if (importContext.getTotalImportFilesCount() > 0) {
                processTables(importContext);
            } else {
                updateStatisticForEmptyArchive(importContext);
            }
        } catch (RuntimeException | IOException e) {
            result.setHasErrors(true);
            handle.rollback();
            log.error(e.getMessage(), e);
        } finally {
            cleanTempTables(handle);
            FileUtils.deleteQuietly(sessionRootDirectory);
        }
    });
}

And at the same time, I need to update some session parameters as the import progresses (sessionService.updateSession(sessionId, EiSessionStatus.RUNNING);.

I'm using one instance of JDBI for transaction and updating session in db. This is method to update session

public void updateSession(UUID sessionId, EiSessionStatus status) {
    asyncJdbi.useHandle(handle -> handle.attach(EiSessionRepository.class)
            .updateEiSessionStatus(sessionId, status));
}

But my session is not updated as the jdbi is waiting for the open transaction to complete. Why jdbi.useHandle doesn't create new handle and execute requests, but wait for the transaction to complete? I want to use the new handle to update the session, not use the transaction in use

0 Answers0