类org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform源码实例Demo

下面列出了怎么用org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: quarkus   文件: QuarkusStrategySelectorBuilder.java
/**
 * 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;
}
 
源代码2 项目: lams   文件: JtaTransactionCoordinatorImpl.java
/**
 * 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();
}
 
源代码3 项目: lams   文件: JtaTransactionCoordinatorImpl.java
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();
}
 
源代码4 项目: lams   文件: JtaPlatformInitiator.java
@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;
}
 
/**
 * 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);
	}
}
 
/**
 * 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);
	}
}
 
源代码7 项目: lams   文件: SpringSessionContext.java
/**
 * 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);
	}
}
 
源代码8 项目: lams   文件: SessionFactoryImpl.java
private boolean canAccessTransactionManager() {
	try {
		return serviceRegistry.getService( JtaPlatform.class ).retrieveTransactionManager() != null;
	}
	catch (Exception e) {
		return false;
	}
}
 
源代码9 项目: lams   文件: TransactionAwareSessionContext.java
/**
    * 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;
   }
 
/**
 * 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);
	}
}
 
@Override
public JtaPlatform initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
	return NoJtaPlatform.INSTANCE;
}
 
@Override
public Class<JtaPlatform> getServiceInitiated() {
	return JtaPlatform.class;
}
 
源代码13 项目: quarkus   文件: QuarkusJtaPlatformInitiator.java
@Override
public JtaPlatform initiateService(Map map, ServiceRegistryImplementor serviceRegistryImplementor) {
    return buildJtaPlatformInstance();
}
 
源代码14 项目: quarkus   文件: QuarkusJtaPlatformInitiator.java
public JtaPlatform buildJtaPlatformInstance() {
    return jtaIsPresent ? getJtaInstance() : getNoJtaInstance();
}
 
源代码15 项目: quarkus   文件: QuarkusJtaPlatformInitiator.java
@Override
public Class<JtaPlatform> getServiceInitiated() {
    return JtaPlatform.class;
}
 
源代码16 项目: lams   文件: Settings.java
public JtaPlatform getJtaPlatform() {
	return sessionFactoryOptions.getServiceRegistry().getService( JtaPlatform.class );
}
 
源代码17 项目: lams   文件: JtaPlatformInitiator.java
@Override
public Class<JtaPlatform> getServiceInitiated() {
	return JtaPlatform.class;
}
 
源代码18 项目: lams   文件: JtaPlatformInitiator.java
@SuppressWarnings({"WeakerAccess", "unused"})
protected JtaPlatform getFallbackProvider(Map configurationValues, ServiceRegistryImplementor registry) {
	return null;
}
 
源代码19 项目: lams   文件: StatelessSessionImpl.java
private JtaPlatform getJtaPlatform() {
	return getFactory().getServiceRegistry().getService( JtaPlatform.class );
}
 
源代码20 项目: lams   文件: StrategySelectorBuilder.java
private void addJtaPlatforms(StrategySelectorImpl strategySelector, Class<? extends JtaPlatform> impl, String... names) {
	for ( String name : names ) {
		strategySelector.registerStrategyImplementor( JtaPlatform.class, name, impl );
	}
}
 
public IgniteTransactionManagerFactory(JtaPlatform platform) {
	this.platform = platform;
}
 
@Override
public void injectServices(ServiceRegistryImplementor serviceRegistryImplementor) {
	this.classLoaderService = serviceRegistryImplementor.getService( ClassLoaderService.class );
	this.jtaPlatform = serviceRegistryImplementor.getService( JtaPlatform.class );
	this.jdbcServices = serviceRegistryImplementor.getService( JdbcServices.class );
}
 
源代码23 项目: gorm-hibernate5   文件: GrailsSessionContext.java
public void initJta() {
    JtaPlatform jtaPlatform = sessionFactory.getServiceRegistry().getService(JtaPlatform.class);
    TransactionManager transactionManager = jtaPlatform.retrieveTransactionManager();
    jtaSessionContext = transactionManager == null ? null : new SpringJtaSessionContext(sessionFactory);
}
 
/** {@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;
}
 
/** {@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;
}
 
 类所在包
 类方法
 同包方法