com.guicedee.guicedpersistence.scanners.PersistenceServiceLoadersBinder 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.scanners;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.google.inject.matcher.Matchers;
import com.guicedee.guicedinjection.GuiceContext;
import com.guicedee.guicedinjection.abstractions.GuiceInjectorModule;
import com.guicedee.guicedinjection.interfaces.IGuiceDefaultBinder;
import com.guicedee.guicedpersistence.db.annotations.Transactional;
import com.guicedee.guicedpersistence.injectors.GuicedPersistenceTxnInterceptor;
import com.guicedee.guicedpersistence.services.IPropertiesConnectionInfoReader;
import com.guicedee.guicedpersistence.services.IPropertiesEntityManagerReader;
import com.guicedee.guicedpersistence.services.ITransactionHandler;
import com.guicedee.guicedpersistence.injectors.CustomJpaLocalTxnInterceptor;
import java.util.ServiceLoader;
import java.util.Set;
public class PersistenceServiceLoadersBinder
implements IGuiceDefaultBinder
{
@SuppressWarnings("Convert2Diamond")
public static final Key> PropertiesEntityManagerReader = Key.get(new TypeLiteral>() {});
@SuppressWarnings("Convert2Diamond")
public static final Key> PropertiesConnectionInfoReader = Key.get(new TypeLiteral>() {});
@SuppressWarnings("Convert2Diamond")
public static final Key> ITransactionHandlerReader = Key.get(new TypeLiteral>() {});
@Override
public void onBind(GuiceInjectorModule module)
{
Set propertiesEntityManager = GuiceContext.instance()
.getLoader(IPropertiesEntityManagerReader.class, true, ServiceLoader.load(
IPropertiesEntityManagerReader.class));
Set IPropertiesConnectionInfoReader = GuiceContext.instance()
.getLoader(IPropertiesConnectionInfoReader.class, true, ServiceLoader.load(
IPropertiesConnectionInfoReader.class));
Set transactionHandlerReader = GuiceContext.instance()
.getLoader(ITransactionHandler.class, true, ServiceLoader.load(
ITransactionHandler.class));
module.bind(PersistenceServiceLoadersBinder.PropertiesEntityManagerReader)
.toInstance(propertiesEntityManager);
module.bind(PersistenceServiceLoadersBinder.PropertiesConnectionInfoReader)
.toInstance(IPropertiesConnectionInfoReader);
module.bind(PersistenceServiceLoadersBinder.ITransactionHandlerReader)
.toInstance(transactionHandlerReader);
module.bindInterceptor(Matchers.any(), Matchers.annotatedWith(Transactional.class), new GuicedPersistenceTxnInterceptor());
module.bindInterceptor(Matchers.any(), Matchers.annotatedWith(com.google.inject.persist.Transactional.class), new CustomJpaLocalTxnInterceptor());
module.bindInterceptor(Matchers.any(), Matchers.annotatedWith(javax.transaction.Transactional.class), new CustomJpaLocalTxnInterceptor());
}
}