Example usage for org.hibernate.boot.spi SessionFactoryOptions getServiceRegistry

List of usage examples for org.hibernate.boot.spi SessionFactoryOptions getServiceRegistry

Introduction

In this page you can find the example usage for org.hibernate.boot.spi SessionFactoryOptions getServiceRegistry.

Prototype

StandardServiceRegistry getServiceRegistry();

Source Link

Document

The service registry to use in building the factory.

Usage

From source file:edu.jhuapl.dorset.components.HibernateServiceTest.java

License:Open Source License

@Test
public void testCreationOfSessionFactory() {
    Properties props = getProperties();
    Config conf = ConfigFactory.parseProperties(props);

    hs = new HibernateService(conf);
    SessionFactory sf = hs.getSessionFactory();
    assertNotNull(sf);//w  w  w.ja  va 2  s  .  c om
    assertFalse(sf.isClosed());

    // traverse through the session factory to get at configuration values
    SessionFactoryOptions sfo = sf.getSessionFactoryOptions();
    StandardServiceRegistry ssr = sfo.getServiceRegistry();
    ConfigurationService cs = ssr.getService(ConfigurationService.class);
    assertEquals(props.getProperty("hibernate.connection.driver_class"),
            cs.getSetting("hibernate.connection.driver_class", StandardConverters.STRING));
    assertEquals(props.getProperty("hibernate.connection.url"),
            cs.getSetting("hibernate.connection.url", StandardConverters.STRING));
    assertEquals(props.getProperty("hibernate.dialect"),
            cs.getSetting("hibernate.dialect", StandardConverters.STRING));
    assertEquals(props.getProperty("hibernate.hbm2ddl.auto"),
            cs.getSetting("hibernate.hbm2ddl.auto", StandardConverters.STRING));

    // check mapping
    ClassMetadata cm = sf.getClassMetadata(TestObject.class);
    String[] names = cm.getPropertyNames();
    assertEquals(1, names.length);
    assertEquals("name", names[0]);
    assertEquals("string", cm.getPropertyType("name").getName());
}

From source file:org.infinispan.hibernate.cache.commons.InfinispanRegionFactory.java

License:LGPL

@Override
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
    log.debug("Starting Infinispan region factory");

    // determine the CacheKeysFactory to use...
    this.cacheKeysFactory = determineCacheKeysFactory(settings, properties);

    try {/*from   ww  w  .j av  a 2 s  . co  m*/
        this.settings = settings;
        transactionManagerlookup = createTransactionManagerLookup(settings, properties);
        transactionManager = transactionManagerlookup.getTransactionManager();

        final Enumeration keys = properties.propertyNames();
        while (keys.hasMoreElements()) {
            final String key = (String) keys.nextElement();
            int prefixLoc;
            if ((prefixLoc = key.indexOf(PREFIX)) != -1) {
                parseProperty(prefixLoc, key, extractProperty(key, properties));
            }
        }

        defaultConfiguration = loadConfiguration(settings.getServiceRegistry(), DEF_INFINISPAN_CONFIG_RESOURCE);
        manager = createCacheManager(properties, settings.getServiceRegistry());
        if (!manager.getCacheManagerConfiguration().isClustered()) {
            // If we got non-clustered cache manager, use non-clustered (local) configuration as defaults
            // for the data types
            defaultConfiguration = loadConfiguration(settings.getServiceRegistry(),
                    INFINISPAN_CONFIG_LOCAL_RESOURCE);
        }
        defineDataTypeCacheConfigurations();
    } catch (CacheException ce) {
        throw ce;
    } catch (Throwable t) {
        throw log.unableToStart(t);
    }
}

From source file:org.infinispan.hibernate.cache.commons.InfinispanRegionFactory.java

License:LGPL

private CacheKeysFactory determineCacheKeysFactory(SessionFactoryOptions settings, Properties properties) {
    return settings.getServiceRegistry().getService(StrategySelector.class).resolveDefaultableStrategy(
            CacheKeysFactory.class, properties.get(AvailableSettings.CACHE_KEYS_FACTORY),
            DefaultCacheKeysFactory.INSTANCE);
}

From source file:org.infinispan.hibernate.cache.commons.tm.HibernateTransactionManagerLookup.java

License:LGPL

/**
 * Transaction manager lookup constructor.
 *
 * @param settings for the Hibernate application
 * @param properties for the Hibernate application
 *//*from   w  ww  . ja  v a 2 s.  com*/
public HibernateTransactionManagerLookup(SessionFactoryOptions settings, Properties properties) {
    this.jtaPlatform = settings != null ? settings.getServiceRegistry().getService(JtaPlatform.class) : null;
}

From source file:org.infinispan.hibernate.cache.v51.InfinispanRegionFactory.java

License:LGPL

@Override
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
    log.debug("Starting Infinispan region factory");

    // determine the CacheKeysFactory to use...
    this.cacheKeysFactory = determineCacheKeysFactory(settings, properties);

    try {//from   www .j a  va  2s  .  com
        this.settings = settings;
        transactionManagerlookup = createTransactionManagerLookup(settings, properties);
        transactionManager = transactionManagerlookup.getTransactionManager();

        final Enumeration keys = properties.propertyNames();
        while (keys.hasMoreElements()) {
            final String key = (String) keys.nextElement();
            int prefixLoc;
            if ((prefixLoc = key.indexOf(PREFIX)) != -1) {
                parseProperty(prefixLoc, key, extractProperty(key, properties));
            }
        }

        String globalStatsProperty = ConfigurationHelper.extractPropertyValue(INFINISPAN_GLOBAL_STATISTICS_PROP,
                properties);
        globalStats = (globalStatsProperty != null) ? Boolean.valueOf(globalStatsProperty) : null;
        if (properties.containsKey(INFINISPAN_USE_SYNCHRONIZATION_PROP)) {
            log.propertyUseSynchronizationDeprecated();
        }

        ServiceRegistry serviceRegistry = settings.getServiceRegistry();
        manager = createCacheManager(properties, serviceRegistry);
        defineDataTypeCacheConfigurations(serviceRegistry);
    } catch (CacheException ce) {
        throw ce;
    } catch (Throwable t) {
        throw log.unableToStart(t);
    }
}

From source file:org.infinispan.hibernate.cache.v53.InfinispanRegionFactory.java

License:LGPL

@Override
public void start(SessionFactoryOptions settings, Map configValues) throws CacheException {
    log.debug("Starting Infinispan region factory");

    // determine the CacheKeysFactory to use...
    this.cacheKeysFactory = determineCacheKeysFactory(settings, configValues);

    try {//from  ww  w.  ja v a 2  s.  c o  m
        this.settings = settings;

        for (Object k : configValues.keySet()) {
            final String key = (String) k;
            int prefixLoc;
            if ((prefixLoc = key.indexOf(PREFIX)) != -1) {
                parseProperty(prefixLoc, key, extractProperty(key, configValues));
            }
        }

        String globalStatsStr = extractProperty(INFINISPAN_GLOBAL_STATISTICS_PROP, configValues);
        if (globalStatsStr != null) {
            globalStats = Boolean.parseBoolean(globalStatsStr);
        }
        if (configValues.containsKey(INFINISPAN_USE_SYNCHRONIZATION_PROP)) {
            log.propertyUseSynchronizationDeprecated();
        }

        StandardServiceRegistry serviceRegistry = settings.getServiceRegistry();
        manager = createCacheManager(toProperties(configValues), serviceRegistry);
        defineDataTypeCacheConfigurations(serviceRegistry);
    } catch (CacheException ce) {
        throw ce;
    } catch (Throwable t) {
        throw log.unableToStart(t);
    }
}

From source file:org.infinispan.hibernate.cache.v53.InfinispanRegionFactory.java

License:LGPL

private CacheKeysFactory determineCacheKeysFactory(SessionFactoryOptions settings, Map properties) {
    return settings.getServiceRegistry().getService(StrategySelector.class).resolveDefaultableStrategy(
            CacheKeysFactory.class, properties.get(AvailableSettings.CACHE_KEYS_FACTORY),
            DefaultCacheKeysFactory.INSTANCE);
}

From source file:org.redisson.hibernate.RedissonRegionFactory.java

License:Apache License

@Override
protected void prepareForUse(SessionFactoryOptions settings, @SuppressWarnings("rawtypes") Map properties)
        throws CacheException {
    this.redisson = createRedissonClient(properties);

    StrategySelector selector = settings.getServiceRegistry().getService(StrategySelector.class);
    cacheKeysFactory = selector.resolveDefaultableStrategy(CacheKeysFactory.class,
            properties.get(Environment.CACHE_KEYS_FACTORY), DefaultCacheKeysFactory.INSTANCE);

}