Java Code Examples for org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform

The following examples show how to use org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: quarkus   Source File: QuarkusStrategySelectorBuilder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Builds the selector.
 *
 * @param classLoaderService The class loading service used to (attempt to) resolve any un-registered
 *        strategy implementations.
 *
 * @return The selector.
 */
public static StrategySelector buildSelector(ClassLoaderService classLoaderService) {
    final StrategySelectorImpl strategySelector = new StrategySelectorImpl(classLoaderService);

    // build the baseline...
    strategySelector.registerStrategyLazily(Dialect.class, new DefaultDialectSelector());
    strategySelector.registerStrategyLazily(JtaPlatform.class, new DefaultJtaPlatformSelector());
    addTransactionCoordinatorBuilders(strategySelector);
    addMultiTableBulkIdStrategies(strategySelector);
    addImplicitNamingStrategies(strategySelector);
    addCacheKeysFactories(strategySelector);

    // Required to support well known extensions e.g. Envers
    // TODO: should we introduce a new integrator SPI to limit these to extensions supported by Quarkus?
    for (StrategyRegistrationProvider provider : classLoaderService.loadJavaServices(StrategyRegistrationProvider.class)) {
        for (StrategyRegistration discoveredStrategyRegistration : provider.getStrategyRegistrations()) {
            applyFromStrategyRegistration(strategySelector, discoveredStrategyRegistration);
        }
    }

    return strategySelector;
}
 
Example 2
/**
 * Construct a JtaTransactionCoordinatorImpl instance.  package-protected to ensure access goes through
 * builder.
 *
 * @param owner The transactionCoordinatorOwner
 * @param autoJoinTransactions Should JTA transactions be auto-joined?  Or should we wait for explicit join calls?
 */
JtaTransactionCoordinatorImpl(
		TransactionCoordinatorBuilder transactionCoordinatorBuilder,
		TransactionCoordinatorOwner owner,
		boolean autoJoinTransactions) {
	this.transactionCoordinatorBuilder = transactionCoordinatorBuilder;
	this.transactionCoordinatorOwner = owner;
	this.autoJoinTransactions = autoJoinTransactions;

	this.observers = new ArrayList<>();

	final JdbcSessionContext jdbcSessionContext = owner.getJdbcSessionOwner().getJdbcSessionContext();

	this.jtaPlatform = jdbcSessionContext.getServiceRegistry().getService( JtaPlatform.class );

	final SessionFactoryOptions sessionFactoryOptions = jdbcSessionContext.getSessionFactory().getSessionFactoryOptions();
	this.preferUserTransactions = sessionFactoryOptions.isPreferUserTransaction();
	this.performJtaThreadTracking = sessionFactoryOptions.isJtaTrackByThread();

	synchronizationRegistered = false;

	pulse();
}
 
Example 3
public JtaTransactionCoordinatorImpl(
		TransactionCoordinatorBuilder transactionCoordinatorBuilder,
		TransactionCoordinatorOwner owner,
		boolean autoJoinTransactions,
		JtaPlatform jtaPlatform,
		boolean preferUserTransactions,
		boolean performJtaThreadTracking,
		TransactionObserver... observers) {
	this.transactionCoordinatorBuilder = transactionCoordinatorBuilder;
	this.transactionCoordinatorOwner = owner;
	this.autoJoinTransactions = autoJoinTransactions;
	this.jtaPlatform = jtaPlatform;
	this.preferUserTransactions = preferUserTransactions;
	this.performJtaThreadTracking = performJtaThreadTracking;

	this.observers = new ArrayList<>();

	if ( observers != null ) {
		Collections.addAll( this.observers, observers );
	}

	synchronizationRegistered = false;

	pulse();
}
 
Example 4
Source Project: lams   Source File: JtaPlatformInitiator.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
@SuppressWarnings( {"unchecked"})
public JtaPlatform initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
	final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM );
	JtaPlatform platform = registry.getService( StrategySelector.class ).resolveStrategy( JtaPlatform.class, setting );

	if ( platform == null ) {
		LOG.debugf( "No JtaPlatform was specified, checking resolver" );
		platform = registry.getService( JtaPlatformResolver.class ).resolveJtaPlatform( configurationValues, registry );
	}

	if ( platform == null ) {
		LOG.debugf( "No JtaPlatform was specified, checking resolver" );
		platform = getFallbackProvider( configurationValues, registry );
	}

	return platform;
}
 
Example 5
Source Project: spring-analysis-note   Source File: SpringSessionContext.java    License: MIT License 5 votes vote down vote up
/**
 * Create a new SpringSessionContext for the given Hibernate SessionFactory.
 * @param sessionFactory the SessionFactory to provide current Sessions for
 */
public SpringSessionContext(SessionFactoryImplementor sessionFactory) {
	this.sessionFactory = sessionFactory;
	try {
		JtaPlatform jtaPlatform = sessionFactory.getServiceRegistry().getService(JtaPlatform.class);
		this.transactionManager = jtaPlatform.retrieveTransactionManager();
		if (this.transactionManager != null) {
			this.jtaSessionContext = new SpringJtaSessionContext(sessionFactory);
		}
	}
	catch (Exception ex) {
		LogFactory.getLog(SpringSessionContext.class).warn(
				"Could not introspect Hibernate JtaPlatform for SpringJtaSessionContext", ex);
	}
}
 
Example 6
Source Project: java-technology-stack   Source File: SpringSessionContext.java    License: MIT License 5 votes vote down vote up
/**
 * Create a new SpringSessionContext for the given Hibernate SessionFactory.
 * @param sessionFactory the SessionFactory to provide current Sessions for
 */
public SpringSessionContext(SessionFactoryImplementor sessionFactory) {
	this.sessionFactory = sessionFactory;
	try {
		JtaPlatform jtaPlatform = sessionFactory.getServiceRegistry().getService(JtaPlatform.class);
		this.transactionManager = jtaPlatform.retrieveTransactionManager();
		if (this.transactionManager != null) {
			this.jtaSessionContext = new SpringJtaSessionContext(sessionFactory);
		}
	}
	catch (Exception ex) {
		LogFactory.getLog(SpringSessionContext.class).warn(
				"Could not introspect Hibernate JtaPlatform for SpringJtaSessionContext", ex);
	}
}
 
Example 7
Source Project: lams   Source File: SpringSessionContext.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new SpringSessionContext for the given Hibernate SessionFactory.
 * @param sessionFactory the SessionFactory to provide current Sessions for
 */
public SpringSessionContext(SessionFactoryImplementor sessionFactory) {
	this.sessionFactory = sessionFactory;
	try {
		JtaPlatform jtaPlatform = sessionFactory.getServiceRegistry().getService(JtaPlatform.class);
		this.transactionManager = jtaPlatform.retrieveTransactionManager();
		if (this.transactionManager != null) {
			this.jtaSessionContext = new SpringJtaSessionContext(sessionFactory);
		}
	}
	catch (Exception ex) {
		LogFactory.getLog(SpringSessionContext.class).warn(
				"Could not introspect Hibernate JtaPlatform for SpringJtaSessionContext", ex);
	}
}
 
Example 8
Source Project: lams   Source File: SessionFactoryImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
private boolean canAccessTransactionManager() {
	try {
		return serviceRegistry.getService( JtaPlatform.class ).retrieveTransactionManager() != null;
	}
	catch (Exception e) {
		return false;
	}
}
 
Example 9
/**
    * Registers transaction synchronization with session in order to clean up and close the session when transaction
    * finishes.
    *
    * @param session
    *            Session to register into transaction synchronization. Cannot be null.
    * @return Returns <code>true</code> if the session was register into any available synchronization strategy,
    *         <code>false</code> otherwise.
    */
   private boolean registerSynchronization(final Session session) {
// Tries Spring's transaction manager synchronization.
if (TransactionSynchronizationManager.isSynchronizationActive()) {

    // If it's allowed, registers synchronization to cleanup session.
    TransactionSynchronizationManager.registerSynchronization(createTransactionSynchronization(session));
    return true;
} else {
    // Tries JTA transaction manager synchronization.
    JtaPlatform jtaPlatform = sessionFactory.getServiceRegistry().getService(JtaPlatform.class);

    // If it's allowed, registers synchronization to cleanup session.
    if (jtaPlatform.canRegisterSynchronization()) {
	List<TransactionSynchronization> synchronizations;

	synchronizations = Arrays.asList(createTransactionSynchronization(session));

	Synchronization jtaSync;
	jtaSync = new JtaAfterCompletionSynchronization(synchronizations);
	jtaPlatform.registerSynchronization(jtaSync);

	return true;
    }
}
return false;
   }
 
Example 10
/**
 * Create a new SpringSessionContext for the given Hibernate SessionFactory.
 * @param sessionFactory the SessionFactory to provide current Sessions for
 */
public SpringSessionContext(SessionFactoryImplementor sessionFactory) {
	this.sessionFactory = sessionFactory;
	try {
		JtaPlatform jtaPlatform = sessionFactory.getServiceRegistry().getService(JtaPlatform.class);
		this.transactionManager = jtaPlatform.retrieveTransactionManager();
		if (this.transactionManager != null) {
			this.jtaSessionContext = new SpringJtaSessionContext(sessionFactory);
		}
	}
	catch (Exception ex) {
		LogFactory.getLog(SpringSessionContext.class).warn(
				"Could not introspect Hibernate JtaPlatform for SpringJtaSessionContext", ex);
	}
}
 
Example 11
@Override
public JtaPlatform initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
	return NoJtaPlatform.INSTANCE;
}
 
Example 12
@Override
public Class<JtaPlatform> getServiceInitiated() {
	return JtaPlatform.class;
}
 
Example 13
Source Project: quarkus   Source File: QuarkusJtaPlatformInitiator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public JtaPlatform initiateService(Map map, ServiceRegistryImplementor serviceRegistryImplementor) {
    return buildJtaPlatformInstance();
}
 
Example 14
Source Project: quarkus   Source File: QuarkusJtaPlatformInitiator.java    License: Apache License 2.0 4 votes vote down vote up
public JtaPlatform buildJtaPlatformInstance() {
    return jtaIsPresent ? getJtaInstance() : getNoJtaInstance();
}
 
Example 15
Source Project: quarkus   Source File: QuarkusJtaPlatformInitiator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Class<JtaPlatform> getServiceInitiated() {
    return JtaPlatform.class;
}
 
Example 16
Source Project: lams   Source File: Settings.java    License: GNU General Public License v2.0 4 votes vote down vote up
public JtaPlatform getJtaPlatform() {
	return sessionFactoryOptions.getServiceRegistry().getService( JtaPlatform.class );
}
 
Example 17
Source Project: lams   Source File: JtaPlatformInitiator.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Class<JtaPlatform> getServiceInitiated() {
	return JtaPlatform.class;
}
 
Example 18
Source Project: lams   Source File: JtaPlatformInitiator.java    License: GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings({"WeakerAccess", "unused"})
protected JtaPlatform getFallbackProvider(Map configurationValues, ServiceRegistryImplementor registry) {
	return null;
}
 
Example 19
Source Project: lams   Source File: StatelessSessionImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
private JtaPlatform getJtaPlatform() {
	return getFactory().getServiceRegistry().getService( JtaPlatform.class );
}
 
Example 20
Source Project: lams   Source File: StrategySelectorBuilder.java    License: GNU General Public License v2.0 4 votes vote down vote up
private void addJtaPlatforms(StrategySelectorImpl strategySelector, Class<? extends JtaPlatform> impl, String... names) {
	for ( String name : names ) {
		strategySelector.registerStrategyImplementor( JtaPlatform.class, name, impl );
	}
}
 
Example 21
public IgniteTransactionManagerFactory(JtaPlatform platform) {
	this.platform = platform;
}
 
Example 22
@Override
public void injectServices(ServiceRegistryImplementor serviceRegistryImplementor) {
	this.classLoaderService = serviceRegistryImplementor.getService( ClassLoaderService.class );
	this.jtaPlatform = serviceRegistryImplementor.getService( JtaPlatform.class );
	this.jdbcServices = serviceRegistryImplementor.getService( JdbcServices.class );
}
 
Example 23
Source Project: gorm-hibernate5   Source File: GrailsSessionContext.java    License: Apache License 2.0 4 votes vote down vote up
public void initJta() {
    JtaPlatform jtaPlatform = sessionFactory.getServiceRegistry().getService(JtaPlatform.class);
    TransactionManager transactionManager = jtaPlatform.retrieveTransactionManager();
    jtaSessionContext = transactionManager == null ? null : new SpringJtaSessionContext(sessionFactory);
}
 
Example 24
/** {@inheritDoc} */
@Nullable @Override protected StandardServiceRegistryBuilder registryBuilder() {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();

    DatasourceConnectionProviderImpl connProvider = new DatasourceConnectionProviderImpl();

    BasicManagedDataSource dataSrc = new BasicManagedDataSource(); // JTA-aware data source.

    dataSrc.setTransactionManager(jotm.getTransactionManager());

    dataSrc.setDefaultAutoCommit(false);

    JdbcDataSource h2DataSrc = new JdbcDataSource();

    h2DataSrc.setURL(CONNECTION_URL);

    dataSrc.setXaDataSourceInstance(h2DataSrc);

    connProvider.setDataSource(dataSrc);

    connProvider.configure(Collections.emptyMap());

    builder.addService(ConnectionProvider.class, connProvider);

    builder.addService(JtaPlatform.class, new TestJtaPlatform());

    builder.applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName());

    return builder;
}
 
Example 25
/** {@inheritDoc} */
@Nullable @Override protected StandardServiceRegistryBuilder registryBuilder() {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();

    DatasourceConnectionProviderImpl connProvider = new DatasourceConnectionProviderImpl();

    BasicManagedDataSource dataSrc = new BasicManagedDataSource(); // JTA-aware data source.

    dataSrc.setTransactionManager(jotm.getTransactionManager());

    dataSrc.setDefaultAutoCommit(false);

    JdbcDataSource h2DataSrc = new JdbcDataSource();

    h2DataSrc.setURL(CONNECTION_URL);

    dataSrc.setXaDataSourceInstance(h2DataSrc);

    connProvider.setDataSource(dataSrc);

    connProvider.configure(Collections.emptyMap());

    builder.addService(ConnectionProvider.class, connProvider);

    builder.addService(JtaPlatform.class, new TestJtaPlatform());

    builder.applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName());

    return builder;
}