com.guicedee.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.guicedee.guicedpersistence.implementations;
import com.google.inject.persist.PersistService;
import com.guicedee.guicedinjection.GuiceContext;
import com.guicedee.guicedinjection.interfaces.IGuicePreDestroy;
import com.guicedee.guicedpersistence.db.DatabaseModule;
import com.guicedee.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);
}
}
}
@Override
public Integer sortOrder()
{
return 500;
}
}