use of org.osgi.service.transaction.control.jpa.JPAEntityManagerProvider 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);
}
}
}
}
use of org.osgi.service.transaction.control.jpa.JPAEntityManagerProvider 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();
}
}
}
}
Aggregations