예제 #1
0
 /**
  * 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;
   JtaPlatform jtaPlatform = sessionFactory.getServiceRegistry().getService(JtaPlatform.class);
   TransactionManager transactionManager = jtaPlatform.retrieveTransactionManager();
   this.jtaSessionContext =
       (transactionManager != null ? new SpringJtaSessionContext(sessionFactory) : null);
 }
  @Override
  public void start() {
    final Configuration configuration = ConfigurationFactory.parseConfiguration(config.getUrl());
    if (jtaPlatform != null) {
      OgmTransactionManagerLookupDelegate.transactionManager =
          jtaPlatform.retrieveTransactionManager();
      final FactoryConfiguration transactionManagerLookupParameter = new FactoryConfiguration();
      transactionManagerLookupParameter.setClass(
          OgmTransactionManagerLookupDelegate.class.getName());
      configuration.addTransactionManagerLookup(transactionManagerLookupParameter);
    }
    cacheManager = CacheManager.create(config.getUrl());

    entityCache =
        new Cache<SerializableKey>(cacheManager.getCache(DefaultDatastoreNames.ENTITY_STORE));
    associationCache =
        new Cache<SerializableKey>(cacheManager.getCache(DefaultDatastoreNames.ASSOCIATION_STORE));
    identifierCache =
        new Cache<SerializableKey>(cacheManager.getCache(DefaultDatastoreNames.IDENTIFIER_STORE));
  }
 @Override
 public TransactionManager getTransactionManager() throws Exception {
   return jtaPlatform == null ? null : jtaPlatform.retrieveTransactionManager();
 }