com.jwebmp.guicedpersistence.implementations.GuicedPersistenceDestroyer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guiced-persistence Show documentation
Show all versions of guiced-persistence Show documentation
A complete JPA 2.1 implementation for Standalone or EE Implementation. Enables Multiple Persistence units
with full JTA Support using BTM. Perfect for Guice implementations, test suites, and Guice enabled Web Applications or EAR Projects.
Requires JDK 8
package com.jwebmp.guicedpersistence.implementations;
import com.google.inject.persist.PersistService;
import com.jwebmp.guicedinjection.GuiceContext;
import com.jwebmp.guicedinjection.interfaces.IGuicePreDestroy;
import com.jwebmp.guicedpersistence.db.DatabaseModule;
import com.jwebmp.logger.LogFactory;
import java.lang.annotation.Annotation;
import java.util.logging.Level;
import java.util.logging.Logger;
public class GuicedPersistenceDestroyer
implements IGuicePreDestroy
{
private static final Logger log = LogFactory.getLog("GuicedPersistenceDestroyer");
@Override
public void onDestroy()
{
for (Class extends Annotation> boundAnnotation : DatabaseModule.getBoundAnnotations())
{
try
{
log.log(Level.INFO, "Stopping EMF and Persist Service [" + boundAnnotation.getCanonicalName() + "]");
PersistService service = GuiceContext.get(PersistService.class, boundAnnotation);
service.stop();
}
catch (Exception e)
{
log.log(Level.SEVERE, "Unable to close entity managers and factories for annotation [" + boundAnnotation.getCanonicalName() + "]", e);
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy