Java Code Examples for org.keycloak.models.utils.KeycloakModelUtils#suspendJtaTransaction()

The following examples show how to use org.keycloak.models.utils.KeycloakModelUtils#suspendJtaTransaction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LiquibaseDBLockProvider.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void releaseLock() {
    KeycloakModelUtils.suspendJtaTransaction(session.getKeycloakSessionFactory(), () -> {
        lazyInit();

        logger.debugf("Going to release database lock namespace=%s", namespaceLocked);
        namespaceLocked = null;
        lockService.releaseLock();
        lockService.reset();
    });
}
 
Example 2
Source File: LiquibaseDBLockProvider.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void destroyLockInfo() {
    KeycloakModelUtils.suspendJtaTransaction(session.getKeycloakSessionFactory(), () -> {
        lazyInit();

        try {
            this.lockService.destroy();
            dbConnection.commit();
            logger.debug("Destroyed lock table");
        } catch (DatabaseException | SQLException de) {
            logger.error("Failed to destroy lock table");
            safeRollbackConnection();
        }
    });
}
 
Example 3
Source File: QuarkusJpaConnectionProviderFactory.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void lazyInit() {
    Instance<EntityManagerFactory> instance = CDI.current().select(EntityManagerFactory.class);

    if (!instance.isResolvable()) {
        throw new RuntimeException("Failed to resolve " + EntityManagerFactory.class + " from Quarkus runtime");
    }

    emf = instance.get();

    try (Connection connection = getConnection()) {
        if (jtaEnabled) {
            KeycloakModelUtils.suspendJtaTransaction(factory, () -> {
                KeycloakSession session = factory.create();
                try {
                    migration(getSchema(), connection, session);
                } finally {
                    session.close();
                }
            });
        } else {
            KeycloakModelUtils.runJobInTransaction(factory, session -> {
                migration(getSchema(), connection, session);
            });
        }
        prepareOperationalInfo(connection);
    } catch (SQLException cause) {
        throw new RuntimeException("Failed to migrate model", cause);
    }
}
 
Example 4
Source File: LiquibaseDBLockProvider.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Override
public void close() {
    KeycloakModelUtils.suspendJtaTransaction(session.getKeycloakSessionFactory(), () -> {
        safeCloseConnection();
    });
}