All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.guicedee.guicedpersistence.scanners.PersistenceServiceLoadersBinder Maven / Gradle / Ivy

Go to download

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

There is a newer version: 62
Show newest version
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());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy