List of usage examples for org.hibernate.engine.config.spi StandardConverters STRING
Converter STRING
To view the source code for org.hibernate.engine.config.spi StandardConverters STRING.
Click Source Link
From source file:com.googlecode.hibernate.audit.listener.AuditListener.java
License:Open Source License
private void processAuditConfigurationObserver(SessionFactoryServiceRegistry serviceRegistry) { String observerClazzProperty = serviceRegistry.getService(ConfigurationService.class) .getSetting(HibernateAudit.AUDIT_CONFIGURATION_OBSERVER_PROPERTY, StandardConverters.STRING, null); if (observerClazzProperty != null) { ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); Class observerClazz = null; try {/* w w w. jav a2s .co m*/ observerClazz = contextClassLoader.loadClass(observerClazzProperty); } catch (ClassNotFoundException ignored) { } try { if (observerClazz == null) { observerClazz = AuditListener.class.forName(observerClazzProperty); } } catch (ClassNotFoundException e) { throw new HibernateException( "Unable to find audit configuration observer class:" + observerClazzProperty, e); } try { AuditConfigurationObserver observer = (AuditConfigurationObserver) observerClazz.newInstance(); observer.auditConfigurationCreated(auditConfiguration); } catch (InstantiationException e) { throw new HibernateException( "Unable to instantiate audit configuration observer from class:" + observerClazzProperty, e); } catch (IllegalAccessException e) { throw new HibernateException( "Unable to instantiate audit configuration observer from class:" + observerClazzProperty, e); } catch (ClassCastException e) { throw new HibernateException("Audit configuration observer class:" + observerClazzProperty + " should implement " + AuditConfigurationObserver.class.getName(), e); } } }
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);/*from www .j av a 2s . co m*/ 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.test.hibernate.cache.util.CacheTestUtil.java
License:LGPL
public static InfinispanRegionFactory startRegionFactory(ServiceRegistry serviceRegistry) { try {//from w w w . jav a2s .c o m final ConfigurationService cfgService = serviceRegistry.getService(ConfigurationService.class); final Properties properties = toProperties(cfgService.getSettings()); String factoryType = cfgService.getSetting(AvailableSettings.CACHE_REGION_FACTORY, StandardConverters.STRING); Class clazz = Thread.currentThread().getContextClassLoader().loadClass(factoryType); InfinispanRegionFactory regionFactory; if (clazz == InfinispanRegionFactory.class) { regionFactory = new TestInfinispanRegionFactory(properties); } else { if (InfinispanRegionFactory.class.isAssignableFrom(clazz)) { regionFactory = createRegionFactory(clazz, properties); } else { throw new IllegalArgumentException(clazz + " is not InfinispanRegionFactory"); } } final SessionFactoryOptionsImpl sessionFactoryOptions = new SessionFactoryOptionsImpl( new SessionFactoryBuilderImpl.SessionFactoryOptionsStateStandardImpl( (StandardServiceRegistry) serviceRegistry)); regionFactory.start(sessionFactoryOptions, properties); return regionFactory; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }