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

项目:gorm-hibernate5    文件:GrailsSessionContext.java   
protected TransactionManager getJtaTransactionManager(Session session) {
    SessionFactoryImplementor sessionFactoryImpl = null;
    if (sessionFactory instanceof SessionFactoryImplementor) {
        sessionFactoryImpl = ((SessionFactoryImplementor) sessionFactory);
    }
    else if (session != null) {
        SessionFactory internalFactory = session.getSessionFactory();
        if (internalFactory instanceof SessionFactoryImplementor) {
            sessionFactoryImpl = (SessionFactoryImplementor) internalFactory;
        }
    }

    if (sessionFactoryImpl == null) {
        return null;
    }

    ServiceBinding<JtaPlatform> sb = sessionFactory.getServiceRegistry().locateServiceBinding(JtaPlatform.class);
    if (sb == null) {
        return null;
    }

    return sb.getService().retrieveTransactionManager();
}
项目:lams    文件:JtaPlatformInitiator.java   
@Override
@SuppressWarnings( {"unchecked"})
public JtaPlatform initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
    final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM );
    final JtaPlatform platform = registry.getService( StrategySelector.class ).resolveStrategy( JtaPlatform.class, setting );
    if ( platform == null ) {
        LOG.debugf( "No JtaPlatform was specified, checking resolver" );
        return registry.getService( JtaPlatformResolver.class ).resolveJtaPlatform( configurationValues, registry );
    }
    return platform;
}
项目:lams    文件:TransactionEnvironmentImpl.java   
public TransactionEnvironmentImpl(SessionFactoryImpl sessionFactory) {
    this.sessionFactory = sessionFactory;
    this.statisticsImplementor = sessionFactory.getStatisticsImplementor();
    this.serviceRegistry = sessionFactory.getServiceRegistry();
    this.jdbcServices = serviceRegistry.getService( JdbcServices.class );
    this.jtaPlatform = serviceRegistry.getService( JtaPlatform.class );
    this.transactionFactory = serviceRegistry.getService( TransactionFactory.class );
}
项目:lams    文件:SessionFactoryImpl.java   
private boolean canAccessTransactionManager() {
    try {
        return serviceRegistry.getService( JtaPlatform.class ).retrieveTransactionManager() != null;
    }
    catch (Exception e) {
        return false;
    }
}
项目: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;
   }
项目:spring4-understanding    文件: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);
    }
}
项目:lams    文件:Settings.java   
public JtaPlatform getJtaPlatform() {
    return jtaPlatform;
}
项目:lams    文件:Settings.java   
void setJtaPlatform(JtaPlatform jtaPlatform) {
    this.jtaPlatform = jtaPlatform;
}
项目:lams    文件:JtaPlatformInitiator.java   
@Override
public Class<JtaPlatform> getServiceInitiated() {
    return JtaPlatform.class;
}
项目:lams    文件:TransactionCoordinatorImpl.java   
@SuppressWarnings({"unchecked"})
private void attemptToRegisterJtaSync() {
    if ( synchronizationRegistered ) {
        return;
    }

    final JtaPlatform jtaPlatform = getTransactionEnvironment().getJtaPlatform();
    if ( jtaPlatform == null ) {
        // if no jta platform was registered we wont be able to register a jta synchronization
        return;
    }

    // Has the local transaction (Hibernate facade) taken on the responsibility of driving the transaction inflow?
    if ( currentHibernateTransaction.isInitiator() ) {
        return;
    }

    final JoinStatus joinStatus = currentHibernateTransaction.getJoinStatus();
    if ( joinStatus != JoinStatus.JOINED ) {
        // the transaction is not (yet) joined, see if we should join...
        if ( !transactionContext.shouldAutoJoinTransaction() ) {
            // we are supposed to not auto join transactions; if the transaction is not marked for join
            // we cannot go any further in attempting to join (register sync).
            if ( joinStatus != JoinStatus.MARKED_FOR_JOINED ) {
                if (isDebugging) {
                    LOG.debug( "Skipping JTA sync registration due to auto join checking" );
                }
                return;
            }
        }
    }

    // IMPL NOTE : At this point the local callback is the "maybe" one.  The only time that needs to change is if
    // we are able to successfully register the transaction synchronization in which case the local callback would become
    // non driving.  To that end, the following checks are simply opt outs where we are unable to register the
    // synchronization

    // Can we resister a synchronization
    if ( !jtaPlatform.canRegisterSynchronization() ) {
        if (isTracing) {
            LOG.trace( "registered JTA platform says we cannot currently register synchronization; skipping" );
        }
        return;
    }

    // Should we resister a synchronization
    if ( !transactionFactory().isJoinableJtaTransaction( this, currentHibernateTransaction ) ) {
        if (isTracing) {
            LOG.trace( "TransactionFactory reported no JTA transaction to join; skipping Synchronization registration" );
        }
        return;
    }

    jtaPlatform.registerSynchronization( new RegisteredSynchronization( getSynchronizationCallbackCoordinator() ) );
    getSynchronizationCallbackCoordinator().synchronizationRegistered();
    synchronizationRegistered = true;
    if (isDebugging) {
        LOG.debug( "successfully registered Synchronization" );
    }
}
项目:lams    文件:TransactionEnvironmentImpl.java   
@Override
public JtaPlatform getJtaPlatform() {
    return jtaPlatform;
}
项目:lams    文件:StrategySelectorBuilder.java   
private void addJtaPlatforms(StrategySelectorImpl strategySelector, Class<? extends JtaPlatform> impl, String... names) {
    for ( String name : names ) {
        strategySelector.registerStrategyImplementor( JtaPlatform.class, name, impl );
    }
}
项目:hibernate-ogm-ignite    文件:IgniteTransactionManagerFactory.java   
public IgniteTransactionManagerFactory(JtaPlatform platform) {
    this.platform = platform;
}
项目:hibernate-ogm-ignite    文件:IgniteDatastoreProvider.java   
@Override
public void injectServices(ServiceRegistryImplementor serviceRegistryImplementor) {
    this.jtaPlatform = serviceRegistryImplementor.getService( JtaPlatform.class );
    this.jdbcServices = serviceRegistryImplementor.getService( JdbcServices.class );
}
项目:ignite-jpa    文件:TestOgm.java   
private static TransactionManager extractJBossTransactionManager(EntityManagerFactory factory) {
    SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) ( (HibernateEntityManagerFactory) factory ).getSessionFactory();
    return sessionFactory.getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager();
}
项目: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);
}
项目:bundles    文件:JtaPlatformProviderImpl.java   
@Override
public JtaPlatform getProvidedJtaPlatform() {
    return new AbstractJtaPlatform() {
        private static final long   serialVersionUID    = 1L;

        @Override
        protected TransactionManager locateTransactionManager() {
            return transactionManager;
        }

        @Override
        protected UserTransaction locateUserTransaction() {
            return new UserTransaction() {

                @Override
                public void begin() throws NotSupportedException, SystemException {
                    transactionManager.begin();
                }

                @Override
                public void commit() throws HeuristicMixedException, HeuristicRollbackException,
                        IllegalStateException, RollbackException, SecurityException, SystemException {
                    transactionManager.commit();
                }

                @Override
                public int getStatus() throws SystemException {
                    return transactionManager.getStatus();
                }

                @Override
                public void rollback() throws IllegalStateException, SecurityException, SystemException {
                    transactionManager.rollback();
                }

                @Override
                public void setRollbackOnly() throws IllegalStateException, SystemException {
                    transactionManager.setRollbackOnly();
                }

                @Override
                public void setTransactionTimeout(int seconds) throws SystemException {
                    transactionManager.setTransactionTimeout(seconds);
                }

            };
        }

    };
}
项目:jipijapa    文件:DefaultJtaPlatform.java   
@Override
public JtaPlatform getProvidedJtaPlatform() {
    return delegate;
}
项目:ignite    文件:HibernateL2CacheTransactionalSelfTest.java   
/** {@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;
}
项目:lams    文件:AbstractTransactionImpl.java   
/**
 * Provide subclasses with convenient access to the configured {@link JtaPlatform}
 *
 * @return The {@link org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform}
 */
protected JtaPlatform jtaPlatform() {
    return transactionCoordinator().getTransactionContext().getTransactionEnvironment().getJtaPlatform();
}
项目:lams    文件:TransactionEnvironment.java   
/**
 * Retrieve the JTA platform for this environment.
 *
 * @return The JTA platform
 */
public JtaPlatform getJtaPlatform();