Search in sources :

Example 1 with AbstractJPAEntityManagerProvider

use of org.apache.aries.tx.control.jpa.common.impl.AbstractJPAEntityManagerProvider in project aries by apache.

the class AbstractManagedJPAEMFLocator method removedService.

@Override
public void removedService(ServiceReference<EntityManagerFactoryBuilder> reference, EntityManagerFactoryBuilder service) {
    boolean emfbLeft;
    ServiceRegistration<JPAEntityManagerProvider> oldReg = null;
    AbstractJPAEntityManagerProvider toClose = null;
    synchronized (this) {
        emfbLeft = activeEMFB.compareAndSet(service, null);
        if (emfbLeft) {
            toClose = providerObject.get();
            oldReg = serviceReg.getAndSet(null);
        }
    }
    if (oldReg != null) {
        try {
            oldReg.unregister();
        } catch (IllegalStateException ise) {
            LOG.debug("An exception occurred when unregistering a service for {}", pid);
        }
    }
    if (toClose != null) {
        try {
            toClose.close();
        } catch (Exception e) {
            LOG.debug("An Exception occured when closing the Resource provider for {}", pid, e);
        }
    }
    try {
        context.ungetService(reference);
    } catch (IllegalStateException ise) {
        LOG.debug("An exception occurred when ungetting the service for {}", reference);
    }
    if (emfbLeft) {
        ServiceReference<EntityManagerFactoryBuilder> newEMFBuilderRef = emfBuilderTracker.getServiceReference();
        if (newEMFBuilderRef != null) {
            EntityManagerFactoryBuilder newEMFBuilder = emfBuilderTracker.getService(newEMFBuilderRef);
            if (newEMFBuilder != null) {
                updateService(newEMFBuilderRef, newEMFBuilder);
            }
        }
    }
}
Also used : AbstractJPAEntityManagerProvider(org.apache.aries.tx.control.jpa.common.impl.AbstractJPAEntityManagerProvider) AbstractJPAEntityManagerProvider(org.apache.aries.tx.control.jpa.common.impl.AbstractJPAEntityManagerProvider) JPAEntityManagerProvider(org.osgi.service.transaction.control.jpa.JPAEntityManagerProvider) EntityManagerFactoryBuilder(org.osgi.service.jpa.EntityManagerFactoryBuilder) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ConfigurationException(org.osgi.service.cm.ConfigurationException)

Example 2 with AbstractJPAEntityManagerProvider

use of org.apache.aries.tx.control.jpa.common.impl.AbstractJPAEntityManagerProvider in project aries by apache.

the class AbstractManagedJPAEMFLocator method updateService.

private void updateService(ServiceReference<EntityManagerFactoryBuilder> reference, EntityManagerFactoryBuilder service) {
    boolean setEMFB;
    synchronized (this) {
        setEMFB = activeEMFB.compareAndSet(null, service);
    }
    if (setEMFB) {
        AbstractJPAEntityManagerProvider provider = null;
        try {
            provider = getResourceProvider(context, service, reference, jpaProperties, providerProperties, onClose);
            providerObject.set(provider);
            ServiceRegistration<JPAEntityManagerProvider> reg = context.registerService(JPAEntityManagerProvider.class, provider, getServiceProperties());
            if (!serviceReg.compareAndSet(null, reg)) {
                throw new IllegalStateException("Unable to set the JDBC connection provider registration");
            }
        } catch (Exception e) {
            LOG.error("An error occurred when creating the resource provider for {}.", pid, e);
            activeEMFB.compareAndSet(service, null);
            if (provider != null) {
                provider.close();
            }
        }
    }
}
Also used : AbstractJPAEntityManagerProvider(org.apache.aries.tx.control.jpa.common.impl.AbstractJPAEntityManagerProvider) AbstractJPAEntityManagerProvider(org.apache.aries.tx.control.jpa.common.impl.AbstractJPAEntityManagerProvider) JPAEntityManagerProvider(org.osgi.service.transaction.control.jpa.JPAEntityManagerProvider) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ConfigurationException(org.osgi.service.cm.ConfigurationException)

Example 3 with AbstractJPAEntityManagerProvider

use of org.apache.aries.tx.control.jpa.common.impl.AbstractJPAEntityManagerProvider in project aries by apache.

the class DelayedJPAEntityManagerProvider method close.

public void close() {
    AbstractJPAEntityManagerProvider toClose = null;
    synchronized (wireToTransactionControl) {
        if (!closed) {
            closed = true;
            toClose = delegate;
            delegate = null;
        }
    }
    if (toClose != null) {
        toClose.close();
    }
}
Also used : AbstractJPAEntityManagerProvider(org.apache.aries.tx.control.jpa.common.impl.AbstractJPAEntityManagerProvider)

Aggregations

AbstractJPAEntityManagerProvider (org.apache.aries.tx.control.jpa.common.impl.AbstractJPAEntityManagerProvider)3 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 ConfigurationException (org.osgi.service.cm.ConfigurationException)2 JPAEntityManagerProvider (org.osgi.service.transaction.control.jpa.JPAEntityManagerProvider)2 EntityManagerFactoryBuilder (org.osgi.service.jpa.EntityManagerFactoryBuilder)1