Search in sources :

Example 1 with ContextInitializer

use of org.picketlink.idm.spi.ContextInitializer in project wildfly by wildfly.

the class JPAIdentityStoreService method start.

@Override
public void start(StartContext startContext) throws StartException {
    this.storeConfig = this.configurationBuilder.create();
    this.transactionalEntityManagerHelper = new TransactionalEntityManagerHelper(this.transactionSynchronizationRegistry.getValue(), this.transactionManager.getValue());
    try {
        configureEntityManagerFactory();
        configureEntities();
    } catch (Exception e) {
        throw ROOT_LOGGER.idmJpaStartFailed(e);
    }
    this.configurationBuilder.addContextInitializer(new ContextInitializer() {

        @Override
        public void initContextForStore(IdentityContext context, IdentityStore<?> store) {
            if (store instanceof JPAIdentityStore) {
                EntityManager entityManager = context.getParameter(JPAIdentityStore.INVOCATION_CTX_ENTITY_MANAGER);
                if (entityManager == null || !entityManager.isOpen()) {
                    context.setParameter(JPAIdentityStore.INVOCATION_CTX_ENTITY_MANAGER, getEntityManager(getTransactionManager().getValue()));
                }
            }
        }
    });
}
Also used : JPAIdentityStore(org.picketlink.idm.jpa.internal.JPAIdentityStore) EntityManager(javax.persistence.EntityManager) ContextInitializer(org.picketlink.idm.spi.ContextInitializer) IdentityContext(org.picketlink.idm.spi.IdentityContext) NamingException(javax.naming.NamingException) StartException(org.jboss.msc.service.StartException) TransactionalEntityManagerHelper(org.wildfly.extension.picketlink.idm.jpa.transaction.TransactionalEntityManagerHelper)

Aggregations

NamingException (javax.naming.NamingException)1 EntityManager (javax.persistence.EntityManager)1 StartException (org.jboss.msc.service.StartException)1 JPAIdentityStore (org.picketlink.idm.jpa.internal.JPAIdentityStore)1 ContextInitializer (org.picketlink.idm.spi.ContextInitializer)1 IdentityContext (org.picketlink.idm.spi.IdentityContext)1 TransactionalEntityManagerHelper (org.wildfly.extension.picketlink.idm.jpa.transaction.TransactionalEntityManagerHelper)1